{"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 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.vb.v\"();\n\tb0s.sort!\"a.vb.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.vb.v\"();\n\tb0s.sort!\"a.vb.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.vb.v\"();\n\tb0s.sort!\"a.vb.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 ※多分使いやすいやつ\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] 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] 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); // ちょっとサボる \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列目までジグザグ (1-indexed)\n j=0, 1, ..., w\n s[0]=0\n sr[i][j]:=i行をj列から右端まで (0-indexed)\n sl[i][j]:=i行を右端からj列まで (0-indexed)\n\n sl[*][w]=sr[*][w]=0\n\n j列までジグザグ j=0, 1, ..., w\n jが偶数\n 0行目をj+1列目から右端まで、1行目を右端からj+1列目まで\n s[j]+sr[0][j]+sl[1][j]\n jが奇数\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); // ちょっとサボる \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//辞書順順列はiota(1,N),nextPermituionを使う\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//最小を返す\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)11)debugPrint!(l,r,nl,nr,()=>FF(nl),()=>FF(nr));\n if(FF(nl)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文字のみ\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<mod(a-(1L< 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分解\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のn個上の親を返す\n //バグあるかも\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=0&&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=1&&b<=size);\n\n T vl=UNIT,vr=UNIT;\n for(long l=a+n,r=b+n;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=0 &&\n y= 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//素因数分解\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//約数をすべて列挙\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までの素数のリスト\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 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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m] 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": "version (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 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 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>>\".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>= 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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> 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 && r0)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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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> 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 && r0)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\"\",\n\t\t\t\"<>\",\n\t\t\t\"< 2ne, >\",\n\t\t\t\"\",\n\t\t\t\"<.>\",\n\t\t\t\"< >\"\n\t\t]));\n\tassert(std.algorithm.equal(solve(` firstarg second \"\" `), [\n\t\t\t\"\",\n\t\t\t\"\",\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; ie)\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 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 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 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>>\".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>>\".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(;i1){\n\t\tfor(;i 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<>= 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=k) cur-=a[i-k];\n if(cur 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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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": "import 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": "import 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]> 1;\n\t\tif(i> 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]= 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= 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": "// 提出解\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// 愚直解\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テストケース\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テンプレ\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// ライブラリ(基本)\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// ライブラリ(追加)\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>>\".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": "void 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(keyt.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.keyr.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(key1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(vx[maxi]) swap(mini,maxi);\n\t\t\tfor(int i=2;ix[maxi]){\n\t\t\t\t\tr+=maxia[i]);\n\t\tint v=iota(n).minElement!(i=>a[i]);\n\t\tif(vx[maxi]) swap(mini,maxi);\n\t\t\tfor(int i=2;ix[maxi]){\n\t\t\t\t\tif(minix-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;ia[maxi]&&maxi<=mini;\n\t\t\tif(a[i]a[maxi]){\n\t\t\t\tif(maxia[maxi]&&maxi<=mini;\n\t\t\tif(a[i]a[maxi]){\n\t\t\t\tif(maxia[maxi]&&maxi<=mini;\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; ic)\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 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ılar = stdin.readln.strip.split.map!(a=> a.to!int()).array;\n\tint toplam = sayılar.maxElement();\n\tsayılar = sayılar.remove( sayılar.countUntil(toplam) ).array;\n\tint bArtıC = sayılar.maxElement();\n\tint a = toplam - bArtıC;\n\tsayılar = sayılar.remove( sayılar.countUntil(bArtıC) ).array;\n\n\tint aArtıC = sayılar.maxElement();\n\tint c = aArtıC - a;\n\tint b = toplam - aArtıC;\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 の中でfをみたす最大(二分探索; binary search) ※テンプレート版\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 の中でfをみたす最大(二分探索; binary search) ※テンプレート版\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 の中でfをみたす最大(二分探索; binary search) ※テンプレート版\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 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// 双方向木DP\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.val0 && 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)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; ib)\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; ia.price < b.price);\n for(int i=0; i 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 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 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 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 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(a.l==b.l ? a.r>b.r : a.l(a.l==b.l ? a.r>b.r : a.l 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(a.l==b.l ? a.r>b.r : a.l(a.l==b.l ? a.r>b.r : a.l 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": "import 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": "import 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<> 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< a & b);\n\tauto oredAns = nd.fold!((a, b) => a | b);\n\tvoid solveBit(int q)\n\t{\n\t\tif (andedOrs&(1<> 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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.fir)continue;\n\t\t\t\tif(x.fi=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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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.fir)continue;\n\t\t\t\tif(x.fi=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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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.fir)continue;\n\t\t\t\tif(x.fi=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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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.fir)continue;\n\t\t\t\tif(x.fi=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 \", [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= 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(jx?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(jb\"(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 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 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]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< f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] 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< 0) {\n auto i = (x+1).bsr;\n foreach (j; 0..i) a ~= e;\n e += d;\n x -= (1< f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] 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(ji){\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(ji){\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(ji){\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(ji){\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(ji){\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>>\".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 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>>\".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< (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< (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 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のindexは1\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)をxに更新 */\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の値 */\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]をvに更新\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のindexは1\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)をxに更新 */\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の値 */\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]をvに更新\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のindexは1\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)をxに更新 */\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の値 */\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]をvに更新\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のindexは1\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)をxに更新 */\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の値 */\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]をvに更新\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のindexは1\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)をxに更新 */\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の値 */\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]をvに更新\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のindexは1\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)をxに更新 */\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の値 */\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]をvに更新\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のindexは1\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)をxに更新 */\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の値 */\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]をvに更新\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=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]= 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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>>\".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>>\".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ısı = stdin.readln.strip.to!int;\n\tstring harfler = stdin.readln.strip.to!string;\n\t\n\t\n\tint enBüyükIndeksi = 0;\n\tchar enBüyükHarf = 'a';\n\tfor ( int i = 0; i < harfler.length; i++ )\n\t{\n\t\tif ( harfler[i] >= enBüyükHarf )\n\t\t{\n\t\t\tenBüyükIndeksi = i;\n\t\t\tenBüyükHarf = harfler[i]; \n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\treturn writeln( enBüyükIndeksi+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": "//Да, я упоролся решать эту задачу Splay-деревом)\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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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] = \"^\"[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ás rápido"}, {"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= 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= 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= 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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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": "import 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": "import 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": "import 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 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 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 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<= 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= 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=2){\n int last=-1;\n foreach(int i, e; a){ // 最右の0に寄せる\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]=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(rb\"(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(rb\"(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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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] 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<= 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<= 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< 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>>\".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>>\".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>>\".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 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>>\".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< 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<1) goto hell;\n }\n if(ret.length= 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 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= 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 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= 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 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<= 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= 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]b\"){\n if((l==0 || a[l-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]b\"){\n if((l==0 || a[l-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": "import 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": "import 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": "import 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": "import 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": "import 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": "import 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": "import 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/// заплатить gap + cur\n\t\t\t/// получить + cur к ответу\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": "import 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[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[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 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 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>>\".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": "// 提出解\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// 愚直解\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テストケース\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テンプレ\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// ライブラリ(基本)\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// ライブラリ(追加)\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 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>>\".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) // 省略可能な場合\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< 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 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; i0)\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>=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= 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 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; i0)\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; i0)\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= 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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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-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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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-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=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=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(){ // テストケース\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(){ // 愚直解\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(){ // 提出解\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一人での出現回数がceil(m/2)を超えている人がいる場合\r\n\t→NO\r\n複数名での出現を含めてならceil(m/2)を超えている人がいる場合\r\n\t→その人にぴったりceil(m/2)回を取らせればあとはてきとうでよい\r\n\t そのために、一人での出現回はその人にとらせ、\r\n\t あとはceil(m/2)になるまでとらせる。その人はもう終わり。\r\n出現回数ceil(m/2)を超えている人がいない場合\r\n\t→絶対安全なのでてきとうに取ればよい\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] 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(){ // テストケース\r\n}\r\nvoid jury(){ // 愚直解\r\n}\r\nvoid solve(){ // 提出解\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一人での出現回数がceil(m/2)を超えている人がいる場合\r\n\t→NO\r\n複数名での出現を含めてならceil(m/2)を超えている人がいる場合\r\n\t→その人にぴったりceil(m/2)回を取らせればあとはてきとうでよい\r\n\t そのために、一人での出現回はその人にとらせ、\r\n\t あとはceil(m/2)になるまでとらせる。その人はもう終わり。\r\n出現回数ceil(m/2)を超えている人がいない場合\r\n\t→絶対安全なのでてきとうに取ればよい\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>>\".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>>\".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 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= 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=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>>\".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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]= 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<= 0; k--) {\r\n auto sG = new Edge[][N];\r\n long mask = ans | ((1L<= 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< 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>>\".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>>\".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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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 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 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 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(ansr[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= 0 ){\n\t\t\ta.sort;\n\t\t\tfor(int j=0; j 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= 0){\n\t\t\tflag = false;\n\t\t}\n\t\t\n\t\ta[i] *= -1;\n\n\t\tif( flag && i+1 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<b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1< 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<b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1<b\"(s);scanf(\"%d \",&m);int[]t;foreach(i;0..m){auto r=readln;t~=(r[0]=='p')*2+(r[2]=='2');}w=1< 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; i0){\n mx=max(mx, len+(r[j]-l[j])+height);\n if((++j) 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=まだない 1=今その途中 2=終わった -1=だめ\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;i0)\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 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; i1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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; i0)\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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; iot) 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; imx)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;ib) 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;ib) 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;ians) 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;ia[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+1mx)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; imx)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; imx)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; imx)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;ib) 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= 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": "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[] arr3 = new int[n];\n\tfor(int i = 0; i r) && arr[i] != arr2[i]) y = 1;\n\tfor(int i = 0; i= l && i <= r) arr3[arr[i]]++, arr4[arr2[i]]++;\n\tfor(int i = 0; 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": "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 [] current = new int[n];\n\tint [] was = new int[n];\n\tfor(int i = 0; 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; ic){\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; ir){\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 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>>\".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>>\".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(b0){\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 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>>\".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>>\".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>>\".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>>\".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>>\".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>>\".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; ia) || ((b-a)%2==0 && b 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 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 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// ----- スタック -----\nclass Stack(T){\n\tprivate T[] xs;\n\tprivate uint j; // j : 次に書き込む位置\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= 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 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 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==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": "// 提出解\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][]: 左端がaである右端、vs[b][]:右端がbである左端\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 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// ライブラリ(基本)\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// ライブラリ(追加)\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>>\".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>>\".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= 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>>\".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 // 連結グラフの個数\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 // 連結グラフの個数\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>>\".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// ※素数に絞っても良いはず\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 整理されているもの ※Edgeは使わなくてもよい\n// 使い方は 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 整理されているもの ※Edgeは使わなくてもよい\n// 使い方は 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 整理されているもの ※Edgeは使わなくてもよい\n// 使い方は 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 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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 a.s!=b.s ? a.s a.s!=b.s ? a.s 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 && 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 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>>\".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= 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>>\".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>>\".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": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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": "import 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": "import 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>>\".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<= 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// 二分探索テンプレート\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// ----- キュー -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : 次に読み出す位置 j: 次に書き込む位置\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// 二分探索テンプレート\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// 二分探索テンプレート\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// 二分探索テンプレート\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// ----- キュー -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : 次に読み出す位置 j: 次に書き込む位置\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 (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=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": "import 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": "import 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": "import 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 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": "import 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< 0) {\r\n int k = C.bsr;\r\n ans = min(ans, (B & ~(1< 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抜けるまでは分からないので\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>>\".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": "// 提出解\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// 愚直解\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テストケース\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テンプレ\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// ライブラリ(基本)\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// ライブラリ(追加)\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>>\".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= 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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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 f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] 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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m] 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 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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]=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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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]=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>>\".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>>\".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// ----- キュー -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : 次に読み出す位置 j: 次に書き込む位置\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// ----- スタック -----\nclass Stack(T){\n\tprivate T[] xs;\n\tprivate uint j; // j : 次に書き込む位置\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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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;i0)ans++;\n\t\t\tif(b[i][j]>0)ans++;\n\t\t\tif(a[i][j] 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>>\".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 (ans1y1){\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 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>>\".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>>\".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>>\".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>>\".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>>\".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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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*vxr2*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*vyr2*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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(rxx2)\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*vxr2*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(ryy2)\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*vyr2*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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(rxx2)\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*vxy2)\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*vyr0*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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(rxx2)\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*vxy2)\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*vyr0*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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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*vxr2*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*vyr2*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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(rxx2)\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)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*vr0y2)\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)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*vr0r0*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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(rxx2)\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*vxr2*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(ryy2)\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*vyr2*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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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(rxx2)\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)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*vry2)\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)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*vrr*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>>\".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>>\".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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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": "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// (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; im[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 f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] 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>>\".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 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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>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>>\".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": "import 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": "import 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": "import 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": "// 提出解\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]; // 自分より貧乏な人数の下限\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// 愚直解\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テストケース\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テンプレ\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// ライブラリ(基本)\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// ライブラリ(追加)\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>>\".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.idb.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; im[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=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>>\".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// ----- キュー -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : 次に読み出す位置 j: 次に書き込む位置\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// ----- キュー -----\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : 次に読み出す位置 j: 次に書き込む位置\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 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.rb.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= 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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]を消す\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"}, {"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/// 遅延伝搬Segment 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/// 遅延伝搬Segment 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< 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=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= 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 < need)\r\n ok = false;\r\n }\r\n writeln(ok ? \"YES\" : \"NO\");\r\n }\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 int need = 0, cur = 0;\r\n bool ok = false;\r\n foreach (i; 0 .. n)\r\n {\r\n need += i;\r\n cur += a[i];\r\n if (cur < need)\r\n ok = false;\r\n }\r\n writeln(ok ? \"YES\" : \"NO\");\r\n }\r\n}"}], "src_uid": "7a8c4ba98a77097faff625b94889b365"} {"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 A = scan!int(N);\r\n\r\n return max(0, A.sum - M);\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n outputForAtCoder(&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>>\".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": "module CodeForces;\r\n\r\nimport std;\r\n\r\nint main()\r\n{\r\n\tint lineNum = stdin.readln.strip.to!int;\r\n\r\n for ( int i = 0; i < lineNum; i++ )\r\n\t{\r\n\t\tint[] oturakSayısıVeBaslangıcEnerjisiİkilisi = stdin.readln.strip.split.map!(a=> a.to!int()).array;\r\n\t\tint başlangıçEnerjisi = oturakSayısıVeBaslangıcEnerjisiİkilisi.back();\r\n\r\n\t\tint[] oturakAralıkMesafeleri = stdin.readln.strip.split.map!( a=> a.to!int() ).array;\r\n\t\tint toplamOturakMesafesi = oturakAralıkMesafeleri.sum();\r\n\r\n\t\twriteln( max(0, toplamOturakMesafesi - başlangıçEnerjisi) );\r\n\t} \r\n return 0;\r\n}\r\n"}], "negative_code": [], "src_uid": "7276d7e3a4b594dc64c1ba56fb1a3628"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1546/problem/A\n// greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nstruct point {\n int x, y;\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[] b = readln.split.map!(to!int).array;\n\n int sum_a = a.sum;\n int sum_b = b.sum;\n\n if(sum_a != sum_b) {\n \"-1\".writeln;\n continue;\n }\n\n point[] idx;\n\n int i, j;\n while(i < n && j < n) {\n while(a[i] <= b[i]) {\n i += 1;\n if(i >= n || j >= n)\n break;\n }\n while(a[j] >= b[j]) {\n j += 1;\n if(i >= n || j >= n)\n break;\n }\n if(i >= n || j >= n)\n break;\n idx ~= point(i, j);\n a[i] -= 1;\n a[j] += 1;\n }\n\n if(a == b) {\n idx.length.writeln;\n idx.each!(it => \"%s %s\".writefln(it.x + 1, it.y + 1));\n } else {\n \"-1\".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\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array;\n auto b = readln.strip.split.map!(to!long).array;\n long suma = a.sum;\n long sumb = b.sum;\n if (suma != sumb) {\n writeln(-1);\n continue;\n }\n long m = 0;\n foreach (i ; 0 .. n) {\n if (b[i] > a[i])\n m += b[i] - a[i];\n }\n writeln(m);\n int i = 0, j = 0;\n while (m--) {\n while (a[i] <= b[i])\n i++;\n while (a[j] >= b[j])\n j++;\n a[i]--;\n a[j]++;\n writefln(\"%d %d\", i + 1, j + 1);\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\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!int).array;\r\n auto b = readln.splitter.map!(to!int).array;\r\n if (a.sum != b.sum) {\r\n \"-1\".writeln;\r\n }\r\n else {\r\n alias Pair = Tuple!(int, \"i\", int, \"j\");\r\n Pair[] ans;\r\n void add_pair(int x, int y) {\r\n a[x]--; a[y]++;\r\n ans ~= Pair(x + 1, y + 1);\r\n }\r\n int[] s, g;\r\n foreach(i; 0 .. n) {\r\n if (a[i] < b[i]) s ~= i;\r\n else g ~= i;\r\n }\r\n int i, j;\r\n for (i = 0; i < s.length; ) {\r\n if (a[s[i]] != b[s[i]]) {\r\n while (a[g[j]] == b[g[j]]) ++j;\r\n add_pair(g[j], s[i]);\r\n }\r\n else {\r\n ++i;\r\n }\r\n }\r\n writefln!\"%s\"(ans.length);\r\n foreach(p; ans) {\r\n writefln!\"%s %s\"(p.i, p.j);\r\n }\r\n }\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\tauto ok = 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\tauto b = RDA;\r\n\r\n\t\tif (a.sum != b.sum) continue;\r\n\r\n\t\tok[ti] = true;\r\n\t\tlong[] x, y;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto d = b[i] - a[i];\r\n\t\t\tif (d >= 0)\r\n\t\t\t{\r\n\t\t\t\tforeach (_; 0..d)\r\n\t\t\t\t\tx ~= i;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tforeach (_; 0..-d)\r\n\t\t\t\t\ty ~= i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..x.length)\r\n\t\t{\r\n\t\t\tauto xx = x.front; x.popFront;\r\n\t\t\tauto yy = y.front; y.popFront;\r\n\t\t\tans[ti] ~= [yy+1, xx+1];\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (ti, e; ans)\r\n\t{\r\n\t\tif (e.empty)\r\n\t\t\twriteln(ok[ti] ? 0 : -1);\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln(e.length);\r\n\t\t\tforeach (ee; e)\r\n\t\t\t\twriteln(ee[0], \" \", ee[1]);\r\n\t\t}\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\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, 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!int).array;\r\n auto b = readln.splitter.map!(to!int).array;\r\n if (a.sum != b.sum) {\r\n \"-1\".writeln;\r\n }\r\n else {\r\n alias Pair = Tuple!(int, \"i\", int, \"j\");\r\n Pair[] ans;\r\n foreach(i; 0 .. n) {\r\n while (a[i] != b[i]) {\r\n if (a[i] > b[i]) {\r\n ans ~= Pair(i + 1, i + 2);\r\n a[i]--;\r\n a[i + 1]++;\r\n }\r\n else {\r\n a[i]++;\r\n a[i + 1]--;\r\n ans ~= Pair(i + 2, i + 1);\r\n }\r\n }\r\n }\r\n writefln!\"%s\"(ans.length);\r\n foreach(p; ans) {\r\n writefln!\"%s %s\"(p.i, p.j);\r\n }\r\n }\r\n }\r\n\r\n} // main\r\n"}], "src_uid": "accfbd68b9723abf4cd29846e80835ec"} {"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 x = readln.strip.to !(int);\n\t\tint step = 0;\n\t\tint pos = 0;\n\t\twhile (pos < x)\n\t\t{\n\t\t\tstep += 1;\n\t\t\tpos += step;\n\t\t}\n\t\twriteln (step + (pos - x == 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\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\t\n\t\tbool f(long y)\n\t\t{\n\t\t\treturn y * (y+1) / 2 < x;\n\t\t}\n\t\tauto r = binarySearch!(f)(0, x) + 1;\n\t\tif (r * (r+1) / 2 == x+1)\n\t\t{\n\t\t\tans[ti] = r+1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[ti] = r;\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": "38afe98586a3b8d6061fe7e3e8fc4d02"} {"source_code": "import std.stdio;\nint main()\n{\n\tlong t=0;\n\treadf(\" %d\", &t);\n\tfor (long i=0; i= 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, 3);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto p = RDA!int;\n\t\tint[int] cnt;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\t++cnt[p[j]];\n\t\t}\n\t\tauto keys = cnt.keys;\n\t\tkeys.sort!\"a > b\"();\n\t\tsize_t pos;\n\t\tint x;\n\t\tforeach (j, key; keys)\n\t\t{\n\t\t\tx += cnt[key];\n\t\t\tif (x > n/2)\n\t\t\t\tbreak;\n\t\t\tpos = j;\n\t\t}\n\n\t\tsize_t l;\n\t\tans[i][0] = cnt[keys[0]];\n\t\tforeach (j, key; keys[0..pos+1])\n\t\t{\n\t\t\tif (j == 0) continue;\n\t\t\tans[i][1] += cnt[key];\n\t\t\tl = j;\n\t\t\tif (ans[i][1] > ans[i][0])\n\t\t\t\tbreak;\n\t\t}\n\t\tforeach (key; keys[l+1..pos+1])\n\t\t{\n\t\t\tans[i][2] += cnt[key];\n\t\t}\n\t\tif (!(ans[i][1] > ans[i][0] && ans[i][2] > ans[i][0]))\n\t\t{\n\t\t\tans[i] = [0, 0, 0];\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}", "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\tint n = rint;\n\t\tlong[] ps = rlong(n);\n\n\t\tX[] xs;\n\t\tlong lastp = -1;\n\t\tint cnt = 0;\n\t\tforeach(p; ps){\n\t\t\tif(lastp >= 0 && lastp != p){\n\t\t\t\txs ~= X(lastp, cnt);\n\t\t\t\tcnt = 0;\n\t\t\t}\n\t\t\tlastp = p;\n\t\t\tcnt += 1;\n\t\t}\n\t\txs ~= X(lastp, cnt);\n\n\t\tint total;\n\t\tforeach(x; xs) total += x.cnt;\n\n\t\tint g, s, b;\n\t\tint sum = g = xs[0].cnt;\n\t\tint i = 1;\n\t\tfor(; i < xs.length; i ++){\n\t\t\tsum += xs[i].cnt;\n\t\t\tif(sum > g * 2){\n\t\t\t\ts = sum - g;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor(i += 1; i < xs.length; i ++){\n\t\t\tsum += xs[i].cnt;\n\t\t\tif(sum * 2 > total){\n\t\t\t\tb = sum - xs[i].cnt - g - s;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(b <= g) g = 0, s = 0, b = 0;\n\n\t\twriteln(g, \" \", s, \" \", b);\n\t}\n}\nstruct X{\n\tlong p;\n\tint cnt;\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 P = new int[N];\n foreach (i; 0 .. N) {\n P[i] = readInt();\n }\n \n const grp = P.group.array;\n const grpLen = cast(int)(grp.length);\n debug {\n writeln(\"grp = \", grp);\n }\n auto sum = new int[grpLen + 1];\n foreach (j; 0 .. grpLen) {\n sum[j + 1] = sum[j] + grp[j][1];\n }\n \n auto ans = new int[3];\n foreach (j; 2 .. grpLen) {\n if (sum[1] - sum[0] < sum[j] - sum[1]) {\n foreach (k; j + 1 .. grpLen + 1) {\n if (sum[1] - sum[0] < sum[k] - sum[j] && 2 * sum[k] <= N) {\n if (ans.sum < sum[k]) {\n ans = [sum[1] - sum[0], sum[j] - sum[1], sum[k] - sum[j]];\n }\n }\n }\n break;\n }\n }\n writeln(ans[0], \" \", ans[1], \" \", ans[2]);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "cff809c3d5682e6b3e71b525c5f8f8b4"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\ndchar[] stringify(ll num){\n dchar[] res;\n while(num > 0){\n res ~= to!dchar('0' + (num % 10));\n num /= 10;\n }\n res.reverse;\n return res;\n}\n\ndchar[][] pow2;\nvoid preProcess(){\n ll num = 1;\n for(int i = 0; i <= 62; ++i){\n pow2 ~= stringify(num);\n num *= 2;\n }\n}\n\nll common(dchar[] w, dchar[] p2){\n int ptr = 0;\n foreach(c; w){\n if(p2[ptr] == c){\n ++ptr;\n }\n if(ptr == p2.length.to!long){\n return ptr.to!long;\n }\n }\n return ptr.to!long;\n}\n\nvoid theCode(){\n auto w = scan!(dchar[]);\n ll mindist = 32;\n for(int i = 0; i < 62; ++i){\n ll com = common(w, pow2[i]);\n ll dist = w.length.to!long + pow2[i].length.to!long - 2 * com;\n mindist = min(dist, mindist);\n }\n writeln(mindist);\n}\n\nvoid main(){\n preProcess();\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\nsize_t solve(string a, string t)\n{\n size_t i, j, matched;\n while (i < a.length && j < t.length) {\n if (a[i] == t[j]) {\n i++;\n j++;\n matched++;\n } else {\n i++;\n }\n }\n return a.length - matched + (t.length - j);\n}\n\nvoid main()\n{\n string[] pow2list;\n long x = 0;\n while (x < 60) {\n pow2list ~= to!string(1L << x);\n x++;\n }\n long t;\n readf!\" %d \"(t);\n while (t--) {\n auto a = readln.strip;\n writeln(pow2list.map!(t => solve(a, t)).minElement);\n }\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\ndchar[] stringify(ll num){\n dchar[] res;\n while(num > 0){\n res ~= to!dchar('0' + (num % 10));\n num /= 10;\n }\n res.reverse;\n return res;\n}\n\ndchar[][] pow2;\nvoid preProcess(){\n ll num = 1;\n for(int i = 0; i <= 50; ++i){\n pow2 ~= stringify(num);\n num *= 2;\n }\n}\n\nll common(dchar[] w, dchar[] p2){\n int ptr = 0;\n foreach(c; w){\n if(p2[ptr] == c){\n ++ptr;\n }\n if(ptr == p2.length.to!long){\n return ptr.to!long;\n }\n }\n return ptr.to!long;\n}\n\nvoid theCode(){\n auto w = scan!(dchar[]);\n ll mindist = 32;\n for(int i = 0; i <= 50; ++i){\n ll com = common(w, pow2[i]);\n ll dist = w.length.to!long + pow2[i].length.to!long - 2 * com;\n mindist = min(dist, mindist);\n }\n writeln(mindist);\n}\n\nvoid main(){\n preProcess();\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": "728e0e5e5d8350a2b79e6a4b5bef407b"} {"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 sort(a);\n auto b = new int[n];\n int i = (n - 1) / 2, j = i + 1;\n b[0] = a[i];\n foreach (k; 1 .. n) {\n debug stderr.writefln (\"[%d, %d)\", i, j);\n if ((k & 1)) {\n b[k] = a[j++];\n } else {\n b[k] = a[--i];\n }\n }\n writefln!(\"%(%s %)\")(b);\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 (_; 0..T) {\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(int[]);\n sort(as);\n int[] bs;\n int i = (as.length.to!int-1)/2, j = (as.length.to!int-1)/2+1;\n for (;;) {\n if (i < 0) break;\n bs ~= as[i];\n if (j >= N) break;\n bs ~= as[j];\n --i;\n ++j;\n }\n writeln(bs.to!(string[]).join(\" \"));\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!int;\n\t\tauto a = RDA;\n\t\ta.sort();\n\t\tauto pos = n / 2;\n\t\tans[ti] ~= a[pos];\n\t\tint l = pos-1;\n\t\tint r = pos+1;\n\t\twhile (true)\n\t\t{\n\t\t\tif (l < 0) break;\n\t\t\tans[ti] ~= a[l];\n\t\t\tif (r == n) break;\n\t\t\tans[ti] ~= a[r];\n\t\t\t--l; ++r;\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": "3c8bfd3199a9435cfbdee1daaacbd1b3"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nvoid main()\n{\n int k;\n readf!\" %d \"(k);\n while (k--) {\n long n, x, t;\n readf!\" %d %d %d \"(n, x, t);\n long tmp = t / x;\n long result = 0;\n\n if (n >= tmp + 1) {\n result += tmp * (n - tmp - 1);\n result += (tmp + 1) * (tmp) / 2;\n } else {\n result = n * (n - 1) / 2;\n }\n writeln(result);\n }\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1539/problem/A\n// math\nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n int k;\n readf(\"%s\\n\", &k);\n\nwhile(k--) {\n long n, x, t;\n readf(\"%s %s %s\\n\", &n, &x, &t);\n long ans = t/x*max(0, n-t/x) + min(n - 1, t/x - 1)*min(n, t/x)/2;\n ans.writeln;\n}\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1539/problem/A\n// \nimport std.stdio;\n\nvoid main() {\n int k;\n readf(\"%s\\n\", &k);\n\nwhile(k--) {\n long n, x, t;\n readf(\"%s %s %s\\n\", &n, &x, &t);\n long ans = t/x*(n-t/x) + (t/x - 1)*(t/x)/2;\n ans.writeln;\n}\n}\n"}], "src_uid": "4df38c9b42b0f0963a121829080d3571"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\n\nvoid main(){\n\n int n; rd(n);\n long a, b; rd(a, b);\n long[] cand;\n for(int i=2; i*i<=a; i++){\n if(a%i==0){\n cand~=i;\n while(a%i==0) a/=i;\n }\n }\n if(a>1) cand~=a;\n for(int i=2; i*i<=b; i++){\n if(b%i==0){\n cand~=i;\n while(b%i==0) b/=i;\n }\n }\n if(b>1) cand~=b;\n foreach(i; 0..(n-1)){\n long s, t; rd(s, t);\n long[] nex;\n foreach(x; cand){\n if(s%x==0 || t%x==0) nex~=x;\n }\n cand.swap(nex);\n }\n\n if(cand.length>0){\n writeln(cand[0]);\n }else{\n writeln(-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", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.format;\n\nlong gcd(long a, long b) {\n if (b == 0) return a;\n else return gcd(b, a%b);\n}\n\nint n;\n\nvoid main() {\n string s = readln.strip;\n n = parse!int(s);\n\n long[] a,b;\n a.length = n;\n b.length = n;\n\n long x = 0;\n foreach (i; 0 .. n) {\n readln.strip.formattedRead(\" %s %s\", a[i], b[i]);\n x = gcd(a[i]*b[i],x);\n }\n\n foreach(i; 0 .. n) {\n long y = gcd(x,a[i]);\n if (y != 1) {\n x = y;\n } else {\n x = gcd(x,b[i]);\n }\n }\n\n if (x == 1)\n writeln(-1);\n else\n writeln(x);\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[] calcFor2Elms(int a, int b) {\n int[] calc(int x) {\n int[] ans;\n auto sq = sqrt(x.to!real).floor();\n auto v = x, k = 2;\n while (v > 1) {\n if (v % k == 0) {\n ans ~= k;\n while (v % k == 0) v /= k;\n }\n ++k;\n if (k > sq) break;\n }\n if (v > 1) ans ~= v;\n return ans;\n }\n return multiwayUnion([calc(a), calc(b)]).array; \n }\n \n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n auto elms = calcFor2Elms(a, b);\n \n debug { elms.writeln; }\n \n foreach (_; 1 .. n) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n int[] cur;\n foreach (e; elms) {\n if (x % e == 0 || y % e == 0) cur ~= e;\n }\n \n elms = cur;\n \n debug { elms.writeln; }\n }\n \n writeln(elms.empty() ? -1 : elms.front);\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[] calcFor2Elms(int a, int b) {\n int[] calc(int x) {\n int[] ans;\n auto sq = sqrt(x.to!real).floor();\n auto v = x, k = 2;\n while (v > 1 && k <= sq) {\n if (v % k == 0) {\n ans ~= k;\n while (v % k == 0) v /= k;\n }\n ++k;\n }\n if (v > 1) ans ~= v;\n return ans;\n }\n return multiwayUnion([calc(a), calc(b)]).array; \n }\n \n int a, b;\n readf(\"%s %s\", &a, &b);\n readln;\n auto elms = calcFor2Elms(a, b);\n \n debug { elms.writeln; }\n \n foreach (_; 1 .. n) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n int[] cur;\n foreach (e; elms) {\n if (x % e == 0 || y % e == 0) cur ~= e;\n }\n \n elms = cur;\n \n debug { elms.writeln; }\n }\n \n writeln(elms.empty() ? -1 : elms.front);\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nbool isPrime (int v)\n{\n\tif (v < 2)\n\t{\n\t\treturn false;\n\t}\n\tfor (int d = 2; d * d <= v; d++)\n\t{\n\t\tif (v % d == 0)\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\t\tauto b = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &a[i], &b[i]);\n\t\t}\n\n\t\tbool [int] cand;\n\t\tfor (int d = 1; d * d <= a[0]; d += 1)\n\t\t{\n\t\t\tif (a[0] % d == 0)\n\t\t\t{\n\t\t\t\tcand[d] = true;\n\t\t\t\tcand[a[0] / d] = true;\n\t\t\t}\n\t\t}\n\t\tfor (int d = 1; d * d <= b[0]; d += 1)\n\t\t{\n\t\t\tif (b[0] % d == 0)\n\t\t\t{\n\t\t\t\tcand[d] = true;\n\t\t\t\tcand[b[0] / d] = true;\n\t\t\t}\n\t\t}\n\n\t\tint [] divs;\n\t\tforeach (k, v; cand)\n\t\t{\n\t\t\tif (isPrime (k))\n\t\t\t{\n\t\t\t\tdivs ~= k;\n\t\t\t}\n\t\t}\n\n\t\tint res = -1;\n\t\tforeach (d; divs)\n\t\t{\n\t\t\tbool ok = true;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (a[i] % d != 0 && b[i] % d != 0)\n\t\t\t\t{\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{\n\t\t\t\tres = d;\n\t\t\t\tbreak;\n\t\t\t}\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.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 auto B = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n B[i] = readLong();\n }\n \n long g = 0;\n foreach (i; 0 .. N) {\n const l = A[i] / gcd(A[i], B[i]) * B[i];\n g = gcd(g, l);\n }\n if (g == 1) {\n writeln(-1);\n } else {\n long ans;\n foreach (a; [A[0], B[0]]) {\n const m = gcd(g, a);\n for (long p = 2; p * p <= m; ++p) {\n if (m % p == 0) {\n ans = p;\n goto found;\n }\n }\n if (m > 1) {\n ans = m;\n goto found;\n }\n }\n assert(false);\n found:\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\n\nvoid main(){\n\n int n; rd(n);\n long a, b; rd(a, b);\n long[] cand;\n for(int i=2; i*i<=a; i++){\n if(a%i==0){\n cand~=i;\n while(a%i) a/=i;\n }\n }\n if(a>1) cand~=a;\n for(int i=2; i*i<=b; i++){\n if(b%i==0){\n cand~=i;\n while(b%i) b/=i;\n }\n }\n if(b>1) cand~=b;\n foreach(i; 0..(n-1)){\n long s, t; rd(s, t);\n long[] nex;\n foreach(x; cand){\n if(s%x==0 || t%x==0) nex~=x;\n }\n cand.swap(nex);\n }\n\n if(cand.length>0){\n writeln(cand[0]);\n }else{\n writeln(-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"}, {"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 auto A = new long[N];\n auto B = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n B[i] = readLong();\n }\n \n long g = 0;\n foreach (i; 0 .. N) {\n const l = A[i] / gcd(A[i], B[i]) * B[i];\n g = gcd(g, l);\n }\n writeln((g == 1) ? -1 : g);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "aba6e64e040952b88e7dcb95e4472e56"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 s = new char[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts[i] = RD!(char[]);\n\t\t}\n\t\t\n\t\tbool visit(int y, int x)\n\t\t{\n\t\t\tif (!inside(y, 0, n) || !inside(x, 0, m)) return true;\n\t\t\tif (s[y][x] == 'G') return false;\n\t\t\tif (s[y][x] == '.')\n\t\t\t{\n\t\t\t\ts[y][x] = '#';\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tbool ok = true;\n\t\tint[][] good;\n\t\t(){\n\t\tforeach (int y; 0..n)\n\t\t{\n\t\t\tforeach (int x; 0..m)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'B')\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\tok &= visit(y-1, x);\n\t\t\t\t\tok &= visit(y+1, x);\n\t\t\t\t\tok &= visit(y, x-1);\n\t\t\t\t\tok &= visit(y, x+1);\n\t\t\t\t\tif (!ok) return;\n\t\t\t\t}\n\t\t\t\telse if (s[y][x] == 'G')\n\t\t\t\t{\n\t\t\t\t\tgood ~= [y, x];\n\t\t\t\t}\n\t\t\t}\n\t\t}}();\n\t\tif (!ok) continue;\n\n\t\tint[][] open;\n\t\tif (s[n-1][m-1] != '#')\n\t\t{\n\t\t\topen ~= [[n-1, m-1]];\n\t\t}\n\t\tauto dist = new int[][](n, m);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tdist[i][] = int.max;\n\t\t}\n\t\tdist[n-1][m-1] = 0;\n\t\twhile (!open.empty)\n\t\t{\n\t\t\tauto nd = open.front; open.popFront;\n\t\t\tauto y = nd[0];\n\t\t\tauto x = nd[1];\n\t\t\tif (y != 0)\n\t\t\t{\n\t\t\t\tauto ny = y-1;\n\t\t\t\tauto nx = x;\n\t\t\t\tif (s[ny][nx] != '#')\n\t\t\t\t{\n\t\t\t\t\tif (dist[y][x]+1 < dist[ny][nx])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[ny][nx] = dist[y][x]+1;\n\t\t\t\t\t\topen ~= [ny, nx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (y != n-1)\n\t\t\t{\n\t\t\t\tauto ny = y+1;\n\t\t\t\tauto nx = x;\n\t\t\t\tif (s[ny][nx] != '#')\n\t\t\t\t{\n\t\t\t\t\tif (dist[y][x]+1 < dist[ny][nx])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[ny][nx] = dist[y][x]+1;\n\t\t\t\t\t\topen ~= [ny, nx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x != 0)\n\t\t\t{\n\t\t\t\tauto ny = y;\n\t\t\t\tauto nx = x-1;\n\t\t\t\tif (s[ny][nx] != '#')\n\t\t\t\t{\n\t\t\t\t\tif (dist[y][x]+1 < dist[ny][nx])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[ny][nx] = dist[y][x]+1;\n\t\t\t\t\t\topen ~= [ny, nx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x != m-1)\n\t\t\t{\n\t\t\t\tauto ny = y;\n\t\t\t\tauto nx = x+1;\n\t\t\t\tif (s[ny][nx] != '#')\n\t\t\t\t{\n\t\t\t\t\tif (dist[y][x]+1 < dist[ny][nx])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[ny][nx] = dist[y][x]+1;\n\t\t\t\t\t\topen ~= [ny, nx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (e; good)\n\t\t{\n\t\t\tauto y = e[0];\n\t\t\tauto x = e[1];\n\t\t\tif (dist[y][x] == int.max)\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}\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 dirs = 4;\nimmutable int [dirs] dRow = [-1, 0, +1, 0];\nimmutable int [dirs] dCol = [ 0, -1, 0, +1];\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\tchar [] [] board;\n\t\tboard ~= '#'.repeat (cols + 2).array;\n\t\tforeach (row; 1..rows + 1)\n\t\t{\n\t\t\tboard ~= '#' ~ readln.strip.dup ~ '#';\n\t\t}\n\t\tboard ~= '#'.repeat (cols + 2).array;\n\n\t\tint goods = 0;\n\t\tforeach (row; 1..rows + 1)\n\t\t{\n\t\t\tgoods += board[row].count ('G');\n\t\t}\n\n\t\tforeach (row; 1..rows + 1)\n\t\t{\n\t\t\tforeach (col; 1..cols + 1)\n\t\t\t{\n\t\t\t\tif (board[row][col] != 'B')\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (dir; 0..dirs)\n\t\t\t\t{\n\t\t\t\t\tauto nRow = row + dRow[dir];\n\t\t\t\t\tauto nCol = col + dCol[dir];\n\t\t\t\t\tif (board[nRow][nCol] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tboard[nRow][nCol] = '#';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tbool recur (int row, int col)\n\t\t{\n\t\t\tif (board[row][col] == '#')\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (board[row][col] == 'B')\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tgoods -= (board[row][col] == 'G');\n\t\t\tboard[row][col] = '#';\n\t\t\tforeach (dir; 0..dirs)\n\t\t\t{\n\t\t\t\tauto nRow = row + dRow[dir];\n\t\t\t\tauto nCol = col + dCol[dir];\n\t\t\t\tif (!recur (nRow, nCol))\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\tbool ok = recur (rows, cols);\n\t\tok &= (goods == 0);\n\t\twriteln (ok ? \"Yes\" : \"No\");\n\t}\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 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 arr = new dchar[][] (n + 2, m + 2);\n foreach (i; 0 .. n+2) {\n foreach (j; 0 .. m+2) {\n arr[i][j] = '#';\n }\n }\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. m+1) {\n readf(\"%s\", &arr[i][j]);\n }\n \n readln;\n }\n \n debug { arr.writeln; }\n \n bool isOkCell(int i, int j) {\n if (arr[i][j] != 'B') { return true; }\n \n foreach (x; -1 .. 2) {\n foreach (y; -1 .. 2) {\n if (abs(x) + abs(y) != 1) { continue; }\n if (arr[i+x][y+j] == 'G') { return false; }\n }\n }\n \n return true;\n }\n \n void mark(int i, int j) {\n if (arr[i][j] != 'B') { return; }\n \n foreach (x; -1 .. 2) {\n foreach (y; -1 .. 2) {\n if (abs(x) + abs(y) != 1) { continue; }\n if (arr[i+x][j+y] == '.') { arr[i+x][j+y] = '#'; }\n }\n }\n }\n \n bool ans = true;\n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. m+1) {\n ans &= isOkCell(i, j);\n mark(i, j);\n }\n }\n \n if (!ans) {\n writeln(\"No\");\n continue;\n }\n \n debug { arr.writeln; }\n \n auto vis = new bool[][] (n+2, m+2);\n foreach (i; 0 .. n+2) {\n vis[i][] = false;\n }\n \n void dfs(int i, int j) {\n if (arr[i][j] == '#') { return; }\n \n vis[i][j] = true;\n foreach (x; -1 .. 2) {\n foreach (y; -1 .. 2) {\n if (abs(x) + abs(y) != 1) { continue; }\n if (vis[i+x][j+y]) { continue; }\n \n dfs(i+x, y+j);\n }\n }\n }\n \n dfs(n, m);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. m+1) {\n if (arr[i][j] == 'G' && !vis[i][j]) { ans = false; }\n }\n }\n \n writeln(ans ? \"Yes\" : \"No\");\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 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 arr = new dchar[][] (n + 2, m + 2);\n foreach (i; 0 .. n+2) {\n foreach (j; 0 .. m+2) {\n arr[i][j] = '#';\n }\n }\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. m+1) {\n readf(\"%s\", &arr[i][j]);\n }\n \n readln;\n }\n \n debug { arr.writeln; }\n \n bool isOkCell(int i, int j) {\n if (arr[i][j] != 'B') { return true; }\n \n foreach (x; -1 .. 2) {\n foreach (y; -1 .. 2) {\n if (abs(x) + abs(y) != 1) { continue; }\n if (arr[i+x][y+j] == 'G') { return false; }\n }\n }\n \n return true;\n }\n \n void mark(int i, int j) {\n if (arr[i][j] != 'B') { return; }\n \n foreach (x; -1 .. 2) {\n foreach (y; -1 .. 2) {\n if (abs(x) + abs(y) != 1) { continue; }\n if (arr[i+x][j+y] != 'G') { arr[i+x][j+y] = '#'; }\n }\n }\n }\n \n bool ans = true;\n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. m+1) {\n ans &= isOkCell(i, j);\n mark(i, j);\n }\n }\n \n if (!ans) {\n writeln(\"No\");\n continue;\n }\n \n debug { arr.writeln; }\n \n auto vis = new bool[][] (n+2, m+2);\n foreach (i; 0 .. n+2) {\n vis[i][] = false;\n }\n \n void dfs(int i, int j) {\n if (arr[i][j] == '#') { return; }\n \n vis[i][j] = true;\n foreach (x; -1 .. 2) {\n foreach (y; -1 .. 2) {\n if (abs(x) + abs(y) != 1) { continue; }\n if (vis[i+x][j+y]) { continue; }\n \n dfs(i+x, y+j);\n }\n }\n }\n \n dfs(n, m);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. m+1) {\n if (arr[i][j] == 'G' && !vis[i][j]) { ans = false; }\n }\n }\n \n writeln(ans ? \"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) { 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 s = new char[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts[i] = RD!(char[]);\n\t\t}\n\t\t\n\t\tbool visit(int y, int x)\n\t\t{\n\t\t\tif (!inside(y, 0, n) || !inside(x, 0, m)) return true;\n\t\t\tif (s[y][x] == 'G') return false;\n\t\t\tif (s[y][x] == '.')\n\t\t\t{\n\t\t\t\ts[y][x] = '#';\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tbool ok = true;\n\t\tint[][] good;\n\t\t(){\n\t\tforeach (int y; 0..n)\n\t\t{\n\t\t\tforeach (int x; 0..m)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'B')\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\tok = visit(y-1, x);\n\t\t\t\t\tok = visit(y+1, x);\n\t\t\t\t\tok = visit(y, x-1);\n\t\t\t\t\tok = visit(y, x+1);\n\t\t\t\t\tif (!ok) return;\n\t\t\t\t}\n\t\t\t\telse if (s[y][x] == 'G')\n\t\t\t\t{\n\t\t\t\t\tgood ~= [y, x];\n\t\t\t\t}\n\t\t\t}\n\t\t}}();\n\t\tif (!ok) continue;\n\n\t\tint[][] open;\n\t\tif (s[n-1][m-1] != '#')\n\t\t{\n\t\t\topen ~= [[n-1, m-1]];\n\t\t}\n\t\tauto dist = new int[][](n, m);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tdist[i][] = int.max;\n\t\t}\n\t\tdist[n-1][m-1] = 0;\n\t\twhile (!open.empty)\n\t\t{\n\t\t\tauto nd = open.front; open.popFront;\n\t\t\tauto y = nd[0];\n\t\t\tauto x = nd[1];\n\t\t\tif (y != 0)\n\t\t\t{\n\t\t\t\tauto ny = y-1;\n\t\t\t\tauto nx = x;\n\t\t\t\tif (s[ny][nx] != '#')\n\t\t\t\t{\n\t\t\t\t\tif (dist[y][x]+1 < dist[ny][nx])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[ny][nx] = dist[y][x]+1;\n\t\t\t\t\t\topen ~= [ny, nx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (y != n-1)\n\t\t\t{\n\t\t\t\tauto ny = y+1;\n\t\t\t\tauto nx = x;\n\t\t\t\tif (s[ny][nx] != '#')\n\t\t\t\t{\n\t\t\t\t\tif (dist[y][x]+1 < dist[ny][nx])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[ny][nx] = dist[y][x]+1;\n\t\t\t\t\t\topen ~= [ny, nx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x != 0)\n\t\t\t{\n\t\t\t\tauto ny = y;\n\t\t\t\tauto nx = x-1;\n\t\t\t\tif (s[ny][nx] != '#')\n\t\t\t\t{\n\t\t\t\t\tif (dist[y][x]+1 < dist[ny][nx])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[ny][nx] = dist[y][x]+1;\n\t\t\t\t\t\topen ~= [ny, nx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x != m-1)\n\t\t\t{\n\t\t\t\tauto ny = y;\n\t\t\t\tauto nx = x+1;\n\t\t\t\tif (s[ny][nx] != '#')\n\t\t\t\t{\n\t\t\t\t\tif (dist[y][x]+1 < dist[ny][nx])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[ny][nx] = dist[y][x]+1;\n\t\t\t\t\t\topen ~= [ny, nx];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (e; good)\n\t\t{\n\t\t\tauto y = e[0];\n\t\t\tauto x = e[1];\n\t\t\tif (dist[y][x] == int.max)\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}\n"}], "src_uid": "a5e649f4d984a5c5365ca31436ad5883"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n\r\n auto solve() {\r\n long subSolve(long N, int[] A) {\r\n int[][int] indecies;\r\n foreach(int i, a; A) {\r\n indecies[a] ~= i;\r\n }\r\n // indecies.deb;\r\n\r\n long ans = -1;\r\n foreach(key, inds; indecies) {\r\n if (inds.length == 1) continue;\r\n\r\n long minDistance = int.max;\r\n foreach(i; 0..inds.length - 1) {\r\n minDistance = min(minDistance, inds[i + 1] - inds[i]);\r\n }\r\n\r\n ans = ans.max(N - minDistance);\r\n }\r\n\r\n return ans;\r\n }\r\n\r\n foreach(i; 0..QN) {\r\n const n = scan!int;\r\n subSolve(n, scan!int(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>>\".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\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\");\n immutable vec =\n readln.chomp.split(' ')\n .to!(uint[]);\n\n auto indexes = (){\n static assert(true);\n size_t[][uint] ret;\n foreach (ind, val; vec)\n ret[val] ~= ind;\n return ret;\n }();\n\n (cast(int)(\n -\n indexes\n .byValue\n .filter!\"a.length > 1\"\n .map!(x => zip(x, x.dropOne)\n .minElement!\"a[1] - a[0]\")\n .map!(x => x[1] - x[0])\n .minElement(n + 1)\n + n\n \n ))\n .writeln;\n }\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!(uint, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n immutable n = read!(uint, \"\\n\");\n immutable vec =\n readln.chomp.split(' ')\n .to!(uint[]);\n\n auto indexes = (){\n static assert(true);\n size_t[][uint] ret;\n foreach (ind, val; vec)\n ret[val] ~= ind;\n return ret;\n }();\n\n (cast(int)(\n -\n indexes\n .byValue\n .filter!\"a.length > 1\"\n .map!(x => zip(x, x.dropOne)\n .minElement!\"a[1] - a[0]\")\n .cache.map!(x => x[1] - x[0])\n .minElement(n + 1)\n + n\n \n ))\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 a = RDA(-1);\r\n\t\t\r\n\t\tauto pos = new int[][](150000);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tpos[a[i]] ~= i;\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..pos.length)\r\n\t\t{\r\n\t\t\tif (pos[i].length < 2) continue;\r\n\t\t\tforeach (j; 0..pos[i].length-1)\r\n\t\t\t{\r\n\t\t\t\tans[ti].chmax(pos[i][j] + n - pos[i][j+1]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (ans[ti] == 0)\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}"}], "negative_code": [], "src_uid": "7ac5f084c403bd26802e1b941105d34b"} {"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, c;\n readf(\"%s %s\", &n, &c);\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 auto dp = new int[][] (n+2, 2);\n dp[0][1] = c;\n \n int[] ans;\n ans ~= 0;\n foreach (i; 0 .. n-1) {\n dp[i+1][0] = min(dp[i][0], dp[i][1]) + a[i];\n dp[i+1][1] = min(dp[i][0] + c, dp[i][1]) + b[i];\n debug { writeln(i, dp[i]); }\n ans ~= min(dp[i+1][0], dp[i+1][1]);\n }\n \n ans.map!(to!string).join(' ').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 string[] s_rd;\nT 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\tauto c = RD!int;\n\tauto a = RDA;\n\tauto b = RDA;\n\n\tauto dp = new long[][](n+1, 2);\n\tdp[0][1] = c;\n\n\tforeach (i; 0..n-1)\n\t{\n\t\tdp[i+1][0] = min(dp[i][0]+a[i], dp[i][1]+a[i]);\n\t\tdp[i+1][1] = min(dp[i][0]+b[i]+c, dp[i][1]+b[i]);\n\t}\n\n\tauto ans = new long[](n);\n\tforeach (i; 0..n-1)\n\t{\n\t\tans[i+1] = min(dp[i+1][0], dp[i+1][1]);\n\t}\n\n\tans.map!(to!string).join(\" \").writeln;\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "845e2c363038a10f438f29b1a9e04494"} {"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 \r\n auto used = new bool[](N + 1);\r\n auto queue = iota(1, N+1).array;\r\n auto ans = Array!int();\r\n int output;\r\n void dfs(int size = 0) {\r\n if (output == N) return;\r\n if (size == N) {\r\n output++;\r\n ans.array.toAnswerString.writeln;\r\n return;\r\n }\r\n\r\n foreach(p; queue) {\r\n if (used[p]) continue;\r\n\r\n if (ans.length < 2 || ans[$ - 1] + ans[$ - 2] != p) {\r\n ans.insertBack(p);\r\n used[p] = true;\r\n dfs(size + 1);\r\n ans.removeBack;\r\n used[p] = false;\r\n }\r\n }\r\n }\r\n\r\n dfs();\r\n\r\n }\r\n\r\n foreach(i; 0..QN) {\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>>\".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 = readln.chomp.to!uint;\n\n foreach (onePosition; 0 .. n) {\n chain(\n iota(n, n - onePosition, -1),\n [1u],\n iota(n - onePosition, 1 , -1)\n ).writefln!\"%(%s %)\";\n }\n }\n}\n// \"\"\n"}], "negative_code": [], "src_uid": "85f0621e6cd7fa233cdee8269310f141"} {"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\twriteln(\"? \", l, \" \", m2);\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{\r\n\t\t\t\tl = m2;\r\n\t\t\t\twriteln(\"? \", l, \" \", r);\r\n\t\t\t\tstdout.flush;\r\n\t\t\t\tm = RD!int;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln(\"? \", m2, \" \", r);\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{\r\n\t\t\t\tr = m2;\r\n\t\t\t\twriteln(\"? \", l, \" \", r);\r\n\t\t\t\tstdout.flush;\r\n\t\t\t\tm = RD!int;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\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}"}, {"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 n = to!int(readln.strip);\r\n writeln(\"? 1 \", n);\r\n stdout.flush;\r\n auto pidx = 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 if (left == mid && right == mid + 1)\r\n {\r\n if (pidx == left) left = mid + 1;\r\n else right = mid;\r\n continue;\r\n }\r\n int lidx, ridx;\r\n if (left < mid)\r\n {\r\n writeln(\"? \", left, \" \", mid);\r\n stdout.flush;\r\n lidx = to!int(readln.strip);\r\n }\r\n if (mid + 1 < right)\r\n {\r\n writeln(\"? \", mid + 1, \" \", right);\r\n stdout.flush;\r\n ridx = to!int(readln.strip);\r\n }\r\n if (left == mid)\r\n {\r\n if (pidx == left || pidx == ridx) left = mid + 1, pidx = ridx;\r\n else right = mid;\r\n continue;\r\n }\r\n if (right == mid + 1)\r\n {\r\n if (pidx == right || pidx == lidx) right = mid, pidx = lidx;\r\n else left = mid + 1;\r\n continue;\r\n }\r\n if (pidx <= mid)\r\n {\r\n if (pidx == lidx) right = mid;\r\n else left = mid + 1;\r\n }\r\n else\r\n {\r\n if (pidx == ridx) left = mid + 1;\r\n else right = mid;\r\n }\r\n pidx = (left > mid ? ridx : lidx);\r\n }\r\n writeln(\"! \", left);\r\n return 0;\r\n}"}], "negative_code": [{"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 n = to!int(readln.strip);\r\n writeln(\"? 1 \", n);\r\n stdout.flush;\r\n auto pidx = 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 if (left == mid && right == mid + 1)\r\n {\r\n if (pidx == left) left = mid + 1;\r\n else right = mid;\r\n continue;\r\n }\r\n int lidx, ridx;\r\n if (left < mid)\r\n {\r\n writeln(\"? \", left, \" \", mid);\r\n stdout.flush;\r\n lidx = to!int(readln.strip);\r\n }\r\n if (mid + 1 < right)\r\n {\r\n writeln(\"? \", mid + 1, \" \", right);\r\n stdout.flush;\r\n ridx = to!int(readln.strip);\r\n }\r\n if (left == mid)\r\n {\r\n if (pidx == left) left = mid + 1, pidx = ridx;\r\n else right = mid;\r\n continue;\r\n }\r\n if (right == mid + 1)\r\n {\r\n if (pidx == right) right = mid, pidx = lidx;\r\n else left = mid + 1;\r\n continue;\r\n }\r\n if (pidx <= mid)\r\n {\r\n if (pidx == lidx) right = mid;\r\n else left = mid + 1;\r\n }\r\n else\r\n {\r\n if (pidx == ridx) left = mid + 1;\r\n else right = mid;\r\n }\r\n if (left > mid) pidx = ridx;\r\n else pidx = lidx;\r\n }\r\n writeln(\"! \", left);\r\n return 0;\r\n}"}, {"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 n = to!int(readln.strip);\r\n writeln(\"? 1 \", n);\r\n stdout.flush;\r\n auto pidx = 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 if (left == mid && right == mid + 1)\r\n {\r\n if (pidx == left) left = mid + 1;\r\n else right = mid;\r\n continue;\r\n }\r\n int lidx, ridx;\r\n if (left < mid)\r\n {\r\n writeln(\"? \", left, \" \", mid);\r\n stdout.flush;\r\n lidx = to!int(readln.strip);\r\n }\r\n if (mid + 1 < right)\r\n {\r\n writeln(\"? \", mid + 1, \" \", right);\r\n stdout.flush;\r\n ridx = to!int(readln.strip);\r\n }\r\n if (left == mid)\r\n {\r\n if (pidx == left) left = mid + 1, pidx = ridx;\r\n else right = mid;\r\n continue;\r\n }\r\n if (right == mid + 1)\r\n {\r\n if (pidx == right) right = mid, pidx = lidx;\r\n else left = mid + 1;\r\n continue;\r\n }\r\n if (pidx < mid)\r\n {\r\n if (pidx == lidx) right = mid;\r\n else left = mid + 1;\r\n }\r\n else\r\n {\r\n if (pidx == ridx) left = mid + 1;\r\n else right = mid;\r\n }\r\n if (left > mid) pidx = ridx;\r\n else pidx = lidx;\r\n }\r\n writeln(\"! \", left);\r\n return 0;\r\n}"}, {"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 n = to!int(readln.strip);\r\n writeln(\"? 1 \", n);\r\n stdout.flush;\r\n auto pidx = 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 if (left == mid)\r\n {\r\n if (pidx == left) left = mid + 1;\r\n else right = mid - 1;\r\n continue;\r\n }\r\n if (right == mid + 1)\r\n {\r\n if (pidx == right) right = mid - 1;\r\n else left = mid + 1;\r\n continue;\r\n }\r\n writeln(\"? \", left, \" \", mid);\r\n stdout.flush;\r\n auto lidx = to!int(readln.strip);\r\n writeln(\"? \", mid + 1, \" \", right);\r\n stdout.flush;\r\n auto ridx = to!int(readln.strip);\r\n if (pidx < mid)\r\n {\r\n if (pidx == lidx) right = mid - 1;\r\n else left = mid + 1;\r\n }\r\n else\r\n {\r\n if (pidx == ridx) left = mid + 1;\r\n else right = mid - 1;\r\n }\r\n if (left > mid) pidx = ridx;\r\n else pidx = lidx;\r\n }\r\n writeln(\"! \", left);\r\n return 0;\r\n}"}], "src_uid": "b3e8fe76706ba17cb285c75459508334"} {"source_code": "import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.string, std.typecons;\r\nimport core.bitop;\r\n\r\nvoid main() {\r\n foreach(i; 0 .. to!int(readln.strip)) {\r\n int n = to!int(readln.strip);\r\n int r = bsr(n);\r\n writeln(pow(2, r)-1);\r\n }\r\n}\r\n", "positive_code": [{"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;\r\n readf!\"%d\\n\"(n);\r\n int res = 0;\r\n while (n)\r\n {\r\n res++;\r\n n /= 2;\r\n }\r\n writeln((1 << (res - 1)) - 1);\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)); }\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 long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD;\n\n\t\tlong x;\n\t\tforeach (i; 0..33)\n\t\t{\n\t\t\tauto bit = 1L << i;\n\t\t\tif (n & bit)\n\t\t\t\tx = bit;\n\t\t}\n\t\tans[ti] = x - 1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "9b4a8bc76d634935f6a1438e8a93a781"} {"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\n long n, k;\n readf(\" %s %s\\n\", n, k);\n auto s = readln().strip.dup;\n\n int ans = -1;\n foreach(c; iota(0,27)) {\n auto cc = 'a' + c;\n int count= 0;\n int tt = 0;\n\n foreach(e; s){ \n if (e == cc) {\n count++;\n } else {\n tt += count / k;\n count = 0;\n }\n }\n \n tt += count/k;\n\n ans = max(tt, ans);\n }\n\n writeln(ans);\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 K = s[1];\n auto S = readln.chomp;\n int ans = 0;\n\n for (char c = 'a'; c <= 'z'; ++c) {\n int tmp = 0;\n int v = 0;\n foreach (i; 0..N) {\n if (S[i] == c) {\n tmp += 1;\n if (tmp == K) {\n v += 1;\n tmp = 0;\n }\n } else {\n tmp = 0;\n }\n }\n ans = max(ans, v);\n }\n\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "6c71c828553e43c699237211005873e5"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\n//-----------------------\n\nvoid main(){\n auto n = readln.chomp.to!int;\n int[][] matrix;\n foreach(i; 0..n){ matrix ~= readln.chomp.split(\" \").map!(to!int).array; }\n matrix.map!(sum).filter!((e) => e >= 2).array.length.writeln;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.format;\n\nvoid main()\n{\n readln; //discard first line\n \n uint numChallenges;\n \n byte a, b, c;\n \n foreach(line; stdin.byLine)\n {\n formattedRead(line, \"%s %s %s\", &a, &b, &c);\n \n if ((a + b + c) > 1) ++numChallenges;\n }\n \n numChallenges.writeln;\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n;\n readf(\"%d\\n\", &n);\n\n int implement = 0;\n for (int i = 0; i < n; ++i) {\n int p, v, t;\n readf(\"%d %d %d\\n\", &p, &v, &t);\n\n if (p+v+t >= 2) {\n implement++;\n } \n }\n\n writefln(\"%d\", implement);\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tint a, b, c;\n\tscanf(\"%d\", &n);\n\tint noproblems = 0;\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tscanf(\"%d %d %d\", &a, &b, &c);\n\t\tnoproblems += (a + b + c) > 1 ? 1 : 0; \n\t}\n\tprintf(\"%d\", noproblems);\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tint problems;\n\n\tfor(int i=0; i x==1).count >= 2) {\n\t\t\tproblems++;\n\t\t}\n\t}\n\n\tproblems.writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tint problems = 0;\n\n\tfor(int i=0; i=2) {\n\t\t\tproblems++;\n\t\t}\n\t}\n\n\tproblems.writeln;\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/231/A\n// implementation, simulation\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.algorithm;\n\nvoid main() {\n int answer = 0;\n foreach(line; stdin.byLine.dropOne)\n answer += (line.split.map!(to!int).sum > 1);\n answer.writeln;\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/231/A\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.algorithm;\n\nvoid main() {\n int answer = 0;\n foreach(line; stdin.byLine.dropOne) {\n if(line.split.map!(to!int).count!(x => x == 1) >= 2)\n answer += 1;\n }\n answer.writeln;\n}\n"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int n;\n readf(\"%s\\n\", &n);\n int ans = 0;\n for(int i = 0; i < n; ++i){\n int a,b,c;\n readf(\"%s %s %s\\n\",&a,&b,&c);\n ans += (a+b+c)>=2;\n }\n writeln(ans);\n}\n"}, {"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\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\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 CF143A()\n{\n int cnt, n = ni();\n for (int i = 0; i < n; ++i)\n if (ni() + ni() + ni() >= 2) ++cnt;\n writeln(cnt);\n}\n\nvoid main()\n{\n CF143A();\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\n\nvoid main() {\n readln;\n\n int ans = 0;\n foreach (string s; stdin.lines) {\n if (s.countchars(\"1\") >= 2) ans++; \n }\n \n ans.writeln;\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 = readln.chomp.to!int;\n\n int ans;\n\n foreach(i ; 0 .. n){\n auto a = readln.split.to!(int[]).sum;\n ans += (a > 1);\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 writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n readln; //discard first line\n \n uint numChallenges;\n \n byte a, b, c;\n \n while(!stdin.eof)\n {\n readf(\"%s %s %s\\n\", &a, &b, &c);\n if (stdin.eof) break;\n writeln(a,b,c);\n \n if ((a + b + c) > 1) ++numChallenges;\n \n }\n \n numChallenges.writeln;\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n readln; //discard first line\n \n uint numChallenges;\n \n byte a, b, c;\n \n while(!stdin.eof)\n {\n readf(\"%s %s %s\\n\", &a, &b, &c);\n \n if ((a + b + c) > 1) ++numChallenges;\n }\n \n numChallenges.writeln;\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n readln; //discard first line\n \n uint numChallenges;\n \n byte a, b, c;\n \n while(!stdin.eof)\n {\n readf(\"%s %s %s\\n\", &a, &b, &c);\n \n if (a + b + c > 1) ++numChallenges;\n }\n \n numChallenges.writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\n\nvoid main() {\n\tint n = readln.chomp.to!int;\n\tint problems;\n\n\tfor(int i=0; i x==1).count >= 2) {\n\t\t\tproblems++;\n\t\t}\n\t}\n}\n"}, {"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\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\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 CF143A()\n{\n int cnt;\n for (int i = 0; i < ni(); ++i)\n if (ni() + ni() + ni() >= 2) ++cnt;\n writeln(cnt);\n}\n\nvoid main()\n{\n CF143A();\n}"}], "src_uid": "3542adc74a41ccfd72008faf983ffab5"} {"source_code": "import std.stdio;\n\nvoid main() {\n int n, s, t;\n scanf(\"%d %d %d\", &n, &s, &t);\n int[] p = new int[n+1];\n for (int i = 1 ; i <= n ; ++i) {\n scanf(\"%d\", &p[i]);\n }\n int ans = 0, flg = 1;\n bool[int] set;\n for ( ; s != t ; ++ans) {\n if (s in set) {flg = 0; break;}\n set[s] = true;\n s = p[s];\n }\n if (!flg) writeln(\"-1\");\n else writeln(ans);\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\nint[] p;\nbool[] e;\n\nint next(int s) {\n if (e[s - 1]) {\n return -1;\n }\n return p[s - 1];\n}\n\nvoid main() {\n int n, s, t; readf(\"%d %d %d\\n\", &n, &s, &t);\n p = stdin.readln.chomp.split.map!(to!int).array;\n e = new bool[n];\n int x = s;\n int i = 0;\n while (true) {\n if (x == t) {\n writeln(i);\n break;\n }\n i++;\n x = next(x);\n if (i == n) {\n writeln(-1);\n break;\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nint[] p;\n\nint next(int s) {\n return p[s - 1];\n}\n\nvoid main() {\n int n, s, t; readf(\"%d %d %d\\n\", &n, &s, &t);\n p = stdin.readln.chomp.split.map!(to!int).array;\n int x = s;\n int i = 0;\n while (true) {\n if (x == t) {\n writeln(i);\n break;\n }\n i++;\n x = next(x);\n if (i == n) {\n writeln(-1);\n break;\n }\n }\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint n, s, t;\n\twhile (readf (\" %s %s %s\", &n, &s, &t) > 0)\n\t{\n\t\ts--;\n\t\tt--;\n\t\tauto p = new int [n + 1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &p[i]);\n\t\t}\n\t\tint res = -1;\n\t\tp[] -= 1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s == t)\n\t\t\t{\n\t\t\t\tres = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ts = p[s];\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, s, t;\nmain_loop:\n\twhile (readf (\" %s %s %s\", &n, &s, &t) > 0)\n\t{\n\t\ts--;\n\t\tt--;\n\t\tauto p = new int [n + 1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s\", &p[i]);\n\t\t}\n\t\tp[] -= 1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s == t)\n\t\t\t{\n\t\t\t\twriteln (i);\n\t\t\t\tcontinue main_loop;\n\t\t\t}\n\t\t\ts = p[s];\n\t\t}\n\t\twriteln (-1);\n\t}\n}\n"}, {"source_code": "module sigod.codeforces.p285B;\n\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\n\nvoid main()\n{\n\tint n, s, t;\n\tstdin.readf(\"%s %s %s\", &n, &s, &t);\n\n\tif (s == t) {\n\t\tstdout.write(\"0\");\n\t\treturn;\n\t}\n\n\tstdin.readln();\n\tint[] p = read_array!(int)();\n\n\t--s;\n\t--t;\n\n\tint result = 0;\n\tint position = s;\n\n\twhile (position != t && p[position] != -1) {\n\t\tauto tmp = position;\n\t\tposition = p[position] - 1;\n\n\t\tp[tmp] = -1;\n\n\t\t++result;\n\t}\n\n\tif (position != t) result = -1;\n\n\tstdout.write(result);\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": [], "src_uid": "b01602b51b9103c0f31c3f50b32aa88d"} {"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\") string[] mat;\n\n void solve(long tc = -1)\n {\n foreach(i; 0 .. n)\n {\n foreach(j; 0 .. n)\n {\n if (mat.at(i).at(j) == '1')\n {\n if (i + 1 >= n || mat.at(i + 1).at(j) == '1' ||\n j + 1 >= n || mat.at(i).at(j + 1) == '1')\n {\n\n }\n else\n {\n writeln(\"NO\");\n return;\n }\n }\n }\n }\n writeln(\"YES\");\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 bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = new string[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts[i] = RD!string;\n\t\t}\n\t\t\n\t\tans[ti] = true;\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\tforeach (j; 0..n-1)\n\t\t\t{\n\t\t\t\tif (s[i][j] == '0') continue;\n\t\t\t\tif (s[i][j+1] == '0' && s[i+1][j] == '0')\n\t\t\t\t\tans[ti] = false;\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"}], "negative_code": [], "src_uid": "eea15ff7e939bfcc7002cacbc8a1a3a5"} {"source_code": "import std.stdio, std.conv, std.algorithm, std.range, std.math, std.string;\n\nclass Stack(T) {\n\tprivate Appender!(T[], T) app;\n\tprivate size_t size = 0;\n\n\tthis() {\n\t\tapp = appender(new T[0]);\n\t}\n\n\tvoid push(T value) {\n\t\tif (app.data().length > size) {\n\t\t\tapp.data[size] = value;\n\t\t} else {\n\t\t\tapp.put(value);\n\t\t}\n\t\t++size;\n\t}\n\n\tT get(size_t i) {\n\t\treturn app.data[i];\n\t}\n\n\tT pop() {\n\t\tif (size == 0) {\n\t\t\tthrow new RangeError();\n\t\t}\n\t\treturn app.data[--size];\n\t}\n\n\tbool empty() {\n\t\treturn size == 0;\n\t}\n\n\tsize_t length() {\n\t\treturn size;\n\t}\n}\n\nenum WinCond {\n\tunknown,\n\tW1, // first player can enforce a win\n\tW2 // second player can enforce a win \n}\nenum LoseCond {\n\tunknown,\n\tL1, // first player can enforce a lose\n\tL2 // second player can enforce a lose\n}\n\nclass StringNode {\n\tpublic StringNode[char.max] edges = null;\n\tWinCond win_cond;\n\tLoseCond lose_cond;\n}\n\nvoid addString(StringNode root, string str) {\n\tforeach (ch; str) {\n\t\tif (root.edges[ch] is null) {\n\t\t\troot.edges[ch] = new StringNode;\n\t\t}\n\t\troot = root.edges[ch];\n\t}\n}\n\nvoid calculateWinLoseState(StringNode root) {\n\t// alias ReturnType = Tuple!(WinCond, LoseCond);\n\tauto stack = new Stack!StringNode;\n\tstack.push(root);\n\n\tfor (size_t i = 0; i != stack.length(); ++i) {\n\t\tforeach (edge; stack.get(i).edges) {\n\t\t\tif (edge !is null) {\n\t\t\t\tstack.push(edge);\n\t\t\t}\n\t\t}\n\t}\n\n\twhile (!stack.empty()) {\n\t\tauto node = stack.pop();\n\t\tassert(node.win_cond == WinCond.unknown);\n\t\tassert(node.lose_cond == LoseCond.unknown);\n\t\tbool no_edges = true;\n\t\tforeach (i, edge; node.edges) {\n\t\t\tif (edge !is null) {\n\t\t\t\t//write(cast(char)i, \", \");\n\t\t\t\tno_edges = false;\n\t\t\t\tassert(edge.win_cond != WinCond.unknown);\n\t\t\t\tassert(edge.lose_cond != LoseCond.unknown);\n\t\t\t\tif (edge.win_cond == WinCond.W2) {\n\t\t\t\t\tnode.win_cond = WinCond.W1;\n\t\t\t\t}\n\t\t\t\tif (edge.lose_cond == LoseCond.L2) {\n\t\t\t\t\tnode.lose_cond = LoseCond.L1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (node.win_cond == WinCond.unknown) {\n\t\t\tnode.win_cond = WinCond.W2;\n\t\t}\n\t\tif (no_edges) {\n\t\t\tnode.lose_cond = LoseCond.L1;\n\t\t} else if (node.lose_cond == LoseCond.unknown) {\n\t\t\tnode.lose_cond = LoseCond.L2;\n\t\t}\n\t\t//writeln(\": \", node.win_cond, \" \", node.lose_cond);\n\t}\n}\n\nvoid main() {\n\tint n, k;\n\treadf(\"%s %s\\n\", &n, &k);\n\tauto root = new StringNode;\n\tforeach (_; 0..n) {\n\t\tstring line;\n\t\twhile (line.empty)\n\t\t\tline = readln().strip;\n\t\taddString(root, line);\n\t}\n\tcalculateWinLoseState(root);\n\tenum first = \"First\";\n\tenum second = \"Second\";\n\tswitch (root.win_cond) {\n\tdefault:\n\t\tassert(false);\n\tcase WinCond.W1:\n\t\tswitch(root.lose_cond) {\n\t\tdefault:\n\t\t\tassert(false);\n\t\tcase LoseCond.L1:\n\t\t\twriteln(first);\n\t\t\tbreak;\n\t\tcase LoseCond.L2:\n\t\t\twriteln(k % 2 == 0 ? second : first);\n\t\t}\n\t\tbreak;\n\tcase WinCond.W2:\n\t\twriteln(second);\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 LET = 26;\nimmutable char START = 'a';\nimmutable int MAX_N = 100_005;\nimmutable int NA = -1;\n\nstruct Node\n{\n\tint [LET] next = NA;\n}\n\nNode [MAX_N] t;\nint m;\nbool cur_outcome;\n\nbool play (int v)\n{\n\tassert (v != NA);\n\n\tbool ok = false;\n\tforeach (d; 0..LET)\n\t{\n\t\tif (t[v].next[d] != NA)\n\t\t{\n\t\t\tok = true;\n\t\t\tif (!play (t[v].next[d]))\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\tif (!ok)\n\t{\n\t\treturn cur_outcome;\n\t}\n\treturn false;\n}\n\nvoid build (const string [] s)\n{\n\tdebug {writeln (s);}\n\tt[] = Node.init;\n\tm = 1;\n\tforeach (cur; s)\n\t{\n\t\tint v = 0;\n\t\tforeach (let; cur)\n\t\t{\n\t\t\tdebug {writeln (v, ' ', let - START);}\n\t\t\tif (t[v].next[let - START] == NA)\n\t\t\t{\n\t\t\t\tt[v].next[let - START] = m;\n\t\t\t\tm++;\n\t\t\t}\n\t\t\tv = t[v].next[let - START];\n\t\t}\n\t}\n}\n\nbool win (bool outcome)\n{\n\tcur_outcome = outcome;\n\treturn play (0);\n}\n\nbool solve (const string [] s, int k)\n{\n\tbuild (s);\n\n\tbool can_win = win (false);\n\tbool can_lose = win (true);\n\tdebug {writeln (can_win, ' ', can_lose);}\n\n\tif (can_win && !can_lose)\n\t{\n\t\treturn k & 1;\n\t}\n\n\tif (!can_win && can_lose)\n\t{\n\t\treturn false;\n\t}\n\n\tif (can_win && can_lose)\n\t{\n\t\treturn true;\n\t}\n\n\tif (!can_win && !can_lose)\n\t{\n\t\treturn false;\n\t}\n\n\tassert (false);\n}\n\nvoid main ()\n{\n\tint n;\n\tint k;\n\twhile (readf (\" %s %s \", &n, &k) > 0)\n\t{\n\t\tauto s = new string [n];\n\t\tforeach (ref x; s)\n\t\t{\n\t\t\tx = readln ().strip ();\n\t\t}\n\n\t\twriteln (solve (s, k) ? \"First\" : \"Second\");\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;\nimmutable E = 26;\n\nint N, K;\nstring[] A;\n\nint V;\nint[][] g;\nint newNode() {\n\tg[V][] = -1;\n\treturn V++;\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = 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\tV = 0;\n\t\tg = new int[][](LIM, E);\n\t\tnewNode;\n\t\tforeach (i; 0 .. N) {\n\t\t\tint u = 0;\n\t\t\tforeach (c; A[i]) {\n\t\t\t\tconst e = c - 'a';\n\t\t\t\tif (g[u][e] == -1) {\n\t\t\t\t\tg[u][e] = newNode;\n\t\t\t\t}\n\t\t\t\tu = g[u][e];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] rts = new int[2];\n\t\tforeach (lf; 0 .. 2) {\n\t\t\tint[] dp = new int[V];\n\t\t\tforeach_reverse (u; 0 .. V) {\n\t\t\t\tbool isLeaf = true;\n\t\t\t\tdp[u] = 0;\n\t\t\t\tforeach (e; 0 .. E) {\n\t\t\t\t\tconst v = g[u][e];\n\t\t\t\t\tif (v != -1) {\n\t\t\t\t\t\tisLeaf = false;\n\t\t\t\t\t\tif (!dp[v]) {\n\t\t\t\t\t\t\tdp[u] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isLeaf && lf) {\n\t\t\t\t\tdp[u] = 1;\n\t\t\t\t}\n\t\t\t}\ndebug{\nwriteln(\"dp = \",dp);\n}\n\t\t\trts[lf] = dp[0];\n\t\t}\n\t\t\n\t\tint k = K;\n\t\tif (k >= 100) {\n\t\t\tk -= (k - 100) / 2 * 2;\n\t\t}\n\t\t\n\t\tint r = 0;\n\t\tforeach (_; 0 .. k) {\n\t\t\tr = rts[r];\n\t\t}\n\t\twriteln(r ? \"First\" : \"Second\");\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\n\nconst int MAX = 100005;\nstring[MAX] s;\nint n, k;\n\nstruct Node {\n char c;\n Node*[char] children;\n}\n\nvoid main() {\n readf(\" %s %s\", n, k);\n readln();\n foreach(i; 0..n) s[i] = readln().chomp();\n\n auto root = new Node();\n foreach(i; 0..n) {\n auto cur = root;\n foreach(c; s[i]) {\n if (c !in cur.children) {\n auto node = new Node();\n node.c = c;\n cur.children[c] = node;\n } \n cur = cur.children[c];\n }\n }\n\n auto canWinMatch = root.children.values.any!(node => can(node, true)); \n auto canLossMatch = root.children.values.any!(node => can(node, false)); \n bool firstWin;\n if (!canWinMatch) {\n firstWin = false;\n } else if (canLossMatch) {\n firstWin = true; \n } else {\n firstWin = (k % 2 == 1);\n }\n writeln(firstWin ? \"First\" : \"Second\");\n}\n\nbool can(Node* node, bool win) {\n if (node.children.empty) {\n return win;\n }\n auto result = true;\n foreach(c; node.children.keys) {\n result &= (can(node.children[c], win) == false);\n }\n return result; \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 LET = 26;\nimmutable char START = 'a';\nimmutable int MAX_N = 100_005;\nimmutable int NA = -1;\n\nstruct Node\n{\n\tint [LET] next = NA;\n}\n\nNode [MAX_N] t;\nint m;\nbool cur_outcome;\n\nbool play (int v)\n{\n\tassert (v != NA);\n\n\tbool ok = false;\n\tforeach (d; 0..LET)\n\t{\n\t\tif (t[v].next[d] != NA)\n\t\t{\n\t\t\tok = true;\n\t\t\tif (!play (t[v].next[d]))\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\tif (!ok)\n\t{\n\t\treturn cur_outcome;\n\t}\n\treturn false;\n}\n\nvoid build (const string [] s)\n{\n\tdebug {writeln (s);}\n\tt[] = Node.init;\n\tm = 1;\n\tforeach (cur; s)\n\t{\n\t\tint v = 0;\n\t\tforeach (let; cur)\n\t\t{\n\t\t\tdebug {writeln (v, ' ', let - START);}\n\t\t\tif (t[v].next[let - START] == NA)\n\t\t\t{\n\t\t\t\tt[v].next[let - START] = m;\n\t\t\t\tm++;\n\t\t\t}\n\t\t\tv = t[v].next[let - START];\n\t\t}\n\t}\n}\n\nbool win (bool outcome)\n{\n\tcur_outcome = outcome;\n\treturn play (0);\n}\n\nbool solve (const string [] s, int k)\n{\n\tbuild (s);\n\n\tbool can_win = win (false);\n\tbool can_lose = win (true);\n\n\tif (can_win && !can_lose)\n\t{\n\t\treturn k & 1;\n\t}\n\n\tif (!can_win && can_lose)\n\t{\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nvoid main ()\n{\n\tint n;\n\tint k;\n\twhile (readf (\" %s %s \", &n, &k) > 0)\n\t{\n\t\tauto s = new string [n];\n\t\tforeach (ref x; s)\n\t\t{\n\t\t\tx = readln ().strip ();\n\t\t}\n\n\t\twriteln (solve (s, k) ? \"First\" : \"Second\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.algorithm, std.range, std.math, std.string;\n\nclass Stack(T) {\n\tprivate Appender!(T[], T) app;\n\tprivate size_t size = 0;\n\n\tthis() {\n\t\tapp = appender(new T[0]);\n\t}\n\n\tvoid push(T value) {\n\t\tif (app.data().length > size) {\n\t\t\tapp.data[size] = value;\n\t\t} else {\n\t\t\tapp.put(value);\n\t\t}\n\t\t++size;\n\t}\n\n\tT get(size_t i) {\n\t\treturn app.data[i];\n\t}\n\n\tT pop() {\n\t\tif (size == 0) {\n\t\t\tthrow new RangeError();\n\t\t}\n\t\treturn app.data[--size];\n\t}\n\n\tbool empty() {\n\t\treturn size == 0;\n\t}\n\n\tsize_t length() {\n\t\treturn size;\n\t}\n}\n\nenum WinCond {\n\tunknown,\n\tW1, // first player can enforce a win\n\tW2 // second player can enforce a win \n}\nenum LoseCond {\n\tunknown,\n\tL1, // first player can enforce a lose\n\tL2 // second player can enforce a lose\n}\n\nclass StringNode {\n\tpublic StringNode[char.max] edges = null;\n\tWinCond win_cond;\n\tLoseCond lose_cond;\n}\n\nvoid addString(StringNode root, string str) {\n\tforeach (ch; str) {\n\t\tif (root.edges[ch] is null) {\n\t\t\troot.edges[ch] = new StringNode;\n\t\t}\n\t\troot = root.edges[ch];\n\t}\n}\n\nvoid calculateWinLoseState(StringNode root) {\n\t// alias ReturnType = Tuple!(WinCond, LoseCond);\n\tauto stack = new Stack!StringNode;\n\tstack.push(root);\n\n\tfor (size_t i = 0; i != stack.length(); ++i) {\n\t\tforeach (edge; stack.get(i).edges) {\n\t\t\tif (edge !is null) {\n\t\t\t\tstack.push(edge);\n\t\t\t}\n\t\t}\n\t}\n\n\twhile (!stack.empty()) {\n\t\tauto node = stack.pop();\n\t\tassert(node.win_cond == WinCond.unknown);\n\t\tassert(node.lose_cond == LoseCond.unknown);\n\t\tbool no_edges = true;\n\t\tforeach (edge; node.edges) {\n\t\t\tif (edge !is null) {\n\t\t\t\tno_edges = false;\n\t\t\t\tassert(edge.win_cond != WinCond.unknown);\n\t\t\t\tassert(edge.lose_cond != LoseCond.unknown);\n\t\t\t\tif (edge.win_cond == WinCond.W2) {\n\t\t\t\t\tnode.win_cond = WinCond.W1;\n\t\t\t\t}\n\t\t\t\tif (edge.lose_cond == LoseCond.L2) {\n\t\t\t\t\tnode.lose_cond = LoseCond.L1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (node.win_cond == WinCond.unknown) {\n\t\t\tnode.win_cond = WinCond.W2;\n\t\t}\n\t\tif (no_edges) {\n\t\t\tnode.lose_cond = LoseCond.L1;\n\t\t} else {\n\t\t\tnode.lose_cond = LoseCond.L2;\n\t\t}\n\t}\n}\n\nvoid main() {\n\tint n, k;\n\treadf(\" %s %s \", &n, &k);\n\tauto root = new StringNode;\n\tforeach (_; 0..n) {\n\t\tstring line;\n\t\treadf(\" %s \", &line);\n\t\taddString(root, line.strip);\n\t}\n\tcalculateWinLoseState(root);\n\tenum first = \"First\";\n\tenum second = \"Second\";\n\tswitch (root.win_cond) {\n\tdefault:\n\t\tassert(false);\n\tcase WinCond.W1:\n\t\tswitch(root.lose_cond) {\n\t\tdefault:\n\t\t\tassert(false);\n\t\tcase LoseCond.L1:\n\t\t\twriteln(first);\n\t\t\tbreak;\n\t\tcase LoseCond.L2:\n\t\t\twriteln(k % 2 == 0 ? second : first);\n\t\t}\n\t\tbreak;\n\tcase WinCond.W2:\n\t\tswitch(root.lose_cond) {\n\t\tdefault:\n\t\t\tassert(false);\n\t\tcase LoseCond.L1:\n\t\t\twriteln(k % 2 == 0 ? first : second);\n\t\t\tbreak;\n\t\tcase LoseCond.L2:\n\t\t\twriteln(second);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\n\nconst int MAX = 100005;\nstring[MAX] s;\nint n, k;\n\nstruct Node {\n char c;\n Node*[char] children;\n}\n\nvoid main() {\n readf(\" %s %s\", n, k);\n readln();\n foreach(i; 0..n) s[i] = readln().chomp();\n\n auto root = new Node();\n foreach(i; 0..n) {\n auto cur = root;\n foreach(c; s[i]) {\n if (c !in cur.children) {\n auto node = new Node();\n node.c = c;\n cur.children[c] = node;\n } \n cur = cur.children[c];\n }\n }\n\n auto canWinMatch = root.children.values.any!(node => can(node, true)); \n auto canLossMatch = root.children.values.any!(node => can(node, false)); \n auto canWin = canWinMatch;\n foreach(i; 0..k-1) {\n canWin = (canLossMatch && canWin) || (canWinMatch && !canWin);\n }\n writeln(canWin ? \"First\" : \"Second\");\n}\n\nbool can(Node* node, bool win) {\n if (node.children.empty) {\n return win;\n }\n auto result = false;\n foreach(c; node.children.keys) {\n result &= (can(node.children[c], win) == false);\n }\n return result; \n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\n\nconst int MAX = 100005;\nstring[MAX] s;\nint n, k;\n\nstruct Node {\n char c;\n Node*[char] children;\n}\n\nvoid main() {\n readf(\" %s %s\", n, k);\n readln();\n foreach(i; 0..n) s[i] = readln().chomp();\n\n auto root = new Node();\n foreach(i; 0..n) {\n auto cur = root;\n foreach(c; s[i]) {\n if (c !in cur.children) {\n auto node = new Node();\n node.c = c;\n cur.children[c] = node;\n } \n cur = cur.children[c];\n }\n }\n\n auto canWinMatch = root.children.values.any!(node => can(node, true)); \n auto canLossMatch = root.children.values.any!(node => can(node, false)); \n auto canWin = canWinMatch;\n foreach(i; 0..k-1) {\n canWin = (canLossMatch && canWin) || (canWinMatch && !canWin);\n }\n writeln(canWin ? \"First\" : \"Second\");\n}\n\nbool can(Node* node, bool win) {\n if (node.children.empty) {\n return win;\n }\n auto result = false;\n foreach(c; node.children.keys) {\n result |= (can(node.children[c], win) == false);\n }\n return result; \n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\n\nconst int MAX = 100005;\nstring[MAX] s;\nint n, k;\n\nstruct Node {\n char c;\n Node*[char] children;\n}\n\nvoid main() {\n readf(\" %s %s\", n, k);\n readln();\n foreach(i; 0..n) s[i] = readln().chomp();\n\n auto root = new Node();\n foreach(i; 0..n) {\n auto cur = root;\n foreach(c; s[i]) {\n if (c !in cur.children) {\n auto node = new Node();\n node.c = c;\n cur.children[c] = node;\n } \n cur = cur.children[c];\n }\n }\n\n bool firstCanWin = root.children.values.any!(node => canWin(node)); \n if (firstCanWin) {\n writeln(k % 2 == 0 ? \"SECOND\" : \"FIRST\");\n } else {\n writeln(\"SECOND\");\n }\n}\n\nbool canWin(Node* node) {\n if (node.children.empty) {\n return true;\n }\n auto result = false;\n foreach(c; node.children.keys) {\n result |= (canWin(node.children[c]) == false);\n }\n return result; \n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\n\nconst int MAX = 100005;\nstring[MAX] s;\nint n, k;\n\nstruct Node {\n char c;\n Node*[char] children;\n}\n\nvoid main() {\n readf(\" %s %s\", n, k);\n readln();\n foreach(i; 0..n) s[i] = readln().chomp();\n\n auto root = new Node();\n foreach(i; 0..n) {\n auto cur = root;\n foreach(c; s[i]) {\n if (c !in cur.children) {\n auto node = new Node();\n node.c = c;\n cur.children[c] = node;\n } \n cur = cur.children[c];\n }\n }\n\n bool firstCanWin = root.children.values.any!(node => canWin(node)); \n if (firstCanWin) {\n writeln(k % 2 == 0 ? \"Second\" : \"First\");\n } else {\n writeln(\"Second\");\n }\n}\n\nbool canWin(Node* node) {\n if (node.children.empty) {\n return true;\n }\n auto result = false;\n foreach(c; node.children.keys) {\n result |= (canWin(node.children[c]) == false);\n }\n return result; \n}\n"}], "src_uid": "2de867c08946eade5f674a98b377343d"} {"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 a = next!int(n);\n auto df = new byte[](n);\n df[n - 1] = 0;\n int sum = a[n - 1];\n foreach_reverse(i; 0 .. n - 1)\n {\n auto ai = a[i];\n assert(sum >= 0 && sum <= a[i + 1]);\n if (sum >= ai) {df[i] = 1; df[i + 1] ^= 1; sum = sum - ai;}\n else {df[i] = 0; df[i + 1] ^= 1; sum = ai - sum;}\n }\n auto f = new byte[](n);\n f[0] = df[0];\n foreach(i; 1 .. n)\n f[i] = f[i - 1] ^ df[i];\n f.map!(fi => fi == 0? '+' : '-').each!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 std.math;\nimport std.stdio;\n\nint n;\n\nint main ()\n{\n\twhile ((readf (\" %d\", &n) >= 0) && !stdin.eof ())\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\n\t\tauto r = new bool [n];\n\t\tr[] = true;\n\t\tauto s = a[n - 1];\n\t\tfor (auto i = n - 2; i >= 0; i--)\n\t\t{\n\t\t\tif (s > 0)\n\t\t\t{\n\t\t\t\tr[i] = false;\n\t\t\t\ts -= a[i];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tr[i] = true;\n\t\t\t\ts += a[i];\n\t\t\t}\n\t\t\tassert (abs (s) <= a[i]);\n\t\t}\n\n\t\tif (s < 0)\n\t\t{\n\t\t\tr[] = r[] ^ 1;\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\twritef (\"%s\", r[i] ? '+' : '-');\n\t\t}\n\t\twritef (\"\\n\");\n\t}\n\treturn 0;\n}\n"}], "negative_code": [], "src_uid": "30f64b963310911196ebf5d624c01cc3"} {"source_code": "import std.stdio;\nimport std.string;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tif (a%2==0)\n\t{\n\t\twriteln(a/2);\n\t\tfor (int i=0; i0)\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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]= 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 (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 b = RDA!int;\n\t\tbool[int] set;\n\t\tlong cnt;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tif (set.get(b[i], false))\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\tset.remove(b[i]);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcnt += set.length*2;\n\t\t\twhile (a.front != b[i])\n\t\t\t{\n\t\t\t\tset[a.front] = true;\n\t\t\t\ta.popFront;\n\t\t\t\tcnt += 2;\n\t\t\t}\n\t\t\ta.popFront;\n\t\t\t++cnt;\n\t\t\tdebug writeln(\"cnt:\", cnt);\n\t\t}\n\t\tans[ti] = cnt;\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 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, m = rint;\n\t\tlong[] as = rlong(n).map!(x => x - 1).array;\n\t\tlong[] bs = rlong(m).map!(x => x - 1).array;\n\t\tlog(\"as:\", as);\n\t\tlog(\"bs:\", bs);\n\n\t\tlong[long] az;\n\t\tforeach(i, a; as) az[a] = i.to!long;\n\t\tlog(\"az:\", az);\n\n\t\tlong[] us = bs.map!(x => az[x]).array;\n\t\tlog(\"us:\", us);\n\n\t\tlong ans;\n\t\tlong umax = 0;\n\t\tforeach(i, u; us){\n\t\t\tif(u < umax) ans += 1;\n\t\t\telse{\n\t\t\t\tans += (u - i) *2 + 1;\n\t\t\t\tumax = u;\n\t\t\t}\n\t\t\tlog(\"i:\", i, \"u:\", u, \"umax:\", umax, \"ans:\", ans);\n\t\t}\n\t\tans.writeln;\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.stdio;\n\nvoid solve() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto A = readln.split.map!(x => x.to!int-1).array;\n auto B = readln.split.map!(x => x.to!int-1).array;\n auto C = new int[](N);\n foreach (i; 0..N) C[A[i]] = i;\n long ans = 0;\n int mx = -1;\n long cnt = 0;\n\n foreach (b; B) {\n if (C[b] < mx) {\n ans += 1;\n } else {\n mx = C[b];\n ans += (C[b] - cnt) * 2 + 1;\n }\n cnt += 1;\n }\n\n ans.writeln;\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) solve;\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 auto nt = r.next!uint;\n foreach (tid; 0 .. nt) {\n immutable n = r.next!uint;\n immutable m = r.next!uint;\n auto a = r.nextA!uint (n);\n auto b = r.nextA!uint (m);\n a[] -= 1;\n b[] -= 1;\n auto rank = new uint[n];\n foreach (i; 0 .. n) {\n rank[a[i]] = i;\n }\n long res = m;\n int e;\n int cur;\n foreach (i; 0 .. m) {\n if (rank[b[i]] > cur) {\n cur = rank[b[i]];\n res += 2 * (rank[b[i]] + e); \n }\n --e;\n }\n writeln (res);\n }\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 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, m = rint;\n\t\tint[] as = rint(n).map!(x => x - 1).array;\n\t\tint[] bs = rint(m).map!(x => x - 1).array;\n\t\tlog(\"as:\", as);\n\t\tlog(\"bs:\", bs);\n\n\t\tint[] az = new int[](n);\n\t\tforeach(int i, a; as) az[a] = i;\n\t\tlog(\"az:\", az);\n\n\t\tint[] us = bs.map!(x => az[x]).array;\n\t\tlog(\"us:\", us);\n\n\t\tint ans;\n\t\tint umax = 0;\n\t\tforeach(int i, u; us){\n\t\t\tif(u < umax) ans += 1;\n\t\t\telse{\n\t\t\t\tans += (u - i) *2 + 1;\n\t\t\t\tumax = u;\n\t\t\t}\n\t\t\tlog(\"i:\", i, \"u:\", u, \"umax:\", umax, \"ans:\", ans);\n\t\t}\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 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 b = RDA!int;\n\t\tbool[int] set;\n\t\tint cnt;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tif (set.get(b[i], false))\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\tset.remove(b[i]);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tcnt += set.length*2;\n\t\t\twhile (a.front != b[i])\n\t\t\t{\n\t\t\t\tset[a.front] = true;\n\t\t\t\ta.popFront;\n\t\t\t\tcnt += 2;\n\t\t\t}\n\t\t\ta.popFront;\n\t\t\t++cnt;\n\t\t\tdebug writeln(\"cnt:\", cnt);\n\t\t}\n\t\tans[ti] = cnt;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "ad434880e047992d2c77e0fe0ce0976f"} {"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 = 26;\n\nchar chr(int u) {\n return cast(char)('a' + u);\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 debug {\n writeln(\"S = \", S);\n stdout.flush;\n }\n \n auto freq = new int[V];\n foreach (i; 0 .. N) {\n ++freq[S[i] - 'a'];\n }\n \n int ansLen;\n auto ans = new char[N];\n ans[] = '?';\n foreach (u; 0 .. V) {\n if (freq[u] == N) {\n ans[] = chr(u);\n goto done;\n }\n }\n foreach (u; 0 .. V) {\n if (freq[u] == 1) {\n ans[ansLen++] = chr(u);\n foreach (v; 0 .. V) {\n if (u != v) {\n foreach (_; 0 .. freq[v]) {\n ans[ansLen++] = chr(v);\n }\n }\n }\n goto done;\n }\n }\n {\n int u0 = -1;\n foreach (u; 0 .. V) {\n if (freq[u] > 0) {\n u0 = u;\n break;\n }\n }\n assert(~u0);\n if (freq[u0] <= N / 2 + 1) {\n ans[0] = chr(u0);\n int pos = 1;\n foreach (_; 1 .. freq[u0]) {\n ans[pos] = chr(u0);\n pos += 2;\n }\n pos = 0;\n foreach (v; u0 + 1 .. V) {\n foreach (_; 0 .. freq[v]) {\n for (; ans[pos] != '?'; ++pos) {}\n ans[pos] = chr(v);\n }\n }\n } else {\n int u1 = -1;\n foreach (u; u0 + 1 .. V) {\n if (freq[u] > 0) {\n u1 = u;\n break;\n }\n }\n assert(~u1);\n int u2 = -1;\n foreach (u; u1 + 1 .. V) {\n if (freq[u] > 0) {\n u2 = u;\n break;\n }\n }\n if (~u2) {\n ans[ansLen++] = chr(u0);\n ans[ansLen++] = chr(u1);\n foreach (_; 1 .. freq[u0]) ans[ansLen++] = chr(u0);\n ans[ansLen++] = chr(u2);\n foreach (_; 1 .. freq[u1]) ans[ansLen++] = chr(u1);\n foreach (_; 1 .. freq[u2]) ans[ansLen++] = chr(u2);\n foreach (u; u2 + 1 .. V) {\n foreach (_; 0 .. freq[u]) ans[ansLen++] = chr(u);\n }\n } else {\n ans[ansLen++] = chr(u0);\n foreach (_; 0 .. freq[u1]) ans[ansLen++] = chr(u1);\n foreach (_; 1 .. freq[u0]) ans[ansLen++] = chr(u0);\n }\n }\n }\n done:{}\n writeln(ans);\n \n debug {\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = S[i] - 'a';\n }\n A.sort;\n int mn = N + 1;\n int[] ams;\n do {\n auto fail = new int[N + 1];\n int j = fail[0] = -1;\n foreach (i; 0 .. N) {\n for (; ~j && A[j] != A[i]; j = fail[j]) {}\n fail[i + 1] = ++j;\n }\n const cost = fail.maxElement;\n // writeln(A, \": \", fail, \" \", cost);\n if (chmin(mn, cost)) {\n ams = A.dup;\n }\n } while (A.nextPermutation);\n writeln(\"mn = \", mn);\n string brt;\n foreach (i; 0 .. N) {\n brt ~= chr(ams[i]);\n }\n writeln(\"brt = \", brt);\n assert(brt == ans);\n }\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 letters = 26;\r\n\r\nstring solve (string s)\r\n{\r\n\tint [letters] d;\r\n\tforeach (ref c; s)\r\n\t{\r\n\t\td[c - 'a'] += 1;\r\n\t}\r\n\r\n\tforeach (let; 0..letters)\r\n\t{\r\n\t\tif (d[let] == 1)\r\n\t\t{\r\n\t\t\tstring res;\r\n\t\t\tres ~= cast (char) (let + 'a');\r\n\t\t\td[let] -= 1;\r\n\t\t\tforeach (x; 0..letters)\r\n\t\t\t{\r\n\t\t\t\tforeach (y; 0..d[x])\r\n\t\t\t\t{\r\n\t\t\t\t\tres ~= cast (char) (x + 'a');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn res;\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (let; 0..letters)\r\n\t{\r\n\t\tif (d[let] > 0)\r\n\t\t{\r\n\t\t\tstring res;\r\n\t\t\tres ~= cast (char) (let + 'a');\r\n\t\t\td[let] -= 1;\r\n\t\t\tstring [2] add;\r\n\t\t\tforeach (x; 0..letters)\r\n\t\t\t{\r\n\t\t\t\tforeach (y; 0..d[x])\r\n\t\t\t\t{\r\n\t\t\t\t\tadd[x > let] ~= cast (char) (x + 'a');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif (add[0].length <= add[1].length + 1)\r\n\t\t\t{\r\n\t\t\t\twhile (!add[0].empty || !add[1].empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tforeach (v; 0..2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!add[v].empty)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tres ~= add[v][0];\r\n\t\t\t\t\t\t\tadd[v].popFront ();\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\treturn res;\r\n\t\t\t}\r\n\r\n\t\t\tif (add[1].empty || add[1].front == add[1].back)\r\n\t\t\t{\r\n\t\t\t\tres ~= add[1];\r\n\t\t\t\tres ~= add[0];\r\n\t\t\t\treturn res;\r\n\t\t\t}\r\n\r\n\t\t\tauto second = add[1][0];\r\n\t\t\tres ~= second;\r\n\t\t\tadd[1].popFront ();\r\n\t\t\tres ~= add[0];\r\n\t\t\tforeach (i, ref c; add[1])\r\n\t\t\t{\r\n\t\t\t\tif (c != second)\r\n\t\t\t\t{\r\n\t\t\t\t\tres ~= c;\r\n\t\t\t\t\tres ~= add[1][0..i];\r\n\t\t\t\t\tres ~= add[1][i + 1..$];\r\n\t\t\t\t\treturn res;\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}\r\n\r\n\tassert (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\twriteln (solve (s));\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "80fd03a1cbdef86a5f00ada85e026890"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\n\tif (n == 1)\n\t\twriteln(\"9 8\");\n\telse\n\t{\n\t\twriteln(n*3, \" \", n*2);\n\t}\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 int a = cin.read_int;\n writeln(a * 9, \" \", a * 8);\n } \n}"}, {"source_code": "import std.stdio;\nbool isSimple(int a)\n{\n\tif (a!=0)\n\t{\n\t\tint c=0;\n\t\tfor (int i=1; i2)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t}\n\telse\n\t{\n\t\treturn false;\n\t}\n}\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint c=0;\n\tint b=a;\n\twhile (true)\n\t{\n\t\tb=b+1;\n\t\tc=c+1;\n\t\tif (!(isSimple(b)) && !(isSimple(c)))\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t}\n\twriteln(b);\n\twriteln(c);\n\treturn 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 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 a = cin.read_int;\n writeln(a * 8, \" \", a * 8);\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 a = cin.read_int;\n writeln(a * 3, \" \", a * 2);\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 a = cin.read_int;\n writeln(a * 3 - a * 2);\n } \n}"}, {"source_code": "import std.stdio;\nbool isSimple(int a)\n{\n\tint c=0;\n\tfor (int i=1; i2)\n\t{\n\t\treturn false;\n\t}\n\telse\n\t{\n\t\treturn true;\n\t}\n}\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint c=4;\n\tint b=0;\n\twhile (true)\n\t{\n\t\tb=a+c;\n\t\tc=c+2;\n\t\tif (!(isSimple(b)))\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t}\n\twriteln(b);\n\twriteln(c);\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; }\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\n\tif (n == 1)\n\t\twriteln(\"9 8\");\n\telse\n\t{\n\t\twriteln(n*2, \" \", n*3);\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "59d5e5ed2bc4b316e950e2a4dbc99d68"} {"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 kss = new int[][26];\n foreach (k; 0 .. L) {\n kss[S[k] - 'a'] ~= k;\n }\n int ans;\n foreach (a; 0 .. 26) {\n int mx;\n foreach (x; 0 .. L) {\n auto cnt = new int[26];\n foreach (k; kss[a]) {\n ++cnt[S[(k + x) % L] - 'a'];\n }\n int num1;\n foreach (b; 0 .. 26) {\n if (cnt[b] == 1) {\n ++num1;\n }\n }\n chmax(mx, num1);\n }\n ans += mx;\n }\n writefln(\"%.10f\", ans / cast(real)(L));\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\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\ts = s ~ s;\n\t\treal invN = 1.0 / n;\n\t\treal res = 0.0;\n\t\tforeach (c; 'a'..'z' + 1)\n\t\t{\n\t\t\tstring [] t;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (s[i] == c)\n\t\t\t\t{\n\t\t\t\t\tt ~= s[i..i + n];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint temp = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tint [letters] d;\n\t\t\t\tforeach (r; t)\n\t\t\t\t{\n\t\t\t\t\td[r[i] - 'a'] += 1;\n\t\t\t\t}\n\t\t\t\tint cur = 0;\n\t\t\t\tforeach (e; 0..letters)\n\t\t\t\t{\n\t\t\t\t\tif (d[e] == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttemp = max (temp, cur);\n\t\t\t}\n\t\t\tres += temp * invN;\n\t\t}\n\t\twritefln (\"%.20f\", res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "4c92218ccbab7d142c2cbb6dd54c510a"} {"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\tlong res = 0;\n\t\tlong saved = 0;\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tauto pairs = a[i] / 2;\n\t\t\tsaved += pairs;\n\t\t\tif (a[i] % 2 == 1 && saved > 0)\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t\tsaved -= 1;\n\t\t\t}\n\t\t}\n\t\tres += saved * 2 / 3;\n\t\twriteln (res);\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.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 prev = 0;\n long ans = 0;\n foreach (e; arr) {\n auto withprev = min(prev, e / 2);\n e -= withprev * 2;\n prev -= withprev;\n ans += withprev;\n \n auto triple = e / 3;\n e -= triple * 3;\n ans += triple;\n \n prev += e;\n }\n \n ans.writeln;\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\nint N;\nlong[] A;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n long ans;\n long sum;\n foreach (i; 0 .. N) {\n sum += A[i];\n const tmp = min(sum / 3, A[i] / 2);\n ans += tmp;\n sum -= tmp * 3;\n }\n writeln(ans);\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 auto arr = readln.chomp.split.map!(to!int).array;\n \n int prev = 0;\n long ans = 0;\n foreach (e; arr) {\n auto withprev = min(prev*2, e);\n e -= withprev;\n prev -= withprev / 2;\n ans += withprev / 2;\n \n auto triple = e / 3;\n e -= triple * 3;\n ans += triple;\n \n prev += 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.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 prev = 0;\n long ans = 0;\n foreach (e; arr) {\n ans += e / 3;\n e = e % 3;\n if (e == 2 && prev > 0) { \n ans += 1;\n e -= 2;\n prev -= 1;\n }\n \n prev += e;\n }\n \n ans.writeln;\n}"}], "src_uid": "a8f3e94845cb15a483ce8f774779efac"} {"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 Seg = Tuple!(int, \"s\", int, \"t\", int, \"d\", int, \"v\");\nalias Env = Tuple!(int, \"v\", int, \"d\", int, \"t\");\n\nvoid main() {\n int n, m, k;\n scan(n, m, k);\n\n auto s = new Seg[](k);\n\n foreach (i ; 0 .. k) {\n int si, ti, di, vi;\n \n scan(si, ti, di, vi);\n si--, ti--, di--;\n s[i] = Seg(si, ti, di, vi);\n }\n\n s.sort();\n\n auto bh = new BinaryHeap!(Array!Env, \"a < b\")();\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 while (!s.empty && s.front.s <= i) {\n bh.insert(Env(s.front.v, s.front.d, s.front.t));\n s.popFront();\n }\n while (!bh.empty && bh.front.t < i) {\n bh.popFront();\n }\n\n if (bh.empty) {\n foreach (j ; 0 .. m + 1) {\n dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);\n }\n continue;\n }\n\n int v = bh.front.v;\n int d = bh.front.d;\n\n debug {\n writeln(v, \" \", d);\n }\n\n foreach (j ; 0 .. m + 1) {\n if (dp[i][j] == inf6) continue;\n // いたずらした場合\n if (j < m) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);\n // しなかった場合\n dp[d + 1][j] = min(dp[d + 1][j], dp[i][j] + v);\n }\n }\n\n debug {\n writefln(\"%(%s\\n%)\", dp);\n }\n\n long ans = inf6;\n\n foreach (j ; 0 .. m + 1) {\n ans = min(ans, dp[n][j]);\n }\n\n writeln(ans);\n}\n\n\nstruct UnionFind {\n private {\n int _size;\n int[] _parent;\n long[] wa;\n int bcnt;\n bool[] bad;\n int[] hen;\n }\n\n this(int N, long[] x) \n in {\n assert(N > 0);\n }\n body {\n _size = N;\n _parent = new int[](_size);\n foreach (i ; 0 .. _size) {\n _parent[i] = i;\n }\n wa = new long[](N);\n wa[] = x.dup;\n bad = new bool[](N);\n hen = new int[](N);\n }\n\n int findRoot(int x)\n in {\n assert(0 <= x && x < _size);\n }\n body {\n if (_parent[x] != x) {\n _parent[x] = findRoot(_parent[x]);\n }\n\n return _parent[x];\n }\n\n bool same(int x, int y)\n in {\n assert(0 <= x && x < _size);\n assert(0 <= y && y < _size);\n }\n body {\n return findRoot(x) == findRoot(y);\n }\n\n void merge(int x, int y)\n in {\n assert(0 <= x && x < _size);\n assert(0 <= y && y < _size);\n }\n body {\n int u = findRoot(x);\n int v = findRoot(y);\n\n if (u == v) return;\n\n _parent[v] = u;\n wa[u] += wa[v];\n wa[v] = 0;\n\n hen[u] += hen[v] + 1;\n hen[v] = 0;\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\nalias Block = Tuple!(int, \"s\", int, \"t\", int, \"d\", long, \"w\");\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 K = s[2];\n auto B = new Block[](K);\n foreach (i; 0..K) {\n s = readln.split.map!(to!int);\n B[i] = Block(s[0], s[1], s[2], s[3].to!long);\n }\n\n B.sort!\"a[0] < b[0]\";\n auto pq = new BinaryHeap!(Array!Block, \"a[3] == b[3] ? a[2] < b[2] : a[3] < b[3]\");\n int p = 0;\n\n auto dp = new long[][](N+2, M+1);\n foreach (i; 0..N+2) dp[i][] = INF;\n dp[1][0] = 0;\n\n foreach (i; 1..N+1) {\n while (!pq.empty && pq.front.t < i) pq.removeFront;\n while (p < K && B[p].s == i) pq.insert(B[p++]);\n auto next = pq.empty ? Block(-1, -1, -1, -INF) : pq.front;\n\n foreach (j; 0..M+1) {\n if (next.s == -1) {\n dp[i+1][j] = min(dp[i+1][j], dp[i][j]);\n } else {\n dp[next.d+1][j] = min(dp[next.d+1][j], dp[i][j] + next.w);\n if (j < M) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);\n }\n }\n }\n\n dp[N+1].reduce!min.writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.stdio;\nimport std.typecons;\n\nalias Envelope = Tuple !(int, q{w}, int, q{d}, int, q{s}, int, q{t}, int, q{i});\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\tn += 1;\n\t\tauto a = new Envelope [k];\n\t\tauto add = new int [] [n + 1];\n\t\tauto rem = new int [] [n + 1];\n\t\tforeach (i, ref e; a)\n\t\t{\n\t\t\treadf (\" %s %s %s %s\", &e.s, &e.t, &e.d, &e.w);\n\t\t\te.i = i;\n\t\t\tadd[e.s] ~= i;\n\t\t\trem[e.t] ~= i;\n\t\t}\n\n\t\tauto t = redBlackTree !(Envelope) ();\n\t\tauto f = new long [] [] (n + 1, m + 1);\n\t\tforeach (ref line; f)\n\t\t{\n\t\t\tline[] = long.max / 2;\n\t\t}\n\t\tf[0][0] = 0;\n\t\tforeach (x; 0..n)\n\t\t{\n\t\t\tforeach (z; add[x])\n\t\t\t{\n\t\t\t\tt.insert (a[z]);\n\t\t\t}\n\t\t\tforeach (y; 0..m + 1)\n\t\t\t{\n\t\t\t\tauto ny = y + !t.empty;\n\t\t\t\tif (ny <= m)\n\t\t\t\t{\n\t\t\t\t\tf[x + 1][ny] =\n\t\t\t\t\t min (f[x + 1][ny],\n\t\t\t\t\t f[x][y]);\n\t\t\t\t}\n\t\t\t\tif (!t.empty)\n\t\t\t\t{\n\t\t\t\t\tf[t.back.d + 1][y] =\n\t\t\t\t\t min (f[t.back.d + 1][y],\n\t\t\t\t\t f[x][y] + t.back.w);\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (z; rem[x])\n\t\t\t{\n\t\t\t\tt.removeKey (a[z]);\n\t\t\t}\n\t\t}\n\t\twriteln (f[n].minElement);\n\t}\n}\n"}], "negative_code": [], "src_uid": "7c4c594185ed0f6a31d49e292e6f85dc"} {"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, k;\n scan(n, k);\n\n auto h = readln.split.to!(int[]);\n\n auto hmin = h.reduce!min;\n auto hmax = h.reduce!max;\n\n if (hmin == hmax) {\n writeln(0);\n return;\n }\n\n auto cnt = new int[](hmax + 1);\n foreach (i ; 0 .. n) {\n cnt[h[i]]++;\n }\n\n foreach_reverse (i ; 0 .. hmax) {\n cnt[i] += cnt[i+1];\n }\n\n debug {\n stderr.writeln(cnt);\n }\n\n int ans;\n int store;\n\n foreach_reverse (i ; 0 .. hmax + 1) {\n if (i == hmin) {\n ans++;\n break;\n }\n if (store + cnt[i] > k) {\n ans++;\n store = cnt[i];\n }\n else {\n store += cnt[i];\n }\n }\n\n writeln(ans);\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\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": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, k;\n rd(n, k);\n auto a = readln.split.to!(int[]);\n\n auto all = reduce!((res, val) => (res && val == a[0]))(true, a);\n if (all) {\n writeln(0);\n return;\n }\n auto freq = new int[](3 * 10 ^^ 5);\n foreach (val; a)\n freq[val]++;\n auto mn = reduce!(min)(a), mx = reduce!(max)(a);\n int num = 0, s = 0;\n for (int h = mx; h > mn; h--) {\n freq[h] += freq[h + 1];\n if ((s += freq[h]) > k) {\n num++;\n s = freq[h];\n }\n }\n writeln(num + (s > 0));\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, k;\n rd(n, k);\n auto a = readln.split.to!(int[]);\n\n auto all = reduce!((res, val) => (res && val == a[0]))(true, a);\n if (all) {\n writeln(0);\n return;\n }\n auto freq = new int[](3 * 10 ^^ 5);\n foreach (val; a)\n freq[val]++;\n auto mn = reduce!(min)(a), mx = reduce!(max)(a);\n int num = 0;\n for (int h = mx, s = 0; h >= mn; h--) {\n freq[h] += freq[h + 1];\n if ((s += freq[h]) > k) {\n num++;\n s = freq[h];\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": "676729309dfbdf4c9d9d7c457a129608"} {"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 core.bitop;\nimport std.exception;\n\nbool check (int i) {\n return 0 == ((i + 1) & i);\n}\n\nvoid main() {\n int x;\n readf (\" %d\", &x);\n int[] a;\n if (check (x)) {\n writeln (0);\n return;\n }\n foreach (ops; 0 .. 40) {\n debug stderr.writeln (x);\n if (ops & 1) {\n ++x;\n } else {\n int j = -1;\n foreach (i; 0 .. 30) {\n if (x & (1 << i)) {\n j = i;\n }\n }\n a ~= j + 1;\n x ^= (1 << (j + 1)) - 1;\n }\n if (check (x)) {\n writeln (ops + 1);\n writefln (\"%(%s %)\", a);\n return;\n }\n }\n enforce (false);\n}\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\t\n\tulong x = read.to!ulong;\n\t\n\tint t = 0;\n\tint[] ns = [];\n\t\n\tint i = 1;\n\tulong m = 1;\n\twhile(m <= x) m *= 2, i += 1;\n\tif(x == m - 1){\n\t\tt = 0, ns = [];\n\t\twriteln(t), writeln(ns.map!(to!string).join(\" \"));\n\t\treturn;\n\t}\n\telse{\n\t\twhile(m > 0){\n\t\t\tm /= 2, i -= 1;\n\t\t\tif(m & x) continue;\n\t\t\tif(m == 0) break;\n\t\t\t\n\t\t\tt += 1;\n\t\t\tns ~= i;\n\t\t\tx ^= m * 2 - 1;\n\t\t\tif((x & (m * 2 - 1)) == m * 2 - 1) break;\n\t\t\t\n\t\t\tt += 1;\n\t\t\tx += 1;\n\t\t}\n\t}\n\twriteln(t);\n\twriteln(ns.map!(to!string).join(\" \"));\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 = RD;\n\n\tlong cnt;\n\tlong[] ans;\n\tforeach (i; 0..20)\n\t{\n\t\tauto y = 1UL << (19 - i);\n\t\tif (x & y) continue;\n\t\tx = x ^ ((y << 1) - 1);\n\t\tans ~= 20 - i;\n\t\t++cnt;\n\t\tif (x == (2^^20)-1) break;\n\t\t++x;\n\t\t++cnt;\n\t}\n\n\tdebug writeln(x);\n\t\n\twriteln(cnt);\n\tif (cnt != 0)\n\t{\n\t\twrite(ans[0]);\n\t\tforeach (e; ans[1..$])\n\t\t\twrite(\" \", e);\n\t\twriteln();\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; }\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 = RD;\n\n\tlong cnt;\n\tlong[] ans;\n\tforeach (i; 0..20)\n\t{\n\t\tauto y = 1UL << (19 - i);\n\t\tif (x & y) continue;\n\t\tx = x ^ ((y << 1) - 1);\n\t\tans ~= 20 - i;\n\t\t++cnt;\n\t\tif (x == (2^^21)-1) break;\n\t\t++x;\n\t\t++cnt;\n\t}\n\n\tdebug writeln(x);\n\t\n\twriteln(cnt);\n\tif (cnt != 0)\n\t{\n\t\twrite(ans[0]);\n\t\tforeach (e; ans[1..$])\n\t\t\twrite(\" \", e);\n\t\twriteln();\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; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 = RD!int;\n\n\tlong cnt;\n\tlong[] ans;\n\tforeach (i; 0..20)\n\t{\n\t\tauto y = 1 << (19 - i);\n\t\tif (x & y) continue;\n\t\tx = x ^ y;\n\t\tans ~= 21 - i;\n\t\t++cnt;\n\t\tif (x == (2^^20)-1) break;\n\t\t++x;\n\t\t++cnt;\n\t}\n\n\tdebug writeln(x);\n\t\n\twriteln(cnt);\n\tif (cnt != 0)\n\t{\n\t\twrite(ans[0]);\n\t\tforeach (e; ans[1..$])\n\t\t\twrite(\" \", e);\n\t\twriteln();\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; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 = RD;\n\n\tlong cnt;\n\tlong[] ans;\n\tforeach (i; 0..20)\n\t{\n\t\tauto y = 1UL << (19 - i);\n\t\tif (x & y) continue;\n\t\tx = x ^ ((y << 1) - 1);\n\t\tans ~= 21 - i;\n\t\t++cnt;\n\t\tif (x == (2^^20)-1) break;\n\t\t++x;\n\t\t++cnt;\n\t}\n\n\tdebug writeln(x);\n\t\n\twriteln(cnt);\n\tif (cnt != 0)\n\t{\n\t\twrite(ans[0]);\n\t\tforeach (e; ans[1..$])\n\t\t\twrite(\" \", e);\n\t\twriteln();\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; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 t = RD!int;\n\n\tlong cnt;\n\tlong[] ans;\n\tforeach (i; 0..6)\n\t{\n\t\tauto x = 1 << (5 - i);\n\t\tif (t & x) continue;\n\t\tt = t ^ x;\n\t\tans ~= 7 - i;\n\t\t++cnt;\n\t\tif (t == 63) break;\n\t\t++t;\n\t\t++cnt;\n\t}\n\n\tdebug writeln(t);\n\t\n\twriteln(cnt);\n\tif (cnt != 0)\n\t{\n\t\twrite(ans[0]);\n\t\tforeach (e; ans[1..$])\n\t\t\twrite(\" \", e);\n\t\twriteln();\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "2510469c09d7d145078e65de81640ddc"} {"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, q;\r\n\t\treadf !(\" %s %s\") (n, q);\r\n\r\n\t\tauto divs = [1];\r\n\t\tint m = n;\r\n\t\tfor (int d = 2; d * d <= m; d++)\r\n\t\t{\r\n\t\t\tif (m % d == 0)\r\n\t\t\t{\r\n\t\t\t\tdivs ~= n / d;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tm /= d;\r\n\t\t\t\t}\r\n\t\t\t\twhile (m % d == 0);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (1 < m && m < n)\r\n\t\t{\r\n\t\t\tdivs ~= n / m;\r\n\t\t}\r\n\t\tauto nDivs = divs.length.to !(int);\r\n\r\n/*\r\n\t\tauto a = new int [n];\r\n\t\tforeach (ref x; a)\r\n\t\t{\r\n\t\t\treadf !(\" %s\") (x);\r\n\t\t}\r\n*/\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = new long [] [nDivs];\r\n\t\tforeach (j, d; divs)\r\n\t\t{\r\n\t\t\tc[j] = new long [d * 2 + 2];\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tc[j][i % d + d] += a[i] * 1L * d;\r\n\t\t\t}\r\n\t\t\tforeach_reverse (k; 1..d)\r\n\t\t\t{\r\n\t\t\t\tc[j][k] = max (c[j][k * 2], c[j][k * 2 + 1]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twriteln (c.map !(line => line[1]).maxElement);\r\n\t\tforeach (r; 0..q)\r\n\t\t{\r\n\t\t\tint i, x;\r\n\t\t\treadf !(\" %s %s\") (i, x);\r\n\t\t\ti -= 1;\r\n\t\t\tauto delta = x - a[i];\r\n\t\t\tforeach (j, d; divs)\r\n\t\t\t{\r\n\t\t\t\tint k = i % d + d;\r\n\t\t\t\tc[j][k] += delta * 1L * d;\r\n\t\t\t\tfor (k >>= 1; k > 0; k >>= 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tc[j][k] = max (c[j][k * 2],\r\n\t\t\t\t\t c[j][k * 2 + 1]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ta[i] = x;\r\n\t\t\twriteln (c.map !(line => line[1]).maxElement);\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": " import std.algorithm;\r\n import std.conv;\r\n import std.range;\r\n import std.stdio;\r\n import std.string;\r\n \r\n \r\n void 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 \r\n \t\tauto divs = [1];\r\n \t\tint m = n;\r\n \t\tfor (int d = 2; d * d <= m; d++)\r\n \t\t{\r\n \t\t\tif (m % d == 0)\r\n \t\t\t{\r\n \t\t\t\tdivs ~= n / d;\r\n \t\t\t\tdo\r\n \t\t\t\t{\r\n \t\t\t\t\tm /= d;\r\n \t\t\t\t}\r\n \t\t\t\twhile (m % d == 0);\r\n \t\t\t}\r\n \t\t}\r\n \t\tif (1 < m && m < n)\r\n \t\t{\r\n \t\t\tdivs ~= n / m;\r\n \t\t}\r\n \t\tauto nDivs = divs.length.to !(int);\r\n \r\n \t\treadln;\r\n \t\tauto a = readln.splitter.map !(to !(int)).array;\r\n \t\tauto c = new long [] [nDivs];\r\n \t\tforeach (j, d; divs)\r\n \t\t{\r\n \t\t\tc[j] = new long [d * 2 + 2];\r\n \t\t\tforeach (i; 0..n)\r\n \t\t\t{\r\n \t\t\t\tc[j][i % d + d] += a[i] * 1L * d;\r\n \t\t\t}\r\n \t\t\tforeach_reverse (k; 1..d)\r\n \t\t\t{\r\n \t\t\t\tc[j][k] = max (c[j][k * 2], c[j][k * 2 + 1]);\r\n \t\t\t}\r\n \t\t}\r\n \r\n \t\twriteln (c.map !(line => line[1]).maxElement);\r\n \t\tforeach (r; 0..q)\r\n \t\t{\r\n \t\t\tint i, x;\r\n \t\t\treadf !(\" %s %s\") (i, x);\r\n \t\treadln;\r\n \t\t\ti -= 1;\r\n \t\t\tauto delta = x - a[i];\r\n \t\t\tforeach (j, d; divs)\r\n \t\t\t{\r\n \t\t\t\tint k = i % d + d;\r\n \t\t\t\tc[j][k] += delta * 1L * d;\r\n \t\t\t\tfor (k >>= 1; k > 0; k >>= 1)\r\n \t\t\t\t{\r\n \t\t\t\t\tc[j][k] = max (c[j][k * 2],\r\n \t\t\t\t\t c[j][k * 2 + 1]);\r\n \t\t\t\t}\r\n \t\t\t}\r\n \t\t\ta[i] = x;\r\n \t\t\twriteln (c.map !(line => line[1]).maxElement);\r\n \t\t}\r\n \t}\r\n }\r\n\r\n"}], "negative_code": [], "src_uid": "560e26bdfab14b919a7deadefa57f2de"} {"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\tlong[long] q;\n\tlong sum;\n\tBigInt ans;\n\tforeach (i; 0 .. n)\n\t{\n\t\tlong x;\n\t\tinput(x);\n\t\tBigInt cur = sum;\n\t\tlong k;\n\t\tforeach (j; -1 .. 2)\n\t\t{\n\n\t\t\tcur -= (x + j) * q.get(x + j, 0);\n\t\t\tk += q.get(x + j, 0);\n\n\t\t}\n\t\tans += x * (i - k) - cur;\n\t\tsum += x;\n\t\tq[x]++;\n\t}\n\twriteln(ans);\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;\nimport std.bigint;\n\nvoid main() {\n int n;\n scan(n);\n auto a = readln.split.to!(int[]);\n\n int[int] cnt;\n BigInt ans;\n\n foreach (i ; 0 .. n) {\n int d;\n if (a[i] in cnt) d += cnt[a[i]];\n if (a[i]+1 in cnt) d += cnt[a[i]+1];\n if (a[i]-1 in cnt) d += cnt[a[i]-1];\n ans += 1L * a[i] * (i - d);\n cnt[a[i]]++;\n debug {\n writeln(cnt);\n }\n }\n\n cnt.clear();\n\n debug {\n writeln(cnt);\n }\n\n foreach_reverse (i ; 0 .. n) {\n int d;\n if (a[i] in cnt) d += cnt[a[i]];\n if (a[i]+1 in cnt) d += cnt[a[i]+1];\n if (a[i]-1 in cnt) d += cnt[a[i]-1];\n ans -= 1L * a[i] * (n - 1 - i - d);\n cnt[a[i]]++;\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": "c7cca8c6524991da6ea1b423a8182d24"} {"source_code": "import std;\r\n\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 auto s = readln.strip.toLower();\r\n if (s == \"yes\")\r\n writeln(\"YES\");\r\n else\r\n writeln(\"NO\");\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 s = readln.strip;\r\n\t\twriteln (s.toLower.equal (\"yes\") ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "4c0b0cb8a11cb1fd40fef47616987029"} {"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, z;\n\t\treadf !(\" %s %s %s\") (n, k, z);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tauto f = new int [] [] (k + 2, z + 1);\n\t\tforeach (ref g; f)\n\t\t{\n\t\t\tg[] = int.min;\n\t\t}\n\t\tf[0][0] = a[0];\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tfor (int j = 0; j * 2 <= i && j <= z; j++)\n\t\t\t{\n\t\t\t\tf[i + 1][j] = max (f[i + 1][j],\n\t\t\t\t f[i][j] + a[i + 1 - j * 2]);\n\t\t\t\tif (j < z)\n\t\t\t\t{\n\t\t\t\t\tf[i + 2][j + 1] = max (f[i + 2][j + 1],\n\t\t\t\t\t f[i][j] + a[i + 1 - j * 2] +\n\t\t\t\t\t a[i - j * 2]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (f[k].maxElement);\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 k = RD!int;\n\t\tauto z = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tforeach (i; 0..min((k-1)/2, z)+1)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (j; 0..k+1-i*2)\n\t\t\t{\n\t\t\t\tcnt += a[j];\n\t\t\t}\n\t\t\tforeach (j; 1..k+1-i*2)\n\t\t\t{\n\t\t\t\tauto best = a[j-1] + a[j];\n\t\t\t\tans[ti].chmax(cnt + best * i);\n\t\t\t\tif (j != k-i*2 && i < z)\n\t\t\t\t\tans[ti].chmax(cnt + best * i - a[k-i*2] + a[k-i*2-2]);\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}"}], "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 k = RD!int;\n\t\tauto z = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tforeach (i; 0..min(k/2, z)+1)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (j; 0..k+1-i*2)\n\t\t\t{\n\t\t\t\tcnt += a[j];\n\t\t\t}\n\t\t\tlong best;\n\t\t\tforeach (j; 1..k+1-i*2)\n\t\t\t{\n\t\t\t\tbest.chmax(a[j-1] + a[j]);\n\t\t\t}\n\t\t\tans[ti].chmax(cnt + best * i);\n\t\t\tif (i != 0)\n\t\t\t\tans[ti].chmax(cnt + best * (i-1) + a[k-i*2] + a[k-i*2+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}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto z = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tforeach (i; 0..min((k-1)/2, z)+1)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (j; 0..k+1-i*2)\n\t\t\t{\n\t\t\t\tcnt += a[j];\n\t\t\t}\n\t\t\tforeach (j; 1..k+1-i*2)\n\t\t\t{\n\t\t\t\tauto best = a[j-1] + a[j];\n\t\t\t\tans[ti].chmax(cnt + best * i);\n\t\t\t\tif (i != 0 && i < z)\n\t\t\t\t\tans[ti].chmax(cnt + best * i - a[k-i*2] + a[k-i*2-2]);\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": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto z = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tforeach (i; 0..min((k-1)/2, z)+1)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (j; 0..k+1-i*2)\n\t\t\t{\n\t\t\t\tcnt += a[j];\n\t\t\t}\n\t\t\tforeach (j; 1..k+1-i*2)\n\t\t\t{\n\t\t\t\tauto best = a[j-1] + a[j];\n\t\t\t\tans[ti].chmax(cnt + best * i);\n\t\t\t\tif (i < z)\n\t\t\t\t\tans[ti].chmax(cnt + best * i - a[k-i*2] + a[k-i*2-2]);\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": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto z = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tforeach (i; 0..min((k-1)/2, z)+1)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (j; 0..k+1-i*2)\n\t\t\t{\n\t\t\t\tcnt += a[j];\n\t\t\t}\n\t\t\tforeach (j; 1..k+1-i*2)\n\t\t\t{\n\t\t\t\tauto best = a[j-1] + a[j];\n\t\t\t\tans[ti].chmax(cnt + best * i);\n\t\t\t\tif (j == k-i*2-1 && i != 0 && i < z)\n\t\t\t\t\tans[ti].chmax(cnt + best * i - a[k-i*2] + a[k-i*2-2]);\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": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto z = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tforeach (i; 0..z+1)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (j; 0..k+1-i*2)\n\t\t\t{\n\t\t\t\tcnt += a[j];\n\t\t\t}\n\t\t\tlong best;\n\t\t\tforeach (j; 1..k+1-i*2)\n\t\t\t{\n\t\t\t\tbest.chmax(a[j-1] + a[j]);\n\t\t\t}\n\t\t\tcnt += best * i;\n\t\t\tans[ti].chmax(cnt);\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": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto z = RD!int;\n\t\tauto a = RDA!int;\n\n\t\tforeach (i; 0..min(k/2, z*2)+1)\n\t\t{\n\t\t\tlong cnt;\n\t\t\tforeach (j; 0..k+1-i)\n\t\t\t{\n\t\t\t\tcnt += a[j];\n\t\t\t}\n\t\t\tlong best;\n\t\t\tforeach (j; 1..k+1-i)\n\t\t\t{\n\t\t\t\tbest.chmax(a[j-1] + a[j]);\n\t\t\t}\n\t\t\tcnt += best * (i/2);\n\t\t\tif (i % 2)\n\t\t\t{\n\t\t\t\tif (a[k-i] < a[k-i-2])\n\t\t\t\t\tcnt += a[k-i-2] - a[k-i];\n\t\t\t}\n\t\t\tans[ti].chmax(cnt);\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}"}], "src_uid": "537791353fe9f5892f28e1793bae2935"} {"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 a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tauto need = new int [] [n + 1];\r\n\t\tauto can = new int [] [n + 1];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] == b[i])\r\n\t\t\t{\r\n\t\t\t\tcan[b[i]] ~= i;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tneed[b[i]] ~= i;\r\n\t\t\t}\r\n\t\t}\r\n\t\tbool ok = true;\r\n\t\tauto answer = new int [m];\r\n\t\tforeach_reverse (j, x; c)\r\n\t\t{\r\n\t\t\tif (!need[x].empty)\r\n\t\t\t{\r\n\t\t\t\tanswer[j] = need[x].front;\r\n\t\t\t\tneed[x].popFront ();\r\n\t\t\t}\r\n\t\t\telse if (!can[x].empty)\r\n\t\t\t{\r\n\t\t\t\tanswer[j] = can[x].front;\r\n\t\t\t}\r\n\t\t\telse if (j < m - 1)\r\n\t\t\t{\r\n\t\t\t\tanswer[j] = answer[m - 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}\r\n\t\t}\r\n\t\tok &= need.all !(empty);\r\n\t\tif (ok)\r\n\t\t{\r\n\t\t\twritefln !(\"YES\\n%(%s %)\") (answer.map !(q{a + 1}));\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.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 int[] aa, bb, cc; get(aa); get(bb); get(cc);\r\n auto ww = new int[][N + 1];\r\n auto rr = new int[](N + 1);\r\n rr[] = -1;\r\n foreach (i; 0..N) {\r\n auto a = aa[i], b = bb[i];\r\n if (a == b) {\r\n rr[a] = i.to!int;\r\n } else {\r\n ww[b] ~= i.to!int;\r\n }\r\n }\r\n\r\n auto res = new int[](M);\r\n int[] rest;\r\n foreach (i, c; cc) {\r\n if (ww[c].empty) {\r\n if (rr[c] == -1) {\r\n rest ~= i.to!int;\r\n } else {\r\n while (!rest.empty) {\r\n res[rest.front] = rr[c];\r\n rest.popFront();\r\n }\r\n res[i] = rr[c];\r\n }\r\n } else {\r\n while (!rest.empty) {\r\n res[rest.front] = ww[c].front;\r\n rest.popFront();\r\n }\r\n res[i] = ww[c].front;\r\n rr[c] = ww[c].front;\r\n ww[c].popFront();\r\n }\r\n }\r\n if (!rest.empty) goto ng;\r\n foreach (w; ww) if (!w.empty) goto ng;\r\n writefln!\"YES\\n%(%d %)\"(res.map!\"a + 1\");\r\n continue;\r\n ng:\r\n writeln(\"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 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(-1);\r\n\t\tauto b = RDA(-1);\r\n\t\tauto c = RDA(-1);\r\n\r\n\t\tauto used = new int[](n);\r\n\t\tused[] = -1;\r\n\t\tauto pos = new int[][](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tused[b[i]] = i;\r\n\t\t\tif (a[i] != b[i])\r\n\t\t\t{\r\n\t\t\t\tpos[b[i]] ~= i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans[ti].length = m;\r\n\t\tint[] s;\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\r\n\t\t\tif (pos[c[i]].empty)\r\n\t\t\t{\r\n\t\t\t\tif (used[c[i]] == -1)\r\n\t\t\t\t\ts ~= i;\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tauto j = used[c[i]];\r\n\t\t\t\t\twhile (!s.empty)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tauto k = s.front; s.popFront;\r\n\t\t\t\t\t\tans[ti][k] = j+1;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tans[ti][i] = j+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\tauto j = pos[c[i]].front; pos[c[i]].popFront;\r\n\t\t\t\twhile (!s.empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto k = s.front; s.popFront;\r\n\t\t\t\t\tans[ti][k] = j+1;\r\n\t\t\t\t}\r\n\t\t\t\tans[ti][i] = j+1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (!s.empty)\r\n\t\t\tans[ti].length = 0;\r\n\t\tforeach (e; pos)\r\n\t\t{\r\n\t\t\tif (!e.empty)\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}\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}"}], "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 a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b = readln.splitter.map !(to !(int)).array;\r\n\t\tauto c = readln.splitter.map !(to !(int)).array;\r\n\t\tauto need = new int [] [n + 1];\r\n\t\tauto can = new int [] [n + 1];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] == b[i])\r\n\t\t\t{\r\n\t\t\t\tcan[b[i]] ~= i;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tneed[b[i]] ~= i;\r\n\t\t\t}\r\n\t\t}\r\n\t\tbool ok = true;\r\n\t\tauto answer = new int [m];\r\n\t\tforeach_reverse (j, x; c)\r\n\t\t{\r\n\t\t\tif (!need[x].empty)\r\n\t\t\t{\r\n\t\t\t\tanswer[j] = need[x].front;\r\n\t\t\t\tneed[x].popFront ();\r\n\t\t\t}\r\n\t\t\telse if (!can[x].empty)\r\n\t\t\t{\r\n\t\t\t\tanswer[j] = can[x].front;\r\n\t\t\t}\r\n\t\t\telse if (j < m - 1)\r\n\t\t\t{\r\n\t\t\t\tanswer[j] = answer[m - 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}\r\n\t\t}\r\n\t\tif (ok)\r\n\t\t{\r\n\t\t\twritefln !(\"YES\\n%(%s %)\") (answer.map !(q{a + 1}));\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"}], "src_uid": "a350430c707bb18a146df9f80e114f45"} {"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\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\n\tas.sort();\n\t\n\tint[long] ac;\n\tforeach(a; as){\n\t\tif(a !in ac) ac[a] = 0;\n\t\tac[a] += 1;\n\t}\n\tlong[] ks = ac.keys;\n\tint f = 0;\n\tforeach(k; ks){\n\t\tif(ac[k] >= 3) f = 9;\n\t\telse if(ac[k] == 2){\n\t\t\tif(f == 1) f = 9;\n\t\t\telse if((k - 1) in ac) f = 9;\n\t\t\telse if(k == 0) f = 9;\n\t\t\telse if(f == 0) f = 1;\n\t\t}\n\t}\n\tif(f == 9){\n\t\t\"cslnb\".writeln;\n\t\treturn;\n\t}\n\t\n\tlong x;\n\tforeach(i, a; as) x += a - i;\n\t\n\tif(x % 2 == 1) \"sjfnb\".writeln;\n\telse \"cslnb\".writeln;\n\t\n\t\n}\n", "positive_code": [{"source_code": "\n\n import core.bitop, std.bitmanip;\n import core.checkedint;\n import std.algorithm, std.functional;\n import std.array, std.container;\n import std.bigint;\n import std.conv;\n import std.datetime.stopwatch;\n import std.math, std.numeric;\n import std.range, std.range.interfaces;\n import std.stdio, std.string;\n import std.typecons;\n \n void 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.length == 2 && arr[0] == 0 && arr[1] <= 1) {\n writeln(\"cslnb\");\n return;\n }\n \n auto copy = false;\n for (int i = 0; i+1 < arr.length; ++i) {\n if (arr[i] == arr[i+1]) {\n if (copy\n || arr[i] == 0\n || (i > 0 && arr[i-1] + 1 == arr[i])) {\n writeln(\"cslnb\");\n return;\n }\n \n copy = true;\n }\n }\n \n auto opt = n.iota;\n \n debug { opt.writeln; }\n \n auto steps = zip(arr, opt).map!\"a[0] - a[1]\".sum(0L);\n \n if (steps % 2 == 1) {\n writeln(\"sjfnb\");\n } else {\n writeln(\"cslnb\");\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;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"cslnb\");\n return;\n }\n\n int[long] mp;\n foreach (a; A) mp[a] += 1;\n int two_count = 0;\n long two = -1;\n\n foreach (k; mp.keys) {\n if (mp[k] >= 3) {\n writeln(\"cslnb\");\n return;\n }\n if (mp[k] == 2) {\n two_count += 1;\n two = k;\n }\n }\n\n if (two_count >= 2) {\n writeln(\"cslnb\");\n return;\n }\n if (two_count == 1 && (two - 1) in mp) {\n writeln(\"cslnb\");\n return;\n }\n if (two_count == 1 && two == 0) {\n writeln(\"cslnb\");\n return;\n }\n\n long sm = 0;\n long mx = -1;\n A.sort();\n\n foreach (a; A) {\n sm += (a - mx - 1) % 2;\n mx += 1;\n }\n\n writeln(sm % 2 ? \"sjfnb\" : \"cslnb\");\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 N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"cslnb\");\n return;\n }\n\n int[long] mp;\n foreach (a; A) mp[a] += 1;\n int two_count = 0;\n long two = -1;\n\n foreach (k; mp.keys) {\n if (mp[k] >= 3) {\n writeln(\"cslnb\");\n return;\n }\n if (mp[k] == 2) {\n two_count += 1;\n two = k;\n }\n }\n\n if (two_count >= 2) {\n writeln(\"cslnb\");\n return;\n }\n if (two_count == 1 && (two - 1) in mp) {\n writeln(\"cslnb\");\n return;\n }\n\n long sm = 0;\n long mx = -1;\n A.sort();\n\n foreach (a; A) {\n sm += (a - mx - 1) % 2;\n mx += 1;\n }\n\n writeln(sm % 2 ? \"sjfnb\" : \"cslnb\");\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 N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"cslnb\");\n return;\n }\n\n int[long] mp;\n foreach (a; A) mp[a] += 1;\n int two_count = 0;\n long two = -1;\n\n foreach (k; mp.keys) {\n if (mp[k] >= 3) {\n writeln(\"cslnb\");\n return;\n }\n if (mp[k] == 2) {\n two_count += 1;\n two = k;\n }\n }\n\n if (two_count >= 2) {\n writeln(\"cslnb\");\n return;\n }\n if (two_count == 1 && (two - 1) in mp) {\n writeln(\"cslnb\");\n return;\n }\n\n long sm = 0;\n long mx = -1;\n A.sort();\n\n foreach (a; A) {\n sm += (a - mx - 1);\n mx += 1;\n }\n\n writeln(sm % 2 ? \"sjfnb\" : \"cslnb\");\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// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\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\tas.sort();\n\t\n\tint[long] ac;\n\tforeach(a; as){\n\t\tif(a !in ac) ac[a] = 0;\n\t\tac[a] += 1;\n\t}\n\tlong[] ks = ac.keys;\n\tint f = 0;\n\tforeach(k; ks){\n\t\tif(ac[k] >= 3) f = 9;\n\t\telse if(ac[k] == 2){\n\t\t\tif(f == 1) f = 9;\n\t\t\telse if((k - 1) in ac) f = 9;\n\t\t\telse if(k == 0) f = 9;\n\t\t\telse f = 1;\n\t\t}\n\t}\n\tif(f == 9){\n\t\t\"cslnb\".writeln;\n\t\treturn;\n\t}\n\t\n\tlong x;\n\tforeach(i, a; as) x += a - i;\n\t\n\tif(x % 2 == 1) \"sjfnb\".writeln;\n\telse \"cslnb\".writeln;\n\t\n\t\n}\n"}, {"source_code": "\n\n import core.bitop, std.bitmanip;\n import core.checkedint;\n import std.algorithm, std.functional;\n import std.array, std.container;\n import std.bigint;\n import std.conv;\n import std.datetime.stopwatch;\n import std.math, std.numeric;\n import std.range, std.range.interfaces;\n import std.stdio, std.string;\n import std.typecons;\n \n void 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.length == 2 && arr[0] == 0 && arr[1] <= 1) {\n writeln(\"cslnb\");\n return;\n }\n \n auto copy = false;\n for (int i = 0; i+1 < arr.length; ++i) {\n if (arr[i] == arr[i+1]) {\n if (copy || (i > 0 && arr[i-1] + 1 == arr[i])) {\n writeln(\"cslnb\");\n return;\n }\n \n copy = true;\n }\n }\n \n auto opt = n.iota;\n \n debug { opt.writeln; }\n \n auto steps = zip(arr, opt).map!\"a[0] - a[1]\".sum(0L);\n \n if (steps % 2 == 1) {\n writeln(\"sjfnb\");\n } else {\n writeln(\"cslnb\");\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 arr = readln.chomp.split.map!(to!int).array;\n \n arr.sort();\n \n if (arr.length == 2 && arr[0] == 0 && arr[1] == 0) {\n writeln(\"cslnb\");\n return;\n }\n \n auto copy = zip(arr, arr.dropOne, arr.drop(2)).filter!\"a[1] == a[2]\".array;\n if (copy.length > 1 \n || (copy.length == 1 \n && (copy[0][0] == copy[0][2] || copy[0][0] + 1 == copy[0][1]))) {\n writeln(\"cslnb\");\n return;\n }\n \n auto opt = n.iota;\n \n debug { opt.writeln; }\n \n auto steps = zip(arr, opt).map!\"a[0] - a[1]\".sum(0L);\n \n if (steps % 2 == 1) {\n writeln(\"sjfnb\");\n } else {\n writeln(\"cslnb\");\n }\n}"}], "src_uid": "dc225c801f55b8d7b40ebcc71b417edb"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nbool solve (int [] a)\n{\n\tsort (a);\n\twhile (a.length > 0)\n\t{\n\t\tif (a.length == 1 || a[$ - 2] != a[$ - 1])\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\ta.length -= 2;\n\t}\n\treturn false;\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) ? \"Conan\" : \"Agasa\");\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\nbool solve() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n int[int] C;\n foreach (a; A) {\n if (a in C) C[a] += 1;\n else C[a] = 1;\n }\n\n auto K = C.keys.dup.sort!\"a > b\"().array;\n foreach (k; K) {\n if (C[k] % 2) return true;\n }\n\n return false;\n}\n\nvoid main() {\n writeln(solve ? \"Conan\" : \"Agasa\");\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\tsort(a);\n\tint pos = n - 1;\n\tint last = n - 1;\n\twhile (pos >= 0)\n\t{\n\t\twhile (pos >= 0 && a[pos] == a[last])\n\t\t\tpos--;\n\t\tif ((last - pos) % 2 == 1)\n\t\t{\n\t\t\twriteln(\"Conan\");\n\t\t\treturn;\n\t\t}\n\t\tlast = pos;\n\t}\n\twriteln(\"Agasa\");\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 A.sort;\n \n bool ans = false;\n foreach (g; A.group) {\n if (g[1] % 2 != 0) {\n ans = true;\n }\n }\n writeln(ans ? \"Conan\" : \"Agasa\");\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;\n\nbool solve() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n if (A.map!(a => a == A[0]).all) {\n if (N % 2) {\n return true;\n } else {\n return false;\n }\n } else {\n return true;\n }\n\n}\n\nvoid main() {\n writeln(solve ? \"Conan\" : \"Agasa\");\n}\n"}], "src_uid": "864593dc3911206b627dab711025e116"} {"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 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 a = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n a[x][y] = A[x][y] - '0';\n }\n \n int[][] ans;\n void oper(int x0, int y0, int x1, int y1, int x2, int y2) {\n ans ~= [x0, y0, x1, y1, x2, y2];\n a[x0][y0] ^= 1;\n a[x1][y1] ^= 1;\n a[x2][y2] ^= 1;\n }\n \n foreach (x; 0 .. M - 2) foreach (y; 0 .. N - 2) {\n if (a[x][y]) {\n oper(x, y, x, y + 1, x + 1, y);\n }\n }\n foreach (x; 0 .. M - 2) {\n const y = N - 2;\n if (a[x][y]) {\n if (a[x][y + 1]) {\n oper(x, y, x, y + 1, x + 1, y);\n } else {\n oper(x, y, x + 1, y, x + 1, y + 1);\n }\n } else {\n if (a[x][y + 1]) {\n oper(x, y + 1, x + 1, y, x + 1, y + 1);\n } else {\n oper(x, y, x, y + 1, x + 1, y);\n oper(x, y, x, y + 1, x + 1, y);\n }\n }\n }\n foreach (y; 0 .. N - 2) {\n const x = M - 2;\n if (a[x][y]) {\n if (a[x + 1][y]) {\n oper(x, y, x + 1, y, x, y + 1);\n } else {\n oper(x, y, x, y + 1, x + 1, y + 1);\n }\n } else {\n if (a[x + 1][y]) {\n oper(x + 1, y, x, y + 1, x + 1, y + 1);\n } else {\n oper(x, y, x + 1, y, x, y + 1);\n oper(x, y, x + 1, y, x, y + 1);\n }\n }\n }\n {\n const x = M - 2, y = N - 2;\n foreach (p; 0 .. 1 << 4) {\n auto bs = new int[4];\n foreach (i; 0 .. 4) {\n if (p & 1 << i) {\n foreach (j; 0 .. 4) {\n if (i != j) {\n bs[j] ^= 1;\n }\n }\n }\n }\n debug {\n writeln(p, \": \", bs);\n }\n bool ok = true;\n foreach (j; 0 .. 4) {\n ok = ok && (a[x + j / 2][y + j % 2] == bs[j]);\n }\n if (ok) {\n if (p & 1 << 0) oper(x, y + 1, x + 1, y, x + 1, y + 1);\n if (p & 1 << 1) oper(x, y, x + 1, y, x + 1, y + 1);\n if (p & 1 << 2) oper(x, y, x, y + 1, x + 1, y + 1);\n if (p & 1 << 3) oper(x, y, x, y + 1, x + 1, y);\n }\n }\n }\n \n writeln(ans.length);\n foreach (row; ans) {\n foreach (i; 0 .. 6) {\n if (i > 0) write(\" \");\n write(row[i] + 1);\n }\n writeln;\n }\n debug {\n writeln(\"a = \", a);\n }\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\tint rows, cols;\n\t\treadf !(\" %s %s\") (rows, cols);\n\t\treadln;\n\t\tuint [] [] board;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tboard ~= readln.strip.map !(q{a - '0'}).array;\n\t\t}\n\n\t\tint [] [] answer;\n\n\t\tvoid go (int row, int col,\n\t\t int row1, int col1, int row2, int col2)\n\t\t{\n\t\t\tanswer ~= [row, col, row1, col1, row2, col2];\n\t\t\tboard[row][col] ^= 1;\n\t\t\tboard[row1][col1] ^= 1;\n\t\t\tboard[row2][col2] ^= 1;\n\t\t}\n\n\t\tforeach_reverse (row; 0..rows)\n\t\t{\n\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t{\n\t\t\t\tif ((row == rows - 1 && rows % 2 == 1) ||\n\t\t\t\t (col == cols - 1 && cols % 2 == 1))\n\t\t\t\t{\n\t\t\t\t\tif (board[row][col])\n\t\t\t\t\t{\n\t\t\t\t\t\tauto row1 = max (row - 1, 0);\n\t\t\t\t\t\tauto col1 = max (col - 1, 0);\n\t\t\t\t\t\tauto row2 = row1 + 1;\n\t\t\t\t\t\tauto col2 = col1;\n\t\t\t\t\t\tif (row2 == row &&\n\t\t\t\t\t\t col2 == col)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trow2 = row1;\n\t\t\t\t\t\t\tcol2 = col1 + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tgo (row, col,\n\t\t\t\t\t\t row1, col1, row2, col2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid doSquare (int row, int col)\n\t\t{\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tauto total = board[row + 0][col + 0] +\n\t\t\t\t board[row + 1][col + 0] +\n\t\t\t\t board[row + 0][col + 1] +\n\t\t\t\t board[row + 1][col + 1];\n\t\t\t\tif (total == 0)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tint [] seqRow;\n\t\t\t\tint [] seqCol;\n\t\t\t\tforeach_reverse (value; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (rowT; row..row + 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (colT; col..col + 2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (board[rowT][colT]\n\t\t\t\t\t\t\t == value)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tseqRow ~= rowT;\n\t\t\t\t\t\t\t\tseqCol ~= colT;\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 (total == 2)\n\t\t\t\t{\n\t\t\t\t\tseqRow.popFront ();\n\t\t\t\t\tseqCol.popFront ();\n\t\t\t\t}\n\t\t\t\tgo (seqRow[0], seqCol[0],\n\t\t\t\t seqRow[1], seqCol[1],\n\t\t\t\t seqRow[2], seqCol[2]);\n\t\t\t}\n\t\t}\n\n\t\tfor (int row = 0; row + 1 < rows; row += 2)\n\t\t{\n\t\t\tfor (int col = 0; col + 1 < cols; col += 2)\n\t\t\t{\n\t\t\t\tdoSquare (row, col);\n\t\t\t}\n\t\t}\n\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 (board[row][col])\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\twriteln (answer.length);\n\t\tforeach (ref line; answer)\n\t\t{\n\t\t\twritefln !(\"%(%s %)\") (line.map !(q{a + 1}));\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(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 m = RD!int;\n\t\tauto s = new char[][](n);\n\t\tforeach (i; 0..n)\n\t\t\ts[i] = RD!(char[]);\n\n\t\tforeach (y; 0..n-1)\n\t\t{\n\t\t\tforeach (x; 0..m-1)\n\t\t\t{\n\t\t\t\tdebug writeln(\"y:\", y, \" x:\", x);\n\t\t\t\tvoid draw(long[] pos)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= [pos[0]+1, pos[1]+1, pos[2]+1, pos[3]+1, pos[4]+1, pos[5]+1];\n\t\t\t\t\tforeach (i; 0..3)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto yy = cast(int)pos[i*2];\n\t\t\t\t\t\tauto xx = cast(int)pos[i*2+1];\n\t\t\t\t\t\ts[yy][xx] = s[yy][xx] == '0' ? '1' : '0';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvoid fin()\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdraw(tmp);\n\t\t\t\t}\n\t\t\t\tvoid fin2()\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp;\n\t\t\t\t\tbool mode;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (mode) continue;\n\t\t\t\t\t\t\t\tmode = true;\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdraw(tmp);\n\t\t\t\t\tfin();\n\t\t\t\t}\n\t\t\t\tif (y == n-2 && x == m-2)\n\t\t\t\t{\n\t\t\t\t\tlong cnt;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (cnt == 4)\n\t\t\t\t\t{\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\t\tdraw([y, x, y+1, x, y+1, x+1]);\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t\t\tfin();\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 3)\n\t\t\t\t\t{\n\t\t\t\t\t\tfin();\t\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tfin2();\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tlong[] tmp;\n\t\t\t\t\t\tint mode;\n\t\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (s[y+i][x+j] == '0')\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif (mode == 2) continue;\n\t\t\t\t\t\t\t\t\t++mode;\n\t\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdraw(tmp);\n\t\t\t\t\t\tfin2();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (y == n-2)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '1' && s[y+1][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y+1, x, y, x+1]);\n\t\t\t\t\telse if (s[y][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y+1][x] == '1')\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t\telse if (x == m-2)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '1' && s[y][x+1] == '1')\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y+1, x, y+1, x+1]);\n\t\t\t\t\telse if (s[y][x+1] == '1')\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '0') continue;\n\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t\twriteln(s[i]);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\tforeach (ee; e)\n\t\t{\n\t\t\tee.map!(to!string).join(\" \").writeln;\n\t\t}\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 m = RD!int;\n\t\tauto s = new char[][](n);\n\t\tforeach (i; 0..n)\n\t\t\ts[i] = RD!(char[]);\n\n\t\tforeach (y; 0..n-1)\n\t\t{\n\t\t\tforeach (x; 0..m-1)\n\t\t\t{\n\t\t\t\tdebug writeln(\"y:\", y, \" x:\", x);\n\t\t\t\tvoid draw(long[] pos)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= [pos[0]+1, pos[1]+1, pos[2]+1, pos[3]+1, pos[4]+1, pos[5]+1];\n\t\t\t\t\tforeach (i; 0..3)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto yy = cast(int)pos[i*2];\n\t\t\t\t\t\tauto xx = cast(int)pos[i*2+1];\n\t\t\t\t\t\ts[yy][xx] = s[yy][xx] == '0' ? '1' : '0';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvoid fin()\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdraw(tmp);\n\t\t\t\t}\n\t\t\t\tvoid fin2()\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp;\n\t\t\t\t\tbool mode;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (mode) continue;\n\t\t\t\t\t\t\t\tmode = true;\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdraw(tmp);\n\t\t\t\t\tfin();\n\t\t\t\t}\n\t\t\t\tif (y == n-2 && x == m-2)\n\t\t\t\t{\n\t\t\t\t\twriteln(s);\n\t\t\t\t\tlong cnt;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (cnt == 4)\n\t\t\t\t\t{\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\t\tdraw([y, x, y+1, x, y+1, x+1]);\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t\t\tfin();\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 3)\n\t\t\t\t\t{\n\t\t\t\t\t\tfin();\t\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tfin2();\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tlong[] tmp;\n\t\t\t\t\t\tint mode;\n\t\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (s[y+i][x+j] == '0')\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif (mode == 2) continue;\n\t\t\t\t\t\t\t\t\t++mode;\n\t\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdraw(tmp);\n\t\t\t\t\t\tfin2();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (y == n-2)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '1' && s[y+1][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y+1, x, y, x+1]);\n\t\t\t\t\telse if (s[y][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y+1][x] == '1')\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t\telse if (x == m-2)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '1' && s[y][x+1] == '1')\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y+1, x, y+1, x+1]);\n\t\t\t\t\telse if (s[y][x+1] == '1')\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '0') continue;\n\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t\twriteln(s[i]);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\tforeach (ee; e)\n\t\t{\n\t\t\tee.map!(to!string).join(\" \").writeln;\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(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 m = RD!int;\n\t\tauto s = new char[][](n);\n\t\tforeach (i; 0..n)\n\t\t\ts[i] = RD!(char[]);\n\n\t\tforeach (y; 0..n-1)\n\t\t{\n\t\t\tforeach (x; 0..m-1)\n\t\t\t{\n\t\t\t\tvoid draw(long[] pos)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= [pos[0]+1, pos[1]+1, pos[2]+1, pos[3]+1, pos[4]+1, pos[5]+1];\n\t\t\t\t\tforeach (i; 0..3)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto yy = cast(int)pos[i*2];\n\t\t\t\t\t\tauto xx = cast(int)pos[i*2+1];\n\t\t\t\t\t\ts[yy][xx] = s[yy][xx] == '0' ? '1' : '0';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvoid fin()\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdraw(tmp);\n\t\t\t\t}\n\t\t\t\tvoid fin2()\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp;\n\t\t\t\t\tbool mode;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (mode) continue;\n\t\t\t\t\t\t\t\tmode = true;\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdraw(tmp);\n\t\t\t\t\tfin();\n\t\t\t\t}\n\t\t\t\tif (y == n-2 && x == m-2)\n\t\t\t\t{\n\t\t\t\t\tlong cnt;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (cnt == 4)\n\t\t\t\t\t{\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\t\tdraw([y, x, y+1, x, y+1, x+1]);\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t\t\tfin();\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 3)\n\t\t\t\t\t{\n\t\t\t\t\t\tfin();\t\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tfin2();\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tlong[] tmp;\n\t\t\t\t\t\tint mode;\n\t\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (s[y+i][x+j] == '0')\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif (mode == 2) continue;\n\t\t\t\t\t\t\t\t\t++mode;\n\t\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfin2();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (y == n-2)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '1' && s[y+1][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y+1, x, y, x+1]);\n\t\t\t\t\telse if (s[y][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y+1][x] == '1')\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t\telse if (x == m-2)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '1' && s[y][x+1] == '1')\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y+1, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y][x+1] == '1')\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '0') continue;\n\t\t\t\t\tdraw([y, x, y, x+1, y+1, 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\twriteln(e.length);\n\t\tforeach (ee; e)\n\t\t{\n\t\t\tee.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\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 rows, cols;\n\t\treadf !(\" %s %s\") (rows, cols);\n\t\treadln;\n\t\tuint [] [] board;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tboard ~= readln.strip.map !(q{a - '0'}).array;\n\t\t}\n\n\t\tint [] [] answer;\n\n\t\tvoid go (int row, int col,\n\t\t int row1, int col1, int row2, int col2)\n\t\t{\n\t\t\tanswer ~= [row, col, row1, col1, row2, col2];\n\t\t\tboard[row][col] ^= 1;\n\t\t\tboard[row1][col1] ^= 1;\n\t\t\tboard[row2][col2] ^= 1;\n\t\t}\n\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 ((row == rows - 1 && rows % 2 == 1) ||\n\t\t\t\t (col == cols - 1 && cols % 2 == 1))\n\t\t\t\t{\n\t\t\t\t\tif (board[row][col])\n\t\t\t\t\t{\n\t\t\t\t\t\tauto row1 = max (row - 1, 0);\n\t\t\t\t\t\tauto col1 = max (col - 1, 0);\n\t\t\t\t\t\tauto row2 = row1 + 1;\n\t\t\t\t\t\tauto col2 = col1;\n\t\t\t\t\t\tif (row2 == row && col2 == col)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trow2 = row1;\n\t\t\t\t\t\t\tcol2 = col1 + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (row2 == row && col2 == col)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tassert (false);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tgo (row, col,\n\t\t\t\t\t\t row1, col1, row2, col2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid doSquare (int row, int col)\n\t\t{\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tauto total = board[row + 0][col + 0] +\n\t\t\t\t board[row + 1][col + 0] +\n\t\t\t\t board[row + 0][col + 1] +\n\t\t\t\t board[row + 1][col + 1];\n\t\t\t\tif (total == 0)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tint [] seqRow;\n\t\t\t\tint [] seqCol;\n\t\t\t\tforeach_reverse (value; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (rowT; row..row + 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (colT; col..col + 2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (board[rowT][colT]\n\t\t\t\t\t\t\t == value)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tseqRow ~= rowT;\n\t\t\t\t\t\t\t\tseqCol ~= colT;\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 (total == 2)\n\t\t\t\t{\n\t\t\t\t\tseqRow = seqRow[1..$] ~ seqRow[0];\n\t\t\t\t\tseqCol = seqCol[1..$] ~ seqCol[0];\n\t\t\t\t}\n\t\t\t\tgo (seqRow[0], seqCol[0],\n\t\t\t\t seqRow[1], seqCol[1],\n\t\t\t\t seqRow[2], seqCol[2]);\n\t\t\t}\n\t\t}\n\n\t\tfor (int row = 0; row + 1 < rows; row += 2)\n\t\t{\n\t\t\tfor (int col = 0; col + 1 < cols; col += 2)\n\t\t\t{\n\t\t\t\tdoSquare (row, col);\n\t\t\t}\n\t\t}\n\n\t\twriteln (answer.length);\n\t\tforeach (ref line; answer)\n\t\t{\n\t\t\twritefln !(\"%(%s %)\") (line.map !(q{a + 1}));\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\tint rows, cols;\n\t\treadf !(\" %s %s\") (rows, cols);\n\t\treadln;\n\t\tuint [] [] board;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tboard ~= readln.strip.map !(q{a - '0'}).array;\n\t\t}\n\n\t\tint [] [] answer;\n\n\t\tvoid go (int row, int col,\n\t\t int row1, int col1, int row2, int col2)\n\t\t{\n\t\t\tanswer ~= [row, col, row1, col1, row2, col2];\n\t\t\tboard[row][col] ^= 1;\n\t\t\tboard[row1][col1] ^= 1;\n\t\t\tboard[row2][col2] ^= 1;\n\t\t}\n\n\t\tforeach_reverse (row; 0..rows)\n\t\t{\n\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t{\n\t\t\t\tif ((row == rows - 1 && rows % 2 == 1) ||\n\t\t\t\t (col == cols - 1 && cols % 2 == 1))\n\t\t\t\t{\n\t\t\t\t\tif (board[row][col])\n\t\t\t\t\t{\n\t\t\t\t\t\tauto row1 = max (row - 1, 0);\n\t\t\t\t\t\tauto col1 = max (col - 1, 0);\n\t\t\t\t\t\tauto row2 = row1 + 1;\n\t\t\t\t\t\tauto col2 = col1;\n\t\t\t\t\t\tif (row2 == rows - 1 ||\n\t\t\t\t\t\t col2 == cols - 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trow2 = row1;\n\t\t\t\t\t\t\tcol2 = col1 + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tgo (row, col,\n\t\t\t\t\t\t row1, col1, row2, col2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid doSquare (int row, int col)\n\t\t{\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tauto total = board[row + 0][col + 0] +\n\t\t\t\t board[row + 1][col + 0] +\n\t\t\t\t board[row + 0][col + 1] +\n\t\t\t\t board[row + 1][col + 1];\n\t\t\t\tif (total == 0)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tint [] seqRow;\n\t\t\t\tint [] seqCol;\n\t\t\t\tforeach_reverse (value; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (rowT; row..row + 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (colT; col..col + 2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (board[rowT][colT]\n\t\t\t\t\t\t\t == value)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tseqRow ~= rowT;\n\t\t\t\t\t\t\t\tseqCol ~= colT;\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 (total == 2)\n\t\t\t\t{\n\t\t\t\t\tseqRow = seqRow[1..$] ~ seqRow[0];\n\t\t\t\t\tseqCol = seqCol[1..$] ~ seqCol[0];\n\t\t\t\t}\n\t\t\t\tgo (seqRow[0], seqCol[0],\n\t\t\t\t seqRow[1], seqCol[1],\n\t\t\t\t seqRow[2], seqCol[2]);\n\t\t\t}\n\t\t}\n\n\t\tfor (int row = 0; row + 1 < rows; row += 2)\n\t\t{\n\t\t\tfor (int col = 0; col + 1 < cols; col += 2)\n\t\t\t{\n\t\t\t\tdoSquare (row, col);\n\t\t\t}\n\t\t}\n\n\t\twriteln (answer.length);\n\t\tforeach (ref line; answer)\n\t\t{\n\t\t\twritefln !(\"%(%s %)\") (line.map !(q{a + 1}));\n\t\t}\n\t}\n}\n"}], "src_uid": "e86044b3438f934b6a9e76854053f117"} {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n immutable vec =\n readln.chomp\n .split(' ')\n .to!(uint[]);\n\n immutable frec = (){\n uint[uint] ret;\n vec.each!(x => ++ ret[x]);\n return ret.assumeUnique;\n }();\n\n ulong previousCost;\n immutable(int)[] ans; ans.reserve(n);\n uint[200_000] stack; /* Imagine having a stack in the standard library */\n assert(stack.length >= n);\n size_t top;\n\n\n if (0 !in frec) {\n writefln!\"0 %(%s %)\"(repeat(-1, n));\n continue;\n }\n\n write(frec[0]);\n previousCost = 0;\n foreach (_; 1 .. frec[0])\n stack[top ++] = 0;\n\n foreach (i; 1 .. n + 1) {\n if (i !in frec) {\n write(' ', previousCost);\n if (top != 0) {\n previousCost += i - stack[-- top];\n } else {\n writefln!\" %(%s %)\"(repeat(-1, n - i));\n continue TEST_LOOP;\n }\n } else {\n write(' ', previousCost + frec[i]);\n foreach (_; 1 .. frec[i])\n stack[top ++] = i;\n }\n }\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\nenum long INF = 1L<<50;\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n\r\n int[int] m;\r\n foreach (a; A) {\r\n m[a] = m.get(a, 0) + 1;\r\n }\r\n\r\n auto s = new RedBlackTree!(int, \"a < b\", true)();\r\n auto f = new long[N + 1];\r\n for (int k = 0; k < N; k++) {\r\n if (k in m) {\r\n foreach (_; 0 .. m[k]) {\r\n s.insert(k);\r\n }\r\n }\r\n if (s.empty) {\r\n f[k + 1] = INF;\r\n } else {\r\n int sm = s.back;\r\n f[k + 1] = f[k] + (k - sm);\r\n s.removeKey(sm);\r\n }\r\n }\r\n auto ans = new long[N + 1];\r\n for (int k = 0; k <= N; k++) {\r\n ans[k] = f[k] + m.get(k, 0);\r\n }\r\n writefln(\"%(%s %)\", ans.map!(x => x >= INF ? -1 : x).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"}], "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\nenum int INF = 1<<28;\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n sort(A);\r\n\r\n int[int] m;\r\n foreach (a; A) {\r\n m[a] = m.get(a, 0) + 1;\r\n }\r\n\r\n auto s = new RedBlackTree!(int, \"a < b\", true)();\r\n auto f = new int[N + 1];\r\n for (int k = 0; k < N; k++) {\r\n if (k in m) {\r\n foreach (_; 0 .. m[k]) {\r\n s.insert(k);\r\n }\r\n }\r\n if (s.empty) {\r\n f[k + 1] = INF;\r\n } else {\r\n int sm = s.back;\r\n f[k + 1] = f[k] + (k - sm);\r\n s.removeKey(sm);\r\n }\r\n }\r\n auto ans = new int[N + 1];\r\n for (int k = 0; k <= N; k++) {\r\n ans[k] = f[k] + m.get(k, 0);\r\n }\r\n writefln(\"%(%s %)\", ans.map!(x => x >= INF ? -1 : x).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"}, {"source_code": "import std;\n\nvoid main () {\n immutable tests = (){ uint t; readf!\"%s\\n\"(t); return t; }();\n\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n immutable n = (){ uint n; readf!\"%s\\n\"(n); return n; }();\n\n immutable vec =\n readln.chomp\n .split(' ')\n .to!(uint[]);\n\n immutable frec = (){\n uint[uint] ret;\n vec.each!(x => ++ ret[x]);\n return ret.assumeUnique;\n }();\n\n uint previousCost;\n immutable(int)[] ans; ans.reserve(n);\n uint[200_000] stack; /* Imagine having a stack in the standard library */\n assert(stack.length >= n);\n size_t top;\n\n\n if (0 !in frec) {\n writefln!\"0 %(%s %)\"(repeat(-1, n));\n continue;\n }\n\n write(frec[0]);\n previousCost = 0;\n foreach (_; 1 .. frec[0])\n stack[top ++] = 0;\n\n foreach (i; 1 .. n + 1) {\n if (i !in frec) {\n write(' ', previousCost);\n if (top != 0) {\n previousCost += i - stack[-- top];\n } else {\n writefln!\" %(%s %)\"(repeat(-1, n - i));\n continue TEST_LOOP;\n }\n } else {\n write(' ', previousCost + frec[i]);\n foreach (_; 1 .. frec[i])\n stack[top ++] = i;\n }\n }\n }\n}\n// \"\"\n"}], "src_uid": "18d19440e6df7316af0682ce99911738"} {"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);}\nvoid writeA(T)(size_t n,T t){foreach(i,v;t.enumerate){write(v);if(i ma) return n;\n else if (n%pi == 0) return pi;\n return n;\n}\n\npure T nsqrt(T)(T n)\n{\n import std.algorithm, std.conv, std.range, core.bitop;\n if (n <= 1) return n;\n T m = T(1) << (n.bsr/2+1);\n return iota(1, m).map!\"a*a\".assumeSorted!\"a <= b\".lowerBound(n).length.to!T;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.math, std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n auto f = new bool[][](n, n);\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n c[i] = 0;\n auto num = cast(long)a[i];\n foreach (j; 0 .. i)\n {\n f[j][i] = false;\n auto m = num * a[j];\n if (m > 0)\n {\n auto r = cast(long)sqrt(cast(double)m);\n if (r * r == m)\n {\n f[j][i] = true;\n ++ c[i];\n }\n }\n }\n }\n auto res = new int[n + 1];\n fill(res, 0);\n foreach (i; 0 .. n)\n {\n auto cnt = 0;\n auto flag = false;\n foreach (j; i .. n)\n {\n if (a[j] == 0)\n {\n if (cnt == 0)\n {\n ++ cnt;\n }\n }\n else\n {\n if (i > 0 && f[i - 1][j])\n {\n -- c[j];\n }\n if (flag == false)\n {\n if (cnt == 0)\n {\n ++ cnt;\n }\n }\n else if (c[j] == 0)\n {\n ++ cnt;\n }\n }\n ++ res[cnt];\n if (a[j] != 0)\n {\n flag = true;\n }\n }\n }\n foreach (i; 1 .. n)\n {\n write(res[i], \" \");\n }\n writeln(res[n]);\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}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.math, std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n auto f = new bool[][](n, n);\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n c[i] = 0;\n auto num = cast(long)a[i];\n foreach (j; 0 .. i)\n {\n f[j][i] = false;\n auto m = num * a[j];\n if (m >= 0)\n {\n auto r = sqrt(cast(double)m);\n if (r - cast(int)r <= 1e-9)\n {\n f[j][i] = true;\n ++ c[i];\n }\n }\n }\n }\n auto res = new int[n + 1];\n fill(res, 0);\n foreach (i; 0 .. n)\n {\n auto cnt = 0;\n foreach (j; i .. n)\n {\n if (i > 0 && f[i - 1][j])\n {\n -- c[j];\n }\n if (c[j] == 0)\n {\n ++ cnt;\n }\n ++ res[cnt];\n }\n }\n foreach (i; 1 .. n)\n {\n write(res[i], \" \");\n }\n writeln(res[n]);\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.string;\nimport std.math, std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n auto f = new bool[][](n, n);\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n c[i] = 0;\n auto num = cast(long)a[i];\n foreach (j; 0 .. i)\n {\n auto m = num * a[j];\n if (m >= 0)\n {\n auto r = sqrt(cast(double)m);\n f[j][i] = false;\n if (cast(long)r == r)\n {\n f[j][i] = true;\n ++ c[i];\n }\n }\n }\n }\n auto res = new int[n + 1];\n fill(res, 0);\n foreach (i; 0 .. n)\n {\n auto cnt = 0;\n foreach (j; i .. n)\n {\n if (i > 0 && f[i - 1][j])\n {\n -- c[j];\n }\n if (c[j] == 0)\n {\n ++ cnt;\n }\n ++ res[cnt];\n }\n }\n foreach (i; 1 .. n)\n {\n write(res[i], \" \");\n }\n writeln(res[n]);\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.string;\nimport std.math, std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n auto f = new bool[][](n, n);\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n c[i] = 0;\n auto num = cast(long)a[i];\n foreach (j; 0 .. i)\n {\n auto m = num * a[j];\n if (m >= 0)\n {\n auto r = sqrt(cast(double)m);\n f[j][i] = false;\n if (r - cast(int)r <= 1e-9)\n {\n f[j][i] = true;\n ++ c[i];\n }\n }\n }\n }\n auto res = new int[n + 1];\n fill(res, 0);\n foreach (i; 0 .. n)\n {\n auto cnt = 0;\n foreach (j; i .. n)\n {\n if (i > 0 && f[i - 1][j])\n {\n -- c[j];\n }\n if (c[j] == 0)\n {\n ++ cnt;\n }\n ++ res[cnt];\n }\n }\n foreach (i; 1 .. n)\n {\n write(res[i], \" \");\n }\n writeln(res[n]);\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.string;\nimport std.math, std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n auto f = new bool[][](n, n);\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n c[i] = 0;\n auto num = cast(double)a[i];\n foreach (j; 0 .. i)\n {\n f[j][i] = false;\n auto m = num * a[j];\n if (m > 0)\n {\n auto r = cast(long)sqrt(m);\n if (r * r == m)\n {\n f[j][i] = true;\n ++ c[i];\n }\n }\n }\n }\n auto res = new int[n + 1];\n fill(res, 0);\n foreach (i; 0 .. n)\n {\n auto cnt = 0;\n auto flag = false;\n foreach (j; i .. n)\n {\n if (a[j] == 0)\n {\n if (cnt == 0) ++ cnt;\n }\n else\n {\n if (i > 0 && f[i - 1][j])\n {\n -- c[j];\n }\n if (flag == false)\n {\n if (cnt == 0) ++ cnt;\n }\n else if (c[j] == 0)\n {\n ++ cnt;\n }\n }\n ++ res[cnt];\n if (a[j] != 0)\n {\n flag = true;\n }\n }\n }\n foreach (i; 1 .. n)\n {\n write(res[i], \" \");\n }\n writeln(res[n]);\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.string;\nimport std.math, std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n auto f = new bool[][](n, n);\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n c[i] = 0;\n auto num = cast(long)a[i];\n foreach (j; 0 .. i)\n {\n f[j][i] = false;\n double m = num * a[j];\n if (m >= 0)\n {\n auto r = cast(long)sqrt(cast(double)m);\n if (r * r == m)\n {\n f[j][i] = true;\n ++ c[i];\n }\n }\n }\n }\n auto res = new int[n + 1];\n fill(res, 0);\n foreach (i; 0 .. n)\n {\n auto cnt = 0;\n foreach (j; i .. n)\n {\n if (i > 0 && f[i - 1][j])\n {\n -- c[j];\n }\n if (c[j] == 0)\n {\n ++ cnt;\n }\n ++ res[cnt];\n }\n }\n foreach (i; 1 .. n)\n {\n write(res[i], \" \");\n }\n writeln(res[n]);\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.string;\nimport std.math, std.algorithm;\n\nvoid solve(int[] a, int n)\n{\n auto f = new bool[][](n, n);\n auto c = new int[n];\n foreach (i; 0 .. n)\n {\n c[i] = 0;\n auto num = cast(long)a[i];\n foreach (j; 0 .. i)\n {\n f[j][i] = false;\n auto m = num * a[j];\n if (m >= 0)\n {\n auto r = cast(long)sqrt(cast(double)m);\n if (r * r == m)\n {\n f[j][i] = true;\n ++ c[i];\n }\n }\n }\n }\n auto res = new int[n + 1];\n fill(res, 0);\n foreach (i; 0 .. n)\n {\n auto cnt = 0;\n foreach (j; i .. n)\n {\n if (i > 0 && f[i - 1][j])\n {\n -- c[j];\n }\n if (c[j] == 0)\n {\n ++ cnt;\n }\n ++ res[cnt];\n }\n }\n foreach (i; 1 .. n)\n {\n write(res[i], \" \");\n }\n writeln(res[n]);\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, 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 auto p = primes(10^^4);\n auto b = new int[][](n);\n foreach (i; 0..n)\n b[i] = div(a[i], p);\n\n auto r = new int[](n+1);\n foreach (i; 0..n) {\n auto rbt = redBlackTree!(false, int[])(b[i]);\n r[1]++;\n foreach (j; i+1..n) {\n if (!rbt.empty && rbt.front == [0]) {\n rbt.removeFront();\n }\n if (b[j] != [0]) {\n rbt.insert(b[j]);\n }\n r[rbt.length]++;\n }\n }\n\n foreach (i; 0..n)\n write(r[i+1], \" \");\n writeln;\n}\n\nauto div(int a, int[] p)\n{\n int[] r;\n if (a == 0) return [0];\n\n if (a < 0) {\n r ~= [-1];\n a = -a;\n }\n\n foreach (pi; p) {\n if (a == 1) break;\n auto c = 0;\n while (a%pi == 0) {\n ++c;\n a /= pi;\n }\n if (c%2 == 1) r ~= pi;\n }\n\n return r;\n}\n\npure T[] primes(T)(T n)\n{\n import std.algorithm, std.bitmanip, std.conv, std.range;\n\n auto sieve = BitArray();\n sieve.length((n+1)/2);\n sieve = ~sieve;\n\n foreach (p; 1..((nsqrt(n)-1)/2+1))\n if (sieve[p])\n for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)\n sieve[q] = false;\n\n auto r = sieve.bitsSet.map!(to!T).map!(\"a*2+1\").array;\n r[0] = 2;\n\n return r;\n}\n\npure T factor(T)(T n, const T[] p)\n{\n auto ma = nsqrt(n)+1;\n foreach (pi; p)\n if (pi > ma) return n;\n else if (n%pi == 0) return pi;\n return n;\n}\n\npure T nsqrt(T)(T n)\n{\n import std.algorithm, std.conv, std.range, core.bitop;\n if (n <= 1) return n;\n T m = T(1) << (n.bsr/2+1);\n return iota(1, m).map!\"a*a\".assumeSorted!\"a <= b\".lowerBound(n).length.to!T;\n}\n"}], "src_uid": "75d05c16baaba4b17ad6a9c1dd641bc0"} {"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 Tuple!(int, int)[] pts;\n foreach (i; 0 .. k) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n pts ~= tuple(x, y);\n }\n \n int[][int] up, dwn;\n foreach (i, p; pts) {\n up[p[1] - p[0]] ~= i.to!int;\n dwn[p[1] + p[0]] ~= i.to!int;\n }\n \n debug { up.writeln; dwn.writeln; }\n \n auto ans = new long[k];\n ans[] = -1;\n \n auto vis = new bool[][] (4, max(n+1, m+1));\n \n Tuple!(int, int) toVis(int x, int y) {\n if (y == 0) { return tuple(0, x); }\n if (y == m) { return tuple(1, x); }\n if (x == 0) { return tuple(2, y); }\n if (x == n) { return tuple(3, y); }\n \n assert(false);\n }\n \n vis[0][0] = vis[1][0] = vis[0][n] = vis[1][n] = true;\n int cx = 0, cy = 0, dir = 1;\n long tm = 0;\n do {\n vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]] = true; \n int nx, ny, mv;\n if (dir == 1) {\n mv = min(n - cx, m - cy);\n nx = cx + mv;\n ny = cy + mv;\n dir = ny != m ? 2 : 4;\n } else if (dir == 2) {\n mv = min(cx, m - cy);\n nx = cx - mv;\n ny = cy + mv;\n dir = ny == m ? 3 : 1;\n } else if (dir == 3) {\n mv = min(cx, cy);\n nx = cx - mv;\n ny = cy - mv;\n dir = nx == 0 ? 4 : 2;\n } else {\n mv = min(n - cx, cy);\n nx = cx + mv;\n ny = cy - mv;\n dir = ny == 0 ? 1 : 3;\n }\n \n bool isUp = (nx - cx).to!long * (ny - cy) > 0;\n int coord = isUp ? ny - nx : ny + nx;\n auto dct = isUp ? &up : &dwn;\n foreach (idx; dct.get(coord, [])) {\n if (ans[idx] != -1) { continue; }\n \n ans[idx] = tm + abs(pts[idx][0] - cx);\n }\n \n cx = nx;\n cy = ny;\n tm += mv;\n \n debug { writeln(cx, ' ', cy, ' ', tm, ' ', dir); }\n \n } while (!vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]]);\n \n ans.each!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\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}\nTuple!(Int, \"b\", Int, \"m\") modSol(Int)(Int b0, Int m0, Int b1, Int m1) {\n Int b, m, x, y;\n const g = gojo(m0, m1, x, y);\n if ((b1 - b0) % g == 0) {\n b = b0 + m0 * ((x * (((b1 - b0) / g) % (m1 / g))) % (m1 / g));\n m = m0 * (m1 / g);\n if ((b %= m) < 0) {\n b += m;\n }\n }\n return Tuple!(Int, \"b\", Int, \"m\")(b, m);\n}\n\n\nenum INF = 10L^^18;\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readLong();\n const N = readLong();\n const K = readInt();\n auto X = new long[K];\n auto Y = new long[K];\n foreach (k; 0 .. K) {\n X[k] = readLong();\n Y[k] = readLong();\n }\n \n long calc(long x, long y) {\n const res = modSol(x, 2 * M, y, 2 * N);\n debug {\n writeln(x, \" \", y, \": \", res);\n }\n return (res.m == 0) ? INF : res.b;\n }\n \n foreach (k; 0 .. K) {\n long ans = INF;\n foreach (x; [X[k], 2 * M - X[k]]) foreach (y; [Y[k], 2 * N - Y[k]]) {\n const res = calc(x, y);\n chmin(ans, res);\n }\n writeln((ans >= INF) ? -1 : ans);\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.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 Tuple!(int, int)[] pts;\n foreach (i; 0 .. k) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n pts ~= tuple(x, y);\n }\n \n int[][int] up, dwn;\n foreach (i, p; pts) {\n up[p[1] - p[0]] ~= i.to!int;\n dwn[p[1] + p[0]] ~= i.to!int;\n }\n \n debug { up.writeln; dwn.writeln; }\n \n auto ans = new long[k];\n ans[] = -1;\n \n auto vis = new bool[][] (4, max(n+1, m+1));\n \n Tuple!(int, int) toVis(int x, int y) {\n if (y == 0) { return tuple(0, x); }\n if (y == m) { return tuple(1, x); }\n if (x == 0) { return tuple(0, y); }\n if (x == n) { return tuple(1, y); }\n \n assert(false);\n }\n \n vis[0][0] = vis[1][0] = vis[0][n] = vis[1][n] = true;\n int cx = 0, cy = 0, dir = 1;\n long tm = 0;\n do {\n vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]] = true; \n int nx, ny, mv;\n if (dir == 1) {\n mv = min(n - cx, m - cy);\n nx = cx + mv;\n ny = cy + mv;\n dir = ny != m ? 2 : 4;\n } else if (dir == 2) {\n mv = min(cx, m - cy);\n nx = cx - mv;\n ny = cy + mv;\n dir = ny == m ? 3 : 1;\n } else if (dir == 3) {\n mv = min(cx, cy);\n nx = cx - mv;\n ny = cy - mv;\n dir = nx == 0 ? 4 : 2;\n } else {\n mv = min(n - cx, cy);\n nx = cx + mv;\n ny = cy - mv;\n dir = ny == 0 ? 1 : 3;\n }\n \n bool isUp = (nx - cx).to!long * (ny - cy) > 0;\n int coord = isUp ? ny - nx : ny + nx;\n auto dct = isUp ? &up : &dwn;\n foreach (idx; dct.get(coord, [])) {\n if (ans[idx] != -1) { continue; }\n \n ans[idx] = tm + abs(pts[idx][0] - cx);\n }\n \n cx = nx;\n cy = ny;\n tm += mv;\n \n debug { writeln(cx, ' ', cy, ' ', tm, ' ', dir); }\n \n } while (!vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]]);\n \n ans.each!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, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n Tuple!(int, int)[] pts;\n foreach (i; 0 .. k) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n pts ~= tuple(x, y);\n }\n \n int[][int] up, dwn;\n foreach (i, p; pts) {\n up[p[1] - p[0]] ~= i.to!int;\n dwn[p[1] + p[0]] ~= i.to!int;\n }\n \n debug { up.writeln; dwn.writeln; }\n \n auto ans = new int[k];\n ans[] = -1;\n \n auto vis = new bool[][] (4, max(n+1, m+1));\n \n Tuple!(int, int) toVis(int x, int y) {\n if (y == 0) { return tuple(0, x); }\n if (y == m) { return tuple(1, x); }\n if (x == 0) { return tuple(2, y); }\n if (x == n) { return tuple(3, y); }\n \n assert(false);\n }\n \n vis[0][0] = vis[1][0] = vis[0][n] = vis[1][n] = true;\n int cx = 0, cy = 0, dir = 1, tm = 0;\n do {\n vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]] = true; \n int nx, ny, mv;\n if (dir == 1) {\n mv = min(n - cx, m - cy);\n nx = cx + mv;\n ny = cy + mv;\n dir = ny != m ? 2 : 4;\n } else if (dir == 2) {\n mv = min(cx, m - cy);\n nx = cx - mv;\n ny = cy + mv;\n dir = ny == m ? 3 : 1;\n } else if (dir == 3) {\n mv = min(cx, cy);\n nx = cx - mv;\n ny = cy - mv;\n dir = nx == 0 ? 4 : 2;\n } else {\n mv = min(n - cx, cy);\n nx = cx + mv;\n ny = cy - mv;\n dir = ny == 0 ? 1 : 3;\n }\n \n bool isUp = (nx - cx).to!long * (ny - cy) > 0;\n int coord = isUp ? ny - nx : ny + nx;\n auto dct = isUp ? &up : &dwn;\n foreach (idx; dct.get(coord, [])) {\n if (ans[idx] != -1) { continue; }\n \n ans[idx] = tm + abs(pts[idx][0] - cx);\n }\n \n cx = nx;\n cy = ny;\n tm += mv;\n \n debug { writeln(cx, ' ', cy, ' ', tm, ' ', dir); }\n \n } while (!vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]]);\n \n ans.each!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, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n Tuple!(int, int)[] pts;\n foreach (i; 0 .. k) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n pts ~= tuple(x, y);\n }\n \n int[][int] up, dwn;\n foreach (i, p; pts) {\n up[p[1] - p[0]] ~= i.to!int;\n dwn[p[1] + p[0]] ~= i.to!int;\n }\n \n debug { up.writeln; dwn.writeln; }\n \n auto ans = new int[k];\n ans[] = -1;\n \n auto vis = new bool[][] (4, max(n+1, m+1));\n \n Tuple!(int, int) toVis(int x, int y) {\n if (y == 0) { return tuple(0, x); }\n if (y == m) { return tuple(1, x); }\n if (x == 0) { return tuple(0, y); }\n if (x == n) { return tuple(1, y); }\n \n assert(false);\n }\n \n vis[0][0] = vis[1][0] = vis[0][n] = vis[1][n] = true;\n int cx = 0, cy = 0, dir = 1, tm = 0;\n do {\n vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]] = true; \n int nx, ny, mv;\n if (dir == 1) {\n mv = min(n - cx, m - cy);\n nx = cx + mv;\n ny = cy + mv;\n dir = ny != m ? 2 : 4;\n } else if (dir == 2) {\n mv = min(cx, m - cy);\n nx = cx - mv;\n ny = cy + mv;\n dir = ny == m ? 3 : 1;\n } else if (dir == 3) {\n mv = min(cx, cy);\n nx = cx - mv;\n ny = cy - mv;\n dir = nx == 0 ? 4 : 2;\n } else {\n mv = min(n - cx, cy);\n nx = cx + mv;\n ny = cy - mv;\n dir = ny == 0 ? 1 : 3;\n }\n \n bool isUp = (nx - cx).to!long * (ny - cy) > 0;\n int coord = isUp ? ny - nx : ny + nx;\n auto dct = isUp ? &up : &dwn;\n foreach (idx; dct.get(coord, [])) {\n if (ans[idx] != -1) { continue; }\n \n ans[idx] = tm + abs(pts[idx][0] - cx);\n }\n \n cx = nx;\n cy = ny;\n tm += mv;\n \n debug { writeln(cx, ' ', cy, ' ', tm, ' ', dir); }\n \n } while (!vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]]);\n \n ans.each!writeln;\n}"}], "src_uid": "27a521d4d59066e50e870e7934d4b190"} {"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)[] 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 arr.schwartzSort!(t => t[0] - t[1]).reverse();\n \n debug { arr.writeln; }\n \n long total = arr.map!(t => t[0]).sum(0L);\n int ans = 0;\n foreach (e; arr) {\n if (total <= m) break;\n \n total -= e[0] - e[1];\n ++ans;\n }\n \n if (total > m) {\n writeln(-1);\n return;\n }\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.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)[] arr;\n auto fnc = (int[] a) => tuple(a[0], a[1]);\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 arr.schwartzSort!(t => t[0] - t[1]).reverse();\n \n debug { arr.writeln; }\n \n long total = arr.map!(t => t[0]).sum(0L);\n int ans = 0;\n foreach (e; arr) {\n if (total <= m) break;\n \n total -= e[0] - e[1];\n ++ans;\n }\n \n if (total > m) {\n writeln(-1);\n return;\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\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 = new int [n];\n\t\tauto b = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &a[i], &b[i]);\n\t\t}\n\t\tb[] = a[] - b[];\n\t\tsort !(q{a > b}) (b);\n\t\tauto total = sum (a, 0L);\n\t\tint res = 0;\n\t\twhile (total > m && !b.empty)\n\t\t{\n\t\t\tres += 1;\n\t\t\ttotal -= b[0];\n\t\t\tb = b[1..$];\n\t\t}\n\t\tif (total > m)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "91541d10c5ae52be8da33412359bd019"} {"source_code": "import std.algorithm;\nimport std.functional;\nimport std.stdio;\n\nimmutable int MAX_N = 31;\nimmutable int MAX_K = 51;\nimmutable int INF = int.max / 4;\nimmutable int NA = -1;\n\nint [] [] [] f;\n\nint mfun (int n, int m, int k)\n{\n\tif (f[n][m][k] == NA)\n\t{\n\t\tf[n][m][k] = fun (n, m, k);\n\t}\n\treturn f[n][m][k];\n}\n\nint fun (int n, int m, int k)\n{\n\tif (k == 0)\n\t{\n\t\treturn 0;\n\t}\n\tif (n * m == k)\n\t{\n\t\treturn 0;\n\t}\n\tif (n * m < k)\n\t{\n\t\treturn INF;\n\t}\n\tint res = INF;\n\tforeach (p; 0..k + 1)\n\t{\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tint cost = m * m;\n\t\t\tres = min (res, cost + mfun (i, m, p) +\n\t\t\t mfun (n - i, m, k - p));\n\t\t}\n\t\tforeach (j; 1..m)\n\t\t{\n\t\t\tint cost = n * n;\n\t\t\tres = min (res, cost + mfun (n, j, p) +\n\t\t\t mfun (n, m - j, k - p));\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tf = new int [] [] [] (MAX_N, MAX_N, MAX_K);\n\tforeach (ref g; f)\n\t{\n\t\tforeach (ref h; g)\n\t\t{\n\t\t\th[] = NA;\n\t\t}\n\t}\n\n\tint tests;\n\treadf (\" %s\", &tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, m, k;\n\t\treadf (\" %s %s %s\", &n, &m, &k);\n\t\twriteln (mfun (n, m, k));\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.algorithm, std.math;\n\nint dp[31][31][51];\nimmutable auto inf = 1 << 29;\n\nint saiki(int n, int m, int k)\n{\n int res = dp[n][m][k];\n if (res != -1) return res;\n if (k == 0)\n {\n dp[n][m][k] = 0;\n return 0;\n }\n if (n * m < k)\n {\n dp[n][m][k] = inf;\n return dp[n][m][k];\n }\n if (n * m == k) return 0;\n res = inf;\n foreach (i; 1 .. (n >> 1) + 1)\n {\n foreach (j; 0 .. to!int(fmin(i * m, k)) + 1)\n {\n auto ret = saiki(i, m, j) + saiki(n - i, m, k - j) + m * m;\n res = to!int(fmin(res, ret));\n }\n }\n foreach (i; 1 .. (m >> 1) + 1)\n {\n foreach (j; 0 .. to!int(fmin(i * n, k)) + 1)\n {\n auto ret = saiki(n, i, j) + saiki(n, m - i, k - j) + n * n;\n res = to!int(fmin(res, ret));\n }\n }\n dp[n][m][k] = res;\n return res;\n}\n\nvoid main(string[] args)\n{\n int t;\n foreach (i; 0 .. 31)\n {\n foreach (j; 0 .. 31)\n {\n foreach (k; 0 .. 51)\n {\n dp[i][j][k] = -1;\n }\n }\n }\n scanf(\"%d\", &t);\n foreach (i; 0 .. t)\n {\n int n, m, k;\n scanf(\"%d%d%d\", &n, &m, &k);\n auto ans = saiki(n, m, k);\n writeln(ans);\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.algorithm, std.math;\n\nint dp[31][31][51];\nimmutable auto inf = 1 << 29;\n\nint saiki(int n, int m, int k)\n{\n int res = dp[n][m][k];\n if (res != -1) return res;\n if (k == 0 || n * m == k) return 0;\n if (n * m < k) return inf;\n res = inf;\n foreach (i; 1 .. (n >> 1) + 1)\n {\n foreach (j; 0 .. to!int(fmin(i * m, k)) + 1)\n {\n auto ret = saiki(i, m, j) + saiki(n - i, m, k - j) + m * m;\n res = to!int(fmin(res, ret));\n }\n }\n foreach (i; 1 .. (m >> 1) + 1)\n {\n foreach (j; 0 .. to!int(fmin(i * n, k)) + 1)\n {\n auto ret = saiki(n, i, j) + saiki(n, m - i, k - j) + n * n;\n res = to!int(fmin(res, ret));\n }\n }\n dp[n][m][k] = res;\n return res;\n}\n\nvoid main(string[] args)\n{\n int t;\n foreach (i; 0 .. 31)\n {\n foreach (j; 0 .. 31)\n {\n foreach (k; 0 .. 51)\n {\n dp[i][j][k] = -1;\n }\n }\n }\n scanf(\"%d\", &t);\n foreach (i; 0 .. t)\n {\n int n, m, k;\n scanf(\"%d%d%d\", &n, &m, &k);\n auto ans = saiki(n, m, k);\n writeln(ans);\n }\n}\n"}], "negative_code": [], "src_uid": "d154c3df1947f52ec370c6ad2771eb47"} {"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 = 4 * 10L^^18;\n\nalias Line = Tuple!(char, \"op\", long, \"a\", long, \"b\");\n\nvoid main() {\n debug {\n for (long n = 1; n < 10^^6; n += 2) {\n assert(gcd(n, n ^ (n << bsr(n))) == 1);\n }\n }\n \n try {\n for (; ; ) {\n const N = readLong();\n if (N == 1) {\n writeln(0);\n continue;\n }\n \n const K = bsr(N);\n const B = N ^ (N << K);\n \n Line[] ans;\n for (int i = 1; ; ++i) {\n if (N << i > LIM) {\n break;\n }\n ans ~= Line('+', N << (i - 1), N << (i - 1));\n }\n ans ~= Line('^', N, N << K);\n for (int i = 1; ; ++i) {\n if (B << i > LIM) {\n break;\n }\n ans ~= Line('+', B << (i - 1), B << (i - 1));\n }\n \n int L;\n for (L = 1; 1L << L < N * B; ++L) {}\n foreach (t; [1L << L, 1L << L | 1]) {\n foreach (y; 0 .. N) {\n if ((t - B * y) % N == 0) {\n const x = (t - B * y) / N;\n long sum;\n foreach (e; 0 .. bsr(x) + 1) {\n if ((x >> e) & 1) {\n if (sum > 0) {\n ans ~= Line('+', sum, N << e);\n }\n sum += N << e;\n }\n }\n foreach (e; 0 .. bsr(y) + 1) {\n if ((y >> e) & 1) {\n if (sum > 0) {\n ans ~= Line('+', sum, B << e);\n }\n sum += B << e;\n }\n }\n assert(sum == t);\n break;\n }\n }\n }\n ans ~= Line('^', 1L << L, 1L << L | 1);\n \n writeln(ans.length);\n foreach (ref line; ans) {\n writefln(\"%s %s %s\", line.a, line.op, line.b);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\nimport std.math;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nauto gcdExt (long a, long b, ref long x, ref long y)\nout (res)\n{\n\tassert (a * x + b * y == res);\n}\nbody\n{\n\tif (a == 0)\n\t{\n\t\tx = 0;\n\t\ty = 1;\n\t\treturn b;\n\t}\n\tauto res = gcdExt (b % a, a, y, x);\n\tx -= (b / a) * y;\n\treturn res;\n}\n\nvoid main ()\n{\n\tlong n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tstring [] answer;\n\t\tanswer ~= format !(\"%s ^ %s\") (n, n); // zero\n\n\t\tvoid getMult (long v, long m)\n\t\t{\n\t\t\tif (m > 1)\n\t\t\t{\n\t\t\t\tanswer ~= format !(\"%s + %s\") (v, v);\n\t\t\t\tgetMult (v * 2, m / 2);\n\t\t\t\tif (m & 1)\n\t\t\t\t{\n\t\t\t\t\tanswer ~= format !(\"%s + %s\")\n\t\t\t\t\t ((v * 2) * (m / 2), v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twhile (true)\n\t\t{\n\t\t\tauto a = uniform (1L, 11L);\n//\t\t\tauto b = uniform (1L, 1100L);\n\t\t\tauto b = n;\n\t\t\tauto na = n * a;\n\t\t\tauto nb = n * b;\n\t\t\tauto nc = na ^ nb;\n\t\t\tlong x, y;\n\t\t\tif (gcdExt (na, nc, x, y) != 1L)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tx = abs (x);\n\t\t\ty = abs (y);\n\t\t\tif ((na * x) / x != na || (nc * y) / y != nc)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (((na * x) ^ (nc * y)) != 1L)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tgetMult (n, a);\n\t\t\tgetMult (n, b);\n\t\t\tanswer ~= format !(\"%s ^ %s\") (na, nb);\n\t\t\tgetMult (na, x);\n\t\t\tgetMult (nc, y);\n\t\t\tanswer ~= format !(\"%s ^ %s\") (na * x, nc * y);\n\t\t\tbreak;\n\t\t}\n\n\t\twriteln (answer.length);\n\t\tforeach (ref line; answer)\n\t\t{\n\t\t\twriteln (line);\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\nimport std.math;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nauto gcdExt (long a, long b, ref long x, ref long y)\nout (res)\n{\n\tassert (a * x + b * y == res);\n}\nbody\n{\n\tif (a == 0)\n\t{\n\t\tx = 0;\n\t\ty = 1;\n\t\treturn b;\n\t}\n\tauto res = gcdExt (b % a, a, y, x);\n\tx -= (b / a) * y;\n\treturn res;\n}\n\nvoid main ()\n{\n\tlong n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tstring [] answer;\n\t\tanswer ~= format !(\"%s ^ %s\") (n, n); // zero\n\n\t\tvoid getMult (long v, long m)\n\t\t{\n\t\t\tif (m > 1)\n\t\t\t{\n\t\t\t\tanswer ~= format !(\"%s + %s\") (v, v);\n\t\t\t\tgetMult (v * 2, m / 2);\n\t\t\t\tif (m & 1)\n\t\t\t\t{\n\t\t\t\t\tanswer ~= format !(\"%s + %s\")\n\t\t\t\t\t ((v * 2) * (m / 2), v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twhile (true)\n\t\t{\n\t\t\tauto a = uniform (1L, 1100L);\n//\t\t\tauto b = uniform (1L, 1100L);\n\t\t\tauto b = n;\n\t\t\tauto na = n * a;\n\t\t\tauto nb = n * b;\n\t\t\tauto nc = na ^ nb;\n\t\t\tlong x, y;\n\t\t\tif (gcdExt (na, nc, x, y) != 1L)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tx = abs (x);\n\t\t\ty = abs (y);\n\t\t\tif ((na * x) / x != na || (nc * y) / y != nc)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (((na * x) ^ (nc * y)) != 1L)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tgetMult (n, a);\n\t\t\tgetMult (n, b);\n\t\t\tanswer ~= format !(\"%s ^ %s\") (na, nb);\n\t\t\tgetMult (na, x);\n\t\t\tgetMult (nc, y);\n\t\t\tanswer ~= format !(\"%s ^ %s\") (na * x, nc * y);\n\t\t\tbreak;\n\t\t}\n\n\t\twriteln (answer.length);\n\t\tforeach (ref line; answer)\n\t\t{\n\t\t\twriteln (line);\n\t\t}\n\t}\n}\n"}], "src_uid": "d8134a016838448ed827233003626362"} {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\treadln;\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tif (n % 4 == 0)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\tint [] a;\n\t\t\tint [] b;\n\t\t\tint cur = 0;\n\t\t\tfor (int i = 0; i < n / 2; i += 2)\n\t\t\t{\n\t\t\t\ta ~= cur + 1;\n\t\t\t\ta ~= cur + 5;\n\t\t\t\tb ~= cur + 2;\n\t\t\t\tb ~= cur + 4;\n\t\t\t\tcur += 6;\n\t\t\t}\n\t\t\twritefln !(\"%(%s %)\") (b ~ a);\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.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 if ((N/2)%2 == 1) {\n writeln(\"NO\");\n continue;\n }\n int[] as, bs;\n int x;\n foreach (_i; 0..N/2) {\n ++x;\n if (x%2 == 1) {\n bs ~= x++;\n as ~= x++;\n } else {\n as ~= x++;\n bs ~= x++;\n }\n }\n writeln(\"YES\");\n writeln((as ~= bs).to!(string[]).join(\" \"));\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\tif ((n / 2) % 2) continue;\n\n\t\tforeach (i; 0..n/2)\n\t\t{\n\t\t\tans[ti] ~= (i+1)*2;\n\t\t}\n\t\tforeach (i; 0..n/2)\n\t\t{\n\t\t\tif (i < n/4)\n\t\t\t\tans[ti] ~= ans[ti][i]-1;\n\t\t\telse\n\t\t\t\tans[ti] ~= ans[ti][i]+1;\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}"}], "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 if ((N/2)%2 == 1) {\n writeln(\"NO\");\n continue;\n }\n int[] as, bs;\n int x;\n foreach (_i; 0..N/2) {\n ++x;\n if (x%2 == 1) {\n bs ~= x++;\n as ~= x++;\n } else {\n as ~= x++;\n bs ~= x++;\n }\n }\n writeln((as ~= bs).to!(string[]).join(\" \"));\n }\n}"}], "src_uid": "0c7e019e1e955cadacca55b4e823a3e5"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array;\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 long sum = a.sum;\n if (sum % n != 0) {\n writeln(-1);\n } else {\n long avg = sum / n;\n writeln(a.count!(x => x > avg));\n }\n }\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1538/problem/B\n// basic 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 long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n\n long total = a.sum();\n \n if(total % n != 0) {\n \"-1\".writeln;\n continue;\n }\n\n long candies = total / n;\n long ans = 0L;\n for(int i = 0; i < n; ++i) {\n if(a[i] > candies)\n ans += 1;\n }\n ans.writeln;\n}\n}\n"}, {"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 sm = sum(ar);\r\n writeln((sm % n != 0) ? -1 : to!int(ar.count!(a => a > sm/n)));\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "b8554e64b92b1b9458955da7d55eba62"} {"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\tint k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto x = readln.splitter.map !(to !(int)).array;\n\t\tint [int] first;\n\t\tint [int] last;\n\t\tforeach (i, ref cur; x)\n\t\t{\n\t\t\tif (cur !in first)\n\t\t\t{\n\t\t\t\tfirst[cur] = i;\n\t\t\t}\n\t\t\tlast[cur] = i;\n\t\t}\n\n\t\tbool canBe (int a, int b)\n\t\t{\n\t\t\tif (a !in first)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tint step = first[a];\n\t\t\tif (b !in last)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn step > last[b];\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (a; 1..n + 1)\n\t\t{\n\t\t\tforeach (b; max (a - 1, 1)..min (a + 1, n) + 1)\n\t\t\t{\n\t\t\t\tif (canBe (a, b))\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", "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.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\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n immutable k = r.next!int;\n immutable a = r.nextA!int(k).idup;\n auto c = new int[n + 1];\n auto first = new int[n+1];\n first[] = int.max;\n auto last = new int[n+1];\n last[] = int.min;\n foreach_reverse (i, j; a) {\n first[j] = i.to!int;\n ++c[j];\n }\n foreach (i, j; a) {\n last[j] = i.to!int;\n }\n int res;\n foreach (i; 1 .. n + 1) {\n foreach (delta; -1 .. 2) {\n int j = i + delta;\n if (j >= 1 && j <= n) {\n if (first[i] > last[j]) ++res;\n }\n }\n }\n writeln (res);\n}\n\n"}], "negative_code": [], "src_uid": "cabb7edf51f32c94415d580b96eef7b7"} {"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[] p; readA(n, p);\n\n auto g = new int[](256); g[] = -1;\n\n auto calcGroup(int pi)\n {\n if (g[pi] >= 0) return g[pi];\n foreach_reverse (pj; max(0, pi-k+1)..pi) {\n if (g[pj] >= 0) {\n if (pi-g[pj]+1 <= k) {\n g[pj+1..pi+1][] = g[pj];\n return g[pj];\n } else {\n g[pj+1..pi+1][] = pj+1;\n return pj+1;\n }\n }\n }\n auto j = max(0, pi-k+1);\n g[j..pi+1] = j;\n return j;\n }\n\n foreach (i, pi; p)\n write(calcGroup(pi), \" \");\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 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 int[int] B;\n auto ans = new int[](N);\n\n foreach (i; 0..N) {\n if (A[i] in B) {\n ans[i] = B[A[i]];\n continue;\n }\n\n int k = max(0, A[i] - K + 1);\n while (k in B && A[i] - B[k] >= K) ++k;\n\n if (k in B) {\n ans[i] = B[k];\n foreach (j; k..A[i]+1) B[j] = B[k];\n } else {\n ans[i] = k;\n foreach (j; k..A[i]+1) B[j] = k;\n }\n }\n\n\n ans.map!(to!string).join(\" \").writeln;\n}\n"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n \n int n, k; rd(n, k);\n auto a=readln.split.to!(int[]);\n\n const int m=256;\n auto root=new int[](m);\n fill(root, -1);\n int[] val;\n foreach(i; 0..n){\n if(root[a[i]]<0){\n // auto left=max(0, a[i]-k+1);\n // while(root[left]>=0) left++;\n // for(int j=left; j=0; j--){\n if(root[j]>=0){\n left=j; break;\n }\n }\n if(left k - 1) {\n\t\t\tauto arr = done.lowerBound(t + k);\n\t\t\tif (!arr.empty) {\n\t\t\t\tt = max(t, arr.back);\n\t\t\t}\n\t\t\tt = max(t + 1, q - k + 1);\n\t\t\tdebug verbose(\"NEW\", t);\n\t\t\ttree.insert(t);\n\t\t}\n\t\tans ~= t;\n\t\tdone.insert(q);\n\t}\n\tforeach (i, d; ans) {\n\t\tif (i) write = \" \";\n\t\td.write;\n\t}\n\twriteln;\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.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\tint[] p = readln.chomp.split.map!(to!int).array;\n\tint ite = 0;\n\tint[] ans;\n\tRedBlackTree!int tree = new RedBlackTree!int();\n\tRedBlackTree!int done = new RedBlackTree!int();\n\ttree.insert(ite);\n\tdone.insert(ite);\n\tforeach (q; p) {\n\t\tint t = tree.lowerBound(q + 1).back;\n\t\tdebug verbose(q, t, tree);\n\t\tif (q - t > k - 1) {\n\t\t\tauto arr = done.upperBound(t);\n\t\t\tif (!arr.empty) {\n\t\t\t\tt = max(t, arr.front);\n\t\t\t}\n\t\t\tt = max(t + 1, q - k + 1);\n\t\t\tt = min(t, 255);\n\t\t\tdebug verbose(\"NEW\", t);\n\t\t\ttree.insert(t);\n\t\t}\n\t\tans ~= t;\n\t\tdone.insert(q);\n\t}\n\tforeach (i, d; ans) {\n\t\tif (i) write = \" \";\n\t\td.write;\n\t}\n\twriteln;\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\tint[] p = readln.chomp.split.map!(to!int).array;\n\tint ite = 0;\n\tint[] ans;\n\tRedBlackTree!int tree = new RedBlackTree!int();\n\tRedBlackTree!int done = new RedBlackTree!int();\n\ttree.insert(ite);\n\tdone.insert(ite);\n\tforeach (q; p) {\n\t\tint t = tree.lowerBound(q + 1).back;\n\t\tdebug verbose(q, t, tree);\n\t\tif (q - t > k - 1) {\n\t\t\tauto arr = done.upperBound(t);\n\t\t\tif (!arr.empty) {\n\t\t\t\tt = max(t, min(t + k - 1, arr.front));\n\t\t\t}\n\t\t\tt = max(t + 1, q - k + 1);\n\t\t\tdebug verbose(\"NEW\", t);\n\t\t\ttree.insert(t);\n\t\t}\n\t\tans ~= t;\n\t\tdone.insert(q);\n\t}\n\tforeach (i, d; ans) {\n\t\tif (i) write = \" \";\n\t\td.write;\n\t}\n\twriteln;\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\tint[] p = readln.chomp.split.map!(to!int).array;\n\tint ite = 0;\n\tint[] ans;\n\tRedBlackTree!int tree = new RedBlackTree!int();\n\tRedBlackTree!int done = new RedBlackTree!int();\n\ttree.insert(ite);\n\tdone.insert(ite);\n\tforeach (q; p) {\n\t\tint t = tree.lowerBound(q + 1).back;\n\t\tdebug verbose(q, t, tree);\n\t\tif (q - t > k - 1) {\n\t\t\tt = max(t + 1, q - k + 1);\n\t\t\tt = max(t, min(done.upperBound(t).front + 1, t + k - 1));\n\t\t\tdebug verbose(\"NEW\", t);\n\t\t\ttree.insert(t);\n\t\t}\n\t\tans ~= t;\n\t\tdone.insert(q);\n\t}\n\tforeach (i, d; ans) {\n\t\tif (i) write = \" \";\n\t\td.write;\n\t}\n\twriteln;\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\tint[] p = readln.chomp.split.map!(to!int).array;\n\tint ite = 0;\n\tint[] ans;\n\tRedBlackTree!int tree = new RedBlackTree!int();\n\tRedBlackTree!int done = new RedBlackTree!int();\n\ttree.insert(ite);\n\tdone.insert(ite);\n\tforeach (q; p) {\n\t\tint t = tree.lowerBound(q + 1).back;\n\t\tdebug verbose(q, t, tree);\n\t\tif (q - t > k - 1) {\n\t\t\tauto arr = done.upperBound(t);\n\t\t\tif (!arr.empty) {\n\t\t\t\tt = max(t, arr.front);\n\t\t\t}\n\t\t\tt = max(t + 1, q - k + 1);\n\t\t\tdebug verbose(\"NEW\", t);\n\t\t\ttree.insert(t);\n\t\t}\n\t\tans ~= t;\n\t\tdone.insert(q);\n\t}\n\tforeach (i, d; ans) {\n\t\tif (i) write = \" \";\n\t\td.write;\n\t}\n\twriteln;\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\tint[] p = readln.chomp.split.map!(to!int).array;\n\tint ite = 0;\n\tint[] ans;\n\tRedBlackTree!int tree = new RedBlackTree!int();\n\tRedBlackTree!int done = new RedBlackTree!int();\n\ttree.insert(ite);\n\tdone.insert(ite);\n\tforeach (q; p) {\n\t\tint t = tree.lowerBound(q + 1).back;\n\t\tdebug verbose(q, t, tree);\n\t\tif (q - t > k - 1) {\n\t\t\tt = max(t + 1, q - k + 1);\n\t\t\tt = max(t, min(done.upperBound(t).front + 1, t + k));\n\t\t\tdebug verbose(\"NEW\", t);\n\t\t\ttree.insert(t);\n\t\t}\n\t\tans ~= t;\n\t\tdone.insert(q);\n\t}\n\tforeach (i, d; ans) {\n\t\tif (i) write = \" \";\n\t\td.write;\n\t}\n\twriteln;\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"}], "src_uid": "deed251d324f7bbe53eefa94f92c3bbc"} {"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 arr = readln.chomp.split.map!(to!int).array;\n \n auto rbt = make!(RedBlackTree!(int, \"a < b\", true));\n int s = 0;\n int minans = 0;\n int[] res;\n foreach (e; arr) {\n int curans = minans;\n int curs = s;\n foreach_reverse (big; rbt) {\n if (curs + e <= m) { break; }\n \n curs -= big;\n curans += 1;\n }\n \n rbt.insert(e);\n s += e;\n \n while (s > m) {\n s -= rbt.back;\n rbt.removeBack();\n minans += 1;\n }\n \n res ~= curans;\n }\n \n res.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 limit = 101;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\treadln;\n\t\tauto t = readln.splitter.map !(to !(int)).array;\n\t\tauto c = new int [limit];\n\n\t\tint [] ans;\n\t\tforeach (int num, ref value; t)\n\t\t{\n\t\t\tauto r = m - value;\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 1..limit)\n\t\t\t{\n\t\t\t\tauto add = min (r / i, c[i]);\n\t\t\t\tcur += add;\n\t\t\t\tr -= add * i;\n\t\t\t}\n\t\t\tans ~= num - cur;\n\t\t\tc[value] += 1;\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\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.ascii, std.typecons;\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 auto rbt = make!(RedBlackTree!int);\n int s = 0;\n foreach (e; arr) {\n int ans = 0;\n int curs = s;\n foreach_reverse (big; rbt) {\n if (curs + e <= m) { break; }\n \n curs -= big;\n ans += 1;\n }\n \n rbt.insert(e);\n s += e;\n \n ans.writeln;\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 n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto rbt = make!(RedBlackTree!int);\n int s = 0;\n int[] res;\n foreach (e; arr) {\n int ans = 0;\n int curs = s;\n foreach_reverse (big; rbt) {\n if (curs + e <= m) { break; }\n \n curs -= big;\n ans += 1;\n }\n \n rbt.insert(e);\n s += e;\n \n res ~= ans;\n }\n \n res.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 arr = readln.chomp.split.map!(to!int).array;\n \n auto rbt = make!(RedBlackTree!(int, \"a < b\", true));\n int s = 0;\n int[] res;\n foreach (e; arr) {\n int ans = 0;\n int curs = s;\n foreach_reverse (big; rbt) {\n if (curs + e <= m) { break; }\n \n curs -= big;\n ans += 1;\n }\n \n rbt.insert(e);\n s += e;\n \n while (rbt.length > 100) {\n rbt.removeFront();\n }\n \n res ~= ans;\n }\n \n res.map!(to!string).join(\" \").writeln;\n}"}], "src_uid": "fe3a6f0d33b1b5b8018e1810ba8ebdd6"} {"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\tn *= 2;\r\n\t\tauto a = readln.strip.map !(q{[-1, +1][a == '(']}).array;\r\n\r\n\t\tbool isOk ()\r\n\t\t{\r\n\t\t\tint bal = 0;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tbal += a[i];\r\n\t\t\t\tif (bal < 0)\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}\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tbool solve (int [] [] actions)\r\n\t\t{\r\n\t\t\tforeach (ref line; actions)\r\n\t\t\t{\r\n\t\t\t\treverse (a[line[0]..line[1]]);\r\n\t\t\t}\r\n\t\t\tif (isOk ())\r\n\t\t\t{\r\n\t\t\t\twriteln (actions.length);\r\n\t\t\t\tforeach (ref line; actions)\r\n\t\t\t\t{\r\n\t\t\t\t\twriteln (line[0] + 1, \" \", line[1]);\r\n\t\t\t\t}\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\t\t\tforeach_reverse (ref line; actions)\r\n\t\t\t{\r\n\t\t\t\treverse (a[line[0]..line[1]]);\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tif (solve ([])) continue;\r\n\r\n\t\t{\r\n\t\t\tint lo = 0;\r\n\t\t\tint bestLo = 0;\r\n\t\t\tint cur = 0;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tcur += a[i];\r\n\t\t\t\tif (bestLo < cur)\r\n\t\t\t\t{\r\n\t\t\t\t\tbestLo = cur;\r\n\t\t\t\t\tlo = i + 1;\r\n\t\t\t\t}\r\n\t\t\t\tif (cur < 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\r\n\t\t\tint hi = n;\r\n\t\t\tint bestHi = 0;\r\n\t\t\tcur = 0;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tcur -= a[i];\r\n\t\t\t\tif (bestHi < cur)\r\n\t\t\t\t{\r\n\t\t\t\t\tbestHi = cur;\r\n\t\t\t\t\thi = i;\r\n\t\t\t\t}\r\n\t\t\t\tif (cur < 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\r\n\t\t\tif (solve ([[lo, hi]])) continue;\r\n\t\t}\r\n\r\n\t\t{\r\n\t\t\tint p = 0;\r\n\t\t\tint up = 0;\r\n\t\t\tint cur = 0;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tcur += a[i];\r\n\t\t\t\tif (up < cur)\r\n\t\t\t\t{\r\n\t\t\t\t\tup = cur;\r\n\t\t\t\t\tp = i + 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (solve ([[0, p], [p, n]])) continue;\r\n\t\t}\r\n\r\n\t\tassert (false);\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 FAIL = [-1];\n\nint N;\nstring S;\n\nint[] hs;\nint im;\n\nint[] solve0() {\n foreach (i; 0 .. 2 * N + 1) {\n if (hs[i] < 0) {\n return FAIL;\n }\n }\n return [];\n}\n\nint[] solve1() {\n int a = -1, b = -1;\n foreach (i; 0 .. 2 * N + 1) if (hs[i] < 0) { a = i - 1; break; }\n foreach_reverse (i; 0 .. 2 * N + 1) if (hs[i] < 0) { b = i + 1; break; }\n assert(hs[a] == 0);\n assert(hs[b] == 0);\n debug {\n writeln(\" a = \", a, \", b = \", b);\n }\n \n if (im <= a) return [im, 2 * N];\n if (b <= im) return [0, im];\n \n int am, bm;\n foreach (i; 0 .. a + 1) if (hs[am] < hs[i]) am = i;\n foreach (i; b .. 2 * N + 1) if (hs[bm] < hs[i]) bm = i;\n debug {\n writeln(\" am = \", am, \", bm = \", bm);\n }\n if (hs[am] + hs[bm] - hs[im] >= 0) {\n return [am, bm];\n }\n \n return FAIL;\n}\n\nint[] solve2() {\n return [0, im, im, 2 * N];\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n N = readInt;\n S = readToken;\n \n hs = new int[2 * N + 1];\n foreach (i; 0 .. 2 * N) {\n hs[i + 1] = hs[i] + ((S[i] == '(') ? +1 : -1);\n }\n im = 0;\n foreach (i; 0 .. 2 * N + 1) {\n if (hs[im] < hs[i]) {\n im = i;\n }\n }\n debug {\n writeln(\" hs = \", hs);\n writeln(\" im = \", im);\n }\n \n int[] ans;\n \n ans = solve0;\n if (ans != FAIL) {\n debug {\n writeln(\" \", S);\n }\n writeln(0);\n continue;\n }\n ans = solve1;\n if (ans != FAIL) {\n debug {\n auto cs = S.dup;\n cs[ans[0] .. ans[1]].reverse;\n writeln(\" \", cs);\n }\n writeln(1);\n writeln(ans[0] + 1, \" \", ans[1]);\n continue;\n }\n ans = solve2;\n if (ans != FAIL) {\n debug {\n auto cs = S.dup;\n cs[ans[0] .. ans[1]].reverse;\n cs[ans[2] .. ans[3]].reverse;\n writeln(\" \", cs);\n }\n writeln(2);\n writeln(ans[0] + 1, \" \", ans[1]);\n writeln(ans[2] + 1, \" \", ans[3]);\n continue;\n }\n \n assert(false);\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\nenum FAIL = [-1];\n\nint N;\nstring S;\n\nint[] hs;\nint im;\n\nint[] solve0() {\n foreach (i; 0 .. 2 * N + 1) {\n if (hs[i] < 0) {\n return FAIL;\n }\n }\n return [];\n}\n\nint[] solve1() {\n int a = -1, b = -1;\n foreach (i; 0 .. 2 * N + 1) if (hs[i] < 0) { a = i - 1; break; }\n foreach_reverse (i; 0 .. 2 * N + 1) if (hs[i] < 0) { b = i + 1; break; }\n assert(hs[a] == 0);\n assert(hs[b] == 0);\n debug {\n writeln(\" a = \", a, \", b = \", b);\n }\n \n if (im <= a) return [im, 2 * N];\n if (b <= im) return [0, im];\n \n int am, bm;\n foreach (i; 0 .. a + 1) if (hs[am] < hs[i]) am = i;\n foreach (i; b .. 2 * N + 1) if (hs[bm] < hs[i]) bm = i;\n debug {\n writeln(\" am = \", am, \", bm = \", bm);\n }\n if (hs[am] + hs[bm] - hs[im] >= 0) {\n return [am, bm];\n }\n \n return FAIL;\n}\n\nint[] solve2() {\n return [0, im, im, 2 * N];\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n N = readInt;\n S = readToken;\n \n hs = new int[2 * N + 1];\n foreach (i; 0 .. 2 * N) {\n hs[i + 1] = hs[i] + ((S[i] == '(') ? +1 : -1);\n }\n foreach (i; 0 .. 2 * N + 1) {\n if (hs[im] < hs[i]) {\n im = i;\n }\n }\n debug {\n writeln(\" hs = \", hs);\n writeln(\" im = \", im);\n }\n \n int[] ans;\n \n ans = solve0;\n if (ans != FAIL) {\n writeln(0);\n continue;\n }\n ans = solve1;\n if (ans != FAIL) {\n writeln(1);\n writeln(ans[0] + 1, \" \", ans[1]);\n continue;\n }\n ans = solve2;\n if (ans != FAIL) {\n writeln(2);\n writeln(ans[0] + 1, \" \", ans[1]);\n writeln(ans[2] + 1, \" \", ans[3]);\n continue;\n }\n \n assert(false);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "07b52abebe1357f388e911f4a68afcfa"} {"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 s = readln.split.map!(to!long);\n auto l = s[0];\n auto r = s[1];\n writeln(l, \" \", l * 2);\n }\n}\n", "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int t;\n rd(t);\n while (t--) {\n int l, r;\n rd(l, r);\n writeln(l, \" \", l * 2);\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": "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 T;\n readf(\" %s\", T);\n foreach(i; 0 .. T) {\n long l, r;\n readf(\" %s %s\", l, r);\n writef(\"%s %s\\n\", l, l*2);\n }\n\n\n}\n"}, {"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\nvoid main() {\n int t;\n readf!\" %s\"(t);\n\n foreach (i; 0 .. t) {\n int l,r;\n readf!\" %s %s\"(l,r);\n\n writeln(l,\" \",2*l);\n }\n}\n"}], "negative_code": [], "src_uid": "a9cd97046e27d799c894d8514e90a377"} {"source_code": "import std.stdio;\nimport std.typecons;\n\nvoid main()\n{\n\tuint n, k;\n\n\treadf(\" %s %s\", &n, &k);\n\n\tuint pairs = n * (n - 1) / 2;\n\t\n\tif(pairs < k * n)\n\t{\n\t\twriteln(\"-1\");\n\t\treturn;\n\t}\n\n\tuint[] wins = new uint[n + 1];\n\tuint[] losses = new uint[n + 1];\n\n\tuint maxLosses = n - 1 - k;\n\n\tTuple!(uint, uint)[] lines;\n\n\tfor(uint i = 1; i <= n; i++)\n\t{\n\t\tfor(uint j = i + 1; j <= n; j++)\n\t\t{\n\t\t\tif(wins[i] < k && losses[j] < maxLosses)\n\t\t\t{\n\t\t\t\twins[i]++;\n\t\t\t\tlosses[j]++;\n\t\t\t\tlines ~= Tuple!(uint, uint)(i, j);\n\t\t\t}\n\t\t\telse if(wins[j] < k && losses[i] < maxLosses)\n\t\t\t{\n\t\t\t\twins[j]++;\n\t\t\t\tlosses[i]++;\n\t\t\t\tlines ~= Tuple!(uint, uint)(j, i);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(lines.length);\n\tforeach(line; lines)\n\t{\n\t\twriteln(line[0], \" \", line[1]);\n\t}\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\n\nint r[1010][1010];\nint a[1000010][2];\n\nvoid solve(int n, int k)\n{\n if (k > n * (n - 1) / 2)\n {\n printf(\"-1\\n\");\n return;\n }\n foreach (int i; 0 .. n)\n {\n foreach (int j; 0 .. n)\n {\n r[i][j] = 0;\n }\n }\n int idx = 0;\n foreach (int i; 0 .. n)\n {\n int cnt = 0;\n for (int j = 0; cnt < k && j < n; ++ j)\n {\n if (j == i || r[i][j] == 1)\n {\n continue;\n }\n a[idx][0] = i + 1;\n a[idx][1] = j + 1;\n ++ idx;\n r[i][j] = r[j][i] = 1;\n ++ cnt;\n }\n if (cnt < k)\n {\n printf(\"-1\\n\");\n return;\n }\n }\n printf(\"%d\\n\", n * k);\n foreach (int i; 0 .. n * k)\n {\n printf(\"%d %d\\n\", a[i][0], a[i][1]);\n }\n}\n\nvoid main(string[] args)\n{\n int n, k;\n while (scanf(\"%d%d\", &n, &k) == 2)\n {\n solve(n, k);\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, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tif (k + k < n)\n\t\t{\n\t\t\twriteln (n * k);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tforeach (j; 1..k + 1)\n\t\t\t\t{\n\t\t\t\t\twriteln (i + 1, ' ', (i + j) % n + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n"}, {"source_code": "module football;\nimport 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\"); }\n\nint n, k;\nvoid readInput() {\n\tscan(n, k);\n}\n\nvoid tc() {\n\treadInput();\n\tif (2*k > n-1) { writeln(\"-1\"); return; }\n\twriteln(n * k);\n\tforeach (i; 0..n) {\n\t\tforeach (j; 0..k) {\n\t\t\twriteln(i + 1, \" \", (i+j+1)%n+1);\n\t\t}\n\t}\n}\n\nvoid main() { tc(); }\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.typecons;\n\nvoid main()\n{\n\tuint n, k;\n\n\treadf(\" %s %s\", &n, &k);\n\n\tuint pairs = n * (n - 1);\n\t\n\tif(pairs < k * n)\n\t{\n\t\twriteln(\"-1\");\n\t\treturn;\n\t}\n\n\tuint[] wins = new uint[n + 1];\n\n\tTuple!(uint, uint)[] lines;\n\n\tfor(uint i = 1; i <= n; i++)\n\t{\n\t\tfor(uint j = i + 1; j <= n; j++)\n\t\t{\n\t\t\tif(wins[i] < k)\n\t\t\t{\n\t\t\t\twins[i]++;\n\t\t\t\tlines ~= Tuple!(uint, uint)(i, j);\n\t\t\t}\n\t\t\telse if(wins[j] < k)\n\t\t\t{\n\t\t\t\twins[j]++;\n\t\t\t\tlines ~= Tuple!(uint, uint)(j, i);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(lines.length);\n\tforeach(line; lines)\n\t{\n\t\twriteln(line[0], \" \", line[1]);\n\t}\n}"}, {"source_code": "import std.stdio;\nimport std.typecons;\n\nvoid main()\n{\n\tuint n, k;\n\n\treadf(\" %s %s\", &n, &k);\n\n\tuint pairs = n * (n - 1);\n\t\n\tif(pairs < k * n)\n\t{\n\t\twriteln(\"-1\");\n\t\treturn;\n\t}\n\n\tuint[] wins = new uint[n + 1];\n\tuint[] losses = new uint[n + 1];\n\n\tuint maxLosses = n - 1 - k;\n\n\tTuple!(uint, uint)[] lines;\n\n\tfor(uint i = 1; i <= n; i++)\n\t{\n\t\tfor(uint j = i + 1; j <= n; j++)\n\t\t{\n\t\t\tif(wins[i] < k && losses[j] < maxLosses)\n\t\t\t{\n\t\t\t\twins[i]++;\n\t\t\t\tlosses[j]++;\n\t\t\t\tlines ~= Tuple!(uint, uint)(i, j);\n\t\t\t}\n\t\t\telse if(wins[j] < k && losses[i] < maxLosses)\n\t\t\t{\n\t\t\t\twins[j]++;\n\t\t\t\tlosses[i]++;\n\t\t\t\tlines ~= Tuple!(uint, uint)(j, i);\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(lines.length);\n\tforeach(line; lines)\n\t{\n\t\twriteln(line[0], \" \", line[1]);\n\t}\n}"}], "src_uid": "14570079152bbf6c439bfceef9816f7e"} {"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\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\treadln;\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tauto c = iota (n - 1).map !(i => b[i + 1] - b[i] - 1).array;\n\t\tsort (c);\n\t\tlong res = n;\n\t\tres += sum (c[0..n - k], 0L);\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, core.stdc.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int).array;\n auto N = s[0];\n auto M = s[1].to!long;\n auto K = s[2].to!long;\n auto A = readln.split.map!(to!long).array;\n\n if (N == 1) {\n writeln(1);\n return;\n }\n\n auto B = (N-1).iota.map!(i => A[i+1] - A[i] - 1).array;\n B.sort!\"a > b\";\n\n long ans = A.back - A.front + 1;\n long cnt = 1;\n int p = 0;\n\n while (cnt < K && p < B.length) {\n ans -= B[p];\n p += 1;\n cnt += 1;\n }\n\n\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "6b2b56a423c247d42493d01e06e4b1d2"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\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\talias Edge = Tuple !(int, q{v}, int, q{w});\n\t\timmutable int steps = 18;\n\t\timmutable int inf = int.max / 2;\n\t\tauto p = new Edge [] [steps];\n\t\tp[0] = new Edge [n];\n\t\tp[0][0] = Edge (-1, inf);\n\t\tauto adj = new int [] [n];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tint v;\n\t\t\tint w;\n\t\t\treadf (\" %s %s\", &v, &w);\n\t\t\tv--;\n\t\t\tp[0][i] = Edge (v, w);\n\t\t\tadj[v] ~= i;\n\t\t}\n\t\tforeach (step; 1..steps)\n\t\t{\n\t\t\tp[step] = p[step - 1].dup;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tint cv = p[step][i].v;\n\t\t\t\tint cw = p[step][i].w;\n\t\t\t\tif (cw < inf)\n\t\t\t\t{\n\t\t\t\t\tp[step][i] = Edge (p[step - 1][cv].v,\n\t\t\t\t\t min (inf, p[step - 1][cv].w + cw));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tauto ans = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v = i;\n\t\t\tans[v] += 1;\n\t\t\tforeach_reverse (step; 0..steps)\n\t\t\t{\n\t\t\t\tif (a[i] >= p[step][v].w)\n\t\t\t\t{\n\t\t\t\t\ta[i] -= p[step][v].w;\n\t\t\t\t\tv = p[step][v].v;\n\t\t\t\t}\n\t\t\t}\n\t\t\tv = p[0][v].v;\n\t\t\tif (v != -1)\n\t\t\t{\n\t\t\t\tans[v] -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint recur (int v)\n\t\t{\n\t\t\tint res = ans[v];\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tres += recur (u);\n\t\t\t}\n\t\t\tans[v] = res;\n\t\t\treturn res;\n\t\t}\n\n\t\trecur (0);\n\t\tans[] -= 1;\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\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\treadln;\n\t\tauto a = readln.split.map !(to !(long)).array;\n\t\talias Edge = Tuple !(int, q{v}, long, q{w});\n\t\timmutable int steps = 18;\n\t\timmutable long inf = long.max / 2;\n\t\tauto p = new Edge [] [steps];\n\t\tp[0] = new Edge [n];\n\t\tp[0][0] = Edge (-1, inf);\n\t\tauto adj = new int [] [n];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tint v;\n\t\t\tlong w;\n\t\t\treadf (\" %s %s\", &v, &w);\n\t\t\tv--;\n\t\t\tp[0][i] = Edge (v, w);\n\t\t\tadj[v] ~= i;\n\t\t}\n\t\tdebug {writeln (p[0]);}\n\t\tforeach (step; 1..steps)\n\t\t{\n\t\t\tp[step] = new Edge [n];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tp[step][i] = p[step - 1][i];\n\t\t\t\tint cv = p[step][i].v;\n\t\t\t\tlong cw = p[step][i].w;\n\t\t\t\tif (cw < inf)\n\t\t\t\t{\n\t\t\t\t\tp[step][i] = Edge (p[step - 1][cv].v,\n\t\t\t\t\t p[step - 1][cv].w + cw);\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (p[step]);}\n\t\t}\n\n\t\tauto ans = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v = i;\n\t\t\tans[v] += 1;\n\t\t\tforeach_reverse (step; 0..steps)\n\t\t\t{\n\t\t\t\tif (a[i] >= p[step][v].w)\n\t\t\t\t{\n\t\t\t\t\ta[i] -= p[step][v].w;\n\t\t\t\t\tv = p[step][v].v;\n\t\t\t\t}\n\t\t\t}\n\t\t\tv = p[0][v].v;\n\t\t\tdebug {writeln (i, \" \", v);}\n\t\t\tif (v != -1)\n\t\t\t{\n\t\t\t\tans[v] -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint recur (int v)\n\t\t{\n\t\t\tdebug {writeln (v);}\n\t\t\tint res = ans[v];\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tres += recur (u);\n\t\t\t}\n\t\t\tans[v] = res;\n\t\t\treturn res;\n\t\t}\n\n\t\trecur (0);\n\t\tans[] -= 1;\n\t\twritefln (\"%(%s %)\", ans);\n\t}\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\nstruct SegTree {\n long[ ][800_000] _t;\n long[ ][ ] t;\n\n static int lc(int i) { return i << 1 | 0x1; }\n static int rc(int i) { return (i << 1) + 2; }\n\n void init(int i, const(long)[ ] a) {\n assert(!a.empty);\n if (a.length == 1)\n t[i] = [a[0]];\n else {\n auto mid = a.length >> 1;\n init(lc(i), a[0 .. mid]);\n init(rc(i), a[mid .. $]);\n t[i] = merge(t[lc(i)], t[rc(i)]).array();\n }\n }\n\n int countLessEqual(int left, int right, long value) const {\n value++;\n\n int get(int i, int lb, int rb, int left, int right) {\n if (left >= right)\n return 0;\n if (lb == left && rb == right)\n return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;\n int mid = (lb + rb) >> 1;\n int a = get(lc(i), lb, mid, left, min(mid, right));\n int b = get(rc(i), mid, rb, max(left, mid), right);\n return a + b;\n }\n\n return get(0, 0, n, left, right);\n }\n}\n\nint gid;\nlong[200_000] _magic;\nlong[ ] magic;\n\nstruct Node {\n int value;\n long distToRoot;\n int left, right;\n int parentLen;\n Node*[ ] children;\n\n void calcDist(long d) {\n distToRoot = d + parentLen;\n magic[gid++] = distToRoot - value;\n left = gid;\n foreach (node; children)\n node.calcDist(distToRoot);\n right = gid;\n }\n}\n\nint n;\nNode[200_000] _nodes;\nNode[ ] nodes;\nSegTree sgt;\n\nvoid main() {\n _nodes[0].parentLen = 0;\n while (read(&n)) {\n nodes = _nodes[0 .. n];\n magic = _magic[0 .. n];\n version (LocalProject)\n foreach (ref node; nodes)\n node.children = null;\n foreach (ref node; nodes)\n read(&node.value);\n foreach (ref node; nodes[1 .. $]) {\n int p, w;\n read(&p, &w);\n p--;\n node.parentLen = w;\n nodes[p].children ~= &node;\n }\n gid = 0;\n nodes[0].calcDist(0);\n debug writeln(magic);\n //debug foreach (ref node; nodes)\n // writeln(node);\n sgt.t = sgt._t[0 .. n << 2];\n version (LocalProject)\n foreach (ref ls; sgt.t)\n ls = null;\n sgt.init(0, magic);\n foreach (ref node; nodes) {\n debug write(node.left, \"..\", node.right, ':', node.distToRoot, '@');\n write(sgt.countLessEqual(node.left, node.right, node.distToRoot), ' ');\n }\n writeln();\n debug writeln();\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.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\n/+\nint myUpperBound(R, T)(R range, T value) if (isRandomAccessRange!R) {\n int left = 0, right = cast(int)range.length;\n while (left != right) {\n int mid = (left + right) >> 1;\n if (value >= range[mid])\n left = mid + 1;\n else\n right = mid;\n }\n return left;\n}\n+/\n\nstruct SegTree {\n //Array!(Array!long) t;\n long[ ][800_000] _t;\n long[ ][ ] t;\n\n static int lc(int i) { return i << 1 | 0x1; }\n static int rc(int i) { return (i << 1) + 2; }\n\n void init(int i, const(long)[ ] a) {\n assert(!a.empty);\n if (a.length == 1)\n t[i] = [a[0]];\n else {\n auto mid = a.length >> 1;\n init(lc(i), a[0 .. mid]);\n init(rc(i), a[mid .. $]);\n //t[i] = Array!long(merge(t[lc(i)][ ], t[rc(i)][ ]));\n t[i] = merge(t[lc(i)], t[rc(i)]).array();\n }\n }\n\n int countLessEqual(int left, int right, long value) const {\n value++;\n\n int get(int i, int lb, int rb, int left, int right) {\n if (left >= right)\n return 0;\n if (lb == left && rb == right)\n return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;\n /+return myUpperBound(t[i], value);+/\n int mid = (lb + rb) >> 1;\n int a = get(lc(i), lb, mid, left, min(mid, right));\n int b = get(rc(i), mid, rb, max(left, mid), right);\n return a + b;\n }\n\n return get(0, 0, n, left, right);\n }\n}\n\nint gid;\nlong[200_000] _magic;\nlong[ ] magic;\n\nstruct Node {\n int value;\n long distToRoot;\n int left, right;\n int parentLen;\n //Array!(Node*) children;\n Node*[ ] children;\n\n void calcDist(long d) {\n distToRoot = d + parentLen;\n magic[gid++] = distToRoot - value;\n left = gid;\n foreach (node; children)\n node.calcDist(distToRoot);\n right = gid;\n }\n}\n\nint n;\nNode[200_000] _nodes;\nNode[ ] nodes;\nSegTree sgt;\n\nvoid main() {\n _nodes[0].parentLen = 0;\n while (scanf(\"%d\", &n) == 1) {\n nodes = _nodes[0 .. n];\n magic = _magic[0 .. n];\n version (LocalProject)\n foreach (ref node; nodes)\n /+node.children.clear();+/\n node.children = null;\n foreach (ref node; nodes)\n scanf(\"%d\", &node.value);\n foreach (ref node; nodes[1 .. $]) {\n int p, w;\n scanf(\"%d%d\", &p, &w);\n p--;\n node.parentLen = w;\n nodes[p].children ~= &node;\n }\n gid = 0;\n nodes[0].calcDist(0);\n debug writeln(magic);\n //debug foreach (ref node; nodes)\n // writeln(node);\n //sgt.t.clear();\n //sgt.t.length = n << 2;\n sgt.t = sgt._t[0 .. n << 2];\n version (LocalProject)\n foreach (ref ls; sgt.t)\n ls = null;\n sgt.init(0, magic);\n foreach (ref node; nodes) {\n debug write(node.left, \"..\", node.right, ':', node.distToRoot, '@');\n printf(\"%d \", sgt.countLessEqual(node.left, node.right, node.distToRoot));\n }\n putchar('\\n');\n debug writeln();\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.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 SegTree {\n long[ ][800_000] _t;\n long[ ][ ] t;\n\n static int lc(int i) { return i << 1 | 0x1; }\n static int rc(int i) { return (i << 1) + 2; }\n\n void init(int i, const(long)[ ] a) {\n assert(!a.empty);\n if (a.length == 1)\n t[i] = [a[0]];\n else {\n auto mid = a.length >> 1;\n init(lc(i), a[0 .. mid]);\n init(rc(i), a[mid .. $]);\n t[i] = merge(t[lc(i)], t[rc(i)]).array();\n }\n }\n\n int countLessEqual(int left, int right, long value) const {\n value++;\n\n int get(int i, int lb, int rb, int left, int right) {\n if (left >= right)\n return 0;\n if (lb == left && rb == right)\n return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;\n int mid = (lb + rb) >> 1;\n int a = get(lc(i), lb, mid, left, min(mid, right));\n int b = get(rc(i), mid, rb, max(left, mid), right);\n return a + b;\n }\n\n return get(0, 0, n, left, right);\n }\n}\n\nint gid;\nlong[200_000] _magic;\nlong[ ] magic;\n\nstruct Node {\n int value;\n long distToRoot;\n int left, right;\n int parentLen;\n Node*[ ] children;\n\n void calcDist(long d) {\n distToRoot = d + parentLen;\n magic[gid++] = distToRoot - value;\n left = gid;\n foreach (node; children)\n node.calcDist(distToRoot);\n right = gid;\n }\n}\n\nint n;\nNode[200_000] _nodes;\nNode[ ] nodes;\nint[199_999] _parents;\nint[ ] parents;\nNode*[199_999] _children;\nNode*[ ] children;\nSegTree sgt;\n\nvoid main() {\n _nodes[0].parentLen = 0;\n while (scanf(\"%d\", &n) == 1) {\n nodes = _nodes[0 .. n];\n magic = _magic[0 .. n];\n children = _children[0 .. n - 1];\n parents = _parents[0 .. n - 1];\n version (LocalProject)\n foreach (ref node; nodes)\n node.children = null;\n foreach (ref node; nodes)\n scanf(\"%d\", &node.value);\n foreach (ref node, ref child, ref parent; lockstep(nodes[1 .. $], children, parents)) {\n child = &node;\n scanf(\"%d%d\", &parent, &node.parentLen);\n parent--;\n }\n auto z = zip(parents, children);\n z.sort!`a[0] < b[0]`;\n int last = 0;\n foreach (pc, count; z.group!`a[0] == b[0]`) {\n nodes[pc[0]].children = children[last .. last + count];\n last += count;\n }\n gid = 0;\n nodes[0].calcDist(0);\n debug writeln(magic);\n //debug foreach (ref node; nodes)\n // writeln(node);\n sgt.t = sgt._t[0 .. n << 2];\n version (LocalProject)\n foreach (ref ls; sgt.t)\n ls = null;\n sgt.init(0, magic);\n foreach (ref node; nodes) {\n debug write(node.left, \"..\", node.right, ':', node.distToRoot, '@');\n printf(\"%d \", sgt.countLessEqual(node.left, node.right, node.distToRoot));\n }\n putchar('\\n');\n debug writeln();\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.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 myUpperBound(R, T)(R range, T value) if (isRandomAccessRange!R) {\n int left = 0, right = cast(int)range.length;\n while (left != right) {\n int mid = (left + right) >> 1;\n if (value >= range[mid])\n left = mid + 1;\n else\n right = mid;\n }\n return left;\n}\n\nstruct SegTree {\n //Array!(Array!long) t;\n long[ ][800_000] _t;\n long[ ][ ] t;\n\n static int lc(int i) { return i << 1 | 0x1; }\n static int rc(int i) { return (i << 1) + 2; }\n\n void init(int i, const(long)[ ] a) {\n assert(!a.empty);\n if (a.length == 1)\n t[i] ~= a[0];\n else {\n auto mid = a.length >> 1;\n init(lc(i), a[0 .. mid]);\n init(rc(i), a[mid .. $]);\n //t[i] = Array!long(merge(t[lc(i)][ ], t[rc(i)][ ]));\n t[i] = merge(t[lc(i)], t[rc(i)]).array();\n }\n }\n\n int countLessEqual(int left, int right, long value) const {\n //value++;\n\n int get(int i, int lb, int rb, int left, int right) {\n if (left >= right)\n return 0;\n if (lb == left && rb == right)\n /+return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;+/\n return myUpperBound(t[i], value);\n int mid = (lb + rb) >> 1;\n int a = get(lc(i), lb, mid, left, min(mid, right));\n int b = get(rc(i), mid, rb, max(left, mid), right);\n return a + b;\n }\n\n return get(0, 0, n, left, right);\n }\n}\n\nint gid;\nlong[200_000] _magic;\nlong[ ] magic;\n\nstruct Node {\n int value;\n long distToRoot;\n int left, right;\n int parentLen;\n //Array!(Node*) children;\n Node*[ ] children;\n\n void calcDist(long d) {\n distToRoot = d + parentLen;\n magic[gid++] = distToRoot - value;\n left = gid;\n foreach (node; children)\n node.calcDist(distToRoot);\n right = gid;\n }\n}\n\nint n;\nNode[200_000] _nodes;\nNode[ ] nodes;\nSegTree sgt;\n\nvoid main() {\n _nodes[0].parentLen = 0;\n while (scanf(\"%d\", &n) == 1) {\n nodes = _nodes[0 .. n];\n magic = _magic[0 .. n];\n version (LocalProject)\n foreach (ref node; nodes)\n /+node.children.clear();+/\n node.children = null;\n foreach (ref node; nodes)\n scanf(\"%d\", &node.value);\n foreach (ref node; nodes[1 .. $]) {\n int p, w;\n scanf(\"%d%d\", &p, &w);\n p--;\n node.parentLen = w;\n nodes[p].children ~= &node;\n }\n gid = 0;\n nodes[0].calcDist(0);\n debug writeln(magic);\n //debug foreach (ref node; nodes)\n // writeln(node);\n //sgt.t.clear();\n //sgt.t.length = n << 2;\n sgt.t = sgt._t[0 .. n << 2];\n version (LocalProject)\n foreach (ref ls; sgt.t)\n ls = null;\n sgt.init(0, magic);\n foreach (ref node; nodes) {\n debug write(node.left, \"..\", node.right, ':', node.distToRoot, '@');\n printf(\"%d \", sgt.countLessEqual(node.left, node.right, node.distToRoot));\n }\n putchar('\\n');\n debug writeln();\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.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 myUpperBound(R, T)(R range, T value) if (isRandomAccessRange!R) {\n int left = 0, right = cast(int)range.length;\n while (left != right) {\n int mid = (left + right) >> 1;\n if (value >= range[mid])\n left = mid + 1;\n else\n right = mid;\n }\n return left;\n}\n\nstruct SegTree {\n Array!(Array!long) t;\n\n static int lc(int i) { return i << 1 | 0x1; }\n static int rc(int i) { return (i << 1) + 2; }\n\n void init(int i, const(long)[ ] a) {\n assert(!a.empty);\n if (a.length == 1)\n t[i] ~= a[0];\n else {\n auto mid = a.length >> 1;\n init(lc(i), a[0 .. mid]);\n init(rc(i), a[mid .. $]);\n t[i] = Array!long(merge(t[lc(i)][ ], t[rc(i)][ ]));\n }\n }\n\n int countLessEqual(int left, int right, long value) const {\n //value++;\n\n int get(int i, int lb, int rb, int left, int right) {\n if (left >= right)\n return 0;\n if (lb == left && rb == right)\n /+return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;+/\n return myUpperBound(t[i][ ], value);\n int mid = (lb + rb) >> 1;\n int a = get(lc(i), lb, mid, left, min(mid, right));\n int b = get(rc(i), mid, rb, max(left, mid), right);\n return a + b;\n }\n\n return get(0, 0, n, left, right);\n }\n}\n\nint gid;\nlong[200_000] _magic;\nlong[ ] magic;\n\nstruct Node {\n int value;\n long distToRoot;\n int left, right;\n int parentLen;\n Array!(Node*) children;\n\n void calcDist(long d) {\n distToRoot = d + parentLen;\n magic[gid++] = distToRoot - value;\n left = gid;\n foreach (node; children)\n node.calcDist(distToRoot);\n right = gid;\n }\n}\n\nint n;\nNode[200_000] _nodes;\nNode[ ] nodes;\nSegTree sgt;\n\nvoid main() {\n _nodes[0].parentLen = 0;\n while (scanf(\"%d\", &n) == 1) {\n nodes = _nodes[0 .. n];\n magic = _magic[0 .. n];\n version (LocalProject)\n foreach (ref node; nodes)\n node.children.clear();\n foreach (ref node; nodes)\n scanf(\"%d\", &node.value);\n foreach (ref node; nodes[1 .. $]) {\n int p, w;\n scanf(\"%d%d\", &p, &w);\n p--;\n node.parentLen = w;\n nodes[p].children ~= &node;\n }\n gid = 0;\n nodes[0].calcDist(0);\n debug writeln(magic);\n //debug foreach (ref node; nodes)\n // writeln(node);\n sgt.t.clear();\n sgt.t.length = n << 2;\n sgt.init(0, magic);\n foreach (ref node; nodes) {\n debug write(node.left, \"..\", node.right, ':', node.distToRoot, '@');\n printf(\"%d \", sgt.countLessEqual(node.left, node.right, node.distToRoot));\n }\n putchar('\\n');\n debug writeln();\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\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\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\talias Edge = Tuple !(int, q{v}, int, q{w});\n\t\timmutable int steps = 18;\n\t\timmutable int inf = int.max / 2;\n\t\tauto p = new Edge [] [steps];\n\t\tp[0] = new Edge [n];\n\t\tp[0][0] = Edge (-1, inf);\n\t\tauto adj = new int [] [n];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tint v;\n\t\t\tint w;\n\t\t\treadf (\" %s %s\", &v, &w);\n\t\t\tv--;\n\t\t\tp[0][i] = Edge (v, w);\n\t\t\tadj[v] ~= i;\n\t\t}\n\t\tdebug {writeln (p[0]);}\n\t\tforeach (step; 1..steps)\n\t\t{\n\t\t\tp[step] = new Edge [n];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tp[step][i] = p[step - 1][i];\n\t\t\t\tint cv = p[step][i].v;\n\t\t\t\tint cw = p[step][i].w;\n\t\t\t\tif (cw < inf)\n\t\t\t\t{\n\t\t\t\t\tp[step][i] = Edge (p[step - 1][cv].v,\n\t\t\t\t\t p[step - 1][cv].w + cw);\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (p[step]);}\n\t\t}\n\n\t\tauto ans = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v = i;\n\t\t\tans[v] += 1;\n\t\t\tforeach_reverse (step; 0..steps)\n\t\t\t{\n\t\t\t\tif (a[i] >= p[step][v].w)\n\t\t\t\t{\n\t\t\t\t\ta[i] -= p[step][v].w;\n\t\t\t\t\tv = p[step][v].v;\n\t\t\t\t}\n\t\t\t}\n\t\t\tv = p[0][v].v;\n\t\t\tdebug {writeln (i, \" \", v);}\n\t\t\tif (v != -1)\n\t\t\t{\n\t\t\t\tans[v] -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint recur (int v)\n\t\t{\n\t\t\tdebug {writeln (v);}\n\t\t\tint res = ans[v];\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\tres += recur (u);\n\t\t\t}\n\t\t\tans[v] = res;\n\t\t\treturn res;\n\t\t}\n\n\t\trecur (0);\n\t\tans[] -= 1;\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "src_uid": "5a146d9d360228313006d54cd5ca56ec"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\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\tif (n < 3)\n\t\t{\n\t\t\twriteln (0);\n\t\t\tcontinue;\n\t\t}\n\t\tauto d = a[1] - a[0];\n\t\tint res = n + 1;\n\t\tforeach (long delta; d - 2..d + 3)\n\t\t{\n\t\t\tforeach (start; a[0] - 1..a[0] + 2)\n\t\t\t{\n\t\t\t\tauto v = sequence !((r, k) =>\n\t\t\t\t start + k * delta);\n\t\t\t\tint cur = 0;\n\t\t\t\tforeach (x, y; zip (a, v))\n\t\t\t\t{\n\t\t\t\t\tif (abs (x - y) > 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur = n + 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 += abs (x - y);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tres = min (res, cur);\n\t\t\t}\n\t\t}\n\t\tif (res > n)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.array, std.math;\n\n int n; rd(n);\n auto as=readln.split.to!(long[]);\n\n if(n<=2){\n writeln(0);\n return;\n }\n\n long[] cand;\n for(long dx=-1; dx<=1; dx++){\n for(long dy=-1; dy<=1; dy++){\n cand~=((as[1]+dx)-(as[0]+dy));\n }\n }\n cand=cand.sort.uniq.array;\n int mn=1_000_000_000;\n foreach(diff; cand)for(long init_diff=-1; init_diff<=1; init_diff++){\n auto pre=as[0]+init_diff;\n int cnt=init_diff.abs.to!(int);\n foreach(i; 1..n){\n bool found=false;\n for(long d=-1; d<=1; d++){\n if((as[i]+d)-(pre)==diff){\n pre=as[i]+d;\n cnt+=d.abs;\n found=true;\n break;\n }\n }\n if(found==false) goto hell;\n }\n mn=min(mn, cnt);\n hell:;\n }\n\n if(mn<=n) writeln(mn);\n else writeln(-1);\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": "79b0794f81acc1c882649d96b1c7f8da"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 x = a.maxElement;\n\t\tauto used = new bool[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlong best;\n\t\t\tint pos;\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tif (used[j]) continue;\n\t\t\t\tauto tmp = gcd(x, a[j]);\n\t\t\t\tdebug writeln(\"tmp:\", tmp);\n\t\t\t\tif (tmp > best)\n\t\t\t\t{\n\t\t\t\t\tbest = tmp;\n\t\t\t\t\tpos = j;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug writeln(\"a[pos]:\", a[pos], \" best:\", best);\n\t\t\tans[ti] ~= a[pos];\n\t\t\tused[pos] = true;\n\t\t\tx = best;\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": "// 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[] token;\nT rd(T = long)() { while(!token.length) token = readln.chomp.split; string res = token[0]; token.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\n\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n ll[] ray;\n arr.sort();\n arr.reverse();\n ll maxel = arr[0];\n bool[long] vis;\n int maxi = 0;\n foreach(i; 0..arr.length){\n if(arr[i] >= maxel){\n maxel = arr[i];\n maxi = to!int(i);\n }\n vis[i] = 0;\n }\n ray ~= maxel;\n vis[maxi] = 1;\n ll cnt = 1;\n ll gcdall = maxel;\n while(cnt < n){\n ll maxgcd = 1;\n foreach(j; 0..n){\n if(!vis[j] && gcd(gcdall, arr[j]) >= maxgcd){\n maxgcd = gcd(gcdall, arr[j]);\n maxi = j;\n }\n }\n ray ~= arr[maxi];\n vis[maxi] = 1;\n gcdall = maxgcd;\n ++cnt;\n }\n foreach(el; ray){\n write(el, \" \");\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": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 x = a.maxElement;\n\t\tauto c = new long[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tc[i] = gcd(x, a[i]);\n\t\t}\n\n\t\tauto index = c.MAKE_IDX!\"a > b\";\n\t\tans[ti].length = n;\n\t\tforeach (ii, i; index)\n\t\t\tans[ti][ii] = a[i];\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "bdd1974e46f99eff3d03ed4174158dd9"} {"source_code": "import std.algorithm, std.container, std.conv, std.range, std.stdio, std.string;\r\nvoid main () {\r\n\tforeach (test; 0..readln.strip.to !(int)) {\r\n\t\treadln;\r\n\t\tint [long] z;\r\n\t\tauto t = redBlackTree !(long);\r\n\t\tlong m = 1, d, r;\r\n\t\talias u = x => (x - d) * m;\r\n\t\talias v = x => x * m + d;\r\n\t\tforeach (c; readln.splitter.map !(to !(long))) {\r\n\t\t\tm *= -1;\r\n\t\t\td = c - d;\r\n\t\t\twhile (!t.empty && v (t.front) < 0) z.remove (t.front), t.removeFront ();\r\n\t\t\twhile (!t.empty && v (t.back) < 0) z.remove (t.back), t.removeBack ();\r\n\t\t\tt.insert (u (c));\r\n\t\t\tz[u (c)] += 1;\r\n\t\t\tr += z.get (u (0), 0);\r\n\t\t}\r\n\t\twriteln (r);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std;\r\nvoid main() {\r\n\tforeach (_; 0..readln.strip.to!int) {\r\n\t\treadln;\r\n\t\tint [long] z;\r\n\t\tauto t = redBlackTree!long;\r\n\t\tlong m = 1, d, r;\r\n\t\talias u = x => (x - d) * m, v = x => x * m + d;\r\n\t\tforeach (c; readln.splitter.map!(to!long)) {\r\n\t\t\tm *= -1, d = c - d;\r\n\t\t\twhile (!t.empty && v(t.front) < 0) z.remove(t.front), t.removeFront;\r\n\t\t\twhile (!t.empty && v(t.back) < 0) z.remove(t.back), t.removeBack;\r\n\t\t\tt.insert(u(c)), z[u(c)] += 1, r += z.get(u(0), 0);\r\n\t\t}\r\n\t\tr.writeln;\r\n\t}\r\n}\r\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\nstruct Storage\r\n{\r\n\tint [long] num;\r\n\tRedBlackTree !(long) t = redBlackTree !(long);\r\n\tint mult = +1;\r\n\tlong delta = 0L;\r\n\r\n\tlong encode (long value)\r\n\t{\r\n\t\treturn (value - delta) * mult;\r\n\t}\r\n\r\n\tlong decode (long value)\r\n\t{\r\n\t\treturn value * mult + delta;\r\n\t}\r\n\r\n\tvoid insert (long value)\r\n\t{\r\n\t\tvalue = encode (value);\r\n\t\tt.insert (value);\r\n\t\tnum[value] += 1;\r\n\t}\r\n\r\n\tvoid cleanup ()\r\n\t{\r\n\t\twhile (!t.empty && decode (t.front) < 0L)\r\n\t\t{\r\n\t\t\tnum.remove (t.front);\r\n\t\t\tt.removeFront ();\r\n\t\t}\r\n\r\n\t\twhile (!t.empty && decode (t.back) < 0L)\r\n\t\t{\r\n\t\t\tnum.remove (t.back);\r\n\t\t\tt.removeBack ();\r\n\t\t}\r\n\t}\r\n\r\n\tint curAnswer ()\r\n\t{\r\n\t\treturn num.get (encode (0L), 0);\r\n\t}\r\n\r\n\tvoid invertAll ()\r\n\t{\r\n\t\tmult *= -1;\r\n\t\tdelta *= -1;\r\n\t}\r\n\r\n\tvoid addToAll (long value)\r\n\t{\r\n\t\tdelta += value;\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\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tStorage s;\r\n\t\tlong res = 0L;\r\n\t\tforeach (i, ref cur; a)\r\n\t\t{\r\n\t\t\ts.invertAll ();\r\n\t\t\ts.addToAll (cur);\r\n\t\t\ts.cleanup ();\r\n\t\t\ts.insert (cur);\r\n\t\t\tres += s.curAnswer ();\r\n\t\t}\r\n\t\twriteln (res);\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+1);\n\tforeach(i; 1 .. n + 1) a[i] = readInt!int;\n\tauto cSum = new long[](n+1);\n\tcSum[0] = 0;\n\tforeach(i; 1 .. n+1)\n\t{\n\t\tif (i&1) cSum[i] = cSum[i-1] - a[i];\n\t\telse cSum[i] = cSum[i-1] + a[i];\n\t}\n\tauto only1Max = new long[](n+1); only1Max[] = long.min;\n\tauto only0Max = new long[](n+1); only0Max[] = long.min;\n\tauto only1Min = new long[](n+1); only1Min[] = long.max;\n\tauto only0Min = new long[](n+1); only0Min[] = long.max;\n\tforeach(i; 0 .. n+1)\n\t{\n\t\tif (i&1)\n\t\t{\n\t\t\tonly1Max[i] = cSum[i];\n\t\t\tonly1Min[i] = cSum[i];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tonly0Max[i] = cSum[i];\n\t\t\tonly0Min[i] = cSum[i];\n\t\t}\n\t}\n\tauto queryOnly1Max = Sparse!(long, max, \"max\")(only1Max);\n\tauto queryOnly0Max = Sparse!(long, max, \"max\")(only0Max);\n\tauto queryOnly1Min = Sparse!(long, min, \"min\")(only1Min);\n\tauto queryOnly0Min = Sparse!(long, min, \"min\")(only0Min);\n\tdebug writeln(cSum);\n\tdebug writeln(only1Max);\n\tdebug writeln(only0Min);\n\tint getLeft(int r)\n\t{\n\t\tint left = -1;\n\t\tint hi = r;\n\t\tint lo = 0;\n\t\twhile (lo <= hi)\n\t\t{\n\t\t\tint mi = (hi + lo) / 2;\n\t\t\t// this - same >= 0 this >= max(same)\n\t\t\t// this - other <= 0 this <= min(other)\n\t\t\tif (cSum[r] >= queryOnly1Max[mi .. r+1].max &&\n\t\t\t cSum[r] <= queryOnly0Min[mi .. r+1].min)\n\t\t\t{\n\t\t\t\tleft = mi;\n\t\t\t\thi = mi - 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo = mi + 1;\n\t\t\t}\n\t\t}\n\t\treturn left;\n\t}\n\tdebug foreach(i; 1 .. n + 1)\n\t{\n\t\twriteln(\"left of \", i, \" \", getLeft(i));\n\t}\n\tint[long] lastWithValue;\n\tlastWithValue[0] = 0;\n\tlong[] ways = new long[](n+1);\n\tforeach(i; 1 .. n+1)\n\t{\n\t\tif (auto last = cSum[i] in lastWithValue)\n\t\t{\n\t\t\tint left = getLeft(i);\n\t\t\tif (*last >= left)\n\t\t\t{\n\t\t\t\tways[i] = 1 + ways[*last];\n\t\t\t}\n\t\t}\n\t\tlastWithValue[cSum[i]] = i;\n\t}\n\tways.sum.writeln;\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<= 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\nlong[2][] primeFact(long x)\n{\n\tlong[2][] ans;\n\tfor (long i = 2; i*i <= x; ++i)\n\t{\n\t\tif (x % i != 0) continue;\n\n\t\tlong r;\n\t\twhile (x % i == 0)\n\t\t{\n\t\t\t++r;\n\t\t\tx /= i;\n\t\t}\n\t\tans ~= [i, r];\n\t}\n\tif (x != 1)\n\t\tans ~= [x, 1];\n\treturn ans;\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 n = RD;\n\n\t\tauto r = primeFact(n);\n\t\twhile (true)\n\t\t{\n\t\t\tlong x = 1;\n\t\t\tforeach (ref e; r)\n\t\t\t{\n\t\t\t\tif (e[1] == 0) continue;\n\t\t\t\tx *= e[0];\n\t\t\t\t--e[1];\n\t\t\t}\n\t\t\tif (x == 1) break;\n\t\t\tans[ti] = x ~ ans[ti];\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}\n"}], "negative_code": [], "src_uid": "f8d064c90f1f2b4a18386795dbcd9cb9"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1504/problem/A\n// greedy\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n string s;\n readf(\"%s\\n\", &s);\n\n bool found = false;\n int n = cast(int)s.length;\n for(uint i = 0; i < n; ++i) {\n if(s[i] == 'a')\n continue;\n found = true;\n \"YES\".writeln;\n (s[0..n-i]~'a'~s[n-i..$]).writeln;\n break;\n }\n if(!found)\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\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 string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = RD!string;\n\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tif (s[$-i-1] != 'a')\n\t\t\t{\n\t\t\t\tans[ti] = s[0..i] ~ 'a' ~ s[i..$];\n\t\t\t\tbreak;\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\twriteln(e);\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "e2dc3de62fc45c7e9ddb92daa5c5d8de"} {"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]);\r\n\t\tint [] ans;\r\n\t\tlong prev = 0;\r\n\t\tforeach (i; p)\r\n\t\t{\r\n\t\t\tif (prev < a[i])\r\n\t\t\t{\r\n\t\t\t\tans.length = 0;\r\n\t\t\t}\r\n\t\t\tans ~= i + 1;\r\n\t\t\tprev += a[i];\r\n\t\t}\r\n\t\tsort (ans);\r\n\t\twriteln (ans.length);\r\n\t\twritefln !(\"%(%s %)\") (ans);\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\nalias P = Tuple!(int, \"i\", long, \"t\");\r\n\r\nvoid main()\r\n{\r\n int T; get(T); while (T--) {\r\n int N; get(N);\r\n long[] AA; get(AA);\r\n P[] ps;\r\n foreach (i, a; AA) ps ~= P(i.to!int + 1, a);\r\n sort!\"a.t < b.t\"(ps);\r\n int[] rs;\r\n long s;\r\n foreach (i; 0..N-1) {\r\n auto p = ps[i];\r\n s += p.t;\r\n if (ps[i + 1].t <= s) {\r\n rs ~= p.i;\r\n } else {\r\n rs = [];\r\n }\r\n }\r\n rs ~= ps[$-1].i;\r\n sort(rs);\r\n writeln(rs.length);\r\n writefln!\"%(%d %)\"(rs);\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\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\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 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\t\r\n\t\tlong[long] zip;\r\n\t\tlong[] unzip;\r\n\t\tauto len = cast(int)compress(a, zip, unzip);\r\n\t\t\r\n\t\tauto cnt = new int[](len);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\t++cnt[cast(int)zip[a[i]]];\r\n\t\t}\r\n\t\tauto b = new long[](len+1);\r\n\t\tforeach (i; 0..len)\r\n\t\t{\r\n\t\t\tb[i+1] = b[i] + cnt[i] * unzip[i];\r\n\t\t}\r\n\t\tdebug writeln(b);\r\n\r\n\t\tauto win = new bool[](len);\r\n\t\tforeach (i; 0..len)\r\n\t\t{\r\n\t\t\tauto x = b[i+1];\r\n\t\t\tdebug writeln(\"i:\", i, \" x:\", x);\r\n\t\t\twhile (x < unzip[len-1])\r\n\t\t\t{\r\n\t\t\t\tbool f(int p)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn x >= unzip[p];\r\n\t\t\t\t}\r\n\t\t\t\tauto r = binarySearch!(f)(0, len);\r\n\t\t\t\tdebug writeln(\"r:\", r);\r\n\t\t\t\tif (b[r+1] <= x) break;\r\n\t\t\t\tx = b[r+1];\r\n\t\t\t}\r\n\t\t\twin[i] = x >= unzip[len-1];\r\n\t\t}\r\n\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tauto p = cast(int)zip[a[i]];\r\n\t\t\tif (win[p])\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\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}"}], "negative_code": [], "src_uid": "debce043777e7e575f77a94edf89c7f1"} {"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, k;\n\twhile (readf (\" %s %s\", &n, &k) > 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\tint res = int.min;\n\t\tforeach (lo; 0..n)\n\t\t{\n\t\t\tforeach (hi; lo + 1..n + 1)\n\t\t\t{\n\t\t\t\tauto b = a[0..lo].dup;\n\t\t\t\tb ~= a[hi..n];\n\t\t\t\tsort !(\"a > b\", SwapStrategy.stable) (b);\n\t\t\t\tauto c = a[lo..hi].dup;\n\t\t\t\tsort !(\"a < b\", SwapStrategy.stable) (c);\n\t\t\t\tint cur = 0;\n\t\t\t\tforeach (i; 0..k)\n\t\t\t\t{\n\t\t\t\t\tif (!b.length ||\n\t\t\t\t\t !c.length ||\n\t\t\t\t\t b[0] <= c[0])\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcur += b[0];\n\t\t\t\t\tb = b[1..$];\n\t\t\t\t\tc = c[1..$];\n }\n foreach (d; c)\n {\n \tcur += d;\n }\n res = max (res, cur);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\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, 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, K;\nint[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = 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 = int.min;\n\t\t\n\t\tforeach (i; 0 .. N) foreach (j; i + 1 .. N + 1) {\n\t\t\tint[] xs, ys;\n\t\t\tforeach (k; 0 .. N) {\n\t\t\t\t((i <= k && k < j) ? xs : ys) ~= A[k];\n\t\t\t}\n\t\t\txs.sort!\"a < b\";\n\t\t\tys.sort!\"a > b\";\n\t\t\tint now = xs.reduce!\"a + b\";\n\t\t\tchmax(ans, now);\n\t\t\tforeach (l; 0 .. K) if (l < xs.length && l < ys.length) {\n\t\t\t\tnow -= xs[l];\n\t\t\t\tnow += ys[l];\n\t\t\t\tchmax(ans, now);\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": [], "src_uid": "ff69d22bc683e5d1d83438585224c774"} {"source_code": "import std.algorithm, std.conv, std.stdio, std.string, std.typecons;\nbool c (T) (T a, T b) {return b == \"\" || tuple (a.length, a) < tuple (b.length, b);}\nvoid r (T) (ref T a, T b) {if (c (b, a)) a = b;}\nstring [3] [256] f;\nvoid main () {\n\tf[0b00001111][2] = \"x\";\n\tf[0b00110011][2] = \"y\";\n\tf[0b01010101][2] = \"z\";\n\tforeach (step; 0..4)\n\t\tforeach (s; 0..256) foreach (sp; 0..3) if (f[s][sp]) {\n\t\t\tif (sp > 1) r (f[s ^ 255][2], \"!\" ~ f[s][sp]);\n\t\t\tr (f[s][2], \"(\" ~ f[s][sp] ~ \")\");\n\t\t\tforeach (t; 0..256) foreach (tp; 0..3) if (f[t][tp]) {\n\t\t\t\tif (min (sp, tp)) r (f[s & t][1], f[s][sp] ~ \"&\" ~ f[t][tp]);\n\t\t\t\tr (f[s | t][0], f[s][sp] ~ \"|\" ~ f[t][tp]);\n\t\t\t}\n\t\t}\n\tforeach (i; 0..readln.strip.to!int) f[readln.strip.to!int (2)][].minElement!c.writeln;\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.stdio, std.string;\nstruct Answer {\n\tstring contents; alias contents this;\n\tint opCmp () (const auto ref Answer that) const {\n\t\tif ((this == \"\") != (that == \"\")) return (this == \"\") - (that == \"\");\n\t\tif (this.length != that.length) return cast (int) (this.length - that.length);\n\t\treturn (this.contents > that.contents) - (this.contents < that.contents);\n\t}\n}\nAnswer [3] [256] fun;\nvoid relax (ref Answer a, Answer b) {if (a > b) a = b;}\nvoid main () {\n\tfun[0b00001111][2] = \"x\";\n\tfun[0b00110011][2] = \"y\";\n\tfun[0b01010101][2] = \"z\";\n\tforeach (step; 0..4)\n\t\tforeach (s; 0..256) foreach (sp; 0..3) {\n\t\t\tstring sc = fun[s][sp];\n\t\t\tif (sc == \"\") continue;\n\t\t\tif (sp >= 2) relax (fun[s ^ 255][2], Answer (\"!\" ~ sc));\n\t\t\tif (sp >= 0) relax (fun[s][2], Answer (\"(\" ~ sc ~ \")\"));\n\t\t\tforeach (t; 0..256) foreach (tp; 0..3) {\n\t\t\t\tstring tc = fun[t][tp];\n\t\t\t\tif (tc == \"\") continue;\n\t\t\t\tif (sp >= 1 && tp >= 1) relax (fun[s & t][1], Answer (sc ~ \"&\" ~ tc));\n\t\t\t\tif (sp >= 0 && tp >= 0) relax (fun[s | t][0], Answer (sc ~ \"|\" ~ tc));\n\t\t\t}\n\t\t}\n\tforeach (i; 0..readln.strip.to !(int)) fun[readln.strip.to!int (2)][].minElement.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\nvoid main() {\n auto hoge = [\"!x&x\",\"x&y&z\",\"!z&x&y\",\"x&y\",\"!y&x&z\",\"x&z\",\"!y&x&z|!z&x&y\",\"(y|z)&x\",\"!y&!z&x\",\"!y&!z&x|x&y&z\",\"!z&x\",\"!z&x|x&y\",\"!y&x\",\"!y&x|x&z\",\"!(y&z)&x\",\"x\",\"!x&y&z\",\"y&z\",\"!x&y&z|!z&x&y\",\"(x|z)&y\",\"!x&y&z|!y&x&z\",\"(x|y)&z\",\"!x&y&z|!y&x&z|!z&x&y\",\"(x|y)&z|x&y\",\"!x&y&z|!y&!z&x\",\"!y&!z&x|y&z\",\"!x&y&z|!z&x\",\"!z&x|y&z\",\"!x&y&z|!y&x\",\"!y&x|y&z\",\"!(y&z)&x|!x&y&z\",\"x|y&z\",\"!x&!z&y\",\"!x&!z&y|x&y&z\",\"!z&y\",\"!z&y|x&y\",\"!x&!z&y|!y&x&z\",\"!x&!z&y|x&z\",\"!y&x&z|!z&y\",\"!z&y|x&z\",\"!(!x&!y|x&y|z)\",\"!(!x&!y|x&y|z)|x&y&z\",\"!z&(x|y)\",\"!z&(x|y)|x&y\",\"!x&!z&y|!y&x\",\"!x&!z&y|!y&x|x&z\",\"!y&x|!z&y\",\"!z&y|x\",\"!x&y\",\"!x&y|y&z\",\"!(x&z)&y\",\"y\",\"!x&y|!y&x&z\",\"!x&y|x&z\",\"!(x&z)&y|!y&x&z\",\"x&z|y\",\"!x&y|!y&!z&x\",\"!x&y|!y&!z&x|y&z\",\"!x&y|!z&x\",\"!z&x|y\",\"!x&y|!y&x\",\"!x&y|!y&x|x&z\",\"!(x&z)&y|!y&x\",\"x|y\",\"!x&!y&z\",\"!x&!y&z|x&y&z\",\"!x&!y&z|!z&x&y\",\"!x&!y&z|x&y\",\"!y&z\",\"!y&z|x&z\",\"!y&z|!z&x&y\",\"!y&z|x&y\",\"!(!x&!z|x&z|y)\",\"!(!x&!z|x&z|y)|x&y&z\",\"!x&!y&z|!z&x\",\"!x&!y&z|!z&x|x&y\",\"!y&(x|z)\",\"!y&(x|z)|x&z\",\"!y&z|!z&x\",\"!y&z|x\",\"!x&z\",\"!x&z|y&z\",\"!x&z|!z&x&y\",\"!x&z|x&y\",\"!(x&y)&z\",\"z\",\"!(x&y)&z|!z&x&y\",\"x&y|z\",\"!x&z|!y&!z&x\",\"!x&z|!y&!z&x|y&z\",\"!x&z|!z&x\",\"!x&z|!z&x|x&y\",\"!x&z|!y&x\",\"!y&x|z\",\"!(x&y)&z|!z&x\",\"x|z\",\"!(!y&!z|x|y&z)\",\"!(!y&!z|x|y&z)|x&y&z\",\"!x&!y&z|!z&y\",\"!x&!y&z|!z&y|x&y\",\"!x&!z&y|!y&z\",\"!x&!z&y|!y&z|x&z\",\"!y&z|!z&y\",\"!y&z|!z&y|x&y\",\"!(!x&!y|x&y|z)|!x&!y&z\",\"!(!x&!y|x&y|z)|!x&!y&z|x&y&z\",\"!x&!y&z|!z&(x|y)\",\"!x&!y&z|!z&(x|y)|x&y\",\"!x&!z&y|!y&(x|z)\",\"!x&!z&y|!y&(x|z)|x&z\",\"!y&(x|z)|!z&y\",\"!y&z|!z&y|x\",\"!x&(y|z)\",\"!x&(y|z)|y&z\",\"!x&z|!z&y\",\"!x&z|y\",\"!x&y|!y&z\",\"!x&y|z\",\"!(x&y)&z|!z&y\",\"y|z\",\"!x&(y|z)|!y&!z&x\",\"!x&(y|z)|!y&!z&x|y&z\",\"!x&(y|z)|!z&x\",\"!x&z|!z&x|y\",\"!x&(y|z)|!y&x\",\"!x&y|!y&x|z\",\"!x&y|!y&z|!z&x\",\"x|y|z\",\"!(x|y|z)\",\"!(x|y|z)|x&y&z\",\"!(!x&y|!y&x|z)\",\"!(x|y|z)|x&y\",\"!(!x&z|!z&x|y)\",\"!(x|y|z)|x&z\",\"!(!x&y|!y&x|z)|!y&x&z\",\"!(x|y|z)|(y|z)&x\",\"!y&!z\",\"!y&!z|x&y&z\",\"!(!x&y|z)\",\"!y&!z|x&y\",\"!(!x&z|y)\",\"!y&!z|x&z\",\"!(!x&y|z)|!y&x\",\"!y&!z|x\",\"!(!y&z|!z&y|x)\",\"!(x|y|z)|y&z\",\"!(!x&y|!y&x|z)|!x&y&z\",\"!(x|y|z)|(x|z)&y\",\"!(!x&z|!z&x|y)|!x&y&z\",\"!(x|y|z)|(x|y)&z\",\"!(!x&y|!y&x|z)|!x&y&z|!y&x&z\",\"!(x|y|z)|(x|y)&z|x&y\",\"!x&y&z|!y&!z\",\"!y&!z|y&z\",\"!(!x&y|z)|!x&y&z\",\"!(!x&y|z)|y&z\",\"!(!x&z|y)|!x&y&z\",\"!(!x&z|y)|y&z\",\"!(!x&y|z)|!x&y&z|!y&x\",\"!y&!z|x|y&z\",\"!x&!z\",\"!x&!z|x&y&z\",\"!(!y&x|z)\",\"!x&!z|x&y\",\"!x&!z|!y&x&z\",\"!x&!z|x&z\",\"!(!y&x|z)|!y&x&z\",\"!(!y&x|z)|x&z\",\"!(x&y|z)\",\"!(x&y|z)|x&y&z\",\"!z\",\"!z|x&y\",\"!x&!z|!y&x\",\"!(x&y|z)|x&z\",\"!y&x|!z\",\"!z|x\",\"!(!y&z|x)\",\"!x&!z|y&z\",\"!(!y&x|z)|!x&y\",\"!x&!z|y\",\"!(!y&z|x)|!y&x&z\",\"!(!y&z|x)|x&z\",\"!(!y&x|z)|!x&y|!y&x&z\",\"!x&!z|x&z|y\",\"!x&y|!y&!z\",\"!(x&y|z)|y&z\",\"!x&y|!z\",\"!z|y\",\"!(!x&!y&z|x&y)\",\"!x&!z|!y&x|y&z\",\"!x&y|!y&x|!z\",\"!z|x|y\",\"!x&!y\",\"!x&!y|x&y&z\",\"!x&!y|!z&x&y\",\"!x&!y|x&y\",\"!(!z&x|y)\",\"!x&!y|x&z\",\"!(!z&x|y)|!z&x&y\",\"!(!z&x|y)|x&y\",\"!(x&z|y)\",\"!(x&z|y)|x&y&z\",\"!x&!y|!z&x\",\"!(x&z|y)|x&y\",\"!y\",\"!y|x&z\",\"!y|!z&x\",\"!y|x\",\"!(!z&y|x)\",\"!x&!y|y&z\",\"!(!z&y|x)|!z&x&y\",\"!(!z&y|x)|x&y\",\"!(!z&x|y)|!x&z\",\"!x&!y|z\",\"!(!z&x|y)|!x&z|!z&x&y\",\"!x&!y|x&y|z\",\"!x&z|!y&!z\",\"!(x&z|y)|y&z\",\"!(!x&!z&y|x&z)\",\"!x&!y|!z&x|y&z\",\"!x&z|!y\",\"!y|z\",\"!x&z|!y|!z&x\",\"!y|x|z\",\"!(x|y&z)\",\"!(x|y&z)|x&y&z\",\"!x&!y|!z&y\",\"!(x|y&z)|x&y\",\"!x&!z|!y&z\",\"!(x|y&z)|x&z\",\"!(!y&!z&x|y&z)\",\"!x&!y|!z&y|x&z\",\"!((x|y)&z|x&y)\",\"!((x|y)&z|x&y)|x&y&z\",\"!x&!y|!z\",\"!x&!y|!z|x&y\",\"!x&!z|!y\",\"!x&!z|!y|x&z\",\"!y|!z\",\"!y|!z|x\",\"!x\",\"!x|y&z\",\"!x|!z&y\",\"!x|y\",\"!x|!y&z\",\"!x|z\",\"!x|!y&z|!z&y\",\"!x|y|z\",\"!x|!y&!z\",\"!x|!y&!z|y&z\",\"!x|!z\",\"!x|!z|y\",\"!x|!y\",\"!x|!y|z\",\"!(x&y&z)\",\"!x|x\"];\n auto N = readln.chomp.to!int;\n foreach (i; 0..N) {\n auto s = readln.chomp.to!int(2);\n writeln(hoge[s]);\n }\n}\n\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 logLogLimit = 3;\nimmutable int logLimit = 1 << logLogLimit;\nimmutable int limit = 1 << logLimit;\nimmutable int prios = 3;\n\nstruct Answer\n{\n\tstring contents;\n\talias contents this;\n\n\tint opCmp () (const auto ref Answer that) const\n\t{\n\t\tif ((that == \"\") != (this == \"\"))\n\t\t{\n\t\t\treturn (this == \"\") - (that == \"\");\n\t\t}\n\t\tif (that.length != this.length)\n\t\t{\n\t\t\treturn cast (int) (this.length) -\n\t\t\t cast (int) (that.length);\n\t\t}\n\t\treturn (that.contents < this.contents) -\n\t\t (this.contents < that.contents);\n\t}\n}\n\nunittest\n{\n\tauto a = Answer (\"x\");\n\tauto b = Answer (\"y\");\n\tauto c = Answer (\"!!y\");\n\tauto d = Answer (\"(x)\");\n\tauto e = Answer (\"\");\n\tassert (a < b);\n\tassert (b < c);\n\tassert (c < d);\n\tassert (d < e);\n}\n\nAnswer [prios] [limit] fun;\n\nvoid relax (ref Answer a, Answer b)\n{\n\tif (a > b)\n\t{\n\t\ta = b;\n\t}\n}\n\nvoid main ()\n{\n\tfun[0b00001111][2] = \"x\";\n\tfun[0b00110011][2] = \"y\";\n\tfun[0b01010101][2] = \"z\";\n\tAnswer [prios] [limit] funPrev;\n\tdo\n\t{\n\t\tfunPrev = fun;\n\t\tdebug {writeln (fun);}\n\t\tforeach (s; 0..limit)\n\t\t{\n\t\t\tforeach (sp; 0..3)\n\t\t\t{\n\t\t\t\tstring sc = fun[s][sp];\n\t\t\t\tif (sc == \"\")\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (sp >= 2)\n\t\t\t\t{\n\t\t\t\t\tauto r = s ^ (limit - 1);\n\t\t\t\t\tauto next = Answer (\"!\" ~ sc);\n\t\t\t\t\trelax (fun[r][2], next);\n\t\t\t\t}\n\n\t\t\t\tif (sp >= 0)\n\t\t\t\t{\n\t\t\t\t\tauto r = s;\n\t\t\t\t\tauto next = Answer (\"(\" ~ sc ~ \")\");\n\t\t\t\t\trelax (fun[r][2], next);\n\t\t\t\t}\n\n\t\t\t\tforeach (t; 0..limit)\n\t\t\t\t{\n\t\t\t\t\tforeach (tp; 0..3)\n\t\t\t\t\t{\n\t\t\t\t\t\tstring tc = fun[t][tp];\n\t\t\t\t\t\tif (tc == \"\")\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (sp >= 1 && tp >= 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tauto r = s & t;\n\t\t\t\t\t\t\tauto next = Answer (sc ~ \"&\" ~ tc);\n\t\t\t\t\t\t\trelax (fun[r][1], next);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (sp >= 0 && tp >= 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tauto r = s | t;\n\t\t\t\t\t\t\tauto next = Answer (sc ~ \"|\" ~ tc);\n\t\t\t\t\t\t\trelax (fun[r][0], next);\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}\n\twhile (funPrev != fun);\n\tdebug {writeln (fun);}\n\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto x = readln.strip.to !(int) (2);\n\t\t\tdebug {writeln (fun[x]);}\n\t\t\twriteln (fun[x][].minElement);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.stdio, std.string;\nalias c = (a, b) => b == \"\" || (a.length != b.length ? a.length < b.length : a < b);\nalias r = (ref a, b) {if (c (b, a)) a = b;};\nstring [3] [256] f;\nvoid main () {\n\tf[15][2] = \"x\";\tf[51][2] = \"y\";\tf[85][2] = \"z\";\n\tforeach (t; 0..4) foreach (u; 0..256) foreach (p; 0..3) if (f[u][p]) {\n\t\t\tif (p > 1) r (f[u ^ 255][2], \"!\" ~ f[u][p]);\n\t\t\tr (f[u][2], \"(\" ~ f[u][p] ~ \")\");\n\t\t\tforeach (v; 0..256) foreach (q; 0..3) if (f[v][q]) {\n\t\t\t\tif (min (p, q)) r (f[u & v][1], f[u][p] ~ \"&\" ~ f[v][q]);\n\t\t\t\tr (f[u | v][0], f[u][p] ~ \"|\" ~ f[v][q]);\n\t\t\t}\n\t\t}\n\tforeach (i; 0..readln.strip.to!int) f[readln.strip.to!int (2)][].minElement!c.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 hoge = [\"!(!x|x)\",\"!(!x|!y|!z)\",\"!(!x|!y|z)\",\"(x)&(y)\",\"!(!x|!z|y)\",\"(x)&(z)\",\"!y|!z&(x)&y|z\",\"(x)&y|z\",\"!(!x|y|z)\",\"!y|z&!z|y&(x)\",\"!(!x|z)\",\"!z|y&(x)\",\"!(!x|y)\",\"!y|z&(x)\",\"!y|!z&(x)\",\"x\",\"!(!y|!z|x)\",\"(y)&(z)\",\"!x|!z&(y)&x|z\",\"(y)&x|z\",\"!x|!y&(z)&x|y\",\"(z)&x|y\",\"!x|!y&x|y|!z&x|z&y|z\",\"x|y&x|z&y|z\",\"!x|!y&!z|y&x|z\",\"!y|z&!z|y&x|y\",\"!x|!z&x|y&x|z\",\"!z|y&x|z\",\"!x|!y&x|y&x|z\",\"!y|z&x|y\",\"!x|!y&x|y|!z&x|z\",\"x|y&x|z\",\"!(!y|x|z)\",\"!x|z&!z|x&(y)\",\"!(!y|z)\",\"!z|x&(y)\",\"!x|!y&!z|x&y|z\",\"!x|z&!z|x&x|y\",\"!y|!z&x|y&y|z\",\"!z|x&y|z\",\"!(!x|y&!y|x|z)\",\"!x|!y&x|y|z&!z|x&!z|y\",\"(!z)&x|y\",\"!z|x&!z|y&x|y\",\"!(x|z)|!y&x|y\",\"!x|!y&x|y|z&!z|x\",\"!y|!z&x|y\",\"!z|x&x|y\",\"!(!y|x)\",\"!x|z&(y)\",\"!x|!z&(y)\",\"y\",\"!x|!y&x|y&y|z\",\"!x|z&x|y\",\"!x|!y&x|y|!z&y|z\",\"x|y&y|z\",\"!(y|z)|!x&x|y\",\"!x|!y&x|y|z&!z|y\",\"!x|!z&x|y\",\"!z|y&x|y\",\"!x|!y&x|y\",\"!x|!y|z&x|y\",\"!x|!y|!z&x|y\",\"x|y\",\"!(!z|x|y)\",\"!x|y&!y|x&(z)\",\"!x|!z&!y|x&y|z\",\"!x|y&!y|x&x|z\",\"!(!z|y)\",\"!y|x&(z)\",\"!y|!z&x|z&y|z\",\"!y|x&y|z\",\"!(!x|z&!z|x|y)\",\"!x|!y|z&!z|y&!y|x&x|z\",\"!(x|y)|!z&x|z\",\"!x|!z&x|z|y&!y|x\",\"(!y)&x|z\",\"!y|x&!y|z&x|z\",\"!y|!z&x|z\",\"!y|x&x|z\",\"!(!z|x)\",\"!x|y&(z)\",\"!x|!z&x|z&y|z\",\"!x|y&x|z\",\"!x|!y&(z)\",\"z\",\"!x|!y|!z&x|z&y|z\",\"x|z&y|z\",\"!(y|z)|!x&x|z\",\"!x|!y|z&!z|y&x|z\",\"!x|!z&x|z\",\"!x|!z|y&x|z\",\"!x|!y&x|z\",\"!y|z&x|z\",\"!x|!y|!z&x|z\",\"x|z\",\"!(!y|z&!z|y|x)\",\"!x|y&!x|z&!y|!z&y|z|x\",\"!(x|y)|!z&y|z\",\"!x|y&!y|!z&y|z|x\",\"!(x|z)|!y&y|z\",\"!x|z&!y|!z&y|z|x\",\"!y|!z&y|z\",\"!y|!z|x&y|z\",\"!(x|y&x|z&y|z)&x|y|z\",\"!x|!y&x|y|z&!x|y&!y|x|!z\",\"!(x|y)|!z&x|y|z\",\"!x|y&!y|x|!z&x|y|z\",\"!(x|z)|!y&x|y|z\",\"!x|z&!z|x|!y&x|y|z\",\"!y|!z&x|y|z\",\"!y|!z&y|z|x\",\"(!x)&y|z\",\"!x|y&!x|z&y|z\",\"!x|!z&y|z\",\"!x|y&y|z\",\"!x|!y&y|z\",\"!x|z&y|z\",\"!x|!y|!z&y|z\",\"y|z\",\"!(y|z)|!x&x|y|z\",\"!x|!y|z&!z|y&x|y|z\",\"!x|!z&x|y|z\",\"!x|!z&x|z|y\",\"!x|!y&x|y|z\",\"!x|!y&x|y|z\",\"!x|!y|!z&x|y|z\",\"x|y|z\",\"!(x|y|z)\",\"!x|y&!y|z&!z|x\",\"!(!x|!y&x|y|z)\",\"!(x|z)|y&!y|x\",\"!(!x|!z&x|z|y)\",\"!(x|y)|z&!z|x\",\"!(!x|!y|z&!z|y&x|y|z)\",\"!(y|z)|x&!x|y|z\",\"!(y|z)\",\"!y|x&!y|z&!z|y\",\"!y|x&(!z)\",\"!y|x&!z|y\",\"!z|x&(!y)\",\"!y|z&!z|x\",\"!(y|z)|x&!y|!z\",\"!(y|z)|x\",\"!(!y|!z&y|z|x)\",\"!(x|y)|z&!z|y\",\"!(!x|z&!z|x|!y&x|y|z)\",\"!(x|z)|y&!y|x|z\",\"!(!x|y&!y|x|!z&x|y|z)\",\"!(x|y)|z&!z|x|y\",\"!x|!y&x|y|!z&!x|y&!y|x|z\",\"!x|y&!y|x|z&!z|x|y\",\"!(!y|!z|x&y|z)\",\"!y|z&!z|y\",\"!(!y|x)|!z&!y|x|z\",\"!y|x|z&!z|y\",\"!(!z|x)|!y&!z|x|y\",\"!y|z&!z|x|y\",\"!x|!y&x|y|!z&!y|x|z\",\"!y|z&!z|y|x\",\"!(x|z)\",\"!x|y&!x|z&!z|x\",\"!x|y&(!z)\",\"!x|y&!z|x\",\"!(!x|!z|y&x|z)\",\"!x|z&!z|x\",\"!(!x|y)|!z&!x|y|z\",\"!x|y|z&!z|x\",\"!(x|z&y|z)\",\"!x|!y|z&!z|x&!z|y\",\"!z\",\"!z|x&!z|y\",\"!x|!y&!z|x\",\"!x|!y|z&!z|x\",\"!(!x|y)|!z\",\"!z|x\",\"!z|y&(!x)\",\"!x|z&!z|y\",\"!(x|z)|y&!x|!z\",\"!(x|z)|y\",\"!(!z|y)|!x&!z|x|y\",\"!x|z&!z|x|y\",\"!x|!y&x|y|!z&!x|y|z\",\"!x|z&!z|x|y\",\"!x|!y&!z|y\",\"!x|!y|z&!z|y\",\"!(!y|x)|!z\",\"!z|y\",\"!x|!y&!z|x|y\",\"!x|!y|z&!z|x|y\",\"!x|!y&x|y|!z\",\"!z|x|y\",\"!(x|y)\",\"!x|y&!x|z&!y|x\",\"!(!x|!y|z&x|y)\",\"!x|y&!y|x\",\"!x|z&(!y)\",\"!x|z&!y|x\",\"!(!x|z)|!y&!x|y|z\",\"!x|y|z&!y|x\",\"!(x|y&y|z)\",\"!x|!y|z&!z|y&!y|x\",\"!x|!z&!y|x\",\"!x|!z|y&!y|x\",\"!y\",\"!y|x&!y|z\",\"!(!x|z)|!y\",\"!y|x\",\"!y|z&(!x)\",\"!x|y&!y|z\",\"!(!y|z)|!x&!y|x|z\",\"!x|y&!y|x|z\",\"!(x|y)|z&!x|!y\",\"!(x|y)|z\",\"!x|!y|!z&y|z&!y|x|z\",\"!x|y&!y|x|z\",\"!x|!z&!y|z\",\"!x|!z|y&!y|z\",\"!x|!z&!y|x|z\",\"!x|!z|y&!y|x|z\",\"!(!z|x)|!y\",\"!y|z\",\"!x|!z&x|z|!y\",\"!y|x|z\",\"!(x|y&x|z)\",\"!x|y&!x|z&!y|!z|x\",\"!x|y&!y|!z\",\"!x|y&!y|!z|x\",\"!x|z&!y|!z\",\"!x|z&!y|!z|x\",\"!x|y|z&!y|!z\",\"!x|y|z&!y|!z|x\",\"!(x|y&x|z&y|z)\",\"!x|!y|z&!x|y&!y|x|!z\",\"!(x|y)|!z\",\"!x|y&!y|x|!z\",\"!(x|z)|!y\",\"!x|z&!z|x|!y\",\"!y|!z\",\"!y|!z|x\",\"!x\",\"!x|y&!x|z\",\"!(!y|z)|!x\",\"!x|y\",\"!(!z|y)|!x\",\"!x|z\",\"!x|!y|!z&y|z\",\"!x|y|z\",\"!(y|z)|!x\",\"!x|!y|z&!z|y\",\"!x|!z\",\"!x|!z|y\",\"!x|!y\",\"!x|!y|z\",\"!x|!y|!z\",\"!x|x\"];\n auto N = readln.chomp.to!int;\n foreach (i; 0..N) {\n auto s = readln.chomp.to!int(2);\n writeln(hoge[s]);\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;\n\nimmutable int x = 0b00001111;\nimmutable int y = 0b00110011;\nimmutable int z = 0b01010101;\nimmutable int nx = 0b11110000;\nimmutable int ny = 0b11001100;\nimmutable int nz = 0b10101010;\nstring[] func;\n\nint not(int a) {\n return 0b11111111 ^ a;\n}\n\nint p_and(string s) {\n return s[0] != '(' && s.canFind(\"|\");\n}\n\nvoid main() {\n func = new string[](256);\n func.fill(\"\");\n func[x] = \"x\";\n func[y] = \"y\";\n func[z] = \"z\";\n func[nx] = \"!x\";\n func[ny] = \"!y\";\n func[nz] = \"!z\";\n\n int[string] d;\n d[\"x\"] = x;\n d[\"y\"] = y;\n d[\"z\"] = z;\n d[\"!x\"] = nx;\n d[\"!y\"] = ny;\n d[\"!z\"] = nz;\n\n\n int cnt = 6;\n for (int i = 3; cnt < 256; ++i) {\n foreach (str; d.keys) {\n auto term = d[str];\n int len = str.length.to!int;\n\n if (len!= 1 && len == i-3) {\n int next = not(term);\n string next_str = \"!(\" ~ str ~ \")\";\n if (func[next] == \"\" || func[next].length > i) {\n func[next] = next_str;\n } else if (func[next].length == i && func[next] > next_str) {\n func[next] = next_str;\n }\n }\n\n foreach (str2; d.keys) {\n if (str == str2) continue;\n if (str.length + str2.length + 1 != i) continue;\n int next = term | d[str2];\n string next_str1 = str ~ \"|\" ~ str2;\n string next_str2 = str2 ~ \"|\" ~ str;\n string next_str = min(next_str1, next_str2);\n if (func[next] == \"\" || func[next].length > i) {\n func[next] = next_str;\n } else if (func[next].length == i && func[next] > next_str) {\n func[next] = next_str;\n }\n }\n\n string str1 = str;\n if (p_and(str)) str1 = \"(\" ~ str ~ \")\";\n\n foreach (str2; d.keys) {\n string str3 = str2;\n if (str == str2) continue;\n if (p_and(str2)) str3 = \"(\" ~ str2 ~ \")\";\n if (str1.length + str3.length + 1 != i) continue;\n\n int next = term & d[str2];\n string next_str1 = str1 ~ \"&\" ~ str3;\n string next_str2 = str3 ~ \"&\" ~ str1;\n string next_str = min(next_str1, next_str2);\n if (func[next] == \"\" || func[next].length > i) {\n func[next] = next_str;\n } else if (func[next].length == i && func[next] > next_str) {\n func[next] = next_str;\n }\n }\n\n }\n\n foreach (j; 0..256) {\n if (func[j].length == i && func[j] != \"\") {\n cnt += 1;\n d[func[j]] = j;\n }\n }\n }\n\n string[string] hoge;\n foreach (i; 0..256) {\n hoge[format(\"%08b\", i)] = func[i];\n }\n\n auto N = readln.chomp.to!int;\n foreach (i; 0..N) {\n auto s = readln.chomp;\n writeln(hoge[s]);\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\nimmutable int x = 0b00001111;\nimmutable int y = 0b00110011;\nimmutable int z = 0b01010101;\nimmutable int nx = 0b11110000;\nimmutable int ny = 0b11001100;\nimmutable int nz = 0b10101010;\nstring[] func;\n\nint not(int a) {\n return 0b11111111 ^ a;\n}\n\nint p_and(string s) {\n return s[0] != '(' && s.canFind(\"|\");\n}\n\nvoid main() {\n func = new string[](256);\n func.fill(\"\");\n func[x] = \"x\";\n func[y] = \"y\";\n func[z] = \"z\";\n func[nx] = \"!x\";\n func[ny] = \"!y\";\n func[nz] = \"!z\";\n\n int[string] d;\n d[\"x\"] = x;\n d[\"y\"] = y;\n d[\"z\"] = z;\n d[\"!x\"] = nx;\n d[\"!y\"] = ny;\n d[\"!z\"] = nz;\n\n\n int cnt = 6;\n for (int i = 3; cnt < 256; ++i) {\n foreach (str; d.keys) {\n auto term = d[str];\n int len = str.length.to!int;\n\n if (len!= 1 && len == i-3) {\n int next = not(term);\n string next_str = \"!(\" ~ str ~ \")\";\n if (func[next] == \"\" || func[next].length > i) {\n func[next] = next_str;\n } else if (func[next].length == i && func[next] > next_str) {\n func[next] = next_str;\n }\n }\n\n foreach (str2; d.keys) {\n if (str == str2) continue;\n if (str.length + str2.length + 1 != i) continue;\n int next = term | d[str2];\n string next_str1 = str ~ \"|\" ~ str2;\n string next_str2 = str2 ~ \"|\" ~ str;\n string next_str = min(next_str1, next_str2);\n if (func[next] == \"\" || func[next].length > i) {\n func[next] = next_str;\n } else if (func[next].length == i && func[next] > next_str) {\n func[next] = next_str;\n }\n }\n\n string str1 = str;\n if (p_and(str)) str1 = \"(\" ~ str ~ \")\";\n\n foreach (str2; d.keys) {\n string str3 = str2;\n if (str == str2) continue;\n if (p_and(str2)) str3 = \"(\" ~ str2 ~ \")\";\n if (str1.length + str3.length + 1 != i) continue;\n\n int next = term & d[str2];\n string next_str1 = str1 ~ \"&\" ~ str3;\n string next_str2 = str3 ~ \"&\" ~ str1;\n string next_str = min(next_str1, next_str2);\n if (next_str == \"!x&\") writeln(str1, \" \", str3, \" \", str, \" \", str2);\n if (func[next] == \"\" || func[next].length > i) {\n func[next] = next_str;\n } else if (func[next].length == i && func[next] > next_str) {\n func[next] = next_str;\n }\n }\n\n }\n\n foreach (j; 0..256) {\n if (func[j].length == i && func[j] != \"\") {\n cnt += 1;\n d[func[j]] = j;\n }\n }\n }\n\n string[string] hoge;\n foreach (i; 0..256) {\n hoge[format(\"%08b\", i)] = func[i];\n }\n\n auto N = readln.chomp.to!int;\n foreach (i; 0..N) {\n auto s = readln.chomp;\n writeln(hoge[s]);\n }\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.stdio, std.string;\nstruct Answer {\n\tstring contents; alias contents this;\n\tint opCmp () (const auto ref Answer that) const {\n\t\tif ((this == \"\") != (that == \"\")) return (this == \"\") - (that == \"\");\n\t\tif (this.length != that.length) return cast (int) (this.length - that.length);\n\t\treturn (this.contents > that.contents) - (this.contents < that.contents);\n\t}\n}\nAnswer [3] [256] fun;\nvoid relax (ref Answer a, Answer b) {if (a > b) a = b;}\nvoid main () {\n\tfun[0b00001111][2] = \"x\";\n\tfun[0b00110011][2] = \"y\";\n\tfun[0b01010101][2] = \"z\";\n\tforeach (step; 0..3)\n\t\tforeach (s; 0..256) foreach (sp; 0..3) {\n\t\t\tstring sc = fun[s][sp];\n\t\t\tif (sc == \"\") continue;\n\t\t\tif (sp >= 2) relax (fun[s ^ 255][2], Answer (\"!\" ~ sc));\n\t\t\tif (sp >= 0) relax (fun[s][2], Answer (\"(\" ~ sc ~ \")\"));\n\t\t\tforeach (t; 0..256) foreach (tp; 0..3) {\n\t\t\t\tstring tc = fun[t][tp];\n\t\t\t\tif (tc == \"\") continue;\n\t\t\t\tif (sp >= 1 && tp >= 1) relax (fun[s & t][1], Answer (sc ~ \"&\" ~ tc));\n\t\t\t\tif (sp >= 0 && tp >= 0) relax (fun[s | t][1], Answer (sc ~ \"|\" ~ tc));\n\t\t\t}\n\t\t}\n\tforeach (i; 0..readln.strip.to !(int)) fun[readln.strip.to!int (2)][].minElement.writeln;\n}\n"}], "src_uid": "e840b008dfd50a9be7061b6788160568"} {"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 foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write((-1)^^(i & 1) * abs(A[i]));\n }\n writeln;\n }\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;\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\tforeach (i, ref c; a)\n\t\t{\n\t\t\tc = abs (c);\n\t\t\tif (i % 2 == 0)\n\t\t\t{\n\t\t\t\tc = -c;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%s %)\") (a);\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 = RDA!int;\n\n\t\tans[ti].length = n;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i % 2)\n\t\t\t\tans[ti][i] = abs(a[i]);\n\t\t\telse\n\t\t\t\tans[ti][i] = -abs(a[i]);\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}"}], "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\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tforeach (i, ref c; a)\n\t\t{\n\t\t\tc = abs (c);\n\t\t\tif (i > 0 && (i % 4 < 2) == (a[i] >= a[i - 1]))\n\t\t\t{\n\t\t\t\tc = -c;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%s %)\") (a);\n\t}\n}\n"}], "src_uid": "d07ae42b7902ba3a49cf4463248710ea"} {"source_code": "immutable multi = true;\n\nint[10] tenPow;\nstatic this()\n{\n tenPow[0] = 1;\n foreach(i; 1 .. 10)\n tenPow[i] = 10 * tenPow[i-1];\n}\n\nvoid solve(int tc)\n{\n auto x1 = readInt!int,\n p1 = readInt!int,\n x2 = readInt!int,\n p2 = readInt!int;\n\n int getPot(int x)\n {\n int ans = 0;\n while (x)\n {\n\tans++;\n\tx /= 10;\n }\n return ans;\n }\n int pot1 = getPot(x1) + p1, pot2 = getPot(x2) + p2;\n if (pot1 > pot2) return writeln(\">\");\n if (pot2 > pot1) return writeln(\"<\");\n auto mnp = min(p1, p2);\n p1 -= mnp;\n p2 -= mnp;\n x1 *= tenPow[p1];\n x2 *= tenPow[p2];\n if (x1 < x2) return writeln(\"<\");\n if (x1 > x2) return writeln(\">\");\n return 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 double x1 = scan!double;\n long p1 = scan;\n double x2 = scan!double;\n long p2 = scan;\n while(x1 >= 10){\n x1 /= 10;\n ++p1;\n }\n while(x2 >= 10){\n x2 /= 10;\n ++p2;\n }\n if(p1 > p2 || (p1 == p2 && x1 > x2)){\n writeln(\">\");\n }else if(p2 > p1 || (p1 == p2 && x1 < x2)){\n writeln(\"<\");\n }else{\n writeln(\"=\");\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\nlong numdigits(long x)\n{\n long ans;\n while (x > 0) {\n ans++;\n x /= 10;\n }\n return ans;\n}\n\nstring cmp(T)(T x1, T x2)\n{\n if (x1 == x2)\n return \"=\";\n else if (x1 < x2)\n return \"<\";\n else\n return \">\";\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n long x1, p1, x2, p2;\n readf!\" %d %d %d %d \"(x1, p1, x2, p2);\n p1 += numdigits(x1);\n p2 += numdigits(x2);\n if (p1 == p2) {\n string s1 = x1.to!string;\n string s2 = x2.to!string;\n while (s1.length < s2.length)\n s1 ~= \"0\";\n while (s2.length < s1.length)\n s2 ~= \"0\";\n writeln(cmp(s1, s2));\n } else if (p1 < p2) {\n writeln(\"<\");\n } else {\n writeln(\">\");\n }\n }\n}\n"}], "negative_code": [], "src_uid": "a4eeaf7252b9115b67b9eca5f2bf621d"} {"source_code": "import std.stdio;\nvoid main()\n{\n int n;\n readf(\" %s\", &n);\n \n for(int i = 0; i < n; i++){\n long a, b, c;\n readf(\" %s %s %s\", &a, &b, &c);\n long total = (a + b + c) / 2;\n writeln(total);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric;\nimport std.typecons, std.functional, std.traits;\nimport std.algorithm, std.container;\nimport core.stdc.stdlib, core.bitop;\n\nvoid main()\n{\n auto N = scanElem;\n foreach(i;0..N)\n {\n auto list = [scanElem, scanElem, scanElem];\n sort(list);\n auto a = list[0];\n auto b = list[1];\n auto diff = list[1] - list[0];\n if(diff>list[2]){\n writeln(diff-list[2]/2+a);\n }else{\n writeln((list[2]-diff)/2+b);\n }\n }\n}\n\nbool isInf(long v) pure\n{\n return v>=INF;\n}\nenum INF = long.max/5;\nenum MOD=10^^9+7L;\n\nstruct ModInt(alias Mod = MOD)\nif(isIntegral!(typeof(Mod)) && isPrime(Mod))\n{\n long value;\n\n this(ModInt!Mod v)\n {\n value = v.value;\n }\n this(long v)\n {\n value = (v%Mod+Mod)%Mod;\n }\n\n private static ModInt!Mod inv(ModInt!Mod v) pure\n {\n ModInt res=1;\n long p = Mod-2;\n while(p!=0)\n {\n if(p&1)res *= v;\n v *= v;\n p >>= 1;\n }\n return res;\n }\n\n ModInt!Mod opBinaryRight(string op, T)(T v) const\n if((op==\"+\"||op==\"-\"||op==\"*\")&&isIntegral!T)\n {\n return ModInt!Mod(mixin(\"v\"~op~\"value\"));\n }\n ModInt!Mod opBinary(string op, T)(T v) const\n if((op==\"+\"||op==\"-\"||op==\"*\")&&(is(T==ModInt!Mod)||isIntegral!T))\n {\n return ModInt!Mod(mixin(\"value\"~op~\"v\"));\n }\n\n ModInt!Mod opBinaryRight(string op, T)(T v) const\n if((op==\"/\")&&isIntegral!T)\n {\n return v * inv(this);\n }\n ModInt!Mod opBinary(string op, T)(T v) const\n if((op==\"/\")&&(is(T==ModInt!Mod)||isIntegral!T))\n {\n return this * inv(ModInt(v));\n }\n\n void opAssign(T)(T v)\n if(isIntegral!T)\n {\n this = ModInt!Mod(v);\n }\n\n void opOpAssign(string op, T)(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 == ModInt(v).value;\n }\n\n long opCast() const {\n return value;\n }\n\n string toString() const {\n return value.to!string;\n }\n}\n@safe pure unittest\n{\n assert(is(ModInt!()));\n assert(is(ModInt!17));\n assert(!is(ModInt!0));\n assert(!is(ModInt!10));\n\n assert(is(ModInt!()==ModInt!(MOD)));\n}\n@safe pure unittest\n{\n alias MInt = ModInt!13;\n assert(MInt.inv(MInt(4))==10);\n assert(MInt.inv(MInt(6))==11);\n assert(MInt.inv(MInt(12))==12);\n}\n@safe pure unittest\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 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}\n@safe pure unittest\n{\n ModInt!() 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(size_t w, size_t h)\n {\n this(new T[w*h], w, h, w);\n }\n\n void setRow(InputRange)(size_t y, InputRange range)\n if(isInputRange!InputRange && is(typeof(grid.front=range.front)))\n {\n foreach(x; 0..width)\n {\n assert(!range.empty);\n this[x, y] = range.front;\n range.popFront;\n }\n }\n\n void setCol(InputRange)(size_t x, InputRange range)\n if(isInputRange!InputRange && is(typeof(T.init=range.front)))\n {\n foreach(y; 0..height)\n {\n assert(!range.empty);\n this[x, y] = range.front;\n range.popFront;\n }\n }\n\n Grid!T copy(){\n if(width == stride){\n return Grid!T(grid.dup, width, height, stride);\n }\n\n auto res = Grid!T(width, height);\n foreach(y;0..height)\n foreach(x;0..width)\n {\n res[x, y] = this[x, y];\n }\n return res;\n }\n\n ref T opIndex(size_t x, size_t y)\n {\n return grid[x+stride*y];\n }\n ref T opIndex(E)(E e)\n if(\n isIntegral!(typeof(e.x)) &&\n isIntegral!(typeof(e.y)))\n {\n return this[e.x, e.y];\n }\n\n Grid!T opIndex(size_t[2] r1, size_t[2] r2)\n {\n auto startOffset = r1[0] + r2[0]*stride;\n auto endOffset = r1[1] + (r2[1] - 1)*stride;\n\n auto resGrid = grid[startOffset .. endOffset];\n auto resStride = stride;\n auto resWidth = r1[1] - r1[0];\n auto resHeight = r2[1] - r2[0];\n return Grid!T(resGrid, resWidth, resHeight, resStride);\n }\n \n Grid!T opIndex(size_t[2] r1, size_t j) { return opIndex(r1, [j, j+1]); }\n Grid!T opIndex(size_t i, size_t[2] r2) { return opIndex([i, i+1], r2); }\n\n size_t[2] opSlice(size_t dim)(size_t start, size_t 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 size_t opDollar(size_t dim : 0)() const { return width; }\n size_t opDollar(size_t dim : 1)() const { return height; }\n\n string toString() {\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(T==long))\n {\n if(this[x,y]>=INF)\n {\n joinStr = \"* \";\n }\n }\n res ~= joinStr;\n }\n res ~= '\\n';\n }\n return res;\n }\n}\n\nstruct Data2{\n long x,y;\n alias a=x, b=y;\n ref long opIndex(size_t i)\n {\n assert(i==0||i==1);\n return i==0?x:y;\n }\n}\nstruct Data3{\n long x,y,z;\n alias a=x, b=y, c=z;\n ref long opIndex(size_t i)\n {\n assert(i==0||i==1||i==2);\n return i==0?x:(i==1?y:z);\n }\n}\n\nlong lcm(long a, long b) pure\n{\n return a * b / gcd(a, b);\n}\n\nclass UnionFind{\n UnionFind parent = null;\n\n void merge(UnionFind a)\n {\n if(same(a)) return;\n a.root.parent = this.root;\n }\n UnionFind root()\n {\n if(parent is null)return this;\n return parent = parent.root;\n }\n bool same(UnionFind a)\n {\n return this.root == a.root;\n }\n}\n\nenum TermColor{\n Blue,\n Red,\n Purple,\n Gray,\n Green,\n Brown,\n Default,\n}\n\nstring termStr(TermColor c) pure\n{\n switch(c)\n {\n case TermColor.Blue: return \"\\033[38;2;122;158;194m\";\n case TermColor.Red: return \"\\033[38;2;204;130;66m\";\n case TermColor.Purple: return \"\\033[38;2;158;123;176m\";\n case TermColor.Gray: return \"\\033[38;2;106;135;89m\";\n case TermColor.Green: return \"\\033[38;2;165;194;97m\";\n case TermColor.Brown: return \"\\033[38;2;204;130;66m\";\n default: return \"\\033[0m\";\n }\n}\n\nvoid print(TermColor C = TermColor.Gray, T...)(T t)\n{\n debug stderr.write(C.termStr, t, TermColor.Default.termStr);\n}\nvoid printf(TermColor C = TermColor.Gray, T...)(T t)\n{\n debug stderr.write(C.termStr);\n debug stderr.writef(t);\n debug stderr.write(TermColor.Default.termStr);\n}\nvoid println(TermColor C = TermColor.Gray, T...)(T t)\n{\n debug stderr.writeln(C.termStr, t, TermColor.Default.termStr);\n}\nvoid printfln(TermColor C = TermColor.Gray, T...)(T t)\n{\n debug stderr.write(C.termStr);\n debug stderr.writefln(t);\n debug stderr.write(TermColor.Default.termStr);\n}\n\n// debug{\n// void write(T...)(T t)\n// {\n// stdout.write(TermColor.Blue.termStr, t, TermColor.Default.termStr);\n// }\n// void writeln(T...)(T t)\n// {\n// stdout.writeln(TermColor.Blue.termStr, t, TermColor.Default.termStr);\n// }\n// void writefln(T...)(T t)\n// {\n// stdout.writefln(TermColor.Blue.termStr, t, TermColor.Default.termStr);\n// }\n// }\n\nT[] scanArray(T = long)()\n{\n return readln.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}\nT scanElem(T = long)()\n{\n char[] res;\n int c = ' ';\n while (isWhite(c) && c != -1)\n {\n c = getchar;\n }\n while (!isWhite(c) && c != -1)\n {\n res ~= cast(char) c;\n c = getchar;\n }\n return res.strip.to!T;\n}\n\nalias scanString = scanElem!string;\n\ntemplate fold(fun...) if (fun.length >= 1)\n{\n auto fold(R, S...)(R r, S seed)\n {\n static if (S.length < 2)\n {\n return reduce!fun(seed, r);\n }\n else\n {\n import std.typecons : tuple;\n\n return reduce!fun(tuple(seed), r);\n }\n }\n}\n\nstruct Factor\n{\n long n;\n long c;\n}\n\n//素因数分解\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//約数をすべて列挙\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までの素数のリスト\nlong[] primes(size_t n) pure\n{\n if(n<2)return [];\n auto table = new long[n+1];\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= 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 a = RDA;\n\t\ta.sort();\n\t\tlong x, y, z;\n\t\tx = a[0];\n\t\ty = a[1];\n\t\tz = a[2];\n\n\t\tlong d = y - x;\n\t\tlong x2 = min(z, d);\n\t\tx += x2;\n\t\tz -= x2;\n\t\tx += z / 2;\n\t\tans[i] = x;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "module main;\n\nimport std.stdio;\n\nvoid main(string[] args){\n long n, input, sum;\n scanf(\"%lld\", &n);\n while (n--) {\n sum = 0;\n for (int i = 0; i < 3; i++ ) {\n scanf(\"%lld\", &input);\n sum += input;\n }\n printf(\"%lld\\n\", sum / 2);\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\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 a = RDA;\n\t\ta.sort();\n\t\tauto b = abs(a[0] - a[1]);\n\t\tauto c = abs(a[1] - a[2]);\n\t\tlong x, y, z;\n\t\tif (b < c)\n\t\t{\n\t\t\tx = a[0];\n\t\t\ty = a[1];\n\t\t\tz = a[2];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tx = a[1];\n\t\t\ty = a[2];\n\t\t\tz = a[0];\n\t\t}\n\t\tauto d = y - x;\n\t\tauto x2 = min(z, d);\n\t\tx += x2;\n\t\tz -= x2;\n\t\tx += z / 2;\n\t\tans[i] = x;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "d9e4a9a32d60e75f3cf959ef7f894fc6"} {"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.map !(q{a == '1'}).array;\n\t\tauto n = s.length.to !(int);\n\t\tauto total = s.sum;\n\t\tauto cur = 0;\n\t\tsize_t res = n;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tres = min (res, cur + (n - i) - (total - cur));\n\t\t\tres = min (res, i - cur + (total - cur));\n\t\t\tcur += s[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) { 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\tans[ti] = long.max;\n\t\tforeach (i; 0..s.length)\n\t\t{\n\t\t\tlong cnt1;\n\t\t\tforeach (j; 0..i)\n\t\t\t{\n\t\t\t\tif (s[j] == '0')\n\t\t\t\t\t++cnt1;\n\t\t\t}\n\t\t\tlong cnt2;\n\t\t\tforeach (j; i..s.length)\n\t\t\t{\n\t\t\t\tif (s[j] == '0')\n\t\t\t\t\t++cnt2;\n\t\t\t}\n\t\t\tdebug writeln(cnt1, \":\", cnt2);\n\t\t\tans[ti].chmin(min(cnt1, i-cnt1) + min(cnt2, s.length-i-cnt2));\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": "803e5ccae683b91a4cc486fbc558b330"} {"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 k = next!int;\n auto adj = new int[][](n, n);\n foreach(ref row; adj) row[] = 1;\n foreach(permutation; 0 .. k)\n {\n auto currentPermutation = next!int(n);\n currentPermutation[] -= 1;\n foreach(i; 0 .. n)\n\t{\n\t auto ci = currentPermutation[i];\n\t foreach(j; i .. n)\n\t {\n\t auto cj = currentPermutation[j];\n\t adj[ci][cj] &= 1;\n\t adj[cj][ci] &= 0;\n\t }\n\t}\n }\n int longestSequenceFrom(int v)\n {\n int longestContinuation = 0;\n foreach(w; 0 .. n)\n if (adj[v][w])\n\t{\n\t longestContinuation =\n\t max(longestContinuation,\n\t\tmemoize!longestSequenceFrom(w));\n\t}\n return 1 + longestContinuation;\n }\n iota(0, n).map!(memoize!longestSequenceFrom).fold!max.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, std.string;\nimport std.algorithm;\n\nint saiki(int num, int k, int[] dp, int[][] pos)\n{\n if (dp[num] != -1)\n {\n return dp[num];\n }\n auto n = cast(int)dp.length - 1;\n dp[num] = 0;\n auto p = new int[k];\n foreach (i; 0 .. k)\n {\n p[i] = pos[i][num];\n }\n foreach (i; 1 .. n + 1)\n {\n if (i != num)\n {\n int j;\n for (j = 0; j < k; ++ j)\n {\n if (pos[j][i] < pos[j][num])\n {\n break;\n }\n }\n if (j == k)\n {\n auto ret = saiki(i, k, dp, pos);\n dp[num] = max(dp[num], ret + 1);\n }\n }\n }\n return dp[num];\n}\n\nvoid solve(int[][] p)\n{\n auto k = cast(int)p.length;\n auto n = cast(int)p[0].length;\n auto pos = new int[][](k, n + 1);\n foreach (i; 0 .. k)\n {\n pos[i][0] = -1;\n foreach (j; 0 .. n)\n {\n pos[i][p[i][j]] = j;\n }\n }\n auto dp = new int[n + 1];\n fill(dp, -1);\n auto ans = saiki(0, k, dp, pos);\n writeln(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[][](k, n);\n foreach (i; 0 .. k)\n {\n foreach (j; 0 .. n)\n {\n readf(\" %d\", &p[i][j]);\n }\n readln();\n }\n solve(p);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint saiki(int num, int k, int[] dp, int[][] pos)\n{\n if (dp[num] != -1)\n {\n return dp[num];\n }\n auto n = cast(int)dp.length - 1;\n dp[num] = 0;\n foreach (i; 1 .. n + 1)\n {\n if (i != num)\n {\n int j;\n for (j = 0; j < k; ++ j)\n {\n if (pos[j][i] < pos[j][num])\n {\n break;\n }\n }\n if (j == k)\n {\n auto ret = saiki(i, k, dp, pos);\n dp[num] = max(dp[num], ret + 1);\n }\n }\n }\n return dp[num];\n}\n\nvoid solve(int[][] p)\n{\n auto k = cast(int)p.length;\n auto n = cast(int)p[0].length;\n auto pos = new int[][](k, n + 1);\n foreach (i; 0 .. k)\n {\n pos[i][0] = -1;\n foreach (j; 0 .. n)\n {\n pos[i][p[i][j]] = j;\n }\n }\n auto dp = new int[n + 1];\n fill(dp, -1);\n auto ans = saiki(0, k, dp, pos);\n writeln(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[][](k, n);\n foreach (i; 0 .. k)\n {\n foreach (j; 0 .. n)\n {\n readf(\" %d\", &p[i][j]);\n }\n readln();\n }\n solve(p);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint saiki(int num, int n, int k, int[] dp, int[][] pos)\n{\n if (dp[num] != -1)\n {\n return dp[num];\n }\n dp[num] = 0;\n foreach (i; 1 .. n + 1)\n {\n if (i != num)\n {\n int j;\n for (j = 0; j < k; ++ j)\n {\n if (pos[j][i] < pos[j][num])\n {\n break;\n }\n }\n if (j == k)\n {\n auto ret = saiki(i, n, k, dp, pos);\n dp[num] = max(dp[num], ret + 1);\n }\n }\n }\n return dp[num];\n}\n\nvoid solve(int[][] p)\n{\n auto k = cast(int)p.length;\n auto n = cast(int)p[0].length;\n auto pos = new int[][](k, n + 1);\n foreach (i; 0 .. k)\n {\n pos[i][0] = -1;\n foreach (j; 0 .. n)\n {\n pos[i][p[i][j]] = j;\n }\n }\n auto dp = new int[n + 1];\n fill(dp, -1);\n auto ans = saiki(0, n, k, dp, pos);\n writeln(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[][](k, n);\n foreach (i; 0 .. k)\n {\n foreach (j; 0 .. n)\n {\n readf(\" %d\", &p[i][j]);\n }\n readln();\n }\n solve(p);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "de87bb6ffd3c703d8845d4dd301bdbf5"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nll dist(ll x, ll y){\n return x*x + y*y;\n}\n\n\n// Main Logic Here\nvoid play(){\n ll d, k;\n d = rd; k = rd;\n ll up = 0;\n ll down = 0;\n bool side = 0;\n while(1){\n ll dis1 = dist(up+k, down);\n ll dis2 = dist(up, down+k);\n if(dis1 < dis2){\n up += k;\n }else{\n down += k;\n }\n if(min(dis1, dis2) > d*d){\n if(side){\n writeln(\"Ashish\");\n return;\n }else{\n writeln(\"Utkarsh\");\n return;\n }\n }\n side = !side;\n }\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.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\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 bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto d = RD;\n\t\tauto k = RD;\n\t\t\n\t\tbool f(long x)\n\t\t{\n\t\t\treturn ((x*k)^^2)*2 <= d^^2;\n\t\t}\n\t\tauto r = binarySearch!(f)(0, d/k+1);\n\t\tdebug writeln(\"r:\", r);\n\t\tif (r == 0)\n\t\t\tans[ti] = true;\n\t\telse if ((r*k)^^2 + ((r+1)*k)^^2 <= d^^2)\n\t\t{\n\t\t\tans[ti] = true;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"Ashish\" : \"Utkarsh\");\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "d4d41e75c68ce5e94c92e1b9876891bf"} {"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 ok = (n % 2 == 0);\r\n\t\tif (ok)\r\n\t\t{\r\n\t\t\tsort (a);\r\n\t\t\tint [] c;\r\n\t\t\tforeach (i; 0..n / 2)\r\n\t\t\t{\r\n\t\t\t\tc ~= a[i];\r\n\t\t\t\tc ~= a[i + $ / 2];\r\n\t\t\t}\r\n\t\t\ta = c;\r\n\t\t\tauto b = a.cycle;\r\n\t\t\tok &= n.iota.all !(i =>\r\n\t\t\t (b[i] < b[i + 1] && b[i + 1] > b[i + 2]) ||\r\n\t\t\t (b[i] > b[i + 1] && b[i + 1] < b[i + 2]));\r\n\t\t}\r\n\t\tif (ok)\r\n\t\t{\r\n\t\t\twriteln (\"YES\");\r\n\t\t\twritefln !(\"%(%s %)\") (a);\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.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 int[] ans;\n if (N % 2 == 0) {\n foreach (i; 0 .. N / 2) {\n ans ~= A[i];\n ans ~= A[i + N / 2];\n }\n debug {\n writeln(ans);\n }\n bool ok = true;\n foreach (i; 0 .. N) {\n const a0 = ans[i];\n const a1 = ans[(i + 1 == N) ? 0 : (i + 1)];\n ok = ok && ((i % 2 == 0) ? (a0 < a1) : (a0 > a1));\n }\n if (!ok) {\n ans = null;\n }\n }\n \n if (ans) {\n writeln(\"YES\");\n foreach (i; 0 .. N) {\n if (i) write(\" \");\n write(ans[i]);\n }\n writeln;\n } else {\n writeln(\"NO\");\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "a30c5562d3df99291132fac20e05e708"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 s = RD!string;\n\n\t\tlong cnt0, cnt1;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == '0')\n\t\t\t\t++cnt0;\n\t\t\telse\n\t\t\t\t++cnt1;\n\t\t}\n\n\t\tans[ti] = min(cnt0, cnt1) % 2 == 1;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e ? \"DA\" : \"NET\");\n\t}\n\tstdout.flush;\n\tdebug readln;\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\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\t\tauto balance = abs (s.count ('0').to !(int) -\n\t\t s.count ('1').to !(int));\n\t\tauto moves = (s.length - balance) / 2;\n\t\twriteln ((moves & 1) ? \"DA\" : \"NET\");\n\t}\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\tauto s = readln.strip;\n\t\tauto balance = abs (s.count ('0') - s.count ('1'));\n\t\tauto moves = (s.length - balance) / 2;\n\t\twriteln ((moves & 1) ? \"DA\" : \"NET\");\n\t}\n}\n"}], "src_uid": "046900001c7326fc8d890a22fa7267c9"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1401/problem/C\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 long[] b;\n b ~= a;\n\n b.sort;\n\n long m = b[0];\n\n bool flag = true;\n for(int i = 0; i < n; i++)\n if(a[i] != b[i] && a[i]%m != 0)\n flag = false;\n\n if(flag)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n }\n\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\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 m = a.minElement;\n\t\tauto p = a.filter !(x => x % m == 0).array;\n\t\tsort (p);\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tif (c % m == 0)\n\t\t\t{\n\t\t\t\tc = p.front;\n\t\t\t\tp.popFront ();\n\t\t\t}\n\t\t}\n\t\twriteln (a.isSorted ? \"YES\" : \"NO\");\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 = RDA;\n\t\tlong x = long.max;\n\t\tforeach (i; 0..n)\n\t\t\tx.chmin(a[i]);\n\n\t\tlong[] arr0, arr1;\n\t\tauto zero = new bool[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] % x)\n\t\t\t{\n\t\t\t\tarr1 ~= a[i];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tarr0 ~= a[i];\n\t\t\t\tzero[i] = true;\n\t\t\t}\n\t\t}\n\t\tarr0.sort();\n\t\tlong last;\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlong y;\n\t\t\tif (zero[i])\n\t\t\t{\n\t\t\t\ty = arr0.front; arr0.popFront;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ty = arr1.front; arr1.popFront;\n\t\t\t}\n\t\t\tif (y < last)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlast = y;\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}\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[] arr = new int[n];\n foreach (ref i; arr) i = cin.readInt;\n bool flag = false;\n if (isSorted(arr)) writeln(\"YES\");\n else {\n int[] arr2 = arr.dup;\n sort(arr);\n for (int i = 0; i < n; i++) {\n if (arr[i] != arr2[i]) {\n if (gcd(arr[i], arr2[i]) && arr2[i] % arr[0] != 0) {\n flag = true;\n break;\n }\n }\n }\n if (flag) writeln(\"NO\");\n else writeln(\"YES\");\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 ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tlong x = long.max;\n\t\tforeach (i; 0..n)\n\t\t\tx.chmin(a[i]);\n\n\t\tlong[] arr;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] % x)\n\t\t\t{\n\t\t\t\tarr ~= a[i];\n\t\t\t}\n\t\t}\n\t\tif (arr.empty)\n\t\t{\n\t\t\tans[ti] = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (i; 0..arr.length-1)\n\t\t{\n\t\t\tif (arr[i+1] < arr[i])\n\t\t\t{\n\t\t\t\tok = false;\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}\n"}], "src_uid": "f2070c2bd7bdbf0919aef1e915a21a24"} {"source_code": "import std.stdio, std.range, std.string, std.conv, std.algorithm;\n\nvoid main() {\n int n, k;\n readf(\"%d %d\\n\", &n, &k);\n\n int[][] ktable = new int[][](n, n);\n\n int p = 1;\n foreach (i; 0..n) {\n foreach (j; 0..(k - 1)) {\n ktable[i][j] = p;\n p++;\n }\n }\n\n int answer = 0;\n foreach (i; 0..n) {\n foreach (j; (k - 1)..n) {\n ktable[i][j] = p;\n if (j == (k - 1)) {\n answer += p;\n }\n p++;\n }\n }\n\n answer.writeln;\n foreach (row; ktable)\n row.map!(to!string).join(\" \").writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.typecons;\nimport std.algorithm;\nvoid main(){\n auto nk = readln.chomp.split.map!(to!int);\n int n = nk[0];\n int k = nk[1];\n\n int l = 1;\n int r = n*n - n*(n-k+1) + 1;\n\n int sum = 0;\n for(int x = r; x <= n*n; x += n-k+1){\n sum += x;\n }\n\n writeln(sum);\n\n foreach(x; 0..n){\n foreach(i; 0..(k-1)){\n write(l);\n l++;\n write(\" \");\n }\n foreach(i; k..(n+1)){\n write(r);\n r++;\n if(i!=n)write(\" \");\n }\n writeln();\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.typecons;\nimport std.algorithm;\nvoid main(){\n auto nk = readln.chomp.split.map!(to!int);\n int n = nk[0];\n int k = nk[1];\n\n int l = 1;\n int r = n*n - n*(n-k+1) + 1;\n\n int sum = 0;\n for(int x = r; x < n*n; x += n-k+1){\n sum += x;\n }\n\n writeln(sum);\n\n foreach(x; 0..n){\n foreach(i; 0..(k-1)){\n write(l);\n l++;\n write(\" \");\n }\n foreach(i; k..(n+1)){\n write(r);\n r++;\n if(i!=n)write(\" \");\n }\n writeln();\n }\n}"}], "src_uid": "272f66f3c71c4997c5a1f0f009c9b99e"} {"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\n\nll getcnt(ll x, ll[] cnts){\n ll mod = to!ll(cnts.length) - 1;\n ll tim = (x / mod) * cnts[inz(mod)];\n tim += cnts[inz(x % mod)];\n return tim;\n}\n\nvoid play(){\n ll a, b;\n a = rd!int; b = rd!int;\n int q = rd!int;\n int lcmab = a * b / gcd(a, b);\n auto tills = new ll[](lcmab+1);\n ll cnt = 0;\n foreach(i; 1..lcmab+1){\n if((i % a) % b != (i % b) % a){\n ++cnt;\n }\n tills[i] = cnt;\n }\n foreach(i; 0..q){\n ll x, y;\n x = rd; y = rd;\n ll cntx = getcnt(x-1, tills);\n ll cnty = getcnt(y, tills);\n write(cnty - cntx, \" \");\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", "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 a, b, q;\n\t\treadf !(\" %s %s %s\") (a, b, q);\n\t\tauto total = a * b;\n\t\tint [] s;\n\t\ts ~= 0;\n\t\tforeach (i; 1..total + 1)\n\t\t{\n\t\t\ts ~= s.back + ((i % a) % b != (i % b) % a);\n\t\t}\n\n\t\tlong go (long limit)\n\t\t{\n\t\t\treturn limit / total * s[total] +\n\t\t\t s[cast (int) (limit % total)];\n\t\t}\n\n\t\tlong [] answer;\n\t\tforeach (w; 0..q)\n\t\t{\n\t\t\tlong l, r;\n\t\t\treadf !(\" %s %s\") (l, r);\n\t\t\tanswer ~= go (r) - go (l - 1);\n\t\t}\n\t\twritefln !(\"%(%s %)\") (answer);\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 int a = r.next!int;\n const int b = r.next!int;\n const int q = r.next!int;\n const int m = a * b;\n auto x = new int[m];\n foreach (i; 0 .. m) {\n if (((i % a) % b) != ((i % b) % a)) x[i] = 1;\n }\n auto y = x.cumulativeFold!\"a+b\".array;\n int s = y.back;\n long cntLess (long t) {\n long u1 = t / m;\n int u2 = (t % m).to!int;\n long res = u1 * s;\n if (u2 > 0) res += y[u2-1];\n return res;\n }\n auto res = new long[q];\n foreach (qid; 0 .. q) {\n long L = r.next!long;\n long R = r.next!long;\n res[qid] = cntLess (R + 1) - cntLess (L);\n }\n writefln!(\"%(%s %)\")(res);\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 abq = readln.split.to!(int[]);\n long A = abq[0];\n long B = abq[1];\n if (A > B) swap(A, B);\n\n long solve(long n) {\n if (n < B) return n;\n\n auto lcm = A * B / gcd(A, B);\n long r = min(n, B-1) + (n / lcm - 1) * B;\n auto m = n / lcm * lcm;\n r += min(m + B, n+1) - m;\n return r;\n }\n\n auto Q = abq[2];\n long[] res;\n foreach (_q; 0..Q) {\n auto lr = readln.split.to!(long[]);\n auto l = lr[0];\n auto r = lr[1];\n res ~= r - l + 1 - solve(r) + solve(l-1);\n }\n writeln(res.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 abq = readln.split.to!(int[]);\n long A = abq[0];\n long B = abq[1];\n if (A > B) swap(A, B);\n\n long solve(long n) {\n if (n <= B) return n;\n\n auto lcm = A * B / gcd(A, B);\n long r = min(n, B-1) + (n / lcm - 1) * B;\n auto m = n / lcm * lcm;\n r += min(m + B, n) - m;\n return r;\n }\n\n auto Q = abq[2];\n long[] res;\n foreach (_q; 0..Q) {\n auto lr = readln.split.to!(long[]);\n auto l = lr[0];\n auto r = lr[1];\n res ~= r - l + 1 - solve(r) + solve(l-1);\n }\n writeln(res.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 abq = readln.split.to!(int[]);\n long A = abq[0];\n long B = abq[1];\n if (A > B) swap(A, B);\n\n long solve(long n) {\n if (n <= B) return n+1;\n\n auto lcm = A * B / gcd(A, B);\n long r = min(n, B) + (n / lcm - 1) * B;\n auto m = n / lcm * lcm;\n r += min(m + B, n+1) - m;\n return r;\n }\n\n auto Q = abq[2];\n long[] res;\n foreach (_q; 0..Q) {\n auto lr = readln.split.to!(long[]);\n auto l = lr[0];\n auto r = lr[1];\n res ~= r - l + 1 - solve(r) + solve(l-1);\n }\n writeln(res.to!(string[]).join(\" \"));\n }\n}"}], "src_uid": "a1effd6a0f6392f46f6aa487158fef7d"} {"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\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\n\tstring ans;\n\tint i = 0, j = n - 1;\n\tlong x = -1;\n\twhile(i <= j){\n\t\tif(as[i] < as[j]){\n\t\t\tif(x < as[i]) x = as[i], ans ~= \"L\", i += 1;\n\t\t\telse if(x < as[j]) x = as[j], ans ~= \"R\", j -= 1;\n\t\t\telse break;\n\t\t}\n\t\telse if(as[j] < as[i]){\n\t\t\tif(x < as[j]) x = as[j], ans ~= \"R\", j -= 1;\n\t\t\telse if(x < as[i]) x = as[i], ans ~= \"L\", i += 1;\n\t\t\telse break;\n\t\t}\n\t\telse{\n\t\t\tif(x >= as[i]) break;\n\t\t\tint c1 = i;\n\t\t\twhile(c1 < j && as[c1] < as[c1 + 1]) c1 += 1;\n\t\t\tint c2 = j;\n\t\t\twhile(i < c2 && as[c2] < as[c2 - 1]) c2 -= 1;\n\t\t\tif(c1 - i < j - c2) x = as[j], ans ~= \"R\", j -= 1;\n\t\t\telse x = as[i], ans ~= \"L\", i += 1;\n\t\t}\n\t}\n\t\n\tans.length.writeln;\n\tans.writeln;\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;\n readf(\"%s\", &n);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n void gole(int p, int lm, int lst, ref dchar[] ans) {\n while (p <= lm && a[p] > lst) {\n ans ~= 'L';\n lst = a[p];\n ++p;\n }\n \n debug { writeln(ans.length); }\n }\n void gor(int p, int lm, int lst, ref dchar[] ans) {\n while (p >= lm && a[p] > lst) {\n ans ~= 'R';\n lst = a[p];\n --p;\n }\n \n debug { writeln(ans.length); }\n }\n int lst = 0;\n int le = 0, r = n-1;\n dchar[] ans;\n while (le <= r) {\n int leok = lst < a[le];\n int rok = lst < a[r];\n if (!leok && !rok) {\n break;\n }\n if (!leok) {\n gor(r, le, lst, ans);\n break;\n }\n if (!rok) {\n gole(le, r, lst, ans);\n break;\n }\n \n if (a[le] < a[r]) {\n ans ~= 'L';\n lst = a[le];\n ++le;\n } else if (a[r] < a[le]) {\n ans ~= 'R';\n lst = a[r];\n --r;\n } else {\n dchar[] ansle;\n dchar[] ansr;\n gole(le, r, lst, ansle);\n gor(r, le, lst, ansr);\n \n if (ansle.length > ansr.length) { ans ~= ansle; }\n else { ans ~= ansr; }\n break;\n }\n }\n \n ans.length.writeln;\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;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto p = a.length - a.findAdjacent !(q{a >= b}).length;\n\t\tauto q = a.length - a.retro.findAdjacent !(q{a >= b}).length;\n\t\tauto lo = a.take (min (p + 1, n)).array;\n\t\tauto hi = a.retro.take (min (q + 1, n)).array;\n\t\tdebug {writeln (lo, \" \", hi);}\n\n\t\tstring res;\n\t\twhile (true)\n\t\t{\n\t\t\tif (lo.empty)\n\t\t\t{\n\t\t\t\tres ~= 'R'.repeat (hi.length).text;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (hi.empty)\n\t\t\t{\n\t\t\t\tres ~= 'L'.repeat (lo.length).text;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (lo.front < hi.front)\n\t\t\t{\n\t\t\t\tres ~= 'L';\n\t\t\t\tlo.popFront ();\n\t\t\t}\n\t\t\telse if (lo.front > hi.front)\n\t\t\t{\n\t\t\t\tres ~= 'R';\n\t\t\t\thi.popFront ();\n\t\t\t}\n\t\t\telse if (lo.length < hi.length)\n\t\t\t{\n\t\t\t\tres ~= 'R'.repeat (hi.length).text;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres ~= 'L'.repeat (lo.length).text;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tres.length = min (res.length, n);\n\t\twriteln (res.length);\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.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;\n\n\tauto cnt_l = new long[](N+1);\n\t{\n\t\tlong last;\n\t\tforeach_reverse (i; 0..N)\n\t\t{\n\t\t\tif (a[i] < last)\n\t\t\t\tcnt_l[i] = cnt_l[i+1] + 1;\n\n\t\t\tlast = a[i];\n\t\t}\n\t}\n\tauto cnt_r = new long[](N+1);\n\t{\n\t\tlong last;\n\t\tforeach (i; 0..N)\n\t\t{\n\t\t\tif (a[i] < last)\n\t\t\t\tcnt_r[i+1] = cnt_r[i] + 1;\n\n\t\t\tlast = a[i];\n\t\t}\n\t}\n\n\tdebug writeln(cnt_l);\n\tdebug writeln(cnt_r);\n\n\tstring ans;\n\tlong last;\n\tuint l, r = cast(uint)(a.length);\n\n\tvoid popL()\n\t{\n\t\tlast = a.front;\n\t\ta.popFront;\n\t\tans ~= \"L\";\n\t\t++l;\n\t}\n\tvoid popR()\n\t{\n\t\tlast = a.back;\n\t\ta.popBack;\n\t\tans ~= \"R\";\n\t\t--r;\n\t}\n\n\twhile (!a.empty)\n\t{\n\t\tif (a.front > last && a.front == a.back)\n\t\t{\n\t\t\tdebug writeln(cnt_l[l], \" \", cnt_r[r]);\n\t\t\tif (cnt_l[l] >= cnt_r[r])\n\t\t\t{\n\t\t\t\tpopL();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpopR;\n\t\t\t}\n\t\t}\n\t\telse if (a.front > last && a.front < a.back)\n\t\t{\n\t\t\tpopL();\n\t\t}\n\t\telse if (a.back > last && a.back < a.front)\n\t\t{\n\t\t\tpopR();\n\t\t}\n\t\telse if (a.front > last)\n\t\t{\n\t\t\tpopL();\n\t\t}\n\t\telse if (a.back > last)\n\t\t{\n\t\t\tpopR();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\twriteln(ans.length);\n\twriteln(ans);\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; }\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 a = RDR.ARR;\n\n\tstring ans;\n\tlong last;\n\twhile (!a.empty)\n\t{\n\t\tif (a.front > last && a.front == a.back)\n\t\t{\n\t\t\tuint l, r = cast(uint)(a.length - 1);\n\t\t\twhile (abs(l - r) >= 0)\n\t\t\t{\n\t\t\t\tif (abs(l - r) <= 1)\n\t\t\t\t{\n\t\t\t\t\tif (a[l] <= a[r])\n\t\t\t\t\t{\n\t\t\t\t\t\tlast = a.front;\n\t\t\t\t\t\ta.popFront;\n\t\t\t\t\t\tans ~= \"L\";\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{\n\t\t\t\t\t\tlast = a.back;\n\t\t\t\t\t\ta.popBack;\n\t\t\t\t\t\tans ~= \"R\";\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (a[l] == a[r])\n\t\t\t\t{\n\t\t\t\t\t++l;\n\t\t\t\t\t--r;\n\t\t\t\t}\n\t\t\t\telse if (a[l] <= a[r])\n\t\t\t\t{\n\t\t\t\t\tlast = a.front;\n\t\t\t\t\ta.popFront;\n\t\t\t\t\tans ~= \"L\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlast = a.back;\n\t\t\t\t\ta.popBack;\n\t\t\t\t\tans ~= \"R\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (a.front > last && a.front < a.back)\n\t\t{\n\t\t\tlast = a.front;\n\t\t\ta.popFront;\n\t\t\tans ~= \"L\";\n\t\t}\n\t\telse if (a.back > last && a.back < a.front)\n\t\t{\n\t\t\tlast = a.back;\n\t\t\ta.popBack;\n\t\t\tans ~= \"R\";\n\t\t}\n\t\telse if (a.front > last)\n\t\t{\n\t\t\tlast = a.front;\n\t\t\ta.popFront;\n\t\t\tans ~= \"L\";\n\t\t}\n\t\telse if (a.back > last)\n\t\t{\n\t\t\tlast = a.back;\n\t\t\ta.popBack;\n\t\t\tans ~= \"R\";\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\twriteln(ans.length);\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "1ae1e051b6c8240eb27c64ae05c342cf"} {"source_code": "import std.stdio;\n\nvoid main() {\n auto pline = new ulong[](2*100_000); \n \n \n long n, t, c;\n \n readf(\"%s %s %s\\n\", &n, &t, &c);\n \n for(int i; i < n; ++i) {\n readf(\"%s \", &pline[i]);\n }\n \n int acc;\n \n auto tline = new long[](1);\n tline[0] = 0;\n \n for(int i; i < n; ++i) {\n if(pline[i] > t)\n tline ~= i + 1;\n //writeln(tline[$ - 1]);\n }\n tline ~= n + 1;\n\n for( int i = 1; i < tline.length; ++i ) {\n if( tline[i] - tline[i - 1] - 1 >= c ) {\n acc += (tline[i] - tline[i - 1]) - c;\n }\n }\n \n writeln(acc);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.algorithm;\nimport std.range;\n\nint n, c, t;\n\nvoid main() {\n scanf(\"%d%d%d\\n\", &n, &t, &c);\n auto a = readln.split.map!(to!int).array;\n size_t p = 0;\n int r = 0;\n foreach (i, v; a) {\n if (v > t) {\n p = i + 1;\n }\n if (i - p + 1 >= c) {\n r++;\n }\n }\n writeln(r);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n\tauto pline = new ulong[](2*100_000);\t\n\t\n\t\n\tlong n, t, c;\n\t\n\treadf(\"%s %s %s\\n\", &n, &t, &c);\n\t\n\tfor(int i; i < n; ++i) {\n\t\treadf(\"%s \", &pline[i]);\n\t}\n\t\n\tint acc;\n\t\n\tauto tline = new ulong[](1);\n\ttline[0] = 0;\n\t\n\tfor(int i; i < n; ++i) {\n\t\tif(pline[i] > t)\n\t\t\ttline ~= i;\n\t}\n\ttline ~= n + 1;\n\t//writeln(\"last n: \", tline[$ - 1]);\n\tfor( int i = 1; i < tline.length; ++i ) {\n\t\tif( tline[i] - tline[i - 1] - 1 >= c ) {\n\t\t\t//writeln(acc);\n\t\t\tacc += (tline[i] - tline[i - 1]) - c;\n\t\t}\n\t}\n\t\n\twriteln(acc);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "import std.stdio;\n\nvoid main() {\n auto pline = new ulong[](2*100_000); \n \n \n long n, t, c;\n \n readf(\"%s %s %s\\n\", &n, &t, &c);\n \n for(int i; i < n; ++i) {\n readf(\"%s \", &pline[i]);\n }\n \n int acc;\n \n auto tline = new long[](1);\n tline[0] = 0;\n \n for(int i; i < n; ++i) {\n if(pline[i] > t)\n tline ~= i;\n }\n tline ~= n + 1;\n\n for( int i = 1; i < tline.length; ++i ) {\n if( tline[i] - tline[i - 1] - 1 >= c ) {\n acc += (tline[i] - tline[i - 1]) - c;\n }\n }\n \n writeln(acc);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "7d1e8769a6b1d5c6680ab530d19e7fa4"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan;\n auto arr = scanArray;\n long summ = 0;\n for(int i = 0; i < n; ++i){\n summ += arr[i];\n }\n long asum = 2*summ;\n if(asum % n != 0 || asum % (n + 1) != 0){\n writeln(\"NO\");\n return;\n }\n asum /= n;\n asum /= (n+1);\n long[] res;\n for(int i = 0; i < n; ++i){\n int previ = (i - 1 + n.to!int) % n.to!int;\n long diff = arr[i] - arr[previ];\n long nai = asum - diff;\n if(nai % n != 0 || nai <= 0){\n writeln(\"NO\");\n return;\n }\n long ai = nai / n.to!long;\n res ~= ai;\n }\n writeln(\"YES\");\n assert(res.length == n);\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, 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.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 B = readarray!long;\r\n\r\n auto A = new long[N];\r\n bool f() {\r\n auto sB = B.reduce!\"a + b\";\r\n long Z = N * (N + 1L) / 2L;\r\n if (sB % Z > 0) {\r\n return false;\r\n }\r\n long sA = sB / Z;\r\n for (int k = 0; k < N; k++) {\r\n int pk = (k + N - 1) % N;\r\n long na = (sA - B[k] + B[pk]);\r\n if (na % N > 0) return false;\r\n if (na <= 0) return false;\r\n A[k] = na / N;\r\n }\r\n return true;\r\n }\r\n auto pos = f();\r\n writeln(pos ? \"YES\" : \"NO\");\r\n if (pos) {\r\n writefln(\"%(%s %)\", A);\r\n }\r\n}\r\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto b = ma(n, readInt!long);\n if (n == 1) { writeln(\"YES\"); writeln(b[0]); return; }\n auto dlt = new long[](n);\n dlt[0] = b[0] - b[n-1];\n foreach(i; 1 .. n)\n dlt[i] = b[i] - b[i-1];\n debug writeln(\"dlt \", dlt);\n long[] aDlt = new long[](n);\n foreach(i; 0 .. n)\n {\n aDlt[i] = -dlt[i] + dlt[0];\n if (aDlt[i]%n != 0) return writeln(\"NO\");\n aDlt[i] /= n;\n }\n debug writeln(\"aDlt \", aDlt);\n long wsum = 0;\n foreach(i; 0 .. n)\n {\n long fact = n - i + 1;\n wsum += fact * aDlt[i];\n }\n long rhs = b[0] - wsum;\n long lhsFact = cast(long)n * (cast(long)n + 1) / 2L;\n if (rhs <= 0) return writeln(\"NO\");\n if (rhs % lhsFact != 0) return writeln(\"NO\");\n rhs /= lhsFact;\n \n aDlt[] += rhs;\n if (aDlt.fold!min <= 0) return writeln(\"NO\");\n \n writeln(\"YES\");\n foreach(d; aDlt)\n {\n write(d, \" \");\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"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan;\n auto arr = scanArray;\n long summ = 0;\n for(int i = 0; i < n; ++i){\n summ += arr[i];\n }\n long asum = 2*summ;\n asum /= n;\n asum /= (n+1);\n long[] res;\n for(int i = 0; i < n; ++i){\n int previ = (i - 1 + n.to!int) % n.to!int;\n long diff = arr[i] - arr[previ];\n long nai = asum - diff;\n if(nai % n != 0 || nai <= 0){\n writeln(\"NO\");\n return;\n }\n long ai = nai / n.to!long;\n res ~= ai;\n }\n writeln(\"YES\");\n assert(res.length == n);\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, 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 solve(){\n auto n = scan!int;\n auto arr = scanArray;\n long summ = arr.sum;\n long asum = 2*summ;\n asum /= n.to!long;\n asum /= (n+1).to!long;\n long[] res;\n for(int i = 0; i < n; ++i){\n long diff = arr[i] - arr[(i - 1 + n) % n];\n long nai = asum - diff;\n if(nai % n != 0 || nai < n){\n writeln(\"NO\");\n return;\n }\n long ai = nai / n.to!long;\n assert(ai <= 1_000_000_000);\n res ~= ai;\n }\n assert(asum == res.sum);\n if(asum != res.sum){\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\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, 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 solve(){\n auto n = scan!int;\n auto arr = scanArray;\n long summ = arr.sum;\n long asum = 2*summ;\n asum /= n;\n asum /= (n+1);\n long[] res;\n for(int i = 0; i < n; ++i){\n long diff = arr[i] - arr[(i - 1 + n) % n];\n long nai = asum - diff;\n if(nai % n != 0 || nai < n){\n writeln(\"NO\");\n return;\n }\n res ~= nai / n;\n }\n writeln(\"YES\");\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, 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 solve(){\n auto n = scan!int;\n auto arr = scanArray;\n long summ = arr.sum;\n long asum = (2*summ) /(n * (n + 1));\n long[] res;\n for(int i = 0; i < n; ++i){\n long diff = arr[i] - arr[(i - 1 + n) % n];\n long nai = asum - diff;\n if(nai % n != 0 || nai < n){\n writeln(\"NO\");\n return;\n }\n res ~= nai / n;\n }\n writeln(\"YES\");\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, 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"}], "src_uid": "21fed74be8462143d77bbbee48dc8a12"} {"source_code": "import std.stdio, std.conv, std.algorithm, std.range, std.math, std.string;\n\nvoid main() {\n\tstring number = stdin.readln().stripRight;\n\tauto n = to!int(number[max(2, $)-2..$]) % 4;\n\twriteln(sum(iota(1, 5).map!(i => i ^^ n)) % 5);\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\nstring S;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tS = readToken;\n\t\t\n\t\tconst n = S[max(cast(int)($) - 2, 0) .. $].to!int % 4;\n\t\tint ans;\n\t\tforeach (a; 1 .. 5) {\n\t\t\tint tmp = 1;\n\t\t\tforeach (_; 0 .. n) {\n\t\t\t\ttmp *= a;\n\t\t\t}\n\t\t\tans += tmp;\n\t\t}\n\t\tans %= 5;\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "static immutable MOD = 4;\nstatic immutable MOD_OVERAL = 5;\nstatic immutable MODS = [\n\t[1, 1, 1, 1],\n\t[1, 2, 4, 3],\n\t[1, 3, 4, 2],\n\t[1, 4, 1, 4]\n];\n\nuint solve(const string n) {\n\tuint sum = 0;\n\tforeach (ch; n) {\n\t\tif (ch < '0' || ch > '9') {break;}\n\t\tsum = ( (sum * 10) + (ch - '0') ) % MOD;\n\t}\n\n\tsum %= MOD;\n\tuint res = 0;\n\tforeach (curMod; MODS) {\n\t\tres += curMod[sum];\n\t}\n\n\treturn res % MOD_OVERAL;\n}\n\nunittest {\n\tassert(4 == solve(\"4\"));\n\tassert(0 == solve(\"124356983594583453458888889\"));\n\tassert(4 == solve(\"0\"));\n\tassert(0 == solve(\"5\"));\n\tassert(0 == solve(\"6\"));\n\tassert(0 == solve(\"7\"));\n\tassert(4 == solve(\"8\"));\n}\n\nint main(string[] argv) {\n\timport std.stdio;\n\twriteln(solve(readln));\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nunittest{\n assert(solve(\"124356983594583453458888889\") == 0, \"Test 1\");\n assert(solve(\"0\") == 4, \"Test 3\");\n assert(solve(\"4\") == 4, \"Test 2\");\n}\n\nint solve(string ns){\n int k;\n if(ns.length == 1){\n if (ns[0] == '0'){\n return 4;\n } else{\n k = (ns[0] - 48) % 4;\n }\n } else {\n k = ((ns[$-1] - 48)+(ns[$-2] - 48)*10) % 4;\n }\n\n int[] n2 = [1,2,4,3];\n int[] n3 = [1,3,4,2];\n int[] n4 = [1,4,1,4];\n\n //writeln(k);\n return (1 + n2[k] + n3[k] + n4[k]) % 5;\n}\n\nvoid main(){\n string s;\n readf(\"%s\\n\",&s);\n //writeln(\"!\",s);\n writeln(solve(s));\n}\n"}], "negative_code": [], "src_uid": "74cbcbafbffc363137a02697952a8539"} {"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 n = readln().chomp.to!int;\r\n \r\n auto tasks = readln().chomp;\r\n bool[] count = new bool[26];\r\n int i = 0;\r\n \r\n while(i < tasks.length)\r\n {\r\n if(count[tasks[i]-'A'])\r\n {\r\n writeln(\"NO\");\r\n continue OUTER; \r\n }\r\n \r\n char cur = tasks[i];\r\n count[tasks[i]-'A'] = true;\r\n while(i < tasks.length -1 && tasks[i+1] == cur) i++;\r\n i++;\r\n }\r\n \r\n writeln(\"YES\");\r\n }\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1520/problem/A\n// implementation, 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 string s;\n readf(\"%s\\n\", &s);\n char[] u;\n char last = 'a';\n foreach(ch; s) {\n if(ch != last) {\n last = ch;\n u ~= ch;\n }\n }\n bool suspicious = false;\n int[] seen = new int[27];\n foreach(ch; u) {\n if(seen[ch - 65] == 1) {\n suspicious = true;\n break;\n }\n seen[ch - 65] = 1;\n }\n if(suspicious)\n \"NO\".writeln;\n else\n \"YES\".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\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 s = RD!string;\r\n\r\n\t\tstring s2 = [s[0]];\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tif (s[i] == s[i-1]) continue;\r\n\t\t\ts2 ~= s[i];\r\n\t\t}\r\n\r\n\t\tbool ok = true;\r\n\t\tbool[char] used;\r\n\t\tforeach (c; s2)\r\n\t\t{\r\n\t\t\tif (used.get(c, false))\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\tused[c] = true;\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}"}], "negative_code": [], "src_uid": "3851854541b4bd168f5cb1e8492ed8ef"} {"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\tlong l, r, m;\n\t\treadf !(\" %s %s %s\") (l, r, m);\n\t\tauto d = r - l;\n\t\tforeach (a; l..r + 1)\n\t\t{\n\t\t\tauto start = max (m - d, 1);\n\t\t\tstart = (start + a - 1) / a * a;\n\t\t\tfor (auto s = start; s <= m + d; s += a)\n\t\t\t{\n\t\t\t\tauto n = s / a;\n\t\t\t\tlong b, c;\n\t\t\t\tif (s < m)\n\t\t\t\t{\n\t\t\t\t\tb = r;\n\t\t\t\t\tc = b + s - m;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tb = l;\n\t\t\t\t\tc = b + s - m;\n\t\t\t\t}\n\t\t\t\twriteln (a, \" \", b, \" \", c);\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\t}\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 size_t t;\n read(t);\n testCase:foreach(tc; 0 .. t)\n {\n long l, r, m;\n read(l), read(r), read(m);\n foreach(ca; l .. r + 1)\n {\n long a = cast(long) ca;\n long b, c;\n long nm = m % a < (a - m % a)? (m - m % a) : (m - m % a + a);\n if (nm == 0)\n nm = a;\n long rem = m - nm;\n if (rem > r - l || rem < l - r) continue;\n long n = nm / a;\n if (rem >= 0)\n c = l;\n else\n c = r;\n b = c + rem;\n assert(a * n + b - c == m);\n assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);\n writeln(a, \" \", b, \" \", c);\n continue testCase;\n }\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\tauto tests = readln.strip.to !(int);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tlong l, r, m;\n\t\treadf !(\" %s %s %s\") (l, r, m);\n\t\tauto d = r - l;\n\t\tforeach (a; l..r + 1)\n\t\t{\n\t\t\tauto start = max (m - d, 1);\n\t\t\tstart = (start + a - 1) / a * a;\n\t\t\tfor (auto s = start; s <= m + d; s += a)\n\t\t\t{\n\t\t\t\tauto n = s / a;\n\t\t\t\tlong b, c;\n\t\t\t\tif (s < 0)\n\t\t\t\t{\n\t\t\t\t\tc = r;\n\t\t\t\t\tb = c + s - m;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tb = l;\n\t\t\t\t\tc = b + s - m;\n\t\t\t\t}\n\t\t\t\twriteln (a, \" \", b, \" \", c);\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"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 size_t t;\n read(t);\n testCase:foreach(tc; 0 .. t)\n {\n long l, r, m;\n read(l), read(r), read(m);\n if (m <= r)\n {\n if (l <= m)\n {\n long a = m;\n long b = l;\n long c = l;\n assert(a * 1 + b - c == m);\n assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);\n writeln(a, \" \", b, \" \", c);\n continue testCase;\n }\n long a = l;\n long c = r;\n long b = m - a + c;\n assert(a * 1 + b - c == m);\n assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);\n writeln(a, \" \", b, \" \", c);\n continue testCase;\n }\n long a = r;\n long n = m / a;\n long bmc = m - a * n;\n assert(bmc <= r - l);\n long c = l;\n long b = c + bmc;\n assert(a * n + b - c == m);\n assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);\n writeln(a, \" \", b, \" \", c);\n }\n}\n"}, {"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 size_t t;\n read(t);\n testCase:foreach(tc; 0 .. t)\n {\n long l, r, m;\n read(l), read(r), read(m);\n foreach(ca; l .. r + 1)\n {\n long a = cast(long) ca;\n long b, c;\n long nm = m % a < (a - m % a)? (m - m % a) : (m - m % a + a);\n long rem = m - nm;\n if (rem > r - l || rem < l - r) continue;\n long n = nm / a;\n if (rem >= 0)\n c = l;\n else\n c = r;\n b = c + rem;\n assert(a * n + b - c == m);\n assert(l <= a && a <= r && l <= b && b <= r && l <= c && c <= r);\n writeln(a, \" \", b, \" \", c);\n continue testCase;\n }\n }\n}\n"}], "src_uid": "39d8677b310bee8747c5112af95f0e33"} {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\"); \n\n char[12][200000] buf;\n bool[const(char)[12]] set;\n int n;\n readf(\" %s\\n\", &n);\n char[] pbuf;\n foreach(i; 0 .. n) {\n readln(pbuf);\n buf[i][0 .. pbuf.length] = pbuf[];\n }\n\n foreach_reverse(i; 0 .. n) {\n if (cast(const)buf[i] !in set) {\n foreach (c; buf[i]) {\n if (c == 255) break;\n write(c);\n }\n set[cast(const)buf[i]] = true;\n }\n }\n\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nstruct Deque(T) {\nprivate:\n size_t size = 0, capacity = 1;\n int frontmark = 0, backmark = 0;\n T[] store = [T.init];\n void resize() {\n store.length *= 3;\n foreach(i; 0 .. capacity) {\n advance(frontmark);\n store[i + capacity] = store[frontmark];\n }\n frontmark = capacity - 1;\n backmark = 2 * capacity;\n capacity *= 3;\n }\n void advance(ref int mark) {\n ++mark;\n if (mark >= capacity) mark = 0;\n }\n void retreat(ref int mark) {\n --mark;\n if (mark < 0) mark = capacity - 1;\n }\npublic:\n string toString() {\n import std.conv : to;\n string result = \"[ \" ~ to!string(store[0]);\n foreach(i; 1 .. capacity) {\n result ~= \", \";\n result ~= to!string(store[i]);\n }\n result ~= \" ]\";\n return result;\n }\n @property bool empty() {\n return (size == 0);\n }\n @property T back() {\n if (empty()) return T.init;\n retreat(backmark);\n immutable savedmark = backmark;\n advance(backmark);\n return store[savedmark];\n }\n void popBack() {\n if (!empty()) {\n retreat(backmark);\n --size;\n }\n }\n void pushBack(T item) {\n if (size == capacity) resize();\n store[backmark] = item;\n advance(backmark);\n ++size;\n }\n @property T front() {\n if (empty()) return T.init;\n advance(frontmark);\n immutable savedmark = frontmark;\n retreat(frontmark);\n return store[savedmark];\n }\n void popFront() {\n if (!empty()) {\n advance(frontmark);\n --size;\n }\n }\n void pushFront(T item) {\n if (size == capacity) resize();\n store[frontmark] = item;\n retreat(frontmark);\n ++size;\n }\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n Deque!(string) stack;\n bool[string] set;\n char[15][200000] buf = void;\n int n;\n readf(\" %s\\n\", &n);\n foreach(i; 0 .. n) {\n char[] pbuf = buf[i];\n readln(pbuf);\n stack.pushBack(cast(string)pbuf);\n }\n while (!stack.empty) {\n string str = stack.back;\n stack.popBack();\n if (!(str in set)) {\n write(str);\n set[str] = true;\n }\n }\n\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\"); \n\n char[12][200000] buf;\n bool[string] set;\n int n;\n readf(\" %s\\n\", &n);\n char[] pbuf;\n foreach(i; 0 .. n) {\n readln(pbuf);\n buf[i][0 .. pbuf.length] = pbuf[];\n }\n foreach_reverse(i; 0 .. n) {\n string str = to!string(buf[i]);\n while (str[$ - 1] == 255) str.length -= 1;\n if (str !in set) {\n write(str);\n set[str] = true;\n }\n }\n\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nstruct Deque(T) {\nprivate:\n size_t size = 0, capacity = 1;\n int frontmark = 0, backmark = 0;\n T[] store = [T.init];\n void resize() {\n store.length *= 3;\n foreach(i; 0 .. capacity) {\n advance(frontmark);\n store[i + capacity] = store[frontmark];\n }\n frontmark = capacity - 1;\n backmark = 2 * capacity;\n capacity *= 3;\n }\n void advance(ref int mark) {\n ++mark;\n if (mark >= capacity) mark = 0;\n }\n void retreat(ref int mark) {\n --mark;\n if (mark < 0) mark = capacity - 1;\n }\npublic:\n string toString() {\n import std.conv : to;\n string result = \"[ \" ~ to!string(store[0]);\n foreach(i; 1 .. capacity) {\n result ~= \", \";\n result ~= to!string(store[i]);\n }\n result ~= \" ]\";\n return result;\n }\n @property bool empty() {\n return (size == 0);\n }\n @property T back() {\n if (empty()) return T.init;\n retreat(backmark);\n immutable savedmark = backmark;\n advance(backmark);\n return store[savedmark];\n }\n void popBack() {\n if (!empty()) {\n retreat(backmark);\n --size;\n }\n }\n void pushBack(T item) {\n if (size == capacity) resize();\n store[backmark] = item;\n advance(backmark);\n ++size;\n }\n @property T front() {\n if (empty()) return T.init;\n advance(frontmark);\n immutable savedmark = frontmark;\n retreat(frontmark);\n return store[savedmark];\n }\n void popFront() {\n if (!empty()) {\n advance(frontmark);\n --size;\n }\n }\n void pushFront(T item) {\n if (size == capacity) resize();\n store[frontmark] = item;\n retreat(frontmark);\n ++size;\n }\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n \n Deque!string stack;\n bool[string] set;\n int n;\n readf(\" %s\", &n);\n foreach(i; 0 .. n) {\n string str;\n readf(\" %s\\n\", &str);\n stack.pushBack(str);\n }\n while (!stack.empty()) {\n string str = stack.back;\n stack.popBack();\n if (!(str in set)) {\n writeln(str);\n set[str] = true;\n }\n }\n\n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.sorting;\nimport std.range.primitives;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\"); \n\n string[] stack;\n bool[string] set;\n int n;\n readf(\" %s\", &n);\n foreach(i; 0 .. n) {\n string str;\n readf(\" %s\\n\", &str);\n stack ~= str;\n }\n while (!stack.empty) {\n string str = stack.back;\n stack.popBack();\n if (str !in set) {\n writeln(str);\n set[str] = true;\n }\n }\n\n return 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\"); \n\n char[15][200000] buf = void;\n bool[string] set;\n int n;\n readf(\" %s\\n\", &n);\n foreach(i; 0 .. n) {\n char[] pbuf;\n readln(pbuf);\n buf[i][0 .. pbuf.length] = pbuf[];\n }\n foreach_reverse(i; 0 .. n) {\n string str = to!string(buf[i]);\n while (str[$ - 1] == 0) str.length -= 1;\n if (str !in set) {\n write(str);\n set[str] = true;\n }\n }\n\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\"); \n\n char[15][200000] buf = void;\n bool[string] set;\n int n;\n readf(\" %s\\n\", &n);\n foreach(i; 0 .. n) {\n char[] pbuf = buf[i];\n readln(pbuf);\n }\n foreach_reverse(i; 0 .. n) {\n string str = cast(string)buf[i];\n while (str[$ - 1] == 0) str.length -= 1;\n if (str !in set) {\n write(str);\n set[str] = true;\n }\n }\n\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\"); \n\n char[15][200000] buf = void;\n bool[string] set;\n int n;\n readf(\" %s\\n\", &n);\n foreach(i; 0 .. n) {\n char[] pbuf = buf[i];\n readln(pbuf);\n }\n foreach_reverse(i; 0 .. n) {\n string str = cast(string)fromStringz(cast(char*)buf[i]);\n if (str !in set) {\n write(str);\n set[str] = true;\n }\n }\n\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\"); \n\n char[15][200000] buf = void;\n bool[string] set;\n int n;\n readf(\" %s\\n\", &n);\n foreach(i; 0 .. n) {\n char[] pbuf;\n readln(pbuf);\n buf[i][0 .. pbuf.length] = pbuf[];\n }\n foreach_reverse(i; 0 .. n) {\n string str = cast(string)buf[i];\n while (str[$ - 1] == 0) str.length -= 1;\n if (str !in set) {\n write(str);\n set[str] = true;\n }\n }\n\n return 0;\n}\n"}], "src_uid": "18f4d9262150294b63d99803250ed49c"} {"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 foreach (i; 0 .. N) {\n ans += (A[i] - 1);\n }\n writeln((ans % 2 != 0) ? \"errorgorn\" : \"maomao90\");\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\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 ([\"maomao90\", \"errorgorn\"][(a.sum - n) % 2]);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "fc75935b149cf9f4f2ddb9e2ac01d1c2"} {"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 n = RD!int;\n\t\tauto s = RD!string;\n\t\tlong cnt1, cnt2;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (s[j] == '1')\n\t\t\t\tbreak;\n\t\t\t++cnt1;\n\t\t}\n\t\tforeach_reverse (j; 0..n)\n\t\t{\n\t\t\tif (s[j] == '1')\n\t\t\t\tbreak;\n\t\t\t++cnt2;\n\t\t}\n\t\tif (cnt1 == n)\n\t\t\tans[i] = n;\n\t\telse\n\t\t\tans[i] = n*2 - min(cnt1, cnt2)*2;\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.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;\nalias ln = long;\n\n\nln maxsum(string str)\n{\n size_t i = 0;\n ln res = 0;\n while(i < str.length && str[i] == '0')\n {\n i++;\n res++;\n }\n if (i >= str.length)\n {\n return res;\n }\n assert(str[i] == '1');\n res += 2;\n res += max(i, maxsum(str[i + 1 .. $]));\n return res;\n}\n\nint main()\n{\n ln t; readf!\" %s \"(t);\n while(t--)\n {\n import std.conv; \n string strn = readln();\n strn = strn[0 .. $ - 1];\n ln n = to!ln(strn);\n string str = readln();\n str = str[0 .. $ - 1];\n ln maxi = -1;\n ln lowi = n + 1;\n foreach(i, c; str)\n\t{\n\t if ( c == '1' )\n\t {\n\t maxi = i;\n\t lowi = min(lowi, i);\n\t }\n\t}\n \n import std.algorithm: reverse;\n w(max(maxsum(str), maxsum(reverse(dup(str))), 2 * (maxi + 1), 2 * (n - lowi)));\n }\n return 0;\n}\n"}], "negative_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;\nalias ln = long;\n\n\nln maxsum(string str)\n{\n size_t i = 0;\n ln res = 0;\n while(i < str.length && str[i] == '0')\n {\n i++;\n res++;\n }\n if (i >= str.length)\n {\n return res;\n }\n assert(str[i] == '1');\n res += 2;\n res += max(i, maxsum(str[i + 1 .. $]));\n return res;\n}\n\nint main()\n{\n ln t; readf!\" %s \"(t);\n while(t--)\n {\n import std.conv; \n string strn = readln();\n strn = strn[0 .. $ - 1];\n ln n = to!ln(strn);\n string str = readln();\n str = str[0 .. $ - 1];\n w(maxsum(str));\n }\n return 0;\n}\n"}], "src_uid": "23575500451a061ed498468f3814c38a"} {"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, std.string;\n// import dkh.foundation, dkh.scanner, dkh.container.deque;\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 string l, r;\n while (s.length) {\n if (s.length == 1) {\n l ~= s;\n break;\n }\n if (s.front == s.back) {\n l ~= s.front;\n r ~= s.back;\n s = s[1..$-1];\n continue;\n }\n if (s[1] == s.back) {\n s = s[1..$];\n continue;\n }\n if (s.front == s[$-1]) {\n s = s[0..$-1];\n continue;\n }\n s = s[1..$-1];\n continue;\n }\n writeln(l ~ r.dup.reverse);\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/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 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 auto s = readln.chomp;\n if (s.length < 4) {\n writeln(s[0]);\n return;\n }\n \n dchar[] ans;\n foreach (i; (s.length/2 - 1).iota.stride(2)) {\n dchar c = 'a';\n while ((s[i] != c && s[i+1] != c) \n || (s[s.length - 1 - i] != c && s[s.length - 1 - i - 1] != c)) { \n c += 1; \n } \n ans ~= c;\n }\n \n auto tail = ans.dup;\n tail.reverse();\n \n if (s.length % 4 != 0) { ans ~= s[s.length/2]; }\n \n ans = ans.chain(tail).array;\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.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\nstring S;\nint N;\n\nvoid main() {\n try {\n for (; ; ) {\n S = readToken();\n N = cast(int)(S.length);\n \n char[] ansL, ansM;\n for (int l = 0, r = N; l < r; ) {\n if (l + 4 <= r) {\n bool found;\n foreach (d; \"abc\") {\n if ((S[l] == d || S[l + 1] == d) && (S[r - 2] == d || S[r - 1] == d)) {\n found = true;\n ansL ~= d;\n break;\n }\n }\n assert(found);\n l += 2;\n r -= 2;\n } else {\n ansM ~= S[l];\n break;\n }\n }\n write(ansL.to!string);\n write(ansM.to!string);\n ansL.reverse;\n write(ansL.to!string);\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"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, std.string;\n// import dkh.foundation, dkh.scanner, dkh.container.deque;\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 string l, r;\n while (s.length) {\n if (s.length == 1) {\n l ~= s;\n break;\n }\n if (s.front == s.back) {\n l ~= s.front;\n r ~= s.back;\n s = s[1..$-1];\n continue;\n }\n if (s[1] == s.back) {\n s = s[1..$];\n continue;\n }\n if (s.front == s[$-1]) {\n s = s[0..$-1];\n continue;\n }\n s = s[1..$-1];\n continue;\n }\n r.dup.reverse;\n writeln(l ~ r);\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/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\nstring S;\nint N;\n\nvoid main() {\n try {\n for (; ; ) {\n S = readToken();\n N = cast(int)(S.length);\n \n string ans;\n foreach (d; \"abc\") {\n string t;\n foreach (e; S) {\n if (e != d) {\n t ~= e;\n }\n }\n t = t.uniq.array.to!string;\n if (!t.empty) {\n if (t.length % 2 == 0) {\n t = t[0 .. $ - 1];\n }\n if (ans.length < t.length) {\n ans = t;\n }\n }\n }\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.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\nstring S;\nint N;\n\nvoid main() {\n try {\n for (; ; ) {\n S = readToken();\n N = cast(int)(S.length);\n \n char[] ansL, ansM;\n for (int l = 0, r = N; l <= r; ) {\n if (l + 4 <= r) {\n bool found;\n foreach (d; \"abc\") {\n if ((S[l] == d || S[l + 1] == d) && (S[r - 2] == d || S[r - 1] == d)) {\n found = true;\n ansL ~= d;\n break;\n }\n }\nif(!found)writeln(l,\" \",r);\n assert(found);\n l += 2;\n r -= 2;\n } else {\n ansM ~= S[l];\n break;\n }\n }\n write(ansL.to!string);\n write(ansM.to!string);\n ansL.reverse;\n write(ansL.to!string);\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "3bebb50d1c2ef9f80e78715614f039d7"} {"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\nconst KB = 1024;\nconst MB = 1024 * 1024;\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 ss = next!string(n);\n int[char] cnt;\n foreach(s; ss)\n foreach(c; s)\n cnt.require(c, 0)++;\n if (cnt.byValue.all!(c => c % n == 0))\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\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 = MB;\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 .. $]))[](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.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 T = read!int;\n\n foreach (t; 0..T)\n {\n\tint n = read!int;\n\treadln;\n\tint[char] inc;\n\t//string[] arr;\n\tforeach (i; 0..n)\n\t{\n\t auto s = readln.strip;\n\t foreach (c; s)\n\t {\n\t\tint *p = c in inc;\n\t\tif (p !is null)\n\t\t inc[c]++;\n\t\telse\n\t\t inc[c] = 1;\n\t }\n\t}\n\n\tbool success = true;\n\tforeach (i, k; inc)\n\t{\n\t if (k % n != 0)\n\t {\n\t\tsuccess = false;\n\t\twriteln(\"NO\");\n\t\tbreak;\n\t }\n\t}\n\tif (success)\n\t writeln(\"YES\");\n\t//writeln (inc);\n }\n\n return 0;\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1397/problem/A\n// simulation, math\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[char] counter;\n\n long n = readln.chomp.to!long;\n string[] s;\n foreach(_; 0..n)\n s ~= readln.strip;\n foreach(str; s) {\n foreach(ch; str) {\n if(ch in counter)\n counter[ch] += 1;\n else\n counter[ch] = 1;\n }\n }\n\n string ans = \"YES\";\n foreach(value; counter.values) {\n if(value%n != 0) {\n ans = \"NO\";\n break;\n }\n }\n ans.writeln;\n }\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\tauto n = readln.strip.to !(int);\n\t\tint [char] d;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (char c; readln.strip)\n\t\t\t{\n\t\t\t\td[c] += 1;\n\t\t\t}\n\t\t}\n\t\twriteln (d.byValue.all !(x => x % n == 0) ? \"YES\" : \"NO\");\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\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 ss = next!string(n);\n int[char] cnt;\n foreach(s; ss)\n foreach(c; s)\n cnt.require(c, 0)++;\n if (cnt.byValue.all!(c => c % n == 0))\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\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 = 4096;\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 .. $]))[](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 bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto cnt = new long[](26);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto s = RD!string;\n\t\t\tforeach (c; s)\n\t\t\t{\n\t\t\t\tauto num = c - 'a';\n\t\t\t\t++cnt[num];\n\t\t\t}\n\t\t}\n\n\t\tans[ti] = true;\n\t\tforeach (i; 0..26)\n\t\t{\n\t\t\tif (cnt[i] % n)\n\t\t\t{\n\t\t\t\tans[ti] = false;\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}\n"}], "negative_code": [], "src_uid": "3d6cd0a82513bc2119c9af3d1243846f"} {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint[] sieveArray (int n) {\n auto a = iota (0, n + 1).map! (i => (i & 1) ? i : 2).array;\n for (int p = 3; p * p <= n; p += 2) {\n if (a[p] == p) {\n foreach (o; iota (p * p, n + 1, 2 * p)) {\n if (a[o] == o) {\n a[o] = p;\n }\n }\n }\n }\n return a;\n}\n\nvoid main() {\n int n;\n readf (\" %d\", &n);\n auto s = sieveArray (n);\n int[int] h = [ 2 : 1 ];\n int idx = 1;\n foreach (i; iota (3, n + 1, 2)) {\n if (s[i] == i) {\n h[i] = ++idx;\n }\n }\n foreach (i; 2 .. n + 1) {\n s[i] = h[s[i]];\n } \n writefln (\"%(%s %)\", s[2 .. $]);\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 N = readln.chomp.to!int;\n auto ans = new int[](N+1);\n\n int tmp = 1;\n foreach (i; 2..N+1) {\n if (ans[i] != 0) continue;\n for (int j = i; j <= N; j += i) {\n ans[j] = tmp;\n }\n tmp += 1;\n }\n\n ans[2..$].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.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 ans = new int[] (n+1);\n int cnt = 1;\n for (int i = 2; i <= n; ++i) {\n bool made = false;\n for (int j = i; j <= n; j += i) {\n if (ans[j] == 0) {\n ans[j] = cnt;\n made = true;\n }\n }\n \n if (made) { cnt += 1; }\n }\n \n ans[2 .. n+1].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;\nimport std.bitmanip;\n\nclass PrimeTable {\n private:\n BitArray a;\n size_t n;\n public:\n bool isPrime (size_t i) const pure nothrow @nogc {\n return (i & 1) ? !a[i>>>1] : (i == 2);\n }\n int[] primes () const pure {\n int[] p;\n if (n > 2) {\n p ~= 2;\n p ~= (~a).bitsSet.map! (i => (2 * i + 1).to!int).array;\n }\n return p;\n }\n this (size_t _n) pure {\n n = _n;\n auto m = n >> 1;\n a.length = max (1, m);\n a[0] = true;\n foreach (i; 1 .. ceil((sqrt (n.to!(double)) - 1.0)).to!(size_t)) {\n if (!a[i]) {\n immutable k = (i << 1) + 1;\n for (size_t j = 2 * i * (i + 1); j < m; j += k) {\n a[j] = true;\n }\n }\n }\n }\n}\n\nvoid main() {\n int n;\n readf (\" %d\", &n);\n auto pt = new PrimeTable (n + 16);\n auto a = new int[n+1];\n int[] q;\n foreach (i; 2 .. n + 1) {\n if (pt.isPrime(i)) {\n q ~= i;\n a[i] = q.length.to!int; \n } else {\n foreach (k, j; q) {\n if ((i % j) == 0) {\n a[i] = k.to!int + 1;\n break;\n }\n }\n }\n }\n writefln (\"%(%s %)\", a[2 .. $]);\n}\n\n"}, {"source_code": "import std.typecons;\nimport core.stdc.stdio;\nimport std.stdio;\nimport std.algorithm;\nimport std.range;\n\nalias PII = Tuple!(int, int);\nalias PLL = Tuple!(long, long);\n\nvoid main()\n{\n uint n;\n scanf(\"%d\", &n);\n\n bool[] primes = new bool[n + 1];\n int[] ans = new int[n + 1];\n fill(primes, true);\n\n int c = 0;\n\n foreach (i; 2 .. n + 1)\n if (primes[i])\n {\n c++;\n ans[i] = c;\n for (auto j = i * i; j <= n; j += i)\n {\n primes[j] = false;\n ans[j] = c;\n }\n }\n\n writefln(\"%(%d%| %)\", ans[2 .. n + 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\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 = new long[](N-1);\n\tlong num = 1;\n\tforeach (i; 2..N+1)\n\t{\n\t\tif (A[i-2] != 0) continue;\n\n\t\tfor (int j = i; j <= N; j += i)\n\t\t{\n\t\t\tA[j-2] = num;\n\t\t}\n\t\t++num;\n\t}\n\n\tA.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "aa3c015c20cb0c1789661fdc78ae9bec"} {"source_code": "import core.stdc.math;\nimport core.stdc.stdio;\nimport core.stdc.stdlib;\nimport std.algorithm;\nint n,y=1;\nint[200005] a;\nvoid main()\n{\n\tscanf(\"%d\",&n);\n\tfor (int i=1;i<=n;++i) scanf(\"%d\",&a[i]);\n\tfor (int i=2;i<=n;++i) y=max(y,abs(a[i]-a[i-1]));\n\tfor (int i=2;i<=n;++i)\n\t{\n\t\tif (y!=1 && (a[i-1]+1==a[i] || a[i-1]-1==a[i]))\n\t\t{\n\t\t\tif ((a[i-1]-1)/y!=(a[i]-1)/y)\n\t\t\t{\n\t\t\t\tputs(\"NO\");\n\t\t\t\texit(0);\n\t\t\t}\n\t\t}\n\t\telse if (a[i-1]+y!=a[i] && a[i-1]-y!=a[i])\n\t\t{\n\t\t\tputs(\"NO\");\n\t\t\texit(0);\n\t\t}\n\t}\n\tprintf(\"YES\\n1000000000 %d\\n\",y);\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///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\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///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 a = arread!int;\n\tif (n == 1)\n\t{\n\t\treturn writefln(\"YES\\n%d %d\", 1, a[0]);\n\t}\n\tint d = abs(a[0] - a[1]);\n\tforeach (i; 1 .. n - 1)\n\t{\n\t\tif (d == 1)\n\t\t\td = abs(a[i] - a[i + 1]);\n\t\telse if (abs(a[i] - a[i + 1]) != 1)\n\t\t{\n\t\t\tif (d != abs(a[i] - a[i + 1]))\n\t\t\t\treturn writeln(\"NO\");\n\t\t}\n\t}\n\tif (d == 0)\n\t\treturn writeln(\"NO\");\n\tif (d == 1)\n\t\treturn writefln(\"YES\\n%d %d\", 10 ^^ 9, 10 ^^ 9);\n\tint y = d, x = 10 ^^ 9;\n\tint x0 = (a[0] + d - 1) / d, y0 = a[0] - d * (x0 - 1);\n\tforeach (i; 1 .. n)\n\t{\n\t\tauto t = a[i] - a[i - 1];\n\t\tif (abs(t) > 1)\n\t\t{\n\t\t\tx0 += (t < 0 ? -1 : 1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\ty0 += (t < 0 ? -1 : 1);\n\t\t}\n\t\tif (x0 < 1 || x0 > x || y0 < 1 || y0 > y)\n\t\t\treturn writeln(\"NO\");\n\t}\n\twritefln(\"YES\\n%d %d\", x, y);\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.algorithm;\n\n\nvoid main()\n{\n\treadln;\n\n\tauto arr = readln.strip.splitter.map!(to!int).array;\n\tauto pairs = zip(arr, arr[1..$]);\n\n\tauto y = pairs.map!(a => abs(a[0] - a[1])).filter!(a => a && a != 1).chain([ 1 ]).front;\n\n\tforeach(u, v; pairs)\n\t{\n\t\tauto d = abs(u - v);\n\n\t\tif(d != y && (d != 1 || min(u, v) % y == 0))\n\t\t{\n\t\t\t`NO`.writeln;\n\t\t\treturn;\n\t\t}\n\t}\n\n\twritefln(\"YES\\n%u %u\", 10 ^^ 9, y);\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.algorithm;\n\n\nvoid main()\n{\n\treadln;\n\n\tint x, p, m;\n\n\tforeach(i, n; readln.strip.splitter.map!(to!int).enumerate)\n\t{\n\t\tif(i)\n\t\t{\n\t\t\tauto d = abs(n - p);\n\n\t\t\tif(!d)\n\t\t\t{\n\t\t\t\t`NO`.writeln;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif(d > 1)\n\t\t\t{\n\t\t\t\tif(x)\n\t\t\t\t{\n\t\t\t\t\tif(d != x)\n\t\t\t\t\t{\n\t\t\t\t\t\t`NO`.writeln;\n\t\t\t\t\t\treturn;\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\tx = d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif(m < n)\n\t\t{\n\t\t\tm = n;\n\t\t}\n\n\t\tp = n;\n\t}\n\n\tif(!x)\n\t{\n\t\tx = m;\n\t}\n\n\twritefln(\"YES\\n%u %u\", 1 + m / x, x);\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.algorithm;\n\n\nvoid main()\n{\n\treadln;\n\n\tint x, p, m;\n\n\tforeach(i, n; readln.strip.splitter.map!(to!int).enumerate)\n\t{\n\t\tif(i)\n\t\t{\n\t\t\tauto d = abs(n - p);\n\n\t\t\tif(d > 1)\n\t\t\t{\n\t\t\t\tif(x)\n\t\t\t\t{\n\t\t\t\t\tif(d != x)\n\t\t\t\t\t{\n\t\t\t\t\t\t`NO`.writeln;\n\t\t\t\t\t\treturn;\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\tx = d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif(m < n)\n\t\t{\n\t\t\tm = n;\n\t\t}\n\n\t\tp = n;\n\t}\n\n\twritefln(\"YES\\n%u %u\", m / x, x);\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.algorithm;\n\n\nvoid main()\n{\n\treadln;\n\n\tauto arr = readln.strip.splitter.map!(to!int).array;\n\tauto pairs = zip(arr, arr[1..$]);\n\n\tauto y = pairs.map!(a => abs(a[0] - a[1])).filter!(a => a != 1).chain([ 1 ]).front;\n\n\tforeach(u, v; pairs)\n\t{\n\t\tauto d = abs(u - v);\n\n\t\tif(d != y || d != 1 || min(u, v) % y == 0)\n\t\t{\n\t\t\t`NO`.writeln;\n\t\t\treturn;\n\t\t}\n\t}\n\n\twritefln(\"YES\\n%u %u\", 10 ^^ 9, y);\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///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\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///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 a = arread!int;\n\tif (n == 1)\n\t{\n\t\treturn writefln(\"YES\\n%d %d\", 1, a[0]);\n\t}\n\tint d = abs(a[0] - a[1]);\n\tforeach (i; 1 .. n - 1)\n\t{\n\t\tif (d == 1)\n\t\t\td = abs(a[i] - a[i + 1]);\n\t\telse if (abs(a[i] - a[i + 1]) != 1)\n\t\t{\n\t\t\tif (d != abs(a[i] - a[i + 1]))\n\t\t\t\treturn writeln(\"NO\");\n\t\t}\n\t}\n\tif (d == 0)\n\t\treturn writeln(\"NO\");\n\tif (d == 1)\n\t\treturn writefln(\"YES\\n%d %d\", 10 ^^ 9, 10 ^^ 9);\n\tint y = d, x = 10 ^^ 9;\n\tint x0 = (a[0] + d - 1) / d, y0 = a[0] - d * (x0 - 1);\n\tforeach (i; 1 .. n)\n\t{\n\t\tauto t = a[i] - a[i - 1];\n\t\tif (abs(t) > 1)\n\t\t{\n\t\t\tx0 += (t < 0 ? -1 : 1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\ty0 += (t < 0 ? -1 : 1);\n\t\t}\n\t\tif (x0 < 1 || x0 > x || y0 < 1 || y0 > y)\n\t\t\treturn writeln(\"NO\");\n\t}\n\twritefln(\"YES\\n%d %d\", y, x);\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///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\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///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 a = arread!int;\n\tif (n == 1)\n\t{\n\t\treturn writefln(\"YES\\n%d %d\", 1, a[0]);\n\t}\n\tint d = abs(a[0] - a[1]);\n\tforeach (i; 1 .. n - 1)\n\t{\n\t\tif (d == 1)\n\t\t\td = abs(a[i] - a[i + 1]);\n\t\telse if (abs(a[i] - a[i + 1]) != 1)\n\t\t{\n\t\t\tif (d != abs(a[i] - a[i + 1]))\n\t\t\t\treturn writeln(\"NO\");\n\t\t}\n\t}\n\tif (d == 0)\n\t\treturn writeln(\"NO\");\n\tif (d == 1)\n\t\treturn writefln(\"YES\\n%d %d\", 10 ^^ 9, 10 ^^ 9);\n\tint x = d, y = 10 ^^ 9;\n\tint x0 = (a[0] + d - 1) / d, y0 = a[0] - d * (x0 - 1);\n\tforeach (i; 1 .. n)\n\t{\n\t\tauto t = a[i] - a[i - 1];\n\t\tif (abs(t) > 1)\n\t\t{\n\t\t\ty0 += (t < 0 ? -1 : 1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tx0 += (t < 0 ? -1 : 1);\n\t\t}\n\t\tif (x0 < 1 || x0 > x || y0 < 1 || y0 > y)\n\t\t\treturn writeln(\"No\");\n\t}\n\twritefln(\"YES\\n%d %d\", y, x);\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///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\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///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 a = arread!int;\n\tif (n == 1)\n\t{\n\t\treturn writefln(\"YES\\n%d %d\", 1, a[0]);\n\t}\n\tint d = abs(a[0] - a[1]);\n\tforeach (i; 1 .. n - 1)\n\t{\n\t\tif (d == 1)\n\t\t\td = abs(a[i] - a[i + 1]);\n\t\telse if (abs(a[i] - a[i + 1]) != 1)\n\t\t{\n\t\t\tif (d != abs(a[i] - a[i + 1]))\n\t\t\t\treturn writeln(\"NO\");\n\t\t}\n\t}\n\tif (d == 0)\n\t\treturn writeln(\"NO\");\n\tif (d == 1)\n\t\treturn writefln(\"YES\\n%d %d\", 10 ^^ 9, 10 ^^ 9);\n\tint x = d, y = 10 ^^ 9;\n\tint x0 = (a[0] + d - 1) / d, y0 = a[0] - d * (x0 - 1);\n\tforeach (i; 1 .. n)\n\t{\n\t\tauto t = a[i] - a[i - 1];\n\t\tif (abs(t) > 1)\n\t\t{\n\t\t\ty0 += (t < 0 ? -1 : 1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tx0 += (t < 0 ? -1 : 1);\n\t\t}\n\t\tif (x0 < 1 || x0 > x || y0 < 1 || y0 > y)\n\t\t\treturn writeln(\"NO\");\n\t}\n\twritefln(\"YES\\n%d %d\", y, x);\n}\n"}], "src_uid": "3b725f11009768904514d87e2c7714ee"} {"source_code": "module _38a;\n\nimport std.algorithm, std.conv, std.stdio, std.array;\n\nint main()\n{\n\tauto n = 0;\n\treadf!\"%d\"(n);\n\treadln();\n\tauto d = new int[n-1];\n\tfor (auto i = 0; i < (n-1); i++) {\n\t\tscanf(\"%d\", &d[i]);\n\t}\n\treadln();\n\n\tauto from_lv =0 , to_lv=0;\n\treadf!\"%d %d\"(from_lv, to_lv);\n\treadln();\n\n\tauto spent_years = 0;\n\tfor (auto i = from_lv; i < to_lv; i++) {\n\t\tspent_years += d[i-1];\n\t}\n\n\twritefln(\"%d\", spent_years);\n return 0;\n}\n", "positive_code": [{"source_code": "import std.c.stdio;\n\nvoid main() {\n int n; scanf(\"%d\", &n);\n int[] d = new int[n];\n int a, b;\n for (int i = 0; i < n - 1; i++) {\n scanf(\"%d\", &d[i]);\n }\n scanf(\"%d %d\", &a, &b);\n int x = 0;\n for (int i = a; i < b; i++) {\n x += d[i - 1];\n }\n printf(\"%d\\n\", x);\n}\n"}, {"source_code": "import std.stdio;\n\nvoid assert_solve(int r,int[] ds, int a, int b){\n int sol = solve(ds,a,b);\n if (sol != r){\n writefln(\"Test %s-(%s,%s): Expected %s, got %s\",ds,a,b,r,sol);\n assert(false);\n }\n}\n\nunittest{\n assert_solve(5,[0,5,6],1,2);\n assert_solve(11,[0,5,6],1,3);\n}\n\nint solve(int[] ds,int a,int b){\n ds[0] = 0;\n for(int i = 1; i < ds.length; i++){\n ds[i] += ds[i-1];\n }\n return ds[b-1] - ds[a-1];\n}\n\nvoid main(){\n int n;\n readf(\"%s\\n\",&n);\n\n int[] ds = new int[n];\n for(int i = 1; i < n; i++){\n readf(\"%s \",ds.ptr+i);\n }\n\n int a,b;\n readf(\"%s %s\\n\",&a,&b);\n\n writeln(solve(ds,a,b));\n}\n"}], "negative_code": [], "src_uid": "69850c2af99d60711bcff5870575e15e"} {"source_code": "import std.algorithm;\nimport std.stdio;\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 s = reduce !(\"a + b\") (0, a);\n\t\tint res;\n\t\tif (s % 2 == 0)\n\t\t{\n\t\t\ts >>= 1;\n\t\t\tint t;\n\t\t\tforeach (i; 0..n - 1)\n\t\t\t{\n\t\t\t\tt += a[i];\n\t\t\t\tif (t == s)\n\t\t\t\t{\n\t\t\t\t\tres++;\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 core.bitop;\nimport std.array;\nimport std.exception;\nimport std.format;\n\n/**\n * On the Web: $(WEB en.wikipedia.org/wiki/Fenwick_tree).\n */\nstruct FenwickTree (T)\n if (is (typeof (T.init + T.init) : T))\n{\n\tprivate T [] table;\n\tprivate int ptwo;\n\n\t@property int length ()\n\t{\n\t\treturn table.length;\n\t}\n\n\tthis (int size)\n\t{\n\t\tenforce (size > 0);\n\t\ttable.length = size;\n\t\tptwo = 1 << bsr (size);\n\t}\n\n\t/**\n\t * Add delta to data[index].\n\t *\n\t * Complexity: $(BIGOH log(n))\n\t */\n\tvoid add (T2 = T) (int index, T2 delta = 1)\n\t{\n\t\tfor ( ; index < length; index |= (index + 1))\n\t\t{\n\t\t\ttable[index] += delta;\n\t\t}\n\t}\n\n\t/**\n\t * Find the sum of data[0..limit].\n\t *\n\t * Complexity: $(BIGOH log(n))\n\t */\n\tT2 sum (T2 = T) (int limit)\n\t{\n\t\tT2 res;\n\t\tfor (limit--; limit >= 0; limit = (limit & (limit + 1)) - 1)\n\t\t{\n\t\t\tres += table[limit];\n\t\t}\n\t\treturn res;\n\t}\n\n\t/**\n\t * Find the sum of data[left..right].\n\t *\n\t * Complexity: $(BIGOH log(n))\n\t */\n\tT2 sum (T2 = T) (int left, int right)\n\t{\n\t\treturn sum !(T2) (right) - sum !(T2) (left);\n\t}\n\n\t/**\n\t * Find leftmost position such that sum of data[0..position] >= bound.\n\t *\n\t * Returns length if no such position can be found.\n\t *\n\t * Complexity: $(BIGOH log(n))\n\t */\n\tint find (T2 = T) (T2 bound)\n\t{\n\t\tT2 csum;\n\t\tint position = 0;\n\t\tfor (int cur = ptwo; cur > 0; cur >>= 1)\n\t\t{\n\t\t\tint npos = position + cur;\n\t\t\tif ((npos <= length) &&\n\t\t\t csum + table[npos - 1] < bound)\n\t\t\t{\n\t\t\t\tposition = npos;\n\t\t\t\tcsum += table[npos - 1];\n\t\t\t}\n\t\t}\n\t\treturn position;\n \t}\n\n\t/**\n\t * Print the contents of table to a string.\n\t *\n\t * Complexity: $(BIGOH (n))\n\t */\n\tstring toString ()\n\t{\n\t\tauto writer = appender !(string) ();\n\t\tforeach (i, c; table)\n\t\t{\n\t\t\tformattedWrite (writer, \"sum[%s..%s] = %s\\n\",\n\t\t\t (i + 1) & i, i + 1, c);\n\t\t}\n\t\treturn writer.data;\n\t}\n}\n\nunittest\n{\n\timmutable int MAX_N = 20;\n\tauto t = FenwickTree !(int) (MAX_N);\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tt.add (i, i);\n\t}\n\tassert (t.sum (MAX_N) == 190);\n\tassert (t.sum !(long) (MAX_N) == 190);\n\tassert (t.find (int.min) == 0);\n\tassert (t.find (54) == 10);\n\tassert (t.find (55) == 10);\n\tassert (t.find (56) == 11);\n\tassert (t.find (long.max) == t.length);\n\tassert (t.sum (10) == 45);\n\tassert (t.sum (10, 20) == 190 - 45);\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tassert (t.sum (i) == t.sum (0, i));\n\t\tassert (t.sum (0, i) + t.sum (i, MAX_N) == 190);\n\t}\n\tassert (t.toString () ==\n\t \"sum[0..1] = 0\\n\" ~\n\t \"sum[0..2] = 1\\n\" ~\n\t \"sum[2..3] = 2\\n\" ~\n\t \"sum[0..4] = 6\\n\" ~\n\t \"sum[4..5] = 4\\n\" ~\n\t \"sum[4..6] = 9\\n\" ~\n\t \"sum[6..7] = 6\\n\" ~\n\t \"sum[0..8] = 28\\n\" ~\n\t \"sum[8..9] = 8\\n\" ~\n\t \"sum[8..10] = 17\\n\" ~\n\t \"sum[10..11] = 10\\n\" ~\n\t \"sum[8..12] = 38\\n\" ~\n\t \"sum[12..13] = 12\\n\" ~\n\t \"sum[12..14] = 25\\n\" ~\n\t \"sum[14..15] = 14\\n\" ~\n\t \"sum[0..16] = 120\\n\" ~\n\t \"sum[16..17] = 16\\n\" ~\n\t \"sum[16..18] = 33\\n\" ~\n\t \"sum[18..19] = 18\\n\" ~\n\t \"sum[16..20] = 70\\n\"\n\t );\n}\n\nimport std.algorithm;\nimport std.stdio;\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 t = FenwickTree !(int) (n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tt.add (i, a[i]);\n\t\t}\n\t\tint res = 0;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (t.sum (0, i) == t.sum (i, n))\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": "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;\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\tconst total = reduce!\"a + b\"(0L, A);\n\t\tlong sum;\n\t\tint ans;\n\t\tforeach (i; 0 .. N - 1) {\n\t\t\tsum += A[i];\n\t\t\tif (sum == total - sum) {\n\t\t\t\t++ans;\n\t\t\t}\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\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 read_string() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int read_int() { \n return read_string.to!int; \n }\n double read_double() { \n return read_string.to!double; \n }\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) i = cin.read_int;\n\n int[] sum_for = new int[n];\n sum_for[0] = arr[0];\n for (int i = 1; i < n; i++) {\n sum_for[i] += arr[i] + sum_for[i - 1];\n }\n\n reverse(arr);\n\n int[] sum_back = new int[n];\n sum_back[0] = arr[0];\n for (int i = 1; i < n; i++) {\n sum_back[i] += arr[i] + sum_back[i - 1];\n }\n\n int count = 0;\n for (int i = 0; i < n - 1; i++) {\n if (sum_for[i] == sum_back[n - 2 - i])\n count++;\n }\n \n writeln(count);\n } \n}"}, {"source_code": "import std.string, std.algorithm, std.conv, std.stdio, std.range;\n\nvoid main()\n{\n readln;\n auto ns = readln.split.map!(to!int);\n auto a = (0~ns.cumulativeFold!\"a+b\".array)[1..$-1];\n auto b = (ns.retro.cumulativeFold!\"a+b\".array.retro.array ~ 0)[1..$-1];\n writeln(a.zip(b).count!\"a[0]==a[1]\");\n}"}, {"source_code": "import std.string, std.algorithm, std.conv, std.stdio, std.range;\n\nvoid main()\n{\n readln;\n auto ns = readln.split.map!(to!int);\n auto a = chain(only(0), ns.cumulativeFold!\"a+b\").array.dropOne.dropBackOne;\n auto b = chain(only(0), ns.retro.cumulativeFold!\"a+b\").array.retro.dropOne.dropBackOne;\n writeln(a.zip(b).count!\"a[0]==a[1]\");\n}"}], "negative_code": [{"source_code": "import core.bitop;\nimport std.array;\nimport std.exception;\nimport std.format;\n\n/**\n * On the Web: $(WEB en.wikipedia.org/wiki/Fenwick_tree).\n */\nstruct FenwickTree (T)\n if (is (typeof (T.init + T.init) : T))\n{\n\tprivate T [] table;\n\tprivate int ptwo;\n\n\t@property int length ()\n\t{\n\t\treturn table.length;\n\t}\n\n\tthis (int size)\n\t{\n\t\tenforce (size > 0);\n\t\ttable.length = size;\n\t\tptwo = 1 << bsr (size);\n\t}\n\n\t/**\n\t * Add delta to data[index].\n\t *\n\t * Complexity: $(BIGOH log(n))\n\t */\n\tvoid add (T2 = T) (int index, T2 delta = 1)\n\t{\n\t\tfor ( ; index < length; index |= (index + 1))\n\t\t{\n\t\t\ttable[index] += delta;\n\t\t}\n\t}\n\n\t/**\n\t * Find the sum of data[0..limit].\n\t *\n\t * Complexity: $(BIGOH log(n))\n\t */\n\tT2 sum (T2 = T) (int limit)\n\t{\n\t\tT2 res;\n\t\tfor (limit--; limit >= 0; limit = (limit & (limit + 1)) - 1)\n\t\t{\n\t\t\tres += table[limit];\n\t\t}\n\t\treturn res;\n\t}\n\n\t/**\n\t * Find the sum of data[left..right].\n\t *\n\t * Complexity: $(BIGOH log(n))\n\t */\n\tT2 sum (T2 = T) (int left, int right)\n\t{\n\t\treturn sum !(T2) (right) - sum !(T2) (left);\n\t}\n\n\t/**\n\t * Find leftmost position such that sum of data[0..position] >= bound.\n\t *\n\t * Returns length if no such position can be found.\n\t *\n\t * Complexity: $(BIGOH log(n))\n\t */\n\tint find (T2 = T) (T2 bound)\n\t{\n\t\tT2 csum;\n\t\tint position = 0;\n\t\tfor (int cur = ptwo; cur > 0; cur >>= 1)\n\t\t{\n\t\t\tint npos = position + cur;\n\t\t\tif ((npos <= length) &&\n\t\t\t csum + table[npos - 1] < bound)\n\t\t\t{\n\t\t\t\tposition = npos;\n\t\t\t\tcsum += table[npos - 1];\n\t\t\t}\n\t\t}\n\t\treturn position;\n \t}\n\n\t/**\n\t * Print the contents of table to a string.\n\t *\n\t * Complexity: $(BIGOH (n))\n\t */\n\tstring toString ()\n\t{\n\t\tauto writer = appender !(string) ();\n\t\tforeach (i, c; table)\n\t\t{\n\t\t\tformattedWrite (writer, \"sum[%s..%s] = %s\\n\",\n\t\t\t (i + 1) & i, i + 1, c);\n\t\t}\n\t\treturn writer.data;\n\t}\n}\n\nunittest\n{\n\timmutable int MAX_N = 20;\n\tauto t = FenwickTree !(int) (MAX_N);\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tt.add (i, i);\n\t}\n\tassert (t.sum (MAX_N) == 190);\n\tassert (t.sum !(long) (MAX_N) == 190);\n\tassert (t.find (int.min) == 0);\n\tassert (t.find (54) == 10);\n\tassert (t.find (55) == 10);\n\tassert (t.find (56) == 11);\n\tassert (t.find (long.max) == t.length);\n\tassert (t.sum (10) == 45);\n\tassert (t.sum (10, 20) == 190 - 45);\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tassert (t.sum (i) == t.sum (0, i));\n\t\tassert (t.sum (0, i) + t.sum (i, MAX_N) == 190);\n\t}\n\tassert (t.toString () ==\n\t \"sum[0..1] = 0\\n\" ~\n\t \"sum[0..2] = 1\\n\" ~\n\t \"sum[2..3] = 2\\n\" ~\n\t \"sum[0..4] = 6\\n\" ~\n\t \"sum[4..5] = 4\\n\" ~\n\t \"sum[4..6] = 9\\n\" ~\n\t \"sum[6..7] = 6\\n\" ~\n\t \"sum[0..8] = 28\\n\" ~\n\t \"sum[8..9] = 8\\n\" ~\n\t \"sum[8..10] = 17\\n\" ~\n\t \"sum[10..11] = 10\\n\" ~\n\t \"sum[8..12] = 38\\n\" ~\n\t \"sum[12..13] = 12\\n\" ~\n\t \"sum[12..14] = 25\\n\" ~\n\t \"sum[14..15] = 14\\n\" ~\n\t \"sum[0..16] = 120\\n\" ~\n\t \"sum[16..17] = 16\\n\" ~\n\t \"sum[16..18] = 33\\n\" ~\n\t \"sum[18..19] = 18\\n\" ~\n\t \"sum[16..20] = 70\\n\"\n\t );\n}\n\nimport std.algorithm;\nimport std.stdio;\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 t = FenwickTree !(int) (n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tt.add (i, a[i]);\n\t\t}\n\t\tint res = 0;\n\t\tforeach (i; 1..n - 1)\n\t\t{\n\t\t\tif (t.sum (0, i) == t.sum (i, n))\n\t\t\t{\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "5358fff5b798ac5e500d0f5deef765c7"} {"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 class folder {\n string name;\n string[] files;\n folder[] folders;\n \n this (string n) {\n name = n;\n }\n }\n \n folder root = new folder(\"root\");\n \n string s;\n while ((s = readln.chomp) !is null) {\n auto els = s.split(\"\\\\\");\n auto start = els[0] ~ els[1];\n auto file = els[$-1];\n els = start ~ els[2 .. $-1];\n \n auto now = root;\n foreach (e; els) {\n if (! now.folders.any!(f => f.name == e)) {\n now.folders ~= new folder(e);\n }\n \n now = now.folders.find!((f, e) => f.name == e)(e)[0];\n }\n \n now.files ~= file;\n }\n \n debug {\n void wf(folder f, int t) {\n (' ').repeat(t).to!string.write;\n writeln(f.name);\n foreach (fs; f.folders) {\n wf(fs, t+2);\n }\n }\n\n wf(root, 0);\n }\n \n Tuple!(int, int) getCnt(folder dir) {\n int dirs = dir.folders.length.to!int;\n int files = dir.files.length.to!int;\n \n auto ans = tuple(dirs, files);\n foreach (d; dir.folders) {\n auto res = getCnt(d);\n ans[0] += res[0];\n ans[1] += res[1];\n }\n \n return ans;\n }\n \n int mxd = 0, mxf = 0;\n foreach (dir; root.folders) {\n auto res = getCnt(dir);\n mxd = max(mxd, res[0]);\n mxf = max(mxf, res[1]);\n }\n \n writeln(mxd, ' ', mxf);\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 class folder {\n string name;\n string[] files;\n folder[] folders;\n \n this (string n) {\n name = n;\n }\n }\n \n folder root = new folder(\"root\");\n \n string s;\n while ((s = readln.chomp) !is null) {\n auto els = s.split(\"\\\\\");\n auto start = els[0] ~ els[1];\n auto file = els[$-1];\n els = start ~ els[2 .. $-1];\n \n auto now = root;\n foreach (e; els) {\n if (! now.folders.any!(f => f.name == e)) {\n now.folders ~= new folder(e);\n }\n \n foreach (f; now.folders) {\n if (e == f.name) {\n now = f;\n break;\n }\n }\n }\n \n now.files ~= file;\n }\n \n debug {\n void wf(folder f, int t) {\n (' ').repeat(t).to!string.write;\n writeln(f.name);\n foreach (fs; f.folders) {\n wf(fs, t+2);\n }\n }\n\n wf(root, 0);\n }\n \n Tuple!(int, int) getCnt(folder dir) {\n int dirs = dir.folders.length.to!int;\n int files = dir.files.length.to!int;\n \n auto ans = tuple(dirs, files);\n foreach (d; dir.folders) {\n auto res = getCnt(d);\n ans[0] += res[0];\n ans[1] += res[1];\n }\n \n return ans;\n }\n \n int mxd = 0, mxf = 0;\n foreach (dir; root.folders) {\n auto res = getCnt(dir);\n mxd = max(mxd, res[0]);\n mxf = max(mxf, res[1]);\n }\n \n writeln(mxd, ' ', mxf);\n}"}], "negative_code": [], "src_uid": "e588d7600429eb6b70a1a9b5eca194f7"} {"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}", "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.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"}, {"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\nsize_t[] solve(string a, string b) {\n\tsize_t[] result;\n\tforeach (i; 0 .. a.length) {\n\t\tif (a[i] != b[i]) {\n\t\t\tresult.assumeSafeAppend ~= i + 1;\n\t\t\tresult.assumeSafeAppend ~= 1;\n\t\t\tresult.assumeSafeAppend ~= i + 1;\n\t\t}\n\t}\n\treturn result;\n}\n\nvoid main() {\n\tlong tt = readln().chomp.to!long;\n\tforeach (t; 0 .. tt) {\n\t\treadln();\n\t\tstring a = readln().chomp;\n\t\tstring b = readln().chomp;\n\t\tif (a == b) {\n\t\t\twriteln(\"0\");\n\t\t}\n\t\telse {\n\t\t\tauto arr = solve(a, b);\n\t\t\twriteln(arr.length, \" \", arr.map!(to!string).join(\" \"));\n\t\t}\n\t}\n}\n\n// 00A00B 00C00D\n// b11a11 00C00D\n// 0A00B1 00C00D\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\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == b[i]) continue;\n\t\t\tif (a[0] == b[i])\n\t\t\t{\n\t\t\t\tans[ti] ~= 1;\n\t\t\t\ta[0] = a[i];\n\t\t\t}\n\t\t\tans[ti] ~= i+1;\n\t\t\tint l, r = i;\n\t\t\twhile (l <= r)\n\t\t\t{\n\t\t\t\tswap(a[l], a[r]);\n\t\t\t\ta[l] = cast(char)(((a[l]-'0')^1) + '0');\n\t\t\t\tif (l != r)\n\t\t\t\t\ta[r] = cast(char)(((a[r]-'0')^1) + '0');\n\t\t\t\t++l; --r;\n\t\t\t}\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}"}], "negative_code": [], "src_uid": "10c9b2d70030f7ed680297455d1f1bb0"} {"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\nbool isv(ref char c){\n return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';\n}\nvoid main(){\n char[] s=readln.strip.to!(char[]),\n t=readln.strip.to!(char[]);\n if(s.length!=t.length)\n writeln(\"No\");\n else{\n foreach(i;0..s.length){\n if((!s[i].isv || !t[i].isv) && (s[i].isv || t[i].isv)){\n writeln(\"No\");\n return;\n }\n }\n writeln(\"Yes\");\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\nbool isVowel(C)(C c) {\n return \"aeiou\".canFind(c);\n}\n\nvoid main() {\n string s = readln.strip;\n string t = readln.strip;\n\n bool[] cv_s = s.map!(c => c.isVowel).array;\n bool[] cv_t = t.map!(c => c.isVowel).array;\n\n if (cv_s == cv_t) {\n writeln(\"Yes\");\n } else {\n writeln(\"No\");\n }\n}\n"}], "negative_code": [], "src_uid": "2b346d5a578031de4d19edb4f8f2626c"} {"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 auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n const K = (N + 1) / 2;\n auto dp = new int[][](K + 1, N);\n foreach (k; 0 .. K + 1) {\n dp[k][] = INF;\n }\n foreach (i; 0 .. N) {\n int cost;\n if (i - 1 >= 0) {\n cost += max(A[i - 1] - A[i] + 1, 0);\n }\n if (i + 1 < N) {\n cost += max(A[i + 1] - A[i] + 1, 0);\n }\n dp[1][i] = cost;\n }\n auto dpMin = new int[N + 1];\n foreach (k; 1 .. K) {\n dpMin[0] = INF;\n foreach (i; 0 .. N) {\n dpMin[i + 1] = min(dpMin[i], dp[k][i]);\n }\n foreach (i; 2 .. N) {\n {\n int cost = dpMin[i - 2];\n cost += max(A[i - 1] - A[i] + 1, 0);\n if (i + 1 < N) {\n cost += max(A[i + 1] - A[i] + 1, 0);\n }\n chmin(dp[k + 1][i], cost);\n }\n {\n int cost = dp[k][i - 2];\n cost -= max(A[i - 1] - A[i - 2] + 1, 0);\n cost += max(A[i - 1] - min(A[i - 2], A[i]) + 1, 0);\n if (i + 1 < N) {\n cost += max(A[i + 1] - A[i] + 1, 0);\n }\n chmin(dp[k + 1][i], cost);\n }\n }\n }\n debug {\n foreach (k; 1 .. K + 1) {\n writeln(k, \": \", dp[k]);\n }\n }\n \n foreach (k; 1 .. K + 1) {\n if (k > 1) write(\" \");\n write(dp[k].minElement);\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;\n\nimmutable int infinity = int.max / 2;\n\nint cost (int prev, int cur, int next)\n{\n\tint res = 0;\n\tres += max (0, prev + 1 - cur);\n\tres += max (0, next + 1 - cur);\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 a = readln.splitter.map !(to !(int)).array;\n\t\tint m = (n + 1) / 2;\n\n\t\tauto f = new int [] [] (2, n);\n\t\tint b = 0;\n\t\tint [] ans;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint prev = (i - 1 >= 0) ? a[i - 1] : -1;\n\t\t\tint next = (i + 1 < n) ? a[i + 1] : -1;\n\t\t\tf[b][i] = cost (prev, a[i], next);\n\t\t}\n\t\tans ~= minElement (f[b]);\n\t\tdebug {writeln (f[b]);}\n\n\t\tforeach (k; 1..m)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tdebug {f[b][] = -1;}\n\t\t\tint minHistory = infinity;\n\t\t\tint best = infinity;\n\t\t\tforeach (i; k * 2..n)\n\t\t\t{\n\t\t\t\tint prev = a[i - 1];\n\t\t\t\tint prevClose = min (prev, a[i - 2] - 1);\n\t\t\t\tint next = (i + 1 < n) ? a[i + 1] : -1;\n\t\t\t\tint cur = cost (prevClose, a[i], next) +\n\t\t\t\t f[!b][i - 2];\n\t\t\t\tcur = min (cur, cost (prev, a[i], next) +\n\t\t\t\t minHistory);\n\n\t\t\t\tf[b][i] = cur;\n\t\t\t\tbest = min (best, cur);\n\t\t\t\tminHistory = min (minHistory, f[!b][i - 2]);\n\t\t\t}\n\t\t\tans ~= best;\n\t\t\tdebug {writeln (f[b]);}\n\t\t}\n\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "negative_code": [], "src_uid": "9534b468bfb6126fc16b896532ced8c5"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n = scan!int;\n auto w = scan!(dchar[]);\n int l1, l2, r1, r2;\n for(int i = n/2; i < n; ++i){\n if(w[i] == '0'){\n l1 = 0;\n r1 = i;\n l2 = 0;\n r2 = i-1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\n return;\n }\n }\n for(int i = 0; i < n/2; ++i){\n if(w[i] == '0'){\n l1 = i;\n r1 = n-1;\n l2 = i+1;\n r2 = n-1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\n return;\n }\n }\n for(int i = 0; i < n; ++i){\n assert(w[i] == '1');\n }\n l1 = 0;\n r1 = n/2;\n l2 = 1;\n r2 = min(n/2 + 1, n-1);\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\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.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid solve(string s)\n{\n int lastzero = -1;\n foreach_reverse (i ; 0 .. cast(int)s.length) {\n if (s[i] == '0') {\n lastzero = i;\n break;\n }\n }\n if (lastzero >= cast(int)s.length / 2) {\n// writeln(s[1 - 1 .. lastzero]);\n// writeln(s[1 - 1 .. lastzero + 1]);\n writefln(\"%d %d %d %d\", 1, lastzero + 1, 1, lastzero);\n return;\n }\n int mididx = cast(int)s.length / 2;\n if (s[mididx - 1] == '1') {\n// writeln(s[mididx + 1 - 1 .. s.length]);\n// writeln(s[mididx - 1 .. s.length - 1]);\n writefln(\"%d %d %d %d\", mididx + 1, s.length, mididx, s.length - 1);\n } else {\n// writeln(s[mididx - 1 .. s.length]);\n// writeln(s[mididx + 1 - 1 .. s.length]);\n writefln(\"%d %d %d %d\", mididx, s.length, mididx + 1, s.length);\n }\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readln.formattedRead!\" %d \"(n);\n string s = readln.strip;\n// writeln(s);\n solve(s);\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\t\t\r\n\t\tlong pos;\r\n\t\tforeach (i; n/2..n)\r\n\t\t{\r\n\t\t\tif (s[i] == '0')\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 != 0)\r\n\t\t{\r\n\t\t\tans[ti] = [1, pos+1, 1, pos];\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (s[n/2-1] == '1')\r\n\t\t\tans[ti] = [n/2, n-1, n/2+1, n];\r\n\t\telse\r\n\t\t\tans[ti] = [n/2+1, n, n/2, n];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e[0], \" \", e[1], \" \", e[2], \" \", e[3]);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n int n = scan!int;\n auto w = scan!(dchar[]);\n int l1, l2, r1, r2;\n for(int i = n/2; i < n; ++i){\n if(w[i] == '0'){\n l1 = 0;\n r1 = i;\n l2 = 0;\n r2 = i-1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\n return;\n }\n }\n for(int i = 0; i < n/2; ++i){\n if(w[i] == '0'){\n l1 = i;\n r1 = n-1;\n l2 = i+1;\n r2 = n-1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\n return;\n }\n }\n for(int i = 0; i < n; ++i){\n assert(w[i] == '1');\n }\n l1 = 0;\n r1 = n/2;\n l2 = 1;\n r2 = n/2 + 1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\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 int n = scan!int;\n auto w = scan!(dchar[]);\n int l1, l2, r1, r2;\n for(int i = 0; i < n/2; ++i){\n if(w[i] == '0'){\n l1 = i;\n r1 = n-1;\n l2 = i+1;\n r2 = n-1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\n return;\n }\n }\n for(int i = n/2; i < n; ++i){\n if(w[i] == '0'){\n l1 = 0;\n r1 = i;\n l2 = 0;\n r2 = i-1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\n return;\n }\n }\n for(int i = 0; i < n; ++i){\n assert(w[i] == '1');\n }\n l1 = 0;\n r1 = n/2;\n l2 = 1;\n r2 = n/2 + 1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\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 int n = scan!int;\n auto w = scan!(dchar[]);\n int l1, l2, r1, r2;\n dchar[] sol1, sol2;\n for(int i = 0; i < n/2; ++i){\n if(w[i] == '0'){\n /* sol1 ~= w[i]; */\n /* for(int j = i + 1; j < n; ++j){ */\n /* sol1 ~= w[j]; */\n /* sol2 ~= w[j]; */\n /* f = 1; */\n /* break; */\n /* } */\n l1 = i;\n r1 = n-1;\n l2 = i+1;\n r2 = n-1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\n return;\n }\n }\n for(int i = n/2; i < n; ++i){\n if(w[i] == '0'){\n /* for(int j = n/2; j < i; ++j){ */\n /* sol1 ~= w[i]; */\n /* sol2 ~= w[i]; */\n /* } */\n /* f = 1; */\n /* sol1 ~= w[i]; */\n l1 = 0;\n r1 = i;\n l2 = 0;\n r2 = i-1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\n return;\n }\n }\n l1 = 0;\n r1 = n/2;\n l2 = 1;\n r2 = n/2 + 1;\n writeln(l1+1, \" \", r1+1, \" \", l2+1, \" \", r2+1);\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.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nvoid solve(string s)\n{\n int lastzero = -1;\n foreach_reverse (i ; 0 .. cast(int)s.length) {\n if (s[i] == '0') {\n lastzero = i;\n break;\n }\n }\n if (lastzero >= s.length / 2) {\n// writeln(s[1 - 1 .. lastzero]);\n// writeln(s[1 - 1 .. lastzero + 1]);\n writefln(\"%d %d %d %d\", 1, lastzero + 1, 1, lastzero);\n return;\n }\n int mididx = cast(int)s.length / 2;\n if (s[mididx - 1] == '1') {\n// writeln(s[mididx + 1 - 1 .. s.length]);\n// writeln(s[mididx - 1 .. s.length - 1]);\n writefln(\"%d %d %d %d\", mididx + 1, s.length, mididx, s.length - 1);\n } else {\n// writeln(s[mididx - 1 .. s.length]);\n// writeln(s[mididx + 1 - 1 .. s.length]);\n writefln(\"%d %d %d %d\", mididx, s.length, mididx + 1, s.length);\n }\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readln.formattedRead!\" %d \"(n);\n string s = readln.strip;\n// writeln(s);\n solve(s);\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 solve(string s)\n{\n int lastzero = -1;\n foreach_reverse (i ; 0 .. cast(int)s.length) {\n if (s[i] == '0') {\n lastzero = i;\n break;\n }\n }\n if (lastzero >= s.length / 2) {\n// writeln(s[1 - 1 .. lastzero]);\n// writeln(s[1 - 1 .. lastzero + 1]);\n writefln(\"%d %d %d %d\", 1, lastzero, 1, lastzero + 1);\n return;\n }\n int mididx = cast(int)s.length / 2;\n if (s[mididx - 1] == '1') {\n// writeln(s[mididx + 1 - 1 .. s.length]);\n// writeln(s[mididx - 1 .. s.length - 1]);\n writefln(\"%d %d %d %d\", mididx + 1, s.length, mididx, s.length - 1);\n } else {\n// writeln(s[mididx - 1 .. s.length]);\n// writeln(s[mididx + 1 - 1 .. s.length]);\n writefln(\"%d %d %d %d\", mididx, s.length, mididx + 1, s.length);\n }\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readln.formattedRead!\" %d \"(n);\n string s = readln.strip;\n// writeln(s);\n solve(s);\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\t\t\r\n\t\tlong pos;\r\n\t\tforeach (i; n/2..n)\r\n\t\t{\r\n\t\t\tif (s[i] == '0')\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 != 0)\r\n\t\t{\r\n\t\t\tans[ti] = [1, pos, 1, pos+1];\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tif (s[n/2-1] == '1')\r\n\t\t\tans[ti] = [n/2, n-1, n/2+1, n];\r\n\t\telse\r\n\t\t\tans[ti] = [n/2, n, n/2+1, n];\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e[0], \" \", e[1], \" \", e[2], \" \", e[3]);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "eadc7f5e1043ac431984ec921c62892d"} {"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 X = readInt();\n const Y = readInt();\n auto B = new int[N];\n foreach (i; 0 .. N) {\n B[i] = readInt();\n }\n \n const M = N + 2;\n auto iss = new int[][M];\n foreach (i; 0 .. N) {\n iss[B[i]] ~= i;\n }\n int fake;\n foreach (b; 1 .. M) {\n if (iss[b].empty) {\n fake = b;\n break;\n }\n }\n \n int mLim;\n foreach (m; 0 .. N - X + 1) {\n if (min(2 * (N - X - m), N - X) >= Y - X) {\n chmax(mLim, m);\n }\n }\n debug {\n writeln(\"mLim = \", mLim);\n }\n \n int must;\n foreach (b; 1 .. M) {\n const len = cast(int)(iss[b].length);\n must += max(len - mLim, 0);\n }\n if (must <= X) {\n int[] hits;\n foreach (b; 1 .. M) {\n const len = cast(int)(iss[b].length);\n if (len - mLim >= 0) {\n hits ~= iss[b][mLim .. len];\n iss[b].length = mLim;\n }\n }\n int x = X - must;\n foreach (b; 1 .. M) {\n const len = cast(int)(iss[b].length);\n const tmp = min(len, x);\n hits ~= iss[b][len - tmp .. len];\n iss[b].length = len - tmp;\n x -= tmp;\n }\n debug {\n writeln(\"hits = \", hits);\n writeln(\"iss = \", iss);\n }\n auto ans = new int[N];\n ans[] = fake;\n foreach (i; hits) {\n ans[i] = B[i];\n }\n int bm;\n foreach (b; 1 .. M) {\n if (iss[bm].length < iss[b].length) {\n bm = b;\n }\n }\n if (2 * iss[bm].length <= N - X) {\n int[] blows;\n foreach (b; 1 .. M) {\n blows ~= iss[b];\n }\n foreach (j; 0 .. Y - X) {\n ans[blows[j]] = B[blows[(j + (N - X) / 2) % (N - X)]];\n }\n } else {\n int[] others;\n foreach (b; 1 .. M) {\n if (b != bm) {\n others ~= iss[b];\n }\n }\n const othersLen = cast(int)(others.length);\n assert(2 * othersLen >= Y - X);\n int y = Y - X;\n foreach (j; 0 .. othersLen) {\n if (y > 0) {\n ans[others[j]] = B[iss[bm][j]];\n --y;\n }\n }\n foreach (j; 0 .. othersLen) {\n if (y > 0) {\n ans[iss[bm][j]] = B[others[j]];\n --y;\n }\n }\n }\n writeln(\"YES\");\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln;\n } else {\n writeln(\"NO\");\n }\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);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x, y;\n\t\treadf !(\" %s %s %s\") (n, x, y);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [int] b;\n\t\tforeach (ref t; a)\n\t\t{\n\t\t\tb[t] += 1;\n\t\t}\n\t\tauto c = b.byPair.array;\n\t\tc.schwartzSort !(q{-a.value});\n\t\ty -= x;\n\n\t\tint [] inPlace;\n\t\twhile (x > 0)\n\t\t{\n\t\t\tint cur = c.front.value;\n\t\t\tauto d = c;\n\t\t\twhile (x > 0 && !d.empty && d.front.value == cur)\n\t\t\t{\n\t\t\t\tinPlace ~= d.front.key;\n\t\t\t\td.front.value -= 1;\n\t\t\t\td.popFront ();\n\t\t\t\tx -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint notFound = 1;\n\t\twhile (notFound in b)\n\t\t{\n\t\t\tnotFound += 1;\n\t\t}\n\n\t\tc.schwartzSort !(q{-a.value});\n\n\t\tint [] left;\n\t\tforeach (ref p; c)\n\t\t{\n\t\t\tforeach (i; 0..p.value)\n\t\t\t{\n\t\t\t\tleft ~= p.key;\n\t\t\t}\n\t\t}\n\n\t\tint [2] [] trans;\n\t\tint len = left.length.to !(int);\n\t\tint hi = len / 2;\n\t\tforeach (lo; 0..len)\n\t\t{\n\t\t\tint dest = left[hi];\n\t\t\tif (y == 0 || left[lo] == dest)\n\t\t\t{\n\t\t\t\tdest = notFound;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ty -= 1;\n\t\t\t}\n\t\t\ttrans ~= [left[lo], dest];\n\t\t\thi = (hi + 1) % (len + !len);\n\t\t}\n\n\t\tif (y > 0)\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue multitest_loop;\n\t\t}\n\n\t\tsort (inPlace);\n\t\tsort (trans);\n\t\tauto q = n.iota.array;\n\t\tmakeIndex (a, q);\n\t\tauto res = new int [n];\n\t\tforeach (i; q)\n\t\t{\n\t\t\tif (!inPlace.empty && inPlace.front == a[i])\n\t\t\t{\n\t\t\t\tres[i] = a[i];\n\t\t\t\tinPlace.popFront ();\n\t\t\t}\n\t\t\telse if (!trans.empty && trans.front[0] == a[i])\n\t\t\t{\n\t\t\t\tres[i] = trans.front[1];\n\t\t\t\ttrans.popFront ();\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\twriteln (\"YES\");\n\t\twritefln !(\"%(%s %)\") (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\tauto tests = readln.strip.to !(int);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x, y;\n\t\treadf !(\" %s %s %s\") (n, x, y);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [int] b;\n\t\tforeach (ref t; a)\n\t\t{\n\t\t\tb[t] += 1;\n\t\t}\n\t\tauto c = b.byPair.array;\n\t\tc.schwartzSort !(q{-a.value});\n\t\ty -= x;\n\n\t\tint [] inPlace;\n\t\twhile (x > 0)\n\t\t{\n\t\t\tint cur = c.front.value;\n\t\t\tauto d = c;\n\t\t\twhile (x > 0 && !d.empty && d.front.value == cur)\n\t\t\t{\n\t\t\t\tinPlace ~= d.front.key;\n\t\t\t\td.front.value -= 1;\n\t\t\t\td.popFront ();\n\t\t\t\tx -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint notFound = 1;\n\t\twhile (notFound in b)\n\t\t{\n\t\t\tnotFound += 1;\n\t\t}\n\n\t\tc.schwartzSort !(q{-a.value});\n\n\t\tint [] left;\n\t\tforeach (ref p; c)\n\t\t{\n\t\t\tforeach (i; 0..p.value)\n\t\t\t{\n\t\t\t\tleft ~= p.key;\n\t\t\t}\n\t\t}\n\n\t\tint [2] [] trans;\n\t\tint len = left.length.to !(int);\n\t\tint hi = c.front.value % (len + !len);\n\t\tforeach (lo; 0..len)\n\t\t{\n\t\t\tint dest = (y > 0) ? left[hi] : notFound;\n\t\t\ty -= 1;\n\t\t\ttrans ~= [left[lo], dest];\n\t\t\thi = (hi + 1) % (len + !len);\n\t\t}\n\n\t\tif (trans.any !(p => p[0] == p[1]))\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue multitest_loop;\n\t\t}\n\n\t\tsort (inPlace);\n\t\tsort (trans);\n\t\tauto q = n.iota.array;\n\t\tmakeIndex (a, q);\n\t\tauto res = new int [n];\n\t\tforeach (i; q)\n\t\t{\n\t\t\tif (!inPlace.empty && inPlace.front == a[i])\n\t\t\t{\n\t\t\t\tres[i] = a[i];\n\t\t\t\tinPlace.popFront ();\n\t\t\t}\n\t\t\telse if (!trans.empty && trans.front[0] == a[i])\n\t\t\t{\n\t\t\t\tres[i] = trans.front[1];\n\t\t\t\ttrans.popFront ();\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\twriteln (\"YES\");\n\t\twritefln !(\"%(%s %)\") (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);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x, y;\n\t\treadf !(\" %s %s %s\") (n, x, y);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [int] b;\n\t\tforeach (ref t; a)\n\t\t{\n\t\t\tb[t] += 1;\n\t\t}\n\t\tauto c = b.byPair.array;\n\t\tc.schwartzSort !(q{-a.value});\n\t\ty -= x;\n\n\t\tint [] inPlace;\n\t\twhile (x > 0)\n\t\t{\n\t\t\tint cur = c.front.value;\n\t\t\tauto d = c;\n\t\t\twhile (x > 0 && !d.empty && d.front.value == cur)\n\t\t\t{\n\t\t\t\tinPlace ~= d.front.key;\n\t\t\t\td.front.value -= 1;\n\t\t\t\td.popFront ();\n\t\t\t\tx -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint notFound = 1;\n\t\twhile (notFound in b)\n\t\t{\n\t\t\tnotFound += 1;\n\t\t}\n\n\t\tc.schwartzSort !(q{-a.value});\n\n\t\tint [] left;\n\t\tforeach (ref p; c)\n\t\t{\n\t\t\tforeach (i; 0..p.value)\n\t\t\t{\n\t\t\t\tleft ~= p.key;\n\t\t\t}\n\t\t}\n\n\t\tint [2] [] trans;\n\t\tint hi = c.front.value;\n\t\tint len = left.length.to !(int);\n\t\tforeach (lo; 0..len)\n\t\t{\n\t\t\tint dest = (y > 0) ? left[hi] : notFound;\n\t\t\ty -= 1;\n\t\t\ttrans ~= [left[lo], dest];\n\t\t\thi = (hi + 1) % len;\n\t\t}\n\n\t\tif (trans.any !(p => p[0] == p[1]))\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue multitest_loop;\n\t\t}\n\n\t\tsort (inPlace);\n\t\tsort (trans);\n\t\tauto q = n.iota.array;\n\t\tmakeIndex (a, q);\n\t\tauto res = new int [n];\n\t\tforeach (i; q)\n\t\t{\n\t\t\tif (!inPlace.empty && inPlace.front == a[i])\n\t\t\t{\n\t\t\t\tres[i] = a[i];\n\t\t\t\tinPlace.popFront ();\n\t\t\t}\n\t\t\telse if (!trans.empty && trans.front[0] == a[i])\n\t\t\t{\n\t\t\t\tres[i] = trans.front[1];\n\t\t\t\ttrans.popFront ();\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\twriteln (\"YES\");\n\t\twritefln !(\"%(%s %)\") (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);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x, y;\n\t\treadf !(\" %s %s %s\") (n, x, y);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [int] b;\n\t\tforeach (ref t; a)\n\t\t{\n\t\t\tb[t] += 1;\n\t\t}\n\t\tauto c = b.byPair.array;\n\t\tc.schwartzSort !(q{-a.value});\n\t\ty -= x;\n\n\t\tint [] inPlace;\n\t\twhile (x > 0)\n\t\t{\n\t\t\tint cur = c.front.value;\n\t\t\tauto d = c;\n\t\t\twhile (x > 0 && !d.empty && d.front.value == cur)\n\t\t\t{\n\t\t\t\tinPlace ~= d.front.key;\n\t\t\t\td.front.value -= 1;\n\t\t\t\td.popFront ();\n\t\t\t\tx -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint notFound = 1;\n\t\twhile (notFound in b)\n\t\t{\n\t\t\tnotFound += 1;\n\t\t}\n\n\t\tc.schwartzSort !(q{-a.value});\n\n\t\tint [] left;\n\t\tforeach (ref p; c)\n\t\t{\n\t\t\tforeach (i; 0..p.value)\n\t\t\t{\n\t\t\t\tleft ~= p.key;\n\t\t\t}\n\t\t}\n\n\t\tint [2] [] trans;\n\t\tint len = left.length.to !(int);\n\t\tint hi = len / 2;\n\t\tforeach (lo; 0..len)\n\t\t{\n\t\t\tint dest = left[hi];\n\t\t\tif (y == 0 || left[lo] == dest)\n\t\t\t{\n\t\t\t\tdest = notFound;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ty -= 1;\n\t\t\t}\n\t\t\ttrans ~= [left[lo], dest];\n\t\t\thi = (hi + 1) % (len + !len);\n\t\t}\n\n\t\tif (trans.any !(p => p[0] == p[1]))\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue multitest_loop;\n\t\t}\n\n\t\tsort (inPlace);\n\t\tsort (trans);\n\t\tauto q = n.iota.array;\n\t\tmakeIndex (a, q);\n\t\tauto res = new int [n];\n\t\tforeach (i; q)\n\t\t{\n\t\t\tif (!inPlace.empty && inPlace.front == a[i])\n\t\t\t{\n\t\t\t\tres[i] = a[i];\n\t\t\t\tinPlace.popFront ();\n\t\t\t}\n\t\t\telse if (!trans.empty && trans.front[0] == a[i])\n\t\t\t{\n\t\t\t\tres[i] = trans.front[1];\n\t\t\t\ttrans.popFront ();\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\twriteln (\"YES\");\n\t\twritefln !(\"%(%s %)\") (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);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x, y;\n\t\treadf !(\" %s %s %s\") (n, x, y);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [int] b;\n\t\tforeach (ref t; a)\n\t\t{\n\t\t\tb[t] += 1;\n\t\t}\n\t\tauto c = b.byPair.array;\n\t\tc.schwartzSort !(q{-a.value});\n\t\ty -= x;\n\n\t\tint [] inPlace;\n\t\twhile (x > 0)\n\t\t{\n\t\t\tint cur = c.front.value;\n\t\t\tauto d = c;\n\t\t\twhile (x > 0 && !d.empty && d.front.value == cur)\n\t\t\t{\n\t\t\t\tinPlace ~= d.front.key;\n\t\t\t\td.front.value -= 1;\n\t\t\t\td.popFront ();\n\t\t\t\tx -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint notFound = 1;\n\t\twhile (notFound in b)\n\t\t{\n\t\t\tnotFound += 1;\n\t\t}\n\n\t\tc.schwartzSort !(q{-a.value});\n\n\t\tint [] left;\n\t\tforeach (ref p; c)\n\t\t{\n\t\t\tforeach (i; 0..p.value)\n\t\t\t{\n\t\t\t\tleft ~= p.key;\n\t\t\t}\n\t\t}\n\n\t\tint [2] [] trans;\n\t\tint len = left.length.to !(int);\n\t\tint hi = len / 2;\n\t\tforeach (lo; 0..len)\n\t\t{\n\t\t\tint dest = (y > 0) ? left[lo] : notFound;\n\t\t\ty -= 1;\n\t\t\ttrans ~= [left[hi], dest];\n\t\t\thi = (hi + 1) % (len + !len);\n\t\t}\n\n\t\tif (trans.any !(p => p[0] == p[1]))\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue multitest_loop;\n\t\t}\n\n\t\tsort (inPlace);\n\t\tsort (trans);\n\t\tauto q = n.iota.array;\n\t\tmakeIndex (a, q);\n\t\tauto res = new int [n];\n\t\tforeach (i; q)\n\t\t{\n\t\t\tif (!inPlace.empty && inPlace.front == a[i])\n\t\t\t{\n\t\t\t\tres[i] = a[i];\n\t\t\t\tinPlace.popFront ();\n\t\t\t}\n\t\t\telse if (!trans.empty && trans.front[0] == a[i])\n\t\t\t{\n\t\t\t\tres[i] = trans.front[1];\n\t\t\t\ttrans.popFront ();\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\twriteln (\"YES\");\n\t\twritefln !(\"%(%s %)\") (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);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, x, y;\n\t\treadf !(\" %s %s %s\") (n, x, y);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint [int] b;\n\t\tforeach (ref t; a)\n\t\t{\n\t\t\tb[t] += 1;\n\t\t}\n\t\tauto c = b.byPair.array;\n\t\tc.schwartzSort !(q{-a.value});\n\t\ty -= x;\n\n\t\tint [] inPlace;\n\t\twhile (x > 0)\n\t\t{\n\t\t\tint cur = c.front.value;\n\t\t\tauto d = c;\n\t\t\twhile (x > 0 && !d.empty && d.front.value == cur)\n\t\t\t{\n\t\t\t\tinPlace ~= d.front.key;\n\t\t\t\td.front.value -= 1;\n\t\t\t\td.popFront ();\n\t\t\t\tx -= 1;\n\t\t\t}\n\t\t}\n\n\t\tint notFound = 1;\n\t\twhile (notFound in b)\n\t\t{\n\t\t\tnotFound += 1;\n\t\t}\n\n\t\tc.schwartzSort !(q{-a.value});\n\n\t\tint [] left;\n\t\tforeach (ref p; c)\n\t\t{\n\t\t\tforeach (i; 0..p.value)\n\t\t\t{\n\t\t\t\tleft ~= p.key;\n\t\t\t}\n\t\t}\n\n\t\tint [2] [] trans;\n\t\tint len = left.length.to !(int);\n\t\tint hi = c.front.value % (len + !len);\n\t\tforeach (lo; 0..len)\n\t\t{\n\t\t\tint dest = (y > 0) ? left[lo] : notFound;\n\t\t\ty -= 1;\n\t\t\ttrans ~= [left[hi], dest];\n\t\t\thi = (hi + 1) % (len + !len);\n\t\t}\n\n\t\tif (trans.any !(p => p[0] == p[1]))\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t\tcontinue multitest_loop;\n\t\t}\n\n\t\tsort (inPlace);\n\t\tsort (trans);\n\t\tauto q = n.iota.array;\n\t\tmakeIndex (a, q);\n\t\tauto res = new int [n];\n\t\tforeach (i; q)\n\t\t{\n\t\t\tif (!inPlace.empty && inPlace.front == a[i])\n\t\t\t{\n\t\t\t\tres[i] = a[i];\n\t\t\t\tinPlace.popFront ();\n\t\t\t}\n\t\t\telse if (!trans.empty && trans.front[0] == a[i])\n\t\t\t{\n\t\t\t\tres[i] = trans.front[1];\n\t\t\t\ttrans.popFront ();\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\twriteln (\"YES\");\n\t\twritefln !(\"%(%s %)\") (res);\n\t}\n}\n"}], "src_uid": "729b33519cc2c02b929f7028edf23269"} {"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 rbt = A.redBlackTree;\r\n auto uf = UnionFind(N + 1);\r\n int rest = N;\r\n\r\n int last;\r\n foreach(a; A) {\r\n if (last < a) {\r\n foreach(other; rbt.lowerBound(a)) {\r\n if (!uf.same(a, other)) {\r\n rest--;\r\n uf.unite(a, other);\r\n }\r\n }\r\n }\r\n rbt.removeKey(a);\r\n if (rest == 1) break;\r\n last = max(last, a);\r\n }\r\n \r\n return rest;\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>>\".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 UnionFind {\r\n int[] parent;\r\n\r\n this(int size) {\r\n parent.length = size;\r\n foreach(i; 0..size) parent[i] = i;\r\n }\r\n\r\n int root(int x) {\r\n if (parent[x] == x) return x;\r\n return parent[x] = root(parent[x]);\r\n }\r\n\r\n int unite(int x, int y) {\r\n int rootX = root(x);\r\n int rootY = root(y);\r\n\r\n if (rootX == rootY) return rootY;\r\n return parent[rootX] = rootY;\r\n }\r\n\r\n bool same(int x, int y) {\r\n int rootX = root(x);\r\n int rootY = root(y);\r\n\r\n return rootX == rootY;\r\n }\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 rbt = A.redBlackTree;\r\n auto uf = UnionFind(N + 1);\r\n int rest = N;\r\n\r\n foreach(a; A) {\r\n foreach(other; rbt.lowerBound(a)) {\r\n if (!uf.same(a, other)) {\r\n rest--;\r\n uf.unite(a, other);\r\n }\r\n }\r\n rbt.removeKey(a);\r\n if (rest == 1) break;\r\n }\r\n \r\n return rest;\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>>\".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 UnionFind {\r\n int[] parent;\r\n\r\n this(int size) {\r\n parent.length = size;\r\n foreach(i; 0..size) parent[i] = i;\r\n }\r\n\r\n int root(int x) {\r\n if (parent[x] == x) return x;\r\n return parent[x] = root(parent[x]);\r\n }\r\n\r\n int unite(int x, int y) {\r\n int rootX = root(x);\r\n int rootY = root(y);\r\n\r\n if (rootX == rootY) return rootY;\r\n return parent[rootX] = rootY;\r\n }\r\n\r\n bool same(int x, int y) {\r\n int rootX = root(x);\r\n int rootY = root(y);\r\n\r\n return rootX == rootY;\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio, std.string, std.conv;\r\nimport std.algorithm.iteration;\r\nimport std.algorithm.searching;\r\nimport std.algorithm.mutation;\r\nimport std.range;\r\nimport std.typecons;\r\nulong prefsum(int n)\r\n{\r\n return (cast(ulong) n*(n + 1)) / 2;\r\n}\r\nulong segsum(int from, int to) {\r\n return prefsum(to) - prefsum(from - 1);\r\n}\r\nvoid solution(ref File input, ref File output) {\r\n auto t = input.readln.chomp.to!int;\r\n while (t-- > 0) {\r\n auto _ = input.readln;\r\n auto source = input.readln.chomp\r\n .split(' ')\r\n .map!(to!int)\r\n .enumerate;\r\n int start = 1, answer;\r\n ulong sum = 0;\r\n foreach (item; source)\r\n {\r\n auto ind = cast(int) item[0] + 1, val = item[1];\r\n sum += val;\r\n //writeln(\"Start: \", start,\r\n // \"Current: \", ind,\r\n // \" Segsum\", segsum(start, ind),\r\n // \"Sum: \", sum);\r\n if (segsum(start, ind) == sum)\r\n {\r\n start = ind + 1;\r\n sum = 0;\r\n answer += 1;\r\n }\r\n }\r\n output.writeln(answer);\r\n }\r\n}\r\nvoid main()\r\n{\r\n File input, output;\r\n debug(1) {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n solution(input, output);\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\r\nimport std.algorithm.iteration;\r\nimport std.algorithm.searching;\r\nimport std.algorithm.mutation;\r\nimport std.range;\r\nimport std.typecons;\r\nint prefsum(int n)\r\n{\r\n return (n*(n + 1)) / 2;\r\n}\r\nint segsum(int from, int to) {\r\n return prefsum(to) - prefsum(from - 1);\r\n}\r\nvoid solution(ref File input, ref File output) {\r\n auto t = input.readln.chomp.to!int;\r\n while (t-- > 0) {\r\n auto _ = input.readln;\r\n auto source = input.readln.chomp\r\n .split(' ')\r\n .map!(to!int)\r\n .enumerate;\r\n int start = 1, answer;\r\n ulong sum = 0;\r\n foreach (item; source)\r\n {\r\n auto ind = cast(int) item[0] + 1, val = item[1];\r\n sum += val;\r\n //writeln(\"Start: \", start,\r\n // \"Current: \", ind,\r\n // \" Segsum\", segsum(start, ind),\r\n // \"Sum: \", sum);\r\n if (segsum(start, ind) == sum)\r\n {\r\n start = ind + 1;\r\n sum = 0;\r\n answer += 1;\r\n }\r\n }\r\n output.writeln(answer);\r\n }\r\n}\r\nvoid main()\r\n{\r\n File input, output;\r\n debug(1) {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n solution(input, output);\r\n}\r\n"}], "src_uid": "b371d47ea08091917ab632e559ee75c6"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n\n// Main Logic Here\nvoid play(){\n ll n;\n n = rd;\n if(n == 1){\n writeln(0);\n }else if(n == 2){\n writeln(1);\n }else if (n == 3){\n writeln(2);\n }else if(n % 2 == 0){\n writeln(2);\n }else{\n writeln(3);\n }\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.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tif (n == 1) continue;\n\t\telse if (n == 2)\n\t\t\tans[ti] = 1;\n\t\telse if (n == 3)\n\t\t\tans[ti] = 2;\n\t\telse if (n % 2 == 0)\n\t\t\tans[ti] = 2;\n\t\telse\n\t\t\tans[ti] = 3;\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\nll[] primes;\n\nvoid prime_sieve(int siz){\n auto isPrime = new bool[](siz+1);\n isPrime[] = 1;\n foreach(p; 2..10000){\n if(isPrime[p]){\n for(ll divi = p*p; divi <= siz; divi += p){\n isPrime[divi.to!int] = 0;\n }\n }\n }\n foreach(k; 2..siz+1){\n if(isPrime[k]) primes ~= k;\n }\n}\n\n\n// Main Logic Here\nvoid play(){\n ll n;\n n = rd;\n ll tak = n;\n foreach(p; primes){\n if(n % p == 0){\n tak = p;\n break;\n }\n }\n writeln(tak - (tak == n));\n}\n\nint main(){\n long t = 1;\n prime_sieve(100000);\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"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\twhile (n != 1)\n\t\t{\n\t\t\tbool ok;\n\t\t\tfor (long i = 2; i*i <= n; ++i)\n\t\t\t{\n\t\t\t\tif (n % i) continue;\n\t\t\t\tn = i;\n\t\t\t\tok = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t\t--n;\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"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\twhile (n != 1)\n\t\t{\n\t\t\tif (n == 2)\n\t\t\t{\n\t\t\t\t++ans[ti];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbool ok;\n\t\t\tfor (long i = 2; i*i <= n; ++i)\n\t\t\t{\n\t\t\t\tif (n % i) continue;\n\t\t\t\tn = i;\n\t\t\t\tok = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t\t--n;\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"}], "src_uid": "614aa068ce74090b6577006c45e549cf"} {"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 a = RDA;\n\tauto b1 = new long[](n);\n\tauto b2 = new long[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tlong[] nums;\n\t\tauto x = a[i];\n\t\twhile (x != 0)\n\t\t{\n\t\t\tnums ~= x % 10;\n\t\t\tx /= 10;\n\t\t}\n\t\tdebug writeln(nums);\n\t\tforeach (j; 0..nums.length)\n\t\t{\n\t\t\tauto tmp = nums[j];\n\t\t\tforeach (k; 0..j+j)\n\t\t\t{\n\t\t\t\ttmp.modm(10);\n\t\t\t}\n\t\t\tb2[i].moda(tmp);\n\t\t\ttmp.modm(10);\n\t\t\tb1[i].moda(tmp);\n\t\t}\n\t}\n\tdebug writeln(b1);\n\tdebug writeln(b2);\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t{\n\t\tauto x = b1[i] + b2[i];\n\t\tx.modm(n);\n\t\tans.moda(x);\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio;\n\nauto calc(long x) {\n long base = 1;\n long result = 0;\n while(x > 0) {\n auto d = x % 10;\n x = x / 10;\n result += d * base;\n base *= 100;\n }\n return result;\n}\n\nvoid main() {\n int MOD = 998244353;\n int n;\n long a, result;\n\n readf(\" %s\", n);\n foreach(i; 0..n) {\n readf(\" %s\", a);\n auto b = calc(a) % MOD;\n result += (b * 10 * n) % MOD + (b * n) % MOD;\n result %= MOD;\n }\n writeln(result);\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\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\t\n\tlong ans;\n\tforeach(w; ws){\n\t\tint i = 0;\n\t\tlong m = 1;\n\t\tfor(; i < w.length; i += 1, m *= 100, m %= mod){\n\t\t\tans += w[i] * 11 * m * n % mod;\n\t\t\tans %= mod;\n\t\t}\n\t}\n\t\n\tans.writeln;\n}\n"}], "negative_code": [], "src_uid": "6e093dbcbcaa7c87c9b62546745984db"} {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm.sorting;\n\nint temp(int a, int b)\n{\n while(b > 0) {\n int temp = b;\n b = a % b;\n a = temp;\n }\n return a;\n}\n\nint main(string[] argv)\n{\n int n, res = 0;\n scanf(\"%d\", &n);\n int[] arr = new int[n];\n for(int i = 0; i < n; i++)\n scanf(\"%d\", &arr[i]);\n arr.sort();\n int mGcd = arr[1] - arr[0];\n for(int i = 2; i < n; i++) {\n mGcd = temp(mGcd, arr[i] - arr[i-1]);\n }\n \n for(int i = 1; i < n; i++) {\n res += (arr[i]-arr[i-1]) / mGcd - 1;\n }\n \n printf(\"%d\\n\", res);\n\n\treturn 0;\n}", "positive_code": [{"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\n\nlong gcd(long a, long b) {\n\twhile (b) {\n\t\ta %= b;\n\t\tswap(a, b);\n\t}\n\treturn a;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint [] a = new int[n];\n\tfor(int i = 0; i < n; i++) {\n\t\tscanf(\"%d\", &a[i]);\n\t}\n\tsort(a);\n\tlong m = 0;\n\tfor(int i = 0; i < n-1; ++i) {\n\t m = gcd(a[i+1]-a[i], m);\n\t}\n\tlong add = 0;\n\tfor(int i = 0; i < n-1; ++i) {\n\t add += (a[i+1]-a[i]) / m - 1;\n\t}\n\tprintf(\"%d\\n\", add);\n\treturn 0;\n}"}, {"source_code": "module main; \nimport core.stdc.stdio; \nimport std.algorithm; \n\nint gcd(int a, int b){ \nwhile (a > 0 && b > 0){ \nif (a > b){ \na = a % b; \n} else { \nb = b % a; \n} \n} \nreturn a + b; \n} \n\nint main(string[] argv) \n{ \nint n; \nscanf(\"%d\", &n); \nint [] arr = new int[n]; \nfor(int i = 0; i arr[i]){\n\t\t mina = arr[i];\n\t\t}\n\t\tif (maxa < arr[i]){\n\t\t maxa = arr[i];\n\t\t}\n\t}\n\tsort(arr);\n\n\tint diff = maxa - mina;\n\tfor(int i = 0; i t[1] - t[0]).array;\n \n auto gcd = dst.fold!gcd;\n \n debug { dst.writeln; gcd.writeln; }\n \n int ans = 0;\n foreach (a, b; lockstep(arr, arr.dropOne)) {\n ans += (b - a) / gcd - 1;\n }\n \n ans.writeln;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio;\nimport std.algorithm.sorting;\n\nint gcd (int a, int b) {\n\tif (b == 0)\n\t\treturn a;\n\telse\n\t\treturn gcd (b, a % b);\n}\n\nint main(string[] argv)\n{\n\tint n;\n\n\tscanf(\"%d\", &n);\n\tint [] a = new int[n];\n\tfor(int i = 0; i < n; i++) scanf(\"%d\", &a[i]);\n\ta.sort();\n\tint small = a[1] - a[0];\n\tfor(int i = 1; i < n - 1; i++)\n\t small = gcd(small, a[i + 1] - a[i]);\n\t\n\tprintf(\"%d\", (a[n - 1] - a[0]) / small - n + 1);\n\t\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm;\n\nint gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n}\n\nint main(string[] argv)\n{\n int n;\n scanf(\"%d\", &n);\n auto arr = new int[n];\n for(int i = 0; i arr[i])\n\t mn = arr[i];\n\t}\n\tfor(int i = 0; i 0) {\n a %= b;\n int t = b;\n b = a;\n a = t;\n }\n g = a;\n }\n int mi = 2000000000;\n int ma = -2000000000;\n for (int i = 0; i < n; ++i) {\n if (mi > x[i]) mi = x[i];\n if (ma < x[i]) ma = x[i];\n }\n int diff = ma - mi;\n diff /= g;\n printf(\"%d\\n\", diff + 1 - n);\n return 0;\n}\n"}], "negative_code": [{"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n int n;\n scanf(\"%d\", &n);\n int [] x = new int[n];\n for(int i = 0; i < n; i++)\n scanf(\"%d\", &x[i]);\n int g = 0;\n for (int i = 0; i < n - 1; i++) {\n int a = x[i] - x[i - 1];\n if (a < 0) a = -a;\n int b = g;\n while (b > 0) {\n a %= b;\n int t = b;\n b = a;\n a = t;\n }\n g = a;\n }\n int mi = 2000000000;\n int ma = -2000000000;\n for (int i = 0; i < n; ++i) {\n if (mi > x[i]) mi = x[i];\n if (ma < x[i]) ma = x[i];\n }\n int diff = ma - mi;\n diff /= g;\n printf(\"%d\\n\", diff + 1 - n);\n return 0;\n}\n"}, {"source_code": "module main;\n\nimport core.stdc.stdio;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\nimport std.numeric;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tint mina=1000000001, maxa =-1000000001;\n\tfor(int i = 0; i arr[i]){\n\t\t mina = arr[i];\n\t\t}\n\t\tif (maxa < arr[i]){\n\t\t maxa = arr[i];\n\t\t}\n\t}\n\tsort(arr);\n\n\tint diff = maxa - mina;\n\tfor(int i = 0; iarr[i+1]-arr[i]){\n\t\t diff = arr[i+1]-arr[i];\n\t\t}\n\tprintf(\"%d\\n\", (maxa-mina)/gcd(mina-maxa,diff)+1-n);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\nimport std.numeric;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tint mina=1000000001, maxa =-1000000001;\n\tfor(int i = 0; i arr[i]){\n\t\t mina = arr[i];\n\t\t}\n\t\tif (maxa < arr[i]){\n\t\t maxa = arr[i];\n\t\t}\n\t}\n\tsort(arr);\n\n\tint diff = maxa - mina;\n\tfor(int i = 0; iarr[i+1]-arr[i]){\n\t\t diff = arr[i+1]-arr[i];\n\t\t}\n if (diff ==0) {\n printf(\"%d\\n\", 0);\n }\n\telse \n\t printf(\"%d\\n\", (maxa-mina)/gcd(mina-maxa,diff)+1-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;\n\n\tscanf(\"%d\", &n);\n\tint [] a = new int[n];\n\tfor(int i = 0; i < n; i++) scanf(\"%d\", &a[i]);\n\ta.sort();\n\tint small = 2000000012;\n\tfor(int i = 0; i < n - 1; i++) \n\t if (a[i + 1] - a[i] < small)\n\t small = a[i + 1] - a[i];\n\t\n\tprintf(\"%d\", (a[n - 1] - a[0]) / small - n + 1);\n\t\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint gcd (int a, int b) {\n if(a < 0)\n a *= -1;\n if(b < 0)\n b *= -1;\n\treturn b ? gcd (b, a % b) : a;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\t//printf(\"%d\", gcd(1,10));\n\tint [] arr = new int[n];\n\tfor(int i = 0; i arr[i])\n\t mn = arr[i];\n\t}\n\t//printf(\"%d\", g);\n\tprintf(\"%d\", (mx - mn)/g + 1 - n);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint gcd (int a, int b) {\n\treturn b ? gcd (b, a % b) : a;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\t//printf(\"%d\", gcd(1,10));\n\tint [] arr = new int[n];\n\tfor(int i = 0; i arr[i])\n\t mn = arr[i];\n\t}\n\t//printf(\"%d\", g);\n\tprintf(\"%d\", (mx - mn)/g + 1 - n);\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\tint mn = 1123456789;\n\tscanf(\"%d\", &n);\n\tint [] a = new int[n];\n\tfor(int i = 0; i0)\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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m] 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 Mask {\n size_t[(100 + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)] data;\n\n int bsf() const {\n foreach (i, x; data)\n if (x)\n return cast(int)(.bsf(x) + (i * size_t.sizeof * 8));\n return -1;\n }\n}\n\nalias Event = Tuple!(int, `t`, bool, `open`, int, `k`, int, `id`);\n\nEvent[200_000] _events;\nMask[100_000] _masks;\n\nvoid main() {\n int n, q;\n while (read(&n, &q)) {\n auto events = _events[0 .. q << 1];\n auto masks = _masks[0 .. q];\n version (LocalProject)\n foreach (ref m; masks)\n m.data[ ] = 0x0;\n foreach (i; 0 .. q) {\n int t, k, d;\n read(&t, &k, &d);\n events[i << 1] = Event(t, true, k, i);\n events[i << 1 | 0x1] = Event(t + d, false, k, i);\n }\n events.multiSort!(`a.t < b.t`, `a.open < b.open`);\n\n Mask cur;\n memset(cur.data.ptr, 0xFF, cur.data.sizeof);\n nextEvent: foreach (ref e; events)\n if (e.open) {\n debug writeln(\"start \", e.id);\n int result = 0;\n foreach (i; 0 .. e.k) {\n int t = cur.bsf();\n debug writeln(\"Got \", t);\n if (~t && t < n) {\n result += t;\n btr(cur.data.ptr, t);\n bts(masks[e.id].data.ptr, t);\n } else {\n writeln(\"-1\");\n cur.data[ ] |= masks[e.id].data[ ];\n masks[e.id].data[ ] = 0x0;\n continue nextEvent;\n }\n }\n writeln(result + e.k);\n } else {\n debug writeln(\"stop \", e.id);\n cur.data[ ] |= masks[e.id].data[ ];\n }\n debug 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\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 Mask {\n size_t[(100 + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)] data;\n\n int bsf() const {\n foreach (i, x; data)\n if (x)\n return cast(int)(.bsf(x) + (i << size_t.sizeof));\n return -1;\n }\n}\n\nalias Event = Tuple!(int, `t`, bool, `open`, int, `k`, int, `id`);\n\nEvent[200_000] _events;\nMask[100_000] _masks;\n\nvoid main() {\n int n, q;\n while (read(&n, &q)) {\n auto events = _events[0 .. q << 1];\n auto masks = _masks[0 .. q];\n version (LocalProject)\n foreach (ref m; masks)\n m.data[ ] = 0x0;\n foreach (i; 0 .. q) {\n int t, k, d;\n read(&t, &k, &d);\n events[i << 1] = Event(t, true, k, i);\n events[i << 1 | 0x1] = Event(t + d, false, k, i);\n }\n events.multiSort!(`a.t < b.t`, `a.open < b.open`);\n\n Mask cur;\n memset(cur.data.ptr, 0xFF, cur.data.sizeof);\n nextEvent: foreach (ref e; events)\n if (e.open) {\n debug writeln(\"start \", e.id);\n int result = 0;\n foreach (i; 0 .. e.k) {\n int t = cur.bsf();\n debug writeln(\"Got \", t);\n if (~t && t < n) {\n result += t;\n btr(cur.data.ptr, t);\n bts(masks[e.id].data.ptr, t);\n } else {\n writeln(\"-1\");\n cur.data[ ] |= masks[e.id].data[ ];\n masks[e.id].data[ ] = 0x0;\n continue nextEvent;\n }\n }\n writeln(result + e.k);\n } else {\n debug writeln(\"stop \", e.id);\n cur.data[ ] |= masks[e.id].data[ ];\n }\n debug writeln();\n }\n}\n"}], "src_uid": "9f46205d62ba05d8bcc2c56f84b2d2b2"} {"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;\nimport std.bigint;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string str;\n readf(\" %s\\n\", &str);\n bool[] prefnd = new bool[str.length];\n int a, b;\n readf(\" %s %s\\n\", &a, &b);\n int pre = 0, pm = 0;\n foreach ( i; 0 .. str.length - 1 ) {\n pre += str[i] - '0';\n pm = pre % a;\n if (pm == 0) prefnd[i] = true;\n pre = pm * 10;\n }\n int ten = 1, sm = 0;\n foreach_reverse( i; 1 .. str.length ) {\n sm = (sm + (str[i] - '0') * ten) % b;\n if (sm == 0 && prefnd[i - 1] && str[i] != '0') {\n writeln(\"YES\\n\", str[0 .. i], \"\\n\", str[i .. $]);\n return 0;\n }\n ten = (ten * 10) % b;\n }\n writeln(\"NO\");\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;\nimport std.bigint;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string str;\n readf(\" %s\\n\", &str);\n bool[] prefnd = new bool[str.length];\n int a, b;\n readf(\" %s %s\\n\", &a, &b);\n long pre = 0, pm = 0;\n foreach ( i; 0 .. str.length - 1 ) {\n pre += str[i] - '0';\n pm = pre % a;\n if (pm == 0) prefnd[i] = true;\n pre = pm * 10;\n }\n long ten = 1, sm = 0;\n foreach_reverse( i; 1 .. str.length ) {\n sm = (sm + (str[i] - '0') * ten) % b;\n if (sm == 0 && prefnd[i - 1] && str[i] != '0') {\n writeln(\"YES\\n\", str[0 .. i], \"\\n\", str[i .. $]);\n return 0;\n }\n ten = (ten * 10) % b;\n }\n writeln(\"NO\");\n\n return 0;\n}"}], "negative_code": [], "src_uid": "695418026140545863313f5f3cc1bf00"} {"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;\nimport std.array;\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 printSpaces(int n) {\n while (n--) {\n write(\" \");\n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.read_int;\n while (t--) {\n string[] arr = stdin.byLineCopy.array;\n // writeln(arr[0..$]);\n int max_len = -999;\n foreach(i; arr) {\n max_len = max(max_len, cast(int)i.length);\n }\n\n for (int i = 0; i < max_len + 2; i++) {\n write(\"*\");\n } \n int alt = 0;\n writeln();\n for (int i = 0; i < arr.length; i++) {\n write(\"*\");\n int sample_len = cast(int)arr[i].length;\n int diff = (max_len - sample_len);\n if (diff % 2 == 0) {\n printSpaces(diff / 2);\n write(arr[i]);\n printSpaces(diff / 2);\n } else {\n if (alt % 2 == 0) {\n printSpaces(diff / 2);\n write(arr[i]);\n printSpaces(diff / 2 + 1);\n alt = 1;\n } else {\n printSpaces(diff / 2 + 1);\n write(arr[i]);\n printSpaces(diff / 2);\n alt = 0;\n }\n }\n writeln(\"*\");\n }\n\n for (int i = 0; i < max_len + 2; i++) {\n write(\"*\");\n }\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 double read_double() {\n return read_string.to!double;\n }\n \n string[] tokens;\n}\n\nvoid printSpaces(int n) {\n while (n--) {\n write(\" \");\n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.read_int;\n string[] arr;\n while (t--) {\n string x;\n foreach (line; stdin.byLineCopy)\n arr ~= line;\n \n // writeln(arr[0..$]);\n int max_len = -999;\n foreach(i; arr) {\n max_len = max(max_len, cast(int)i.length);\n }\n\n for (int i = 0; i < max_len + 2; i++) {\n write(\"*\");\n } \n int alt = 0;\n writeln();\n for (int i = 0; i < arr.length; i++) {\n write(\"*\");\n int sample_len = cast(int)arr[i].length;\n int diff = (max_len - sample_len);\n if (diff % 2 == 0) {\n printSpaces(diff / 2);\n write(arr[i]);\n printSpaces(diff / 2);\n } else {\n if (alt % 2 == 0) {\n printSpaces(diff / 2);\n write(arr[i]);\n printSpaces(diff / 2 + 1);\n alt = 1;\n } else {\n printSpaces(diff / 2 + 1);\n write(arr[i]);\n printSpaces(diff / 2);\n alt = 0;\n }\n }\n writeln(\"*\");\n }\n\n for (int i = 0; i < max_len + 2; i++) {\n write(\"*\");\n }\n } \n}"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n string[] text;\n int longest = 0;\n immutable border = \"*\";\n immutable fill = \" \";\n\n string line;\n while ((line = readln) != null) {\n line = line.chomp;\n text ~= line;\n longest = max(longest, line.length);\n }\n\n bool roundLeft = true;\n\n writeln(border, border.replicate(longest), border);\n foreach (string s; text) {\n int numSpaces = (longest - s.length) / 2;\n\n string spaces = fill.replicate(numSpaces);\n\n if ((s.length + longest) % 2 == 1) {\n if (roundLeft) {\n writeln(border, spaces, s, spaces, fill, border);\n } else {\n writeln(border, fill, spaces, s, spaces, border);\n }\n\n roundLeft = !roundLeft;\n } else {\n writeln(border, spaces, s, spaces, border);\n }\n }\n writeln(border, border.replicate(longest), border);\n}\n"}], "negative_code": [], "src_uid": "a017393743ae70a4d8a9d9dc40410653"} {"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;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto s = readln.chomp.split.array;\n \n auto total = s.map!(x => x.length).sum + s.length - 1;\n \n debug { total.writeln; }\n \n int mx = 1;\n int [string] vals;\n \n int[] nrs;\n foreach (e; s) {\n if (e !in vals) vals[e] = mx++;\n \n nrs ~= vals[e];\n }\n \n debug { nrs.writeln; }\n \n auto ans = total;\n foreach (st; 0 .. n) {\n auto gain = 0;\n auto len = 0;\n foreach (end; st+1 .. n) {\n debug { nrs[st..end].writeln; }\n auto regs = 1;\n \n len += 1;\n gain += s[end-1].length - 1 + cast(int)(end-1 != st);\n \n for (int p = end; p + len <= n; ++p) {\n if (nrs[st..end] == nrs[p..p+len]) {\n debug { p.writeln; }\n ++regs;\n p += len - 1;\n }\n }\n \n if (regs > 1) ans = min(ans, total - gain * regs);\n }\n }\n \n ans.writeln;\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;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto s = readln.chomp.split.array;\n \n auto total = s.length - 1 + s.map!(x => x.length).sum;\n \n debug { total.writeln; }\n \n int mx = 1;\n int [string] vals;\n \n int[] nrs;\n foreach (e; s) {\n if (e !in vals) vals[e] = mx++;\n \n nrs ~= vals[e];\n }\n \n debug { nrs.writeln; }\n \n auto ans = total;\n foreach (st; 0 .. n) {\n auto gain = 0;\n foreach (end; st+1 .. n) {\n debug { nrs[st..end].writeln; }\n auto regs = 1;\n \n gain += s[end-1].length - 1 + cast(int)(end-1 != st);\n \n for (int p = end; p + end - st <= n; ++p) {\n if (nrs[st..end] == nrs[p..p+end-st]) {\n debug { p.writeln; }\n ++regs;\n p += end-st - 1;\n }\n }\n \n if (regs > 1) ans = min(ans, total - gain * regs);\n }\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "1fb69f26fb14076df31534c77bf40c1e"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n dchar[][] words;\n for(int i = 0; i < n; ++i){ words ~= scan!(dchar[]); }\n auto rbt = redBlackTree!(dchar[])(words);\n\n auto after = redBlackTree!(dchar[]);\n\n auto cback = new dchar[][n];\n\n bool f = 0;\n for(int i = 0; i < n; ++i){\n if(words[i].front == words[i].back){\n f = 1;\n break;\n }else if(words[i].length >= 2){\n dchar[] rev;\n rev ~= words[i];\n rev.reverse;\n if(rev in rbt || words[i] in after){\n f = 1;\n break;\n }\n\n if(rev.length == 3){\n after.insert(rev[1..$]);\n cback[i] ~= rev[0..2];\n show(\"af: \", rev[1..$], \"bef: \", rev[0..2]);\n }\n }\n }\n auto before = redBlackTree!(dchar[]);\n for(int i = n-1; i >= 0; --i){\n if(cback[i].length){\n before.insert(cback[i]);\n }else if(words[i] in before){\n f = 1;\n break;\n }\n }\n writeln( (f) ? \"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", "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 (string [] s, int n)\r\n{\r\n\tif (s.any !(c => c.front == c.back))\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n\tauto t = s.map !(c => c.retro.text).array;\r\n\tint [string] first2;\r\n\tint [string] last2;\r\n\tint [string] first3;\r\n\tint [string] last3;\r\n\tforeach_reverse (i; 0..n)\r\n\t{\r\n\t\tfirst2[s[i][0..2]] = i;\r\n\t\tfirst3[s[i]] = i;\r\n\t}\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tlast2[t[i][0..2]] = i;\r\n\t\tlast3[t[i]] = i;\r\n\t}\r\n\tforeach (c, posC; first3)\r\n\t{\r\n\t\tif (c in last3 && posC < last3[c])\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\tif (c.length == 2 && c in last2 && posC < last2[c])\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\t}\r\n\tforeach (d, posD; last3)\r\n\t{\r\n\t\tif (d in first3 && first3[d] < posD)\r\n\t\t{\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\tif (d.length == 2 && d in first2 && first2[d] < posD)\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 n = readln.strip.to !(int);\r\n\t\tauto s = new string [n];\r\n\t\tforeach (ref c; s)\r\n\t\t{\r\n\t\t\tc = readln.strip;\r\n\t\t}\r\n\t\twriteln (solve (s, n) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std;\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 X = new string[N];\r\n foreach (i; 0 .. N) X[i] = readln.chomp;\r\n\r\n bool f() {\r\n bool[string] s;\r\n foreach (i; 0 .. N) {\r\n auto x = X[i];\r\n auto r = reverse(x.dup);\r\n if (x == r) return true;\r\n if (r in s) return true;\r\n if (x.length == 2) {\r\n for (char c = 'a'; c <= 'z'; c++) {\r\n auto x1 = [c] ~ x;\r\n auto r1 = reverse(x1.dup);\r\n if (r1 in s) return true;\r\n }\r\n } else if (x.length == 3) {\r\n auto x1 = x[1 .. $];\r\n auto r1 = reverse(x1.dup);\r\n if (r1 in s) return true;\r\n }\r\n s[x] = true;\r\n }\r\n return false;\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"}], "negative_code": [{"source_code": "import std;\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 X = new string[N];\r\n foreach (i; 0 .. N) X[i] = readln.chomp;\r\n\r\n bool f() {\r\n bool[string] s;\r\n foreach (i; 0 .. N) {\r\n auto x = X[i];\r\n if (x.length == 1) return true;\r\n auto r = reverse(x.dup);\r\n if (x == r) return true;\r\n if (r in s) return true;\r\n if (x.length == 2) {\r\n for (char c = 'a'; c <= 'z'; c++) {\r\n auto r1 = [c] ~ r;\r\n if (r1 in s) return true;\r\n }\r\n } else if (x.length == 3) {\r\n auto x1 = x[1 .. $];\r\n auto r1 = reverse(x1.dup);\r\n if (r1 in s) return true;\r\n }\r\n s[x] = true;\r\n }\r\n return false;\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"}, {"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, int n)\r\n{\r\n\tif (s.any !(c => c.front == c.back))\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n\tauto t = s.map !(c => c.retro.text).array;\r\n\tint [string] first;\r\n\tint [string] last;\r\n\tforeach_reverse (i; 0..n)\r\n\t{\r\n\t\tfirst[s[i][0..2]] = i;\r\n\t}\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tlast[t[i][0..2]] = i;\r\n\t}\r\n\tforeach (c, posC; first)\r\n\t{\r\n\t\tif (c in last && posC < last[c])\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 n = readln.strip.to !(int);\r\n\t\tauto s = new string [n];\r\n\t\tforeach (ref c; s)\r\n\t\t{\r\n\t\t\tc = readln.strip;\r\n\t\t}\r\n\t\twriteln (solve (s, n) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "src_uid": "6d5aefc5a08194e35826764d60c8db3c"} {"source_code": "import std.algorithm, std.array, std.stdio, std.string;\nvoid main () {\n\tauto s = readln.strip;\n\tbool [string] ans;\n\tauto n = s.length;\n\tauto f = new bool [2] [n + 1];\n\tf[n] = [true, true];\n\tforeach_reverse (p; 0..n + 1)\n\t\tforeach (k; 0..2) {\n\t\t\tint m = k + 2;\n\t\t\tif (p - m >= 5 && (f[p][!k] || f[p][k] && (p + m > n || s[p..p + m] != s[p - m..p]))) {\n\t\t\t\tf[p - m][k] = true;\n\t\t\t\tans[s[p - m..p]] = true;\n\t\t\t}\n\t\t}\n\twritefln (\"%s%-(\\n%s%)\", ans.length, ans.byKey.array.sort);\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.chomp;\n auto N = S.length.to!int;\n\n auto used = new bool[][](N+1, 4);\n bool[string] ans;\n\n void dfs(int r, int plen) { // [0..r)\n if (used[r][plen]) return;\n used[r][plen] = true;\n \n foreach (i; 2..4) {\n if (r - i > 4 && (i != plen || S[r-i..r] != S[r..r+plen])) {\n ans[S[r-i..r]] = true;\n dfs(r-i, i);\n }\n }\n }\n\n dfs(N, 0);\n auto anss = ans.keys.dup;\n anss.sort();\n \n ans.keys.length.writeln;\n foreach (a; anss) a.writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tstring [] ans;\n\t\tauto n = s.length;\n\t\tauto f = new bool [2] [n + 1];\n\t\tf[n][0] = true;\n\t\tf[n][1] = true;\n\t\tfor (int p = n; p >= 5; p--)\n\t\t{\n\t\t\tif (p + 2 <= n && (f[p + 2][1] ||\n\t\t\t f[p + 2][0] && (p + 2 + 2 > n ||\n\t\t\t s[p + 2..p + 2 + 2] != s[p..p + 2])))\n\t\t\t{\n\t\t\t\tf[p][0] = true;\n\t\t\t\tans ~= s[p..p + 2];\n\t\t\t}\n\t\t\tif (p + 3 <= n && (f[p + 3][0] ||\n\t\t\t f[p + 3][1] && (p + 3 + 3 > n ||\n\t\t\t s[p + 3..p + 3 + 3] != s[p..p + 3])))\n\t\t\t{\n\t\t\t\tf[p][1] = true;\n\t\t\t\tans ~= s[p..p + 3];\n\t\t\t}\n\t\t}\n\n\t\tsort (ans);\n\t\tans = ans.uniq.array;\n\t\twriteln (ans.length);\n\t\tforeach (t; ans)\n\t\t{\n\t\t\twriteln (t);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "dd7ccfee8c2a19bf47d65d5a62ac0071"} {"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 letters = 26;\n\nvoid main ()\n{\n\tforeach (test; 0..readln.strip.to !(int))\n\t{\n\t\tauto s = readln.strip;\n\t\tauto n = readln.strip.to !(int);\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint [letters] num;\n\t\tforeach (ref c; s)\n\t\t{\n\t\t\tnum[c - 'a'] += 1;\n\t\t}\n\n\t\tauto answer = new char [n];\n\t\tchar now = 'z';\n\t\tint res = 0;\n\t\twhile (res < n)\n\t\t{\n\t\t\tauto zeroes = a.count (0);\n\t\t\twhile (num[now - 'a'] < zeroes)\n\t\t\t{\n\t\t\t\tnow = cast (char) (now - 1);\n\t\t\t}\n\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (a[i] == 0)\n\t\t\t\t{\n\t\t\t\t\tanswer[i] = now;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres += zeroes;\n\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (answer[i] == now)\n\t\t\t\t{\n\t\t\t\t\tforeach (j; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\ta[j] -= abs (i - j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (answer[i] == now)\n\t\t\t\t{\n\t\t\t\t\ta[i] = -1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnow = cast (char) (now - 1);\n\t\t}\n\t\twriteln (answer);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string : split, strip;\nimport std.algorithm : map, group, sort, filter;\nimport std.conv : to;\nimport std.utf : toUTF32;\nimport std.array : array;\nimport std.range : enumerate, walkLength;\nimport std.math : abs;\n\nvoid main()\n{\n int q;\n readf!\"%d\\n\"(q);\n\n foreach (i; 0..q) {\n int m;\n dchar[] s = readln.strip.toUTF32.dup;\n readf!\"%d\\n\"(m);\n auto t = readln.strip.split.map!(to!int).array;\n auto r = new dchar[m]; // result\n auto f = 0; // filled chars\n\n // letters available in s\n s.sort!\"a > b\";\n auto g = s.group;\n\n // fill zeros in t with largest available letter\n while (f < m) {\n // indices of zeros\n auto c = t.enumerate.filter!\"a.value == 0\".array;\n while (g.front[1] < c.length) {\n g.popFront;\n }\n\n foreach (e; c) {\n // fill zeros from largest valid letter\n r[e.index] = g.front[0];\n\n // update distance for all other letters\n foreach (j; 0..m) {\n if (t[j] > 0) {\n t[j] -= abs(cast(int) j - cast(int) e.index);\n }\n }\n\n t[e.index] = -1;\n }\n\n f += c.length;\n g.popFront; // letter is now invalid\n }\n\n writeln(r);\n }\n}"}], "negative_code": [], "src_uid": "bc2f2b98c50a0165b7204a6d595eec4b"} {"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.split.to!(int[]);\n writeln(n[1], \" \", n[2], \" \", n[2]);\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 auto a = r.nextA!uint (4);\n writeln (a[1], ' ', a[2], ' ', a[2]);\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\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto abcd = RDA;\n\t\tans[ti] = [abcd[1], abcd[2], abcd[2]];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0], \" \", e[1], \" \", e[2]);\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(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 abcd = RDA;\n\t\tans[ti] = [abcd[2], abcd[2], abcd[1]];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0], \" \", e[1], \" \", e[2]);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "821d48c9a67d37ad7acc50d4d0d0d723"} {"source_code": "import std.algorithm, std.string, std.stdio, std.conv, std.range ;\n\nvoid main()\n{\n auto nm = readln.split.map!(to!int);\n auto n = nm[0], m = nm[1];\n auto lines = n.iota.map!(_ => readln.chomp).array;\n lines = lines.strip!(a => a == repeat(\".\").take(lines[0].length).array.join(\"\"));\n auto lines1 = lines[0].length.iota.array.map!(i => lines.transversal(i).array);\n auto lines2 = lines1.strip!(a => a == repeat(\".\").take(lines1[0].length).array.join(\"\"));\n lines2[0].length.iota.array.map!(i => lines2.transversal(i).array).each!writeln;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.format;\nimport std.container;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\n\nclass Line\n{\n public const ptrdiff_t firstStar;\n public const ptrdiff_t lastStar;\n public const string line;\n\n this(in string line)\n {\n this.firstStar = std.string.indexOf(line, '*');\n this.lastStar = std.string.lastIndexOf(line, '*');\n this.line = line;\n }\n\n invariant()\n {\n assert(firstStar <= lastStar, format(\"Last star cannot be before the first one: %s, %s\", firstStar, lastStar));\n assert(firstStar >= 0 || (firstStar == -1 && lastStar == -1), \"Both indexes must be -1 or >= 0\");\n }\n}\n\nvoid testDotsCount(in string line, in ptrdiff_t firstStar, in ptrdiff_t lastStar)\n{\n Line l;\n l = new Line(line);\n assert(l.firstStar == firstStar, format(\"Bad first star index: expected %s, got %s\", firstStar, l.firstStar));\n assert(l.lastStar == lastStar, format(\"Bad last star index: expected %s, got %s\", lastStar, l.lastStar));\n}\n\nunittest\n{\n testDotsCount(\"..*...\", 2, 2);\n}\n\nunittest\n{\n testDotsCount(\"*...\", 0, 0);\n}\n\nunittest\n{\n testDotsCount(\"*\", 0, 0);\n}\n\nunittest\n{\n testDotsCount(\"***\", 0, 2);\n}\n\nunittest\n{\n testDotsCount(\"..***...*.*..\", 2, 10);\n}\n\nvoid main()\n{\n string firstLine = stdin.readln();\n int rows;\n int cols;\n formattedRead(firstLine, \"%s %s\", &rows, &cols);\n\n ptrdiff_t minFirstStar = -1;\n ptrdiff_t maxLastStar = -1;\n\n Line[50] lines;\n\n int firstLineWithStar = rows;\n int lastLineWithStar = 0;\n\n for (int i = 0; i < rows; i++) {\n Line l = new Line(stdin.readln());\n lines[i] = l;\n maxLastStar = max(maxLastStar, l.lastStar);\n if (l.firstStar != -1) {\n lastLineWithStar = i;\n firstLineWithStar = min(firstLineWithStar, i);\n if (minFirstStar == -1) {\n minFirstStar = l.firstStar;\n } else {\n minFirstStar = min(minFirstStar, l.firstStar);\n }\n }\n }\n for (int i = firstLineWithStar; i <= lastLineWithStar; i++)\n {\n stdout.writeln(lines[i].line[minFirstStar .. maxLastStar + 1]);\n }\n}\n\n\n\n"}], "negative_code": [], "src_uid": "d715095ff068f4d081b58fbfe103a02c"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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;\n\t\tauto b = RD;\n\t\tauto c = RD;\n\t\tauto n = RD;\n\t\tif ((a+b+c+n) % 3 != 0)\n\t\t\tcontinue;\n\t\t\n\t\tauto m = max(a, b, c);\n\t\tauto d = m * 3 - a - b - c;\n\t\tans[ti] = d <= n;\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.container;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.stdio;\nimport std.utf;\nimport std.math;\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 testCase:foreach(tc; 0 .. t)\n {\n long[3] a;\n read(a);\n long n = next!long;\n sort(a[]);\n if (a[2] - a[1] + a[2] - a[0] <= n)\n {\n n -= 2 * a[2] - a[1] - a[0];\n if (n % 3 == 0)\n {\n writeln(\"YES\");\n continue testCase;\n }\n }\n writeln(\"NO\");\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=0 && r-b>=0 && r-c>=0)\n\t\t\t{\n\t\t\t\twriteln(\"YES\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twriteln(\"NO\");\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"NO\");\n\t\t}\n\t}\n\treturn 0;\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 a, b, c, n;\n\t\treadf !(\" %s %s %s %s\") (a, b, c, n);\n\t\tauto s = a + b + c + n;\n\t\tbool ok = (s % 3 == 0);\n\t\ts /= 3;\n\t\tok &= (s >= a) && (s >= b) && (s >= c);\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\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\nbool solve()\n{\n int a = readInt;\n int b = readInt;\n int c = readInt;\n int n = readInt;\n int sum = a + b + c + n;\n if (sum % 3)\n {\n return false;\n }\n sum /= 3;\n return a <= sum && b <= sum && c <= sum;\n}\n\nvoid main()\n{\n int T = readInt;\n while (T--)\n {\n writeln(solve ? \"YES\" : \"NO\");\n }\n}\n"}], "negative_code": [], "src_uid": "bc5fb5d6882b86d83e5c86f21d806a52"} {"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 auto n = r.next!uint;\n writeln (n);\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 (_; 0..T) {\n auto N = readln.chomp.to!long;\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!int;\n\t\tans[ti] = n;\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;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!long;\n if (N == 1) {\n writeln(1);\n } else {\n writeln(2);\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 auto n = r.next!uint;\n writeln (n > 1 ? 2 : 1);\n }\n}\n\n"}], "src_uid": "740c05c036b646d8fb6b391af115d7f0"} {"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 long s, b;\r\n foreach (a; AA) {\r\n s += a;\r\n b += (a + X - 1) / X;\r\n }\r\n writeln((s + X - 1) / X, \" \", b);\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\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, 2);\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\tauto tot = a.sum;\r\n\t\tans[ti][0] = (tot+x-1) / x;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tans[ti][1] += (a[i]+x-1) / x;\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}"}, {"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 maxx = 0, rem = 0;\n foreach(a; arr){\n maxx += (a/x) + (a % x != 0);\n ll r = a % x;\n if(r == 0) r = x;\n rem += x - r;\n }\n writeln(maxx - rem/x, \" \", maxx);\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": [], "src_uid": "b36d7f840abe998185a988fe8dd2ec75"} {"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;\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;\nT lcm (T)(T a,T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow X binpow(X,Y)(X base,Y exp)\n\tif(!isFloatingPoint!Y && !is(typeof(exp.im)))\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)\n\tif(!isFloatingPoint!Y && !is(typeof(exp.im)))\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);}\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}\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\tint opCmp(ref const pair!(X,Y) s_) const pure nothrow\n\t{\n\t\tint cmp=0-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in 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)(in X a_) pure nothrow @property @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @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,in X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m] 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\n\n\nvoid main() {\n int n;\n while (read(&n)) {\n if (n == 1)\n writeln(\"-1\");//Thanks to Alexit.\n else\n foreach (y; n + 1L .. 1_000_000_001L) {\n //I just believe it works.\n long num = n * y;\n long denom = y - n;\n if (!(num % denom) && num / denom <= 1_000_000_000) {\n writeln(n, ' ', num / denom, ' ', y);\n break;\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.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\n\n\nvoid main() {\n int n;\n while (read(&n))\n foreach (y; n + 1L .. 1_000_000_001L) {\n //I just believe it works.\n long num = n * y;\n long denom = y - n;\n if (!(num % denom) && num / denom <= 1_000_000_000) {\n writeln(n, ' ', num / denom, ' ', y);\n break;\n }\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\n\n\nvoid main() {\n int n;\n while (read(&n))\n foreach (y; n + 1L .. 1_000_000_001L) {\n //I just believe it works.\n long num = n * y;\n long denom = y - n;\n if (!(num % denom)) {\n writeln(n, ' ', num / denom, ' ', y);\n break;\n }\n }\n}\n"}], "src_uid": "f60ea0f2caaec16894e84ba87f90c061"} {"source_code": "// stay simple, stay naive\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\n int n; readf!\"%d\"(n);\n int[] a = new int[n + 2];\n int[] cnt = new int[n + 2];\n foreach(i; 1 .. n + 1) {\n readf!\" %d\"(a[i]);\n cnt[a[i]]++;\n }\n int mx = 1;\n foreach(i; 2 .. n + 1) {\n if (cnt[i] > cnt[mx]) mx = i;\n }\n\n immutable int B = cast(int)(std.math.sqrt(cast(real)(n)));\n debug { writefln!\"B = %s\"(B); }\n int ans = 0;\n\n int[] c = new int[n + 1];\n foreach(i; 1 .. B) {\n int l = 1, tot = 0, num = i;\n void upd(int x, int d) {\n tot -= (c[x] == num);\n c[x] += d;\n tot += (c[x] == num);\n }\n foreach(r; 1 .. n + 1) {\n upd(a[r], 1);\n while (l <= r && c[a[r]] > num) {\n upd(a[l++], -1);\n }\n if (tot > 1) {\n ans = max(ans, r - l + 1);\n }\n }\n while (l <= n) {\n upd(a[l++], -1);\n }\n }\n debug { \"Fuck!\".writeln; }\n\n int[] lastPos = new int[n + 2];\n foreach(i; 1 .. n + 1) {\n if (i != mx && cnt[i] >= B) {\n foreach(j; 0 .. n + 1) {\n lastPos[j] = -1;\n }\n int t = cnt[mx];\n lastPos[t] = 0;\n foreach(j; 1 .. n + 1) {\n t += (a[j] == i) - (a[j] == mx);\n if (lastPos[t] == -1) lastPos[t] = j;\n else ans = max(ans, j - lastPos[t]);\n }\n }\n }\n\n ans.writeln;\n\n}\n", "positive_code": [{"source_code": "// stay simple, stay naive\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\n int n; readf!\"%d\"(n);\n int[] a = new int[n + 2];\n int[] cnt = new int[n + 2];\n foreach(i; 1 .. n + 1) {\n readf!\" %d\"(a[i]);\n cnt[a[i]]++;\n }\n int mx = 1;\n foreach(i; 2 .. n + 1) {\n if (cnt[i] > cnt[mx]) mx = i;\n }\n \n immutable int B = 314;\n int ans = 0;\n\n int[] c = new int[n + 1];\n foreach(i; 1 .. B) {\n int l = 1, tot = 0;\n void upd(int x, int d) {\n tot -= (c[x] == i);\n c[x] += d;\n tot += (c[x] == i);\n }\n foreach(r; 1 .. n + 1) {\n upd(a[r], 1);\n while (l <= r && c[a[r]] > i) {\n upd(a[l++], -1);\n }\n if (tot > 1) {\n ans = max(ans, r - l + 1);\n }\n }\n while (l <= n) {\n upd(a[l++], -1);\n }\n }\n debug { \"Fuck!\".writeln; }\n\n int[] lastPos = new int[n + 2];\n foreach(i; 1 .. n + 1) {\n if (i != mx && cnt[i] >= B) {\n foreach(j; 0 .. n + 1) {\n lastPos[j] = -1;\n }\n int t = cnt[mx];\n lastPos[t] = 0;\n foreach(j; 1 .. n + 1) {\n t += (a[j] == i) - (a[j] == mx);\n if (lastPos[t] == -1) lastPos[t] = j;\n else ans = max(ans, j - lastPos[t]);\n }\n }\n }\n \n ans.writeln;\n\n}\n"}], "negative_code": [], "src_uid": "c824b4c073262803060194c2ce1d14b7"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1520/problem/C\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\n if(n == 2) {\n \"-1\".writeln;\n continue;\n }\n\n int[][] matrix = new int[][](n,n);\n int i = 1;\n bool flag = false;\n for(int y = 0; y < n; ++y) {\n for(int x = 0; x < n; ++x) {\n if(!flag && i*2 > n*n) {\n flag = true;\n i = 1;\n }\n if(flag) {\n matrix[y][x] = i*2-1;\n i += 1;\n }\n else {\n matrix[y][x] = i*2;\n i+=1;\n }\n }\n }\n for(int k = 0; k < n; k++) {\n for(int j = 0; j < n; j++) {\n writef(\"%s \", matrix[k][j]);\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\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\r\n\t\tif (n == 2) continue;\r\n\r\n\t\tans[ti] = new int[][](n, n);\r\n\t\tint num = 1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tans[ti][i][i] = num;\r\n\t\t\t++num;\r\n\t\t}\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..n-i)\r\n\t\t\t{\r\n\t\t\t\tans[ti][i+j][j] = num;\r\n\t\t\t\t++num;\r\n\t\t\t}\r\n\t\t\tforeach (j; 0..n-i)\r\n\t\t\t{\r\n\t\t\t\tans[ti][j][i+j] = num;\r\n\t\t\t\t++num;\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\tee.map!(to!string).join(\" \").writeln;\r\n\t\t}\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "e215e94dd196dde381adc13406d2d72a"} {"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 cnt = new long[](n+1);\r\n\t\tforeach (i; 0..n)\r\n\t\t\tcnt[i+1] = cnt[i] + (a[i] == 0 ? 1 : 0);\r\n\t\tforeach (l; 0..n)\r\n\t\t{\r\n\t\t\tforeach (r; l+1..n+1)\r\n\t\t\t{\r\n\t\t\t\tans[ti] += r-l + cnt[r]-cnt[l];\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\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\tauto x = new int [] [] (n + 1, n + 1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n + 1)\r\n\t\t\t{\r\n\t\t\t\tbool [int] s;\r\n\t\t\t\tforeach (k; i..j)\r\n\t\t\t\t{\r\n\t\t\t\t\ts[a[k]] = true;\r\n\t\t\t\t}\r\n\t\t\t\tx[i][j] = 0;\r\n\t\t\t\twhile (x[i][j] in s)\r\n\t\t\t\t{\r\n\t\t\t\t\tx[i][j] += 1;\r\n\t\t\t\t}\r\n\t\t\t\tx[i][j] += 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto f = new int [] [] (n + 1, n + 1);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; i + 1..n + 1)\r\n\t\t\t{\r\n\t\t\t\tf[i][j] = x[i][j];\r\n\t\t\t\tforeach (k; i..j)\r\n\t\t\t\t{\r\n\t\t\t\t\tf[i][j] = max (f[i][j],\r\n\t\t\t\t\t f[i][k] + x[k][j]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\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 + 1)\r\n\t\t\t{\r\n\t\t\t\tres += f[i][j];\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}, {"source_code": "// cheese-cracker [2022-02-12]\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n long summ = 0;\n for(int i = 1; i <= n; ++i){\n summ += i * (n + 1 - i);\n }\n for(int i = 1; i <= n; ++i){\n if(arr[i-1] == 0){\n summ += i * (n + 1 - i);\n }\n }\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; 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 auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt;\n }\n \n auto mex = new int[][](N + 1, N + 1);\n foreach (i; 0 .. N) {\n bool[int] app;\n foreach (j; i .. N) {\n app[A[j]] = true;\n for (int x = 0; ; ++x) {\n if (x !in app) {\n mex[i][j + 1] = x;\n break;\n }\n }\n }\n }\n \n auto dp = new int[][](N + 1, N + 1);\n foreach_reverse (i; 0 .. N) foreach (j; i + 1 .. N + 1) {\n dp[i][j] = 1 + mex[i][j];\n foreach (k; i + 1 .. j) {\n chmax(dp[i][j], dp[i][k] + dp[k][j]);\n }\n }\n int ans;\n foreach_reverse (i; 0 .. N) foreach (j; i + 1 .. N + 1) {\n ans += dp[i][j];\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "8775da9b78d8236c4606d150df450952"} {"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 sorted = arr.array.sort;\r\n \r\n if(arr.equal(sorted))\r\n writeln(0);\r\n else if(arr[0] == 1 || arr[arr.length-1] == arr.length)\r\n writeln(1);\r\n else if(arr[0] != arr.length || arr[arr.length-1] != 1)\r\n writeln(2);\r\n else\r\n writeln(3);\r\n }\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1525/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;\n readf(\"%d\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%d\\n\", &n);\n int[] a = readln.split.map!(to!int).array;\n bool is_sorted = true;\n for(int i = 1; i < n; ++i) {\n if(a[i] < a[i - 1]) {\n is_sorted = false;\n break;\n }\n }\n if(is_sorted) {\n \"0\".writeln;\n continue;\n }\n if(a[0] == 1 || a[$-1] == n) {\n \"1\".writeln;\n continue;\n }\n if(a[0] == n && a[$-1] == 1) {\n \"3\".writeln;\n continue;\n }\n \"2\".writeln;\n}\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\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 sorted = arr.array.sort;\r\n \r\n if(arr.equal(sorted))\r\n writeln(0);\r\n else if(arr[0] == 1 || arr[arr.length-1] == arr.length)\r\n writeln(1);\r\n else if(arr[0] != arr.length || arr[arr.length-1] == 1)\r\n writeln(2);\r\n else\r\n writeln(3);\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;\r\n auto sorted = arr.array.sort.array;\r\n \r\n int res = 0;\r\n int o = 0;\r\n int e = 0;\r\n \r\n if(arr == sorted)\r\n writeln(0);\r\n else if(arr[0] == 1 || arr[$] == arr.length)\r\n writeln(1);\r\n else if(arr[0] != arr.length || arr[$] == 1)\r\n writeln(2);\r\n else\r\n writeln(3);\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;\r\n \r\n int res = 0;\r\n int o = 0;\r\n int e = 0;\r\n while(e < arr.length)\r\n {\r\n if(arr[e] != e+1)\r\n {\r\n res++;\r\n while(e < arr.length && arr[e] != e+1)\r\n e++;\r\n e--;\r\n }\r\n else \r\n {\r\n o++;\r\n }\r\n e++;\r\n }\r\n \r\n if(o == 0)\r\n writeln(res+1);\r\n else\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;\r\n \r\n int res = 0;\r\n int o = 0;\r\n int e = 0;\r\n while(e < arr.length)\r\n {\r\n if(arr[e] != e+1)\r\n {\r\n res++;\r\n while(e < arr.length && arr[e] != e+1)\r\n e++;\r\n e--;\r\n }\r\n else \r\n {\r\n o++;\r\n }\r\n e++;\r\n }\r\n \r\n if(o == 0)\r\n writeln(2);\r\n else\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;\r\n \r\n int res = 0;\r\n int o = 0;\r\n int e = 0;\r\n while(e < arr.length)\r\n {\r\n if(arr[e] != e+1)\r\n {\r\n res++;\r\n while(e < arr.length && arr[e] != e+1)\r\n e++;\r\n }\r\n else \r\n {\r\n o++;\r\n }\r\n e++;\r\n }\r\n \r\n if(o == 0)\r\n writeln(2);\r\n else\r\n writeln(res);\r\n }\r\n}"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1525/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;\n readf(\"%d\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%d\\n\", &n);\n int[] a = readln.split.map!(to!int).array;\n bool is_sorted = true;\n for(int i = 1; i < n; ++i) {\n if(a[i] < a[i - 1]) {\n is_sorted = false;\n break;\n }\n }\n if(is_sorted) {\n \"0\".writeln;\n continue;\n }\n if(a[0] == 1 || a[$-1] == 1) {\n \"1\".writeln;\n continue;\n }\n if(a[0] == n && a[$-1] == 1) {\n \"3\".writeln;\n continue;\n }\n \"2\".writeln;\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1525/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;\n readf(\"%d\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%d\\n\", &n);\n int[] a = readln.split.map!(to!int).array;\n bool is_sorted = true;\n for(int i = 1; i < n; ++i) {\n if(a[i] < a[i - 1]) {\n is_sorted = false;\n break;\n }\n }\n if(is_sorted) {\n \"0\".writeln;\n continue;\n }\n if(a[0] == 1) {\n \"1\".writeln;\n continue;\n }\n if(a[0] == n && a[$-1] == 1) {\n \"3\".writeln;\n continue;\n }\n \"2\".writeln;\n}\n}\n\n"}], "src_uid": "c212524cc1ad8e0332693e3cf644854b"} {"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 a = uninitializedArray!(uint[][]) (n, m);\n auto b = uninitializedArray!(uint[][]) (n, m);\n foreach (i; 0 .. n) foreach (j; 0 .. m) a[i][j] = r.next!uint;\n foreach (i; 0 .. n) foreach (j; 0 .. m) b[i][j] = r.next!uint;\n bool test () {\n foreach (d; 0 .. n + m - 1) {\n uint[] X, Y;\n foreach (i; 0 .. n) {\n immutable j = d - i;\n if (j >= 0 && j < m) {\n X ~= a[i][j];\n Y ~= b[i][j];\n }\n }\n X.sort ();\n Y.sort ();\n debug stderr.writeln (\"d = \", d);\n debug stderr.writeln (\"X = \", X);\n debug stderr.writeln (\"Y = \", Y);\n if (!equal (X, Y)) return false;\n }\n return true;\n }\n write (test () ? \"YES\" : \"NO\");\n}\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, zip;\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\n int n, m;\n\n readf(\" %s %s\", n, m);\n auto a = new int[][n];\n auto diga = new int[][m+n];\n foreach(i; 0.. n) {\n a[i] = new int[m];\n\n foreach(j; 0..m) {\n readf(\" %s\", a[i][j]);\n diga[i+j] ~= a[i][j];\n }\n }\n\n auto b = new int[][n];\n auto digb = new int[][m+n];\n foreach(i; 0.. n) {\n b[i] = new int[m];\n\n foreach(j; 0..m) {\n readf(\" %s\", b[i][j]);\n digb[i+j] ~= b[i][j];\n }\n }\n\n foreach(i;0..m+n) {\n sort(diga[i]);\n sort(digb[i]);\n //foreach\n //bool eq = zip(diga[i], digb[i]).array.all!(a=>a[0]==a[1]);\n foreach(j;0..diga[i].length) {\n if (diga[i][j] != digb[i][j]) { writeln(\"NO\"); return; }\n }\n }\n\n\n // writeln(a);\n // writeln(b);\n\n writeln(\"YES\");\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, zip;\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\n int n, m;\n\n readf(\" %s %s\", n, m);\n auto a = new int[][n];\n auto diga = new int[][2*n];\n foreach(i; 0.. n) {\n a[i] = new int[m];\n\n foreach(j; 0..m) {\n readf(\" %s\", a[i][j]);\n diga[i+j] ~= a[i][j];\n }\n }\n\n auto b = new int[][n];\n auto digb = new int[][2*n];\n foreach(i; 0.. n) {\n b[i] = new int[m];\n\n foreach(j; 0..m) {\n readf(\" %s\", b[i][j]);\n digb[i+j] ~= b[i][j];\n }\n }\n\n foreach(i;0..2*n) {\n sort(diga[i]);\n sort(digb[i]);\n //foreach\n //bool eq = zip(diga[i], digb[i]).array.all!(a=>a[0]==a[1]);\n foreach(j;0..diga[i].length) {\n if (diga[i][j] != digb[i][j]) { writeln(\"NO\"); return; }\n }\n }\n\n\n // writeln(a);\n // writeln(b);\n\n writeln(\"YES\");\n\n}\n"}], "src_uid": "77e2ddc4684fccd1856c93c2fc6e1ce2"} {"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\nconst INF = 1<<28;\n\nstring s;\n\nbool isVowel(char c) {\n return \"aiueoAIUEO\".count(c) > 0;\n}\n\nvoid main() {\n s = readln.chomp;\n int N = cast(int)s.length;\n auto xs = new int[N];\n foreach (i, c; s) {\n xs[i] = c.isVowel ? -1 : 2;\n }\n auto sum = new int[N + 1]; sum[0] = 0;\n foreach (int i; 0 .. N) {\n sum[i + 1] = sum[i] + xs[i];\n }\n struct P {\n int index, value;\n }\n\n auto ys = new P[N + 1];\n foreach (int i; 0 .. N + 1) {\n ys[i] = P(i, sum[i]);\n }\n ys.sort!\"a.value == b.value ? a.index < b.index : a.value < b.value\";\n auto t = new RedBlackTree!int(iota(0, N + 1, 1).array);\n int ans = 0;\n foreach (y; ys) {\n auto end = t.back;\n ans = max(ans, end - y.index);\n t.removeKey(y.index);\n }\n\n if (ans == 0) {\n writeln(\"No solution\");\n return;\n }\n\n int count = 0;\n foreach (int i; 0 .. N + 1) {\n if (i + ans > N) break;\n if (sum[i + ans] - sum[i] >= 0) {\n count++;\n }\n }\n writeln(ans, \" \", count);\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\nstring s;\n\nbool isVowel(dchar c) {\n return \"aiueo\".count(std.ascii.toLower(c)) > 0;\n}\n\nvoid main() {\n s = readln.chomp.dup;\n int N = cast(int)s.length;\n\n auto sum = new int[N + 1];\n sum[0] = 0;\n foreach (int i, c; s) {\n sum[i + 1] = sum[i] + (!c.isVowel);\n }\n //writeln(sum);\n\n bool check(int c) {\n int minLen = int.max / 2;\n for (int i = 0; i < N; i++) {\n int lb = i, ub = N; // (lb, ub]\n if (sum[N] - sum[i] < c) break;\n while (lb + 1 < ub) {\n int mid = (lb + ub) / 2;\n //writeln(\"c\", [lb, ub]);\n (sum[mid] - sum[i] >= c ? ub : lb) = mid;\n }\n minLen = min(minLen, ub - i);\n }\n //writeln([c, minLen]);\n return 3 * c >= minLen;\n }\n\n int lb = 0, ub = sum[N] + 1;\n while (lb + 1 < ub) {\n //writeln([lb, ub]);\n int mid = (lb + ub) / 2;\n (check(mid) ? lb : ub) = mid;\n }\n int ans = min(N, lb * 3);\n\n if (ans == 0) {\n writeln(\"No solution\");\n return;\n }\n\nfirst:\n int count = 0;\n for (int i = 0; i < N; i++) {\n if (i + ans > N) break;\n if ( 3 * (sum[i + ans] - sum[i]) >= ans ) {\n if ( ans != min(ans * 2, N - i) && 3 * (sum[min(i + ans * 2, N)] - sum[i]) >= min(ans * 2, N - i) ) {\n ans = min(ans * 2, N - i);\n goto first;\n }\n count++;\n }\n }\n writeln(ans, \" \", count);\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\nstring s;\n\nbool isVowel(dchar c) {\n return \"aiueo\".count(std.ascii.toLower(c)) > 0;\n}\n\nvoid main() {\n s = readln.chomp.dup;\n int N = cast(int)s.length;\n\n auto sum = new int[N + 1];\n sum[0] = 0;\n foreach (int i, c; s) {\n sum[i + 1] = sum[i] + (!c.isVowel);\n }\n //writeln(sum);\n\n bool check(int l) {\n for (int i = 0; i < N; i++) {\n if (i + l > N) break;\n if ( 3 * (sum[i + l] - sum[i]) >= l ) return true;\n }\n return false;\n }\n \n int lb = 0, ub = N + 1;\n while (lb + 1 < ub) {\n int mid = (lb + ub) / 2;\n (check(mid) ? lb : ub) = mid;\n }\n int ans = lb;\n\n if (ans == 0) {\n writeln(\"No solution\");\n return;\n }\n\n int count = 0;\n for (int i = 0; i < N; i++) {\n if (i + ans > N) break;\n if ( 3 * (sum[i + ans] - sum[i]) >= ans ) {\n count++;\n }\n }\n writeln(ans, \" \", count);\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\nstring s;\n\nbool isVowel(dchar c) {\n return \"aiueo\".count(std.ascii.toLower(c)) > 0;\n}\n\nvoid main() {\n s = readln.chomp.dup;\n int N = cast(int)s.length;\n\n auto sum = new int[N + 1];\n sum[0] = 0;\n foreach (int i, c; s) {\n sum[i + 1] = sum[i] + (!c.isVowel);\n }\n //writeln(sum);\n\n bool check(int c) {\n int minLen = N;\n for (int i = 0; i < N; i++) {\n int lb = i, ub = N; // (lb, ub]\n if (sum[N] - sum[i] < c) break;\n while (lb + 1 < ub) {\n int mid = (lb + ub) / 2;\n (sum[mid] - sum[i] >= c ? lb : ub) = mid;\n }\n minLen = min(minLen, ub);\n }\n return 3 * c >= minLen;\n }\n \n int lb = 0, ub = sum[N] + 1;\n while (lb + 1 < ub) {\n //writeln([lb, ub]);\n int mid = (lb + ub) / 2;\n (check(mid) ? lb : ub) = mid;\n }\n int ans = min(N, lb * 3);\n\n if (ans == 0) {\n writeln(\"No solution\");\n return;\n }\n\n int count = 0;\n for (int i = 0; i < N; i++) {\n if (i + ans > N) break;\n if ( 3 * (sum[i + ans] - sum[i]) >= ans ) {\n count++;\n }\n }\n writeln(ans, \" \", count);\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\nstring s;\n\nbool isVowel(dchar c) {\n return \"aiueo\".count(std.ascii.toLower(c)) > 0;\n}\n\nvoid main() {\n s = readln.chomp.dup;\n int N = cast(int)s.length;\n\n auto sum = new int[N + 1];\n sum[0] = 0;\n foreach (int i, c; s) {\n sum[i + 1] = sum[i] + (!c.isVowel);\n }\n //writeln(sum);\n\n bool check(int c) {\n int minLen = int.max / 2;\n for (int i = 0; i < N; i++) {\n int lb = i, ub = N; // (lb, ub]\n if (sum[N] - sum[i] < c) break;\n while (lb + 1 < ub) {\n int mid = (lb + ub) / 2;\n //writeln(\"c\", [lb, ub]);\n (sum[mid] - sum[i] >= c ? ub : lb) = mid;\n }\n minLen = min(minLen, ub - i);\n }\n //writeln([c, minLen]);\n return 3 * c >= minLen;\n }\n\n int lb = 0, ub = sum[N] + 1;\n while (lb + 1 < ub) {\n //writeln([lb, ub]);\n int mid = (lb + ub) / 2;\n (check(mid) ? lb : ub) = mid;\n }\n int ans = min(N, lb * 3);\n\n if (ans == 0) {\n writeln(\"No solution\");\n return;\n }\n\n int count = 0;\n for (int i = 0; i < N; i++) {\n if (i + ans > N) break;\n if ( 3 * (sum[i + ans] - sum[i]) >= ans ) {\n count++;\n }\n }\n writeln(ans, \" \", count);\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\nconst INF = 1<<28;\n\nstring s;\n\nbool isVowel(char c) {\n return \"aiueoAIUEO\".count(c) > 0;\n}\n\nvoid main() {\n s = readln.chomp;\n int N = cast(int)s.length;\n auto xs = new int[N];\n foreach (i, c; s) {\n xs[i] = c.isVowel ? -1 : 2;\n }\n auto sum = new int[N + 1]; sum[0] = 0;\n foreach (int i; 0 .. N) {\n sum[i + 1] = sum[i] + xs[i];\n }\n struct P {\n int index, value;\n }\n\n auto ys = new P[N + 1];\n foreach (int i; 0 .. N + 1) {\n ys[i] = P(i, sum[i]);\n }\n ys.sort!\"a.value == b.value ? a.index < b.index : a.value < b.value\";\n auto t = new RedBlackTree!int(iota(0, N + 1, 1).array);\n int ans = 0;\n foreach (y; ys) {\n auto end = t.back;\n ans = max(ans, end - y.index);\n t.removeKey(y.index);\n }\n\n if (ans == 0) {\n writeln(\"No solution\");\n }\n\n int count = 0;\n foreach (int i; 0 .. N + 1) {\n if (i + ans > N) break;\n if (sum[i + ans] - sum[i] >= 0) {\n count++;\n }\n }\n writeln(ans, \" \", count);\n}\n"}], "src_uid": "763aa950a9a8e5c975a6028e014de20f"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.typecons, std.math, std.array;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array.sort.array;\n long mindiff = a[1] - a[0];\n size_t minidx = 0;\n foreach (i ; 1 .. n - 1) {\n if (a[i + 1] - a[i] < mindiff) {\n mindiff = a[i + 1] - a[i];\n minidx = i;\n }\n }\n// writeln(mindiff);\n// writeln(minidx);\n// writeln(a);\n if (a.length <= 2) {\n writeln(a.map!text.joiner(\" \"));\n } else {\n auto b = a[minidx + 1 .. $] ~ a[0 .. minidx + 1];\n writeln(b.map!text.joiner(\" \"));\n }\n }\n}\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1537/problem/C\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 int n = readln.chomp.to!int;\n long[] h = readln.split.map!(to!long).array;\n\n h.sort;\n\n if(n == 2) {\n writefln(\"%s %s\", h[0], h[1]);\n continue;\n }\n\n int idx = 0;\n long minima = long.max;\n\n for(int i = 0; i < n - 1; ++i) {\n if(h[i + 1] - h[i] < minima) {\n minima = h[i + 1] - h[i];\n idx = i + 1;\n }\n }\n for(int i = idx; i < n; ++i) {\n writef(\"%s \", h[i]);\n }\n for(int i = 0; i < idx; ++i) {\n writef(\"%s \", h[i]);\n }\n \"\".writeln;\n}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.typecons, std.math, std.array;\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long).array.sort.array;\n long mindiff = a[1] - a[0];\n size_t minidx = 0;\n foreach (i ; 1 .. n - 1) {\n if (a[i + 1] - a[i] < mindiff) {\n mindiff = a[i + 1] - a[i];\n minidx = i;\n }\n }\n auto b = a[minidx .. $] ~ a[0 .. minidx];\n writeln(b.map!text.joiner(\" \"));\n }\n}\n"}], "src_uid": "3342e71884677534b7a126f89d441585"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto a = scanArray;\n auto b = scanArray;\n tup[] zipp;\n for(int i = 0; i < n; ++i){\n zipp ~= tup(a[i], b[i], i);\n }\n zipp.sort;\n /* long[] mxf; */\n /* long mx = 0; */\n /* for(int i = 0; i < n; ++i){ */\n /* mx = max(mx, b[i]); */\n /* mxf ~= mx; */\n /* } */\n /* long[] mxr = new long[](n); */\n /* mx = 0; */\n /* for(int i = n-1; i >= 0; --i){ */\n /* mx = max(mx, b[i]); */\n /* mxr[i] = mx; */\n /* } */\n /* show(mxf, mxr); */\n dchar[] res = new dchar[](n);\n res[] = '0';\n dchar cr = '0';\n long last = zipp[n-1][1];\n\n long lef = 0;\n b.sort;\n long[int] bvals;\n for(int i = n-1; i >= 0; --i){\n bvals[b[i].to!int] = lef++;\n }\n long left = 0;\n long c = 0;\n for(int i = n-1; i >= 0; --i){\n left = max(left, bvals[zipp[i][1].to!int]);\n res[zipp[i][2]] = '1';\n show(left, i);\n if(left - c == 0){\n break;\n }\n ++c;\n }\n\n /* /1* for(int i = 0; i < n; ++i){ *1/ */\n /* /1* if(mxf[i] >= mxr[i]){ *1/ */\n /* if(zipp[i][1] >= zipp[n-1][1]){ */\n /* cr = '1'; */\n /* /1* res[zipp[i][2]] = '1'; *1/ */\n /* }else{ */\n /* } */\n /* res[zipp[i][2]] = cr; */\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, long, int);\n", "positive_code": [{"source_code": "// Not my code! Taken from https://codeforces.com/contest/1608/submission/138747137\n// Added a @trusted readln wrapper, removed assumeSafeAppend and marked everything as @safe\n// Then commented out safe.\n\n//@safe:\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nauto readln() @trusted { return std.stdio.readln; }\n\nvoid main ()\n{\n auto tests = readln.strip.to !(int);\n foreach (test; 0..tests)\n {\n\tauto n = readln.strip.to !(int);\n\tauto a0 = readln.splitter.map !(to !(int)).array;\n\tauto b0 = readln.splitter.map !(to !(int)).array;\n\tauto answer = new int [n];\n\n\tvoid solve (const ref int [] a, const ref int [] b)\n\t{\n\t auto s = redBlackTree !((i, j) => a[i] < a[j], int);\n\t auto t = redBlackTree !((i, j) => b[i] < b[j], int);\n\t foreach (i; 0..n)\n\t {\n\t\ts.insert (i);\n\t\tt.insert (i);\n\t }\n\t auto p = n.iota.array;\n\t p.sort !((i, j) => a[i] < a[j]);\n\n\t foreach (i; p)\n\t {\n\t\tauto q = [i];\n\t\twhile (!q.empty)\n\t\t{\n\t\t auto j = q.front;\n\t\t q.popFront ();\n\n\t\t while (true)\n\t\t {\n\t\t\tauto slo = s.lowerBound (j);\n\t\t\tif (slo.empty)\n\t\t\t{\n\t\t\t break;\n\t\t\t}\n\t\t\tauto k = slo.front;\n\t\t\ts.removeKey (k);\n\t\t\tt.removeKey (k);\n\t\t\tq ~= k;\n\t\t }\n\n\t\t while (true)\n\t\t {\n\t\t\tauto tlo = t.lowerBound (j);\n\t\t\tif (tlo.empty)\n\t\t\t{\n\t\t\t break;\n\t\t\t}\n\t\t\tauto k = tlo.front;\n\t\t\ts.removeKey (k);\n\t\t\tt.removeKey (k);\n\t\t\tq ~= k;\n\t\t }\n\t\t}\n\n\t\tauto left = s.upperBound (i);\n\t\tif (left.empty)\n\t\t{\n\t\t answer[i] = 1;\n\t\t}\n\t }\n\t}\n\n\tsolve (a0, b0);\n\tsolve (b0, a0);\n\twritefln !(\"%(%s%)\") (answer);\n }\n}\n"}, {"source_code": "// Not my code! Taken from https://codeforces.com/contest/1608/submission/138747137\n// Added a @trusted readln wrapper, removed assumeSafeAppend and marked everything as @safe\n\n@safe:\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nauto readln() @trusted { return std.stdio.readln; }\n\nvoid main ()\n{\n auto tests = readln.strip.to !(int);\n foreach (test; 0..tests)\n {\n\tauto n = readln.strip.to !(int);\n\tauto a0 = readln.splitter.map !(to !(int)).array;\n\tauto b0 = readln.splitter.map !(to !(int)).array;\n\tauto answer = new int [n];\n\n\tvoid solve (const ref int [] a, const ref int [] b)\n\t{\n\t auto s = redBlackTree !((i, j) => a[i] < a[j], int);\n\t auto t = redBlackTree !((i, j) => b[i] < b[j], int);\n\t foreach (i; 0..n)\n\t {\n\t\ts.insert (i);\n\t\tt.insert (i);\n\t }\n\t auto p = n.iota.array;\n\t p.sort !((i, j) => a[i] < a[j]);\n\n\t foreach (i; p)\n\t {\n\t\tauto q = [i];\n\t\twhile (!q.empty)\n\t\t{\n\t\t auto j = q.front;\n\t\t q.popFront ();\n\n\t\t while (true)\n\t\t {\n\t\t\tauto slo = s.lowerBound (j);\n\t\t\tif (slo.empty)\n\t\t\t{\n\t\t\t break;\n\t\t\t}\n\t\t\tauto k = slo.front;\n\t\t\ts.removeKey (k);\n\t\t\tt.removeKey (k);\n\t\t\tq ~= k;\n\t\t }\n\n\t\t while (true)\n\t\t {\n\t\t\tauto tlo = t.lowerBound (j);\n\t\t\tif (tlo.empty)\n\t\t\t{\n\t\t\t break;\n\t\t\t}\n\t\t\tauto k = tlo.front;\n\t\t\ts.removeKey (k);\n\t\t\tt.removeKey (k);\n\t\t\tq ~= k;\n\t\t }\n\t\t}\n\n\t\tauto left = s.upperBound (i);\n\t\tif (left.empty)\n\t\t{\n\t\t answer[i] = 1;\n\t\t}\n\t }\n\t}\n\n\tsolve (a0, b0);\n\tsolve (b0, a0);\n\twritefln !(\"%(%s%)\") (answer);\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 auto B = readarray!int;\r\n auto IDX = iota(N).array.sort!((i, j) => B[i] > B[j]).array;\r\n int limA = A[IDX[0]];\r\n char[] ans = new char[N]; ans[] = '0';\r\n ans[IDX[0]] = '1';\r\n auto M = new int[N];\r\n M[N-1] = A[IDX[N-1]];\r\n for (int i = N - 2; i >= 0; i--) {\r\n M[i] = max(M[i+1], A[IDX[i]]);\r\n }\r\n for (int i = 1; i < N; i++) {\r\n int k = IDX[i];\r\n /*\r\n writeln([i, k]);\r\n writeln(\"M[k]: \", M[k]);\r\n writeln(\"limA: \", limA);\r\n */\r\n if (M[i] > limA) {\r\n ans[k] = '1';\r\n limA = min(limA, A[k]);\r\n }\r\n }\r\n writeln(ans);\r\n}\r\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\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 a0 = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b0 = readln.splitter.map !(to !(int)).array;\r\n\t\tauto answer = new int [n];\r\n\r\n\t\tvoid solve (const ref int [] a, const ref int [] b)\r\n\t\t{\r\n\t\t\tauto s = redBlackTree !((i, j) => a[i] < a[j], int);\r\n\t\t\tauto t = redBlackTree !((i, j) => b[i] < b[j], int);\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\ts.insert (i);\r\n\t\t\t\tt.insert (i);\r\n\t\t\t}\r\n\t\t\tauto p = n.iota.array;\r\n\t\t\tp.sort !((i, j) => a[i] < a[j]);\r\n\r\n\t\t\tforeach (i; p)\r\n\t\t\t{\r\n\t\t\t\tauto q = [i];\r\n\t\t\t\twhile (!q.empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto j = q.front;\r\n\t\t\t\t\tq.popFront ();\r\n\t\t\t\t\tq.assumeSafeAppend ();\r\n\r\n\t\t\t\t\twhile (true)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tauto slo = s.lowerBound (j);\r\n\t\t\t\t\t\tif (slo.empty)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tauto k = slo.front;\r\n\t\t\t\t\t\ts.removeKey (k);\r\n\t\t\t\t\t\tt.removeKey (k);\r\n\t\t\t\t\t\tq ~= k;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\twhile (true)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tauto tlo = t.lowerBound (j);\r\n\t\t\t\t\t\tif (tlo.empty)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tauto k = tlo.front;\r\n\t\t\t\t\t\ts.removeKey (k);\r\n\t\t\t\t\t\tt.removeKey (k);\r\n\t\t\t\t\t\tq ~= k;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tauto left = s.upperBound (i);\r\n\t\t\t\tif (left.empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[i] = 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tsolve (a0, b0);\r\n\t\tsolve (b0, a0);\r\n\t\twritefln !(\"%(%s%)\") (answer);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto a = scanArray;\n auto b = scanArray;\n tup[] zipp;\n for(int i = 0; i < n; ++i){\n zipp ~= tup(a[i], b[i], i);\n }\n zipp.sort;\n /* long[] mxf; */\n /* long mx = 0; */\n /* for(int i = 0; i < n; ++i){ */\n /* mx = max(mx, b[i]); */\n /* mxf ~= mx; */\n /* } */\n /* long[] mxr = new long[](n); */\n /* mx = 0; */\n /* for(int i = n-1; i >= 0; --i){ */\n /* mx = max(mx, b[i]); */\n /* mxr[i] = mx; */\n /* } */\n /* show(mxf, mxr); */\n dchar[] res = new dchar[](n);\n res[] = '0';\n dchar cr = '0';\n long last = zipp[n-1][1];\n\n long lef = 0;\n b.sort;\n long[int] bvals;\n for(int i = n-1; i >= 0; --i){\n bvals[b[i].to!int] = ++lef;\n }\n long left = 0;\n long c = 0;\n for(int i = n-1; i >= 0; --i){\n left = max(left, bvals[zipp[i][1].to!int]) - c;\n res[zipp[i][2]] = '1';\n show(left, i);\n if(left == 0){\n break;\n }\n ++c;\n }\n\n /* /1* for(int i = 0; i < n; ++i){ *1/ */\n /* /1* if(mxf[i] >= mxr[i]){ *1/ */\n /* if(zipp[i][1] >= zipp[n-1][1]){ */\n /* cr = '1'; */\n /* /1* res[zipp[i][2]] = '1'; *1/ */\n /* }else{ */\n /* } */\n /* res[zipp[i][2]] = cr; */\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, long, int);\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto a = scanArray;\n auto b = scanArray;\n tup[] zipp;\n for(int i = 0; i < n; ++i){\n zipp ~= tup(a[i], b[i], i);\n }\n zipp.sort;\n /* long[] mxf; */\n /* long mx = 0; */\n /* for(int i = 0; i < n; ++i){ */\n /* mx = max(mx, b[i]); */\n /* mxf ~= mx; */\n /* } */\n /* long[] mxr = new long[](n); */\n /* mx = 0; */\n /* for(int i = n-1; i >= 0; --i){ */\n /* mx = max(mx, b[i]); */\n /* mxr[i] = mx; */\n /* } */\n /* show(mxf, mxr); */\n dchar[] res = new dchar[](n);\n dchar cr = '0';\n for(int i = 0; i < n; ++i){\n /* if(mxf[i] >= mxr[i]){ */\n if(zipp[i][1] >= zipp[n-1][1]){\n cr = '1';\n /* res[zipp[i][2]] = '1'; */\n }else{\n }\n res[zipp[i][2]] = cr;\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, long, int);\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto a = scanArray;\n auto b = scanArray;\n tup[] zipp;\n for(int i = 0; i < n; ++i){\n zipp ~= tup(a[i], b[i], i);\n }\n zipp.sort;\n long[] mxf;\n long mx = 0;\n for(int i = 0; i < n; ++i){\n mx = max(mx, b[i]);\n mxf ~= mx;\n }\n long[] mxr = new long[](n);\n mx = 0;\n for(int i = n-1; i >= 0; --i){\n mx = max(mx, b[i]);\n mxr[i] = mx;\n }\n show(mxf, mxr);\n dchar[] res = new dchar[](n);\n for(int i = 0; i < n; ++i){\n if(mxf[i] >= mxr[i]){\n res[zipp[i][2]] = '1';\n }else{\n res[zipp[i][2]] = '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, long, int);\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 auto B = readarray!int;\r\n auto IDX = iota(N).array.sort!((i, j) => B[i] > B[j]).array;\r\n int limA = A[IDX[0]];\r\n char[] ans = new char[N]; ans[] = '0';\r\n ans[IDX[0]] = '1';\r\n auto M = new int[N];\r\n M[N-1] = A[IDX[N-1]];\r\n for (int i = N - 2; i >= 0; i--) {\r\n M[i] = max(M[i+1], A[IDX[i]]);\r\n }\r\n for (int i = 1; i < N; i++) {\r\n int k = IDX[i];\r\n if (M[k] > limA) {\r\n ans[k] = '1';\r\n limA = min(limA, A[k]);\r\n }\r\n }\r\n writeln(ans);\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 = read!int;\r\n auto A = readarray!int;\r\n auto B = readarray!int;\r\n auto IDX = iota(N).array.sort!((i, j) => B[i] > B[j]).array;\r\n int limA = A[IDX[0]];\r\n char[] ans = new char[N]; ans[] = '0';\r\n ans[IDX[0]] = '1';\r\n for (int i = 1; i < N; i++) {\r\n int k = IDX[i];\r\n if (A[k] > limA) {\r\n ans[k] = '1';\r\n }\r\n }\r\n writeln(ans);\r\n}\r\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\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 a0 = readln.splitter.map !(to !(int)).array;\r\n\t\tauto b0 = readln.splitter.map !(to !(int)).array;\r\n\t\tauto answer = new int [n];\r\n\r\n\t\tvoid solve (const ref int [] a, const ref int [] b)\r\n\t\t{\r\n\t\t\tauto s = redBlackTree !((i, j) => a[i] < a[j], int);\r\n\t\t\tauto t = redBlackTree !((i, j) => b[i] < b[j], int);\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\ts.insert (i);\r\n\t\t\t\tt.insert (i);\r\n\t\t\t}\r\n\t\t\tauto p = n.iota.array;\r\n\t\t\tp.sort !((i, j) => a[i] < a[j]);\r\n\r\n\t\t\tforeach (i; p)\r\n\t\t\t{\r\n\t\t\t\tauto lo = t.lowerBound (i).array;\r\n\t\t\t\tforeach (j; lo)\r\n\t\t\t\t{\r\n\t\t\t\t\ts.removeKey (j);\r\n\t\t\t\t\tt.removeKey (j);\r\n\t\t\t\t}\r\n\t\t\t\tauto left = s.upperBound (i);\r\n\t\t\t\tif (left.empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[i] = 1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tsolve (a0, b0);\r\n\t\tsolve (b0, a0);\r\n\t\twritefln !(\"%(%s%)\") (answer);\r\n\t}\r\n}\r\n"}], "src_uid": "f9cf1a6971a7003078b63195198e5a51"} {"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\") Tuple!(long, long)[] enemies;\n\n void solve(long tc = -1)\n {\n auto reqbull = iota(0, n).map!(i => (enemies.at(pmod(i - 1, n))[1] >= enemies.at(i)[0])?\n 0 : enemies.at(i)[0] - enemies.at(pmod(i - 1, n))[1]).array;\n auto reqbulls = reqbull.sum;\n writeln(iota(0, n).map!(i => reqbulls - reqbull.at(i) + enemies.at(i)[0]).fold!min);\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.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\tauto a = new long [n];\n\t\tauto b = new long [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %s %s\") (a[i], b[i]);\n\t\t}\n\n\t\tlong cur = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlong temp = a[i];\n\t\t\tif (i > 0)\n\t\t\t{\n\t\t\t\ttemp = max (0L, temp - b[i - 1]);\n\t\t\t}\n\t\t\tcur += temp;\n\t\t}\n\n\t\tlong res = cur;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto prev = (i + n - 1) % n;\n\t\t\tauto next = (i + 1) % n;\n\t\t\tcur -= a[i];\n\t\t\tcur -= max (0L, a[next] - b[i]);\n\t\t\tcur += a[next];\n\t\t\tcur += max (0L, a[i] - b[prev]);\n\t\t\tres = min (res, cur);\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) { 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 ab = new long[][](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tab[i] = [RD, RD];\n\t\t}\n\t\tauto d = new long[](n);\n\t\tforeach (i; 0..n-1)\n\t\t{\n\t\t\td[i+1] = min(ab[i][1], ab[i+1][0]);\n\t\t}\n\t\td[0] = min(ab[$-1][1], ab[0][0]);\n\t\t\n\t\tauto pos = d.MIN_POS;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tans[ti] += ab[i][0];\n\t\t\tans[ti] -= d[i];\n\t\t}\n\t\tdebug writeln(ans);\n\t\tans[ti] += d[pos];\n\t\tdebug writeln(ab);\n\t\tdebug writeln(d);\n\t\tdebug writeln(\"pos:\", pos);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "414d1f0cef26fbbf4ede8eac32a1dd48"} {"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\tstruct node\n\t{\n\t\tbool leaf;\n\t\tint cnt;\n\t\tint[26] go;\n\t}\n\n\tnode[] tr;\n\ttr.length = 2;\n\tlong gans;\n\tvoid add(string s)\n\t{\n\t\tint ans;\n\t\tbool fl;\n\t\tint len;\n\t\tint v = 1;\n\t\ttr[v].cnt++;\n\t\tforeach (int i; 0 .. cast(int) s.length)\n\t\t{\n\t\t\tchar c = s[i];\n\t\t\tassert(isAlpha(c));\n\t\t\t// debug enter(c);\n\t\t\tif (tr[v].go[c - 'a'] == 0)\n\t\t\t{\n\t\t\t\tif (fl && tr[v].leaf && len < i)\n\t\t\t\t{\n\t\t\t\t\tans -= i;\n\t\t\t\t\tans += len + 1;\n\t\t\t\t}\n\t\t\t\tfl = 0;\n\t\t\t\ttr[v].go[c - 'a'] = cast(int) tr.length;\n\t\t\t\ttr.length++;\n\t\t\t}\n\t\t\tv = tr[v].go[c - 'a'];\n\t\t\tif (tr[v].cnt == 1 && len == 0)\n\t\t\t{\n\t\t\t\tfl = 1;\n\t\t\t\tlen = i + 1;\n\t\t\t}\n\t\t\tans++;\n\t\t}\n\t\tif (fl && tr[v].leaf && len < cast(int) s.length)\n\t\t{\n\t\t\tans -= s.length;\n\t\t\tans += len + 1;\n\t\t}\n\t\tgans += ans;\n\t\tif (!tr[v].leaf)\n\t\t{\n\t\t\ttr[v].leaf = 1;\n\t\t\tv = 1;\n\t\t\tforeach (c; s)\n\t\t\t{\n\t\t\t\ttr[v].cnt++;\n\t\t\t\tv = tr[v].go[c - 'a'];\n\t\t\t}\n\t\t\ttr[v].cnt++;\n\t\t}\n\t\tdebug write(ans, ' ', s, '\\n');\n\t}\n\n\tbool sep(char c)\n\t{\n\t\treturn c == '\\n' || c == ' ' || c == '.' || c == ',' || c == '\\''\n\t\t\t|| c == '?' || c == '!' || c == '-';\n\t}\n\t//38\n\tstring buf;\n\tint k;\n\twhile (true)\n\t{\n\t\tbuf = readln.strip;\n\t\tif (buf.length == 0)\n\t\t\tbreak;\n\t\tk++;\n\t\tforeach (c; buf)\n\t\t{\n\t\t\tif (sep(c))\n\t\t\t\tgans++;\n\t\t}\n\t\tauto a = buf.splitter(ctRegex!(`[.,' ?!-]`)).filter!(x => !x.empty);\n\t\tforeach (x; a)\n\t\t{\n\t\t\tadd(x);\n\t\t}\n\t}\n\t// debug writeln(k, ' ', gans);\n\twriteln(gans + k);\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\nstring text;\nstring nextWord()\n{\n string res = null;\n while(!text.empty && text[0].isAlpha)\n {\n res ~= text[0];\n text = text[1 .. $];\n }\n return res;\n}\nstring nextNonWord()\n{\n string res = null;\n while(!text.empty && !text[0].isAlpha)\n {\n res ~= text[0];\n text = text[1 .. $];\n }\n return res;\n}\n\n\nclass ptNode\n{\n ptNode[26] chTrans;\n bool isTerminal;\n int noTerminalDescendants;\n}\n\nint insert(ptNode root, string str)\n{\n int surelyInserted = 0;\n int probablyCompleted = 0;\n ptNode node = root;\n auto nodePath = new ptNode[](1);\n nodePath[0] = root;\n auto origstr = str;\n bool isnew = false;\n bool iscompleted = false;\n while(!str.empty)\n {\n if (node.chTrans[str[0] - 'a'] is null)\n\t{\n\t node.chTrans[str[0] - 'a'] = new ptNode;\n\t}\n node = node.chTrans[str[0] - 'a'];\n str = str[1 .. $];\n nodePath ~= node;\n }\n isnew = !nodePath[$ - 1].isTerminal;\n str = origstr;\n int lc = int.max;\n int hc = int.min;\n foreach(i, pnode; nodePath)\n {\n if (pnode.noTerminalDescendants == 1 && pnode !is root)\n\t{\n\t lc = min(cast(int) i, lc);\n\t hc = max(cast(int) i, hc);\n\t}\n if (isnew) pnode.noTerminalDescendants++;\n }\n int res = 0;\n debug writeln(\"doing \", str);\n if (lc != int.max && nodePath[hc].isTerminal)\n {\n assert(hc >= lc);\n if (hc - lc > 1)\n\t{\n\t debug writeln(\"for word \", str, \" saved \", hc - lc - 1);\n\t debug writeln(\"from \", lc, \" - \", hc);\n\t res = cast(int) str.length - (hc - lc) + 1;\n\t}\n else\n\tres = cast(int) str.length;\n }\n else\n {\n res = cast(int) str.length;\n }\n nodePath[$ - 1].isTerminal = true;\n return res;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n inputFile.readf!\"%s\"(text);\n ptNode root = new ptNode;\n int cost = 0;\n while(true)\n {\n auto nonWord = nextNonWord();\n auto word = nextWord();\n if (nonWord is null && word is null) break;\n if (nonWord !is null) { cost += nonWord.length; debug writeln(nonWord.length); }\n if (word !is null)\n\t{\n\t auto pcost = root.insert(word);\n\t debug writeln(pcost);\n\t cost += pcost;\n\t}\n }\n cost.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;\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\nstring text;\nstring nextWord()\n{\n int len = 0;\n auto ntext = text;\n while(!ntext.empty && ntext[0].isAlpha)\n {\n ntext = ntext[1 .. $];\n len++;\n }\n auto res = text[0 .. len];\n text = ntext;\n return res;\n}\nstring nextNonWord()\n{\n int len = 0;\n auto ntext = text;\n while(!ntext.empty && !ntext[0].isAlpha)\n {\n ntext = ntext[1 .. $];\n len++;\n }\n auto res = text[0 .. len];\n text = ntext;\n return res;\n}\n\n\nclass ptNode\n{\n ptNode[26] chTrans;\n bool isTerminal;\n int noTerminalDescendants;\n}\n\nint insert(ptNode root, string str)\n{\n ptNode node = root;\n auto nodePath = new ptNode[](1);\n nodePath[0] = root;\n auto origstr = str;\n bool isnew = false;\n while(!str.empty)\n {\n if (node.chTrans[str[0] - 'a'] is null)\n\tnode.chTrans[str[0] - 'a'] = new ptNode;\n node = node.chTrans[str[0] - 'a'];\n str = str[1 .. $];\n nodePath ~= node;\n }\n isnew = !nodePath[$ - 1].isTerminal;\n str = origstr;\n int lc = -1;\n int hc = -1;\n foreach(i, pnode; nodePath)\n {\n if (pnode.noTerminalDescendants == 1 && pnode !is root)\n\t{\n\t if (lc == -1)\n\t {\n\t lc = cast(int)i;\n\t hc = cast(int)i;\n\t }\n\t else\n\t {\n\t hc = cast(int)i;\n\t }\n\t}\n if (isnew) pnode.noTerminalDescendants++;\n }\n int res = 0;\n if (lc != -1 && nodePath[hc].isTerminal && hc - lc > 1)\n res = cast(int) str.length - (hc - lc) + 1;\n else\n res = cast(int) str.length;\n nodePath[$ - 1].isTerminal = true;\n return res;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n inputFile.readf!\"%s\"(text);\n ptNode root = new ptNode;\n int cost = 0;\n while(true)\n {\n auto nonWord = nextNonWord();\n auto word = nextWord();\n debug writeln(nonWord, \"|\", word);\n if (nonWord.length == 0 && word.length == 0) break;\n if (nonWord.length > 0) { cost += nonWord.length; debug writeln(nonWord.length); }\n if (word.length > 0)\n\t{\n\t auto pcost = root.insert(word);\n\t debug writeln(pcost);\n\t cost += pcost;\n\t}\n }\n cost.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;\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\nstring text;\nstring nextWord()\n{\n string res = null;\n while(!text.empty && text[0].isAlpha)\n {\n res ~= text[0];\n text = text[1 .. $];\n }\n return res;\n}\nstring nextNonWord()\n{\n string res = null;\n while(!text.empty && !text[0].isAlpha)\n {\n res ~= text[0];\n text = text[1 .. $];\n }\n return res;\n}\n\n\nclass ptNode\n{\n ptNode[30] chTrans;\n bool isTerminal;\n int noTerminalDescendants;\n}\n\nint insert(ptNode root, string str)\n{\n int surelyInserted = 0;\n int probablyCompleted = 0;\n ptNode node = root;\n auto nodePath = new ptNode[](1);\n nodePath[0] = root;\n auto origstr = str;\n bool isnew = false;\n bool iscompleted = false;\n while(!str.empty)\n {\n if (node.chTrans[str[0] - 'a'] is null)\n\t{\n\t node.chTrans[str[0] - 'a'] = new ptNode;\n\t}\n node = node.chTrans[str[0] - 'a'];\n str = str[1 .. $];\n nodePath ~= node;\n }\n isnew = !nodePath[$ - 1].isTerminal;\n str = origstr;\n int lc = int.max;\n int hc = int.min;\n foreach(i, pnode; nodePath)\n {\n if (pnode.noTerminalDescendants == 1 && pnode !is root)\n\t{\n\t lc = min(cast(int) i, lc);\n\t hc = max(cast(int) i, hc);\n\t}\n if (isnew) pnode.noTerminalDescendants++;\n }\n int res = 0;\n debug writeln(\"doing \", str);\n if (lc != int.max && nodePath[hc].isTerminal)\n {\n assert(hc >= lc);\n if (hc - lc > 1)\n\t{\n\t debug writeln(\"for word \", str, \" saved \", hc - lc - 1);\n\t debug writeln(\"from \", lc, \" - \", hc);\n\t res = cast(int) str.length - (hc - lc) + 1;\n\t}\n else\n\tres = cast(int) str.length;\n }\n else\n {\n res = cast(int) str.length;\n }\n nodePath[$ - 1].isTerminal = true;\n return res;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n inputFile.readf!\"%s\"(text);\n ptNode root = new ptNode;\n int cost = 0;\n while(true)\n {\n auto nonWord = nextNonWord();\n auto word = nextWord();\n if (nonWord is null && word is null) break;\n if (nonWord !is null) { cost += nonWord.length; debug writeln(nonWord.length); }\n if (word !is null)\n\t{\n\t auto pcost = root.insert(word);\n\t debug writeln(pcost);\n\t cost += pcost;\n\t}\n }\n cost.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;\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\nstring text;\nstring nextWord()\n{\n int len = 0;\n auto ntext = text;\n while(!ntext.empty && ntext[0].isAlpha)\n {\n ntext = ntext[1 .. $];\n len++;\n }\n auto res = text[0 .. len];\n text = ntext;\n return res;\n}\nstring nextNonWord()\n{\n int len = 0;\n auto ntext = text;\n while(!ntext.empty && !ntext[0].isAlpha)\n {\n ntext = ntext[1 .. $];\n len++;\n }\n auto res = text[0 .. len];\n text = ntext;\n return res;\n}\n\n\nclass ptNode\n{\n ptNode[26] chTrans;\n bool isTerminal;\n int noTerminalDescendants;\n}\n\nint insert(ptNode root, string str)\n{\n ptNode node = root;\n auto nodePath = new ptNode[](1);\n nodePath[0] = root;\n auto origstr = str;\n bool isnew = false;\n while(!str.empty)\n {\n if (node.chTrans[str[0] - 'a'] is null)\n\tnode.chTrans[str[0] - 'a'] = new ptNode;\n node = node.chTrans[str[0] - 'a'];\n str = str[1 .. $];\n nodePath ~= node;\n }\n isnew = !nodePath[$ - 1].isTerminal;\n str = origstr;\n int lc = int.max;\n int hc = int.min;\n foreach(i, pnode; nodePath)\n {\n if (pnode.noTerminalDescendants == 1 && pnode !is root)\n\t{\n\t lc = min(cast(int) i, lc);\n\t hc = max(cast(int) i, hc);\n\t}\n if (isnew) pnode.noTerminalDescendants++;\n }\n int res = 0;\n if (lc != int.max && nodePath[hc].isTerminal && hc - lc > 1)\n res = cast(int) str.length - (hc - lc) + 1;\n else\n res = cast(int) str.length;\n nodePath[$ - 1].isTerminal = true;\n return res;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n inputFile.readf!\"%s\"(text);\n ptNode root = new ptNode;\n int cost = 0;\n while(true)\n {\n auto nonWord = nextNonWord();\n auto word = nextWord();\n debug writeln(nonWord, \"|\", word);\n if (nonWord.length == 0 && word.length == 0) break;\n if (nonWord.length > 0) { cost += nonWord.length; debug writeln(nonWord.length); }\n if (word.length > 0)\n\t{\n\t auto pcost = root.insert(word);\n\t debug writeln(pcost);\n\t cost += pcost;\n\t}\n }\n cost.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"}], "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\nstring text;\nstring nextWord()\n{\n string res = null;\n while(!text.empty && text[0].isAlpha)\n {\n res ~= text[0];\n text = text[1 .. $];\n }\n return res;\n}\nstring nextNonWord()\n{\n string res = null;\n while(!text.empty && !text[0].isAlpha)\n {\n res ~= text[0];\n text = text[1 .. $];\n }\n return res;\n}\n\n\nclass ptNode\n{\n ptNode[30] chTrans;\n bool isTerminal;\n int noTerminalDescendants;\n}\n\nint insert(ptNode root, string str)\n{\n int surelyInserted = 0;\n int probablyCompleted = 0;\n ptNode node = root;\n auto nodePath = new ptNode[](1);\n nodePath[0] = root;\n auto origstr = str;\n bool isnew = false;\n bool iscompleted = false;\n while(!str.empty)\n {\n if (node.chTrans[str[0] - 'a'] is null)\n\t{\n\t isnew = true;\n\t node.chTrans[str[0] - 'a'] = new ptNode;\n\t}\n node = node.chTrans[str[0] - 'a'];\n str = str[1 .. $];\n nodePath ~= node;\n }\n str = origstr;\n int lc = int.max;\n int hc = int.min;\n foreach(i, pnode; nodePath)\n {\n if (pnode.noTerminalDescendants == 1 && pnode !is root)\n\t{\n\t lc = min(cast(int) i, lc);\n\t hc = max(cast(int) i, hc);\n\t}\n if (isnew) pnode.noTerminalDescendants++;\n }\n int res = 0;\n debug writeln(\"doing \", str);\n if (lc != int.max && nodePath[hc].isTerminal)\n {\n assert(hc >= lc);\n if (hc - lc > 1)\n\t{\n\t debug writeln(\"for word \", str, \" saved \", hc - lc - 1);\n\t debug writeln(\"from \", lc, \" - \", hc);\n\t res = cast(int) str.length - (hc - lc) + 1;\n\t}\n else\n\tres = cast(int) str.length;\n }\n else\n {\n res = cast(int) str.length;\n }\n nodePath[$ - 1].isTerminal = true;\n return res;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n inputFile.readf!\"%s\"(text);\n ptNode root = new ptNode;\n int cost = 0;\n while(true)\n {\n auto nonWord = nextNonWord();\n auto word = nextWord();\n if (nonWord is null && word is null) break;\n if (nonWord !is null) { cost += nonWord.length; debug writeln(nonWord.length); }\n if (word !is null)\n\t{\n\t auto pcost = root.insert(word);\n\t debug writeln(pcost);\n\t cost += pcost;\n\t}\n }\n cost.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;\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\nstring text;\nstring nextWord()\n{\n string res = text[0 .. 0];\n while(!text.empty && text[0].isAlpha)\n {\n res.length++;\n text = text[1 .. $];\n }\n return res;\n}\nstring nextNonWord()\n{\n string res = text[0 .. 0];\n while(!text.empty && !text[0].isAlpha)\n {\n res.length++;\n text = text[1 .. $];\n }\n return res;\n}\n\n\nclass ptNode\n{\n ptNode[26] chTrans;\n bool isTerminal;\n int noTerminalDescendants;\n}\n\nint insert(ptNode root, string str)\n{\n ptNode node = root;\n auto nodePath = new ptNode[](1);\n nodePath[0] = root;\n auto origstr = str;\n bool isnew = false;\n while(!str.empty)\n {\n if (node.chTrans[str[0] - 'a'] is null)\n\tnode.chTrans[str[0] - 'a'] = new ptNode;\n node = node.chTrans[str[0] - 'a'];\n str = str[1 .. $];\n nodePath ~= node;\n }\n isnew = !nodePath[$ - 1].isTerminal;\n str = origstr;\n int lc = int.max;\n int hc = int.min;\n foreach(i, pnode; nodePath)\n {\n if (pnode.noTerminalDescendants == 1 && pnode !is root)\n\t{\n\t lc = min(cast(int) i, lc);\n\t hc = max(cast(int) i, hc);\n\t}\n if (isnew) pnode.noTerminalDescendants++;\n }\n int res = 0;\n if (lc != int.max && nodePath[hc].isTerminal && hc - lc > 1)\n res = cast(int) str.length - (hc - lc) + 1;\n else\n res = cast(int) str.length;\n nodePath[$ - 1].isTerminal = true;\n return res;\n}\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n inputFile.readf!\"%s\"(text);\n ptNode root = new ptNode;\n int cost = 0;\n while(true)\n {\n auto nonWord = nextNonWord();\n auto word = nextWord();\n if (nonWord.length == 0 && word.length == 0) break;\n if (nonWord.length > 0) { cost += nonWord.length; debug writeln(nonWord.length); }\n if (word.length > 0)\n\t{\n\t auto pcost = root.insert(word);\n\t debug writeln(pcost);\n\t cost += pcost;\n\t}\n }\n cost.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"}], "src_uid": "de6361f522936eac3d88b7268b8c2793"} {"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;\n\t\tauto b = s.dup;\n\t\tsort (representation (b));\n\t\twriteln (b);\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 readln;\n auto s = readln.chomp.to!(dchar[]).sort();\n writeln(s);\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\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": "8616ede6867c8aacde986a123ec8a921"} {"source_code": "module cf_63A;\n\nimport std.stdio;\nimport std.algorithm;\n\nstruct Member {\n string name, type;\n\n int opCmp(ref const Member other) {\n int[string] TYPE_PRIORITY = [\n \"rat\": 1, \"woman\": 2, \"child\": 2, \"man\": 3, \"captain\": 4\n ];\n\n return TYPE_PRIORITY[type] - TYPE_PRIORITY[other.type];\n }\n}\n\nvoid main() {\n int n;\n Member[] crew;\n\n readf(\"%d\", &n);\n crew = new Member[n];\n for (int i = 0; i < n; ++i) {\n readf(\" %s %s\\n\", &crew[i].name, &crew[i].type);\n }\n\n sort!(\"a < b\", SwapStrategy.stable)(crew);\n for (int i = 0; i < crew.length; ++i) {\n writeln(crew[i].name);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n string[] ns = new string[n];\n string[] ks = new string[n];\n foreach (i; 0 .. n) {\n string name, kind; readf(\"%s %s\\n\", &name, &kind);\n ns[i] = name;\n ks[i] = kind;\n }\n foreach (i; 0 .. n) {\n if (ks[i] == \"rat\") {\n writeln(ns[i]);\n }\n }\n foreach (i; 0 .. n) {\n if (ks[i] == \"woman\" || ks[i] == \"child\") {\n writeln(ns[i]);\n }\n }\n foreach (i; 0 .. n) {\n if (ks[i] == \"man\") {\n writeln(ns[i]);\n }\n }\n foreach (i; 0 .. n) {\n if (ks[i] == \"captain\") {\n writeln(ns[i]);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "753113fa5130a67423f2e205c97f8017"} {"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 MO = 1000000007L;\n\nint N;\nint[] P;\nint[] X;\nint[][] G;\n\nlong[] solve(int u) {\n\tlong[] dp = new long[2];\n\tdp[X[u]] += 1;\n\tforeach (v; G[u]) {\n\t\tlong[] res = solve(v);\n\t\tdp[1] = (dp[1] * (res[0] + res[1]) + dp[0] * res[1]) % MO;\n\t\tdp[0] = (dp[0] * (res[0] + res[1]) ) % MO;\n\t}\ndebug{\nwriteln(u,\" \",dp);\n}\n\treturn dp;\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tP = new int[N];\n\t\tX = new int[N];\n\t\tP[0] = -1;\n\t\tforeach (u; 1 .. N) {\n\t\t\tP[u] = readInt;\n\t\t}\n\t\tforeach (u; 0 .. N) {\n\t\t\tX[u] = readInt;\n\t\t}\n\t\t\n\t\tG = new int[][N];\n\t\tforeach (u; 1 .. N) {\n\t\t\tG[P[u]] ~= u;\n\t\t}\n\t\t\n\t\tconst res = solve(0);\n\t\tlong ans = (res[1] % MO + MO) % MO;\n\t\twriteln(ans);\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.functional;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int MOD = 1_000_000_007;\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\tfor (int i = 1; i < n; i++)\n\t\t{\n\t\t\tint j;\n\t\t\treadf (\" %s\", &j);\n\t\t\ta[j] ~= i;\n\t\t\ta[i] ~= j;\n\t\t}\n\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\n\t\tauto f = new int [2] [n];\n\n\t\tvoid recur (int v, int p)\n\t\t{\n\t\t\tf[v][0] = 1;\n\t\t\tf[v][1] = 0;\n\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\n\t\t\t\trecur (u, v);\n\n\t\t\t\tlong c0 = f[u][0] + f[u][1];\n\t\t\t\tif (c0 >= MOD)\n\t\t\t\t{\n\t\t\t\t\tc0 -= MOD;\n\t\t\t\t}\n\t\t\t\tlong c1 = f[u][1];\n\n\t\t\t\tint n0 = (c0 * f[v][0]) % MOD;\n\t\t\t\tint n1 = (c1 * f[v][0] + c0 * f[v][1]) % MOD;\n\t\t\t\tf[v][0] = n0;\n\t\t\t\tf[v][1] = n1;\n\t\t\t}\n\n\t\t\tif (b[v])\n\t\t\t{\n\t\t\t\tf[v][1] = f[v][0];\n\t\t\t\tf[v][0] = 0;\n\t\t\t}\n\t\t}\n\n\t\trecur (0, NA);\n\t\twriteln (f[0][1]);\n\t}\n}\n"}], "negative_code": [], "src_uid": "e571191fadf6b0b26bd2f16295f32077"} {"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 a = RD!int;\n\t\tauto b = RD!int;\n\t\tif (min(a, b)*2 < max(a, b))\n\t\t\tans[i] = false;\n\t\telse\n\t\t\tans[i] = (a+b) % 3 == 0;\n\t}\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;\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 t;\n r(t);\n while(t--)\n {\n long a, b;\n r(a, b);\n long r = 2 * b - a;\n if (r % 3 == 0 && r >= 0 && (b - 2 * r / 3) >= 0)\n\t{\n\t w(\"YES\");\n\t}\n else\n\t{\n\t w(\"NO\");\n\t}\n }\n return 0;\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\tlong a = rlong, b = rlong;\n\t\tstring ans = \"YES\";\n\t\tif((a + b) % 3 != 0) ans = \"NO\";\n\t\tif(a < (a + b) / 3) ans = \"NO\";\n\t\tif(b < (a + b) / 3) ans = \"NO\";\n\t\tans.writeln;\n\t}\n}\n"}], "negative_code": [{"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 t;\n r(t);\n while(t--)\n {\n long a, b;\n r(a, b);\n long r = 2 * b - a;\n if (r % 3 == 0)\n\t{\n\t w(\"YES\");\n\t}\n else\n\t{\n\t w(\"NO\");\n\t}\n }\n return 0;\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 bool[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tans[i] = (a+b) % 3 == 0;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "0a720a0b06314fde783866b47f35af81"} {"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 immutable int MXD = 10 ^^ 6;\n immutable int INFINT = 10 ^^ 9 + 23;\n immutable long INF = 10L ^^ 18 + 23;\n \n alias rbt = RedBlackTree!(int, \"a < b\", true);\n auto arrival = new int[] (n+1);\n auto depart = new rbt[] (n+1);\n foreach (i; 0 .. n+1) {\n arrival[i] = INFINT;\n depart[i] = make!(rbt);\n }\n \n alias pr = Tuple!(int, int);\n auto flightsIn = new pr[][] (MXD + 1);\n auto flightsOut = new pr[][] (MXD + 1);\n long curv = 0;\n foreach (_; 0 .. m) {\n int d, f, t, c;\n readf(\"%s %s %s %s\", &d, &f, &t, &c);\n readln;\n \n if (f != 0) { \n flightsIn[d] ~= tuple(f, c);\n } else { \n flightsOut[d] ~= tuple(t, c); \n if (!depart[t].empty()) { curv -= depart[t].front; }\n depart[t].insert(c);\n curv += depart[t].front;\n }\n \n }\n \n if (depart.dropOne.any!(c => c.empty())) {\n writeln(-1);\n return;\n }\n \n int badSets = n;\n long ans = INF;\n outer: foreach (rborder; 0 .. MXD+1 - k) {\n foreach (t; flightsOut[rborder]) {\n curv -= depart[t[0]].front;\n depart[t[0]].removeKey(t[1]);\n \n if (depart[t[0]].empty()) { break outer; }\n \n curv += depart[t[0]].front;\n }\n \n if (rborder < k) { continue; }\n \n foreach (t; flightsIn[rborder-k]) {\n if (arrival[t[0]] == INFINT) { badSets -= 1; }\n else { curv -= arrival[t[0]]; }\n \n arrival[t[0]] = min(arrival[t[0]], t[1]);\n curv += arrival[t[0]];\n }\n \n if (badSets == 0) { ans = min(ans, curv); }\n }\n \n writeln(ans != INF ? ans : -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;\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 K = s[2];\n\n auto go = new Tuple!(int, long)[][](N);\n auto back = new Tuple!(int, long)[][](N);\n\n foreach (_; 0..M) {\n s = readln.split.map!(to!int);\n if (s[2] == 0)\n go[s[1]-1] ~= tuple(s[0], s[3].to!long);\n else\n back[s[2]-1] ~= tuple(s[0], s[3].to!long);\n }\n\n foreach (i; 0..N)\n go[i].sort!\"a[0] < b[0]\"();\n foreach (i; 0..N)\n back[i].sort!\"a[0] < b[0]\"();\n\n if (go.map!(g => g.length == 0).any ||\n back.map!(b => b.length == 0).any) {\n writeln(-1);\n return;\n }\n\n foreach (i; 0..N)\n foreach (j; 1..go[i].length) \n go[i][j][1] = min(go[i][j][1], go[i][j-1][1]);\n \n foreach (i; 0..N) \n for (int j = back[i].length.to!int - 1; j >= 1; --j)\n back[i][j-1][1] = min(back[i][j-1][1], back[i][j][1]);\n\n\n auto q1 = new BinaryHeap!(Array!(Tuple!(int, int, long)), \"a[0] > b[0]\");\n auto q2 = new BinaryHeap!(Array!(Tuple!(int, int, long)), \"a[0] > b[0]\");\n \n foreach (i; 0..N)\n foreach (j; 0..go[i].length)\n q1.insert(tuple(go[i][j][0], i, go[i][j][1]));\n foreach (i; 0..N)\n foreach (j; 0..back[i].length)\n q2.insert(tuple(back[i][j][0], i, (j + 1 == back[i].length ? INF : back[i][j+1][1])));\n\n int used_cnt = 0;\n auto used = new bool[](N);\n auto ans1 = new long[](N);\n auto ans2 = new long[](N);\n foreach (i; 0..N)\n ans2[i] = back[i][0][1];\n long sum1 = 0;\n long sum2 = ans2.sum;\n long ans = INF;\n bool end = false;\n \n \n while (!q1.empty && !end) {\n auto t = q1.front;\n auto d = t[0];\n auto n = t[1];\n auto c = t[2];\n q1.removeFront;\n sum1 -= ans1[n];\n ans1[n] = c;\n sum1 += ans1[n];\n if (!used[n]) {\n used_cnt += 1;\n used[n] = true;\n }\n\n if (used_cnt < N)\n continue;\n\n\n while (!q2.empty && q2.front()[0] <= d + K) {\n t = q2.front;\n n = t[1];\n c = t[2];\n q2.removeFront;\n \n if (c == INF) {\n end = true;\n break;\n }\n \n sum2 -= ans2[n];\n ans2[n] = c;\n sum2 += ans2[n];\n }\n\n if (!end)\n ans = min(ans, sum1 + sum2);\n }\n\n if (ans >= INF)\n ans = -1;\n ans.writeln;\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;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n \n alias rbt = RedBlackTree!(int, \"a < b\", true);\n auto arrivals = new rbt[] (n+1);\n auto depart = new rbt[] (n+1);\n foreach (i; 0 .. n+1) {\n arrivals[i] = make!(rbt);\n depart[i] = make!(rbt);\n }\n \n immutable int MXD = 10 ^^ 6;\n \n alias pr = Tuple!(int, int);\n auto flightsIn = new pr[][] (MXD + 1);\n auto flightsOut = new pr[][] (MXD + 1);\n long curv = 0;\n foreach (_; 0 .. m) {\n int d, f, t, c;\n readf(\"%s %s %s %s\", &d, &f, &t, &c);\n readln;\n \n if (f != 0) { \n flightsIn[d] ~= tuple(f, c);\n } else { \n flightsOut[d] ~= tuple(t, c); \n if (!depart[t].empty()) { curv -= depart[t].front; }\n depart[t].insert(c);\n curv += depart[t].front;\n }\n \n }\n \n if (depart.dropOne.any!(c => c.empty())) {\n writeln(-1);\n return;\n }\n \n immutable long INF = 10L ^^ 18 + 23;\n int badSets = n;\n long ans = INF;\n outer: foreach (rborder; 0 .. MXD+1 - k) {\n foreach (t; flightsOut[rborder]) {\n curv -= depart[t[0]].front;\n depart[t[0]].removeKey(t[1]);\n \n if (depart[t[0]].empty()) { break outer; }\n \n curv += depart[t[0]].front;\n }\n \n if (rborder < k) { continue; }\n \n foreach (t; flightsIn[rborder-k]) {\n if (arrivals[t[0]].empty()) { badSets -= 1; }\n else { curv -= arrivals[t[0]].front; }\n \n arrivals[t[0]].insert(t[1]);\n curv += arrivals[t[0]].front;\n }\n \n if (badSets == 0) { ans = min(ans, curv); }\n }\n \n writeln(ans != INF ? ans : -1);\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^^13;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const K = readInt();\n auto D = new int[M];\n auto S = new int[M];\n auto T = new int[M];\n auto C = new long[M];\n foreach (i; 0 .. M) {\n D[i] = readInt();\n S[i] = readInt() - 1;\n T[i] = readInt() - 1;\n C[i] = readLong();\n }\n \n const dLim = (M == 0) ? 1 : (D.maxElement + 1);\n auto iss = new int[][dLim];\n foreach (i; 0 .. M) {\n iss[D[i]] ~= i;\n }\n \n auto ls = new long[dLim];\n auto rs = new long[dLim];\n \n long now;\n auto mns = new long[N];\n \n mns[] = INF;\n now = N * INF;\n foreach (d; 0 .. dLim) {\n foreach (i; iss[d]) {\n if (T[i] == -1) {\n now -= mns[S[i]];\n chmin(mns[S[i]], C[i]);\n now += mns[S[i]];\n }\n }\n ls[d] = now;\n }\n \n mns[] = INF;\n now = N * INF;\n foreach_reverse (d; 0 .. dLim) {\n foreach (i; iss[d]) {\n if (S[i] == -1) {\n now -= mns[T[i]];\n chmin(mns[T[i]], C[i]);\n now += mns[T[i]];\n }\n }\n rs[d] = now;\n }\n \n long ans = INF;\n foreach (d; 0 .. dLim - K - 1) {\n chmin(ans, ls[d] + rs[d + K + 1]);\n }\n writeln((ans >= INF) ? -1 : 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;\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 K = s[2];\n\n auto go = new Tuple!(int, long)[][](N);\n auto back = new Tuple!(int, long)[][](N);\n\n foreach (_; 0..M) {\n s = readln.split.map!(to!int);\n if (s[2] == 0)\n go[s[1]-1] ~= tuple(s[0], s[3].to!long);\n else\n back[s[2]-1] ~= tuple(s[0], s[3].to!long);\n }\n\n foreach (i; 0..N)\n go[i].sort!\"a[0] < b[0]\"();\n foreach (i; 0..N)\n back[i].sort!\"a[0] < b[0]\"();\n\n if (go.map!(g => g.length == 0).any ||\n back.map!(b => b.length == 0).any) {\n writeln(-1);\n return;\n }\n\n foreach (i; 0..N)\n foreach (j; 1..go[i].length) \n go[i][j][1] = min(go[i][j][1], go[i][j-1][1]);\n \n foreach (i; 0..N) \n for (int j = back[i].length.to!int - 1; j >= 1; --j)\n back[i][j-1][1] = min(back[i][j-1][1], back[i][j][1]);\n\n\n auto q1 = new BinaryHeap!(Array!(Tuple!(int, int, long)), \"a[0] > b[0]\");\n auto q2 = new BinaryHeap!(Array!(Tuple!(int, int, long)), \"a[0] > b[0]\");\n \n foreach (i; 0..N)\n foreach (j; 0..go[i].length)\n q1.insert(tuple(go[i][j][0], i, go[i][j][1]));\n foreach (i; 0..N)\n foreach (j; 0..back[i].length)\n q2.insert(tuple(back[i][j][0], i, (j + 1 == back[i].length ? INF : back[i][j+1][1])));\n\n int used_cnt = 0;\n auto used = new bool[](N);\n auto ans1 = new long[](N);\n auto ans2 = new long[](N);\n foreach (i; 0..N)\n ans2[i] = back[i][0][1];\n long sum1 = 0;\n long sum2 = ans2.sum;\n long ans = INF;\n \n \n while (!q1.empty) {\n auto t = q1.front;\n auto d = t[0];\n auto n = t[1];\n auto c = t[2];\n q1.removeFront;\n sum1 -= ans1[n];\n ans1[n] = c;\n sum1 += ans1[n];\n if (!used[n]) {\n used_cnt += 1;\n used[n] = true;\n }\n\n if (used_cnt < N)\n continue;\n\n\n while (!q2.empty && q2.front()[0] <= d + K) {\n t = q2.front;\n n = t[1];\n c = t[2];\n q2.removeFront;\n sum2 -= ans2[n];\n ans2[n] = c;\n sum2 += ans2[n];\n }\n\n ans = min(ans, sum1 + sum2);\n }\n\n if (ans >= INF)\n ans = -1;\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;\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 K = s[2];\n\n auto go = new Tuple!(int, long)[][](N);\n auto back = new Tuple!(int, long)[][](N);\n\n foreach (_; 0..M) {\n s = readln.split.map!(to!int);\n if (s[2] == 0)\n go[s[1]-1] ~= tuple(s[0], s[3].to!long);\n else\n back[s[2]-1] ~= tuple(s[0], s[3].to!long);\n }\n\n foreach (i; 0..N)\n go[i].sort!\"a[0] < b[0]\"();\n foreach (i; 0..N)\n back[i].sort!\"a[0] < b[0]\"();\n\n if (go.map!(g => g.length == 0).any ||\n back.map!(b => b.length == 0).any) {\n writeln(-1);\n return;\n }\n\n foreach (i; 0..N)\n foreach (j; 1..go[i].length) \n go[i][j][1] = min(go[i][j][1], go[i][j-1][1]);\n \n foreach (i; 0..N) \n for (int j = back[i].length.to!int - 1; j >= 1; --j)\n back[i][j-1][1] = min(back[i][j-1][1], back[i][j][1]);\n\n\n auto q1 = new BinaryHeap!(Array!(Tuple!(int, int, long)), \"a[0] > b[0]\");\n auto q2 = new BinaryHeap!(Array!(Tuple!(int, int, long)), \"a[0] > b[0]\");\n \n foreach (i; 0..N)\n foreach (j; 0..go[i].length)\n q1.insert(tuple(go[i][j][0], i, go[i][j][1]));\n foreach (i; 0..N)\n foreach (j; 0..back[i].length)\n q2.insert(tuple(back[i][j][0], i, (j + 1 == back[i].length ? INF : back[i][j+1][1])));\n\n int used_cnt = 0;\n auto used = new bool[](N);\n auto ans1 = new long[](N);\n auto ans2 = new long[](N);\n foreach (i; 0..N)\n ans2[i] = back[i][0][1];\n long sum1 = 0;\n long sum2 = ans2.sum;\n long ans = INF;\n \n \n while (!q1.empty) {\n auto t = q1.front;\n auto d = t[0];\n auto n = t[1];\n auto c = t[2];\n q1.removeFront;\n sum1 -= ans1[n];\n ans1[n] = c;\n sum1 += ans1[n];\n if (!used[n]) {\n used_cnt += 1;\n used[n] = true;\n }\n\n if (used_cnt < N)\n continue;\n\n while (!q2.empty && q2.front()[0] <= d + K) {\n t = q2.front;\n d = t[0];\n n = t[1];\n c = t[2];\n q2.removeFront;\n sum2 -= ans2[n];\n ans2[n] = c;\n sum2 += ans2[n];\n }\n\n ans = min(ans, sum1 + sum2);\n }\n\n if (ans >= INF)\n ans = -1;\n ans.writeln;\n}\n"}], "src_uid": "34eb5063498e0849ecf231a0bd3dfc69"} {"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 a = rint, b = rint, c = rint, d = rint;\n\tint[] ans;\n\tif(a == 0 && b == 0){\n\t\tif(c + 1 == d){\n\t\t\tans ~= 3;\n\t\t\tforeach(i; 0 .. c) ans ~= 2, ans ~= 3;\n\t\t}\n\t\telse if(c == d){\n\t\t\tforeach(i; 0 .. d) ans ~= 2, ans ~= 3;\n\t\t}\n\t\telse if(c == d + 1){\n\t\t\tforeach(i; 0 .. d) ans ~= 2, ans ~= 3;\n\t\t\tans ~= 2;\n\t\t}\n\t}\n\telse if(c == 0 && d == 0){\n\t\tif(a + 1 == b){\n\t\t\tans ~= 1;\n\t\t\tforeach(i; 0 .. a) ans ~= 0, ans ~= 1;\n\t\t}\n\t\telse if(a == b){\n\t\t\tforeach(i; 0 .. a) ans ~= 0, ans ~= 1;\n\t\t}\n\t\telse if(a == b + 1){\n\t\t\tforeach(i; 0 .. b) ans ~= 0, ans ~= 1;\n\t\t\tans ~= 0;\n\t\t}\n\t}\n\telse if(a == 0 && d == 0){\n\t\tif(b + 1 == c){\n\t\t\tforeach(i; 0 .. b) ans ~= 2, ans ~= 1;\n\t\t\tans ~= 2;\n\t\t}\n\t\telse if(b == c){\n\t\t\tforeach(i; 0 .. b) ans ~= 2, ans ~= 1;\n\t\t}\n\t\telse if(b == c + 1){\n\t\t\tans ~= 1;\n\t\t\tforeach(i; 0 .. c) ans ~= 2, ans ~= 1;\n\t\t}\n\t}\n\telse if(a > b){\n\t}\n\telse if(c < d){\n\t}\n\telse if(b - a == c - d){\n\t\tforeach(i; 0 .. a) ans ~= 0, ans ~= 1;\n\t\tforeach(i; 0 .. b - a) ans ~= 2, ans ~= 1;\n\t\tforeach(i; 0 .. d) ans ~= 2, ans ~= 3;\n\t}\n\telse if(b - a - 1 == c - d){\n\t\tans ~= 1;\n\t\tforeach(i; 0 .. a) ans ~= 0, ans ~= 1;\n\t\tforeach(i; 0 .. b - a - 1) ans ~= 2, ans ~= 1;\n\t\tforeach(i; 0 .. d) ans ~= 2, ans ~= 3;\n\t}\n\telse if(b - a == c - d - 1){\n\t\tforeach(i; 0 .. a) ans ~= 0, ans ~= 1;\n\t\tforeach(i; 0 .. b - a) ans ~= 2, ans ~= 1;\n\t\tforeach(i; 0 .. d) ans ~= 2, ans ~= 3;\n\t\tans ~= 2;\n\t}\n\telse if(b - a - 1 == c - d - 1){\n\t\tans ~= 1;\n\t\tforeach(i; 0 .. a) ans ~= 0, ans ~= 1;\n\t\tforeach(i; 0 .. b - a - 1) ans ~= 2, ans ~= 1;\n\t\tforeach(i; 0 .. d) ans ~= 2, ans ~= 3;\n\t\tans ~= 2;\n\t}\n\n\tif(ans.length == 0) \"NO\".writeln;\n\telse{\n\t\t\"YES\".writeln;\n\t\tans.map!(to!string).array.join(\" \").writeln;\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\nint[] solveGreedy(int[] as) {\n const n = as.sum;\n foreach (s; 0 .. 4) {\n int[] ps;\n auto bs = as.dup;\n if (bs[s] > 0) {\n --bs[s];\n ps ~= s;\n foreach (i; 1 .. n) {\n foreach (x; 0 .. 4) {\n if (bs[x] > 0 && abs(x - ps[i - 1]) == 1) {\n --bs[x];\n ps ~= x;\n goto found;\n }\n }\n goto failed;\n found:\n }\n return ps;\n }\n failed:\n }\n return null;\n}\n\nvoid main() {\n debug {\n foreach (a; 0 .. 10) foreach (b; 0 .. 10) foreach (c; 0 .. 10) foreach (d; 0 .. 10) {\n const n = a + b + c + d;\n if (0 < n && n <= 10) {\n int[] perm;\n perm ~= repeat(0, a).array;\n perm ~= repeat(1, b).array;\n perm ~= repeat(2, c).array;\n perm ~= repeat(3, d).array;\n int[] ans;\n do {\n bool ok = true;\n foreach (i; 0 .. n - 1) {\n ok = ok && (abs(perm[i + 1] - perm[i]) == 1);\n }\n if (ok) {\n ans = perm.dup;\n break;\n }\n } while (perm.nextPermutation);\n const res = solveGreedy([a, b, c, d]);\n writeln([a, b, c, d], \": \", ans, \" \", res);\n assert((ans != null) == (res != null));\n }\n }\n }\n \n try {\n for (; ; ) {\n auto A = new int[4];\n foreach (x; 0 .. 4) {\n A[x] = readInt();\n }\n const res = solveGreedy(A);\n if (res) {\n writeln(\"YES\");\n foreach (i, x; res) {\n if (i > 0) write(\" \");\n write(x);\n }\n writeln();\n } else {\n writeln(\"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "a981e174f1f3864d50deb541834f7831"} {"source_code": "// https://codeforces.com/problemset/problem/467/B\nimport std.stdio;\nimport std.conv;\nimport std.array;\nimport std.algorithm;\n\nvoid main() {\n int[] words = readln.split.map!(x => x.to!int).array;\n int n = words[0];\n int m = words[1];\n int k = words[2];\n\n int[] armies;\n\n foreach(x; stdin.byLine)\n armies ~= x.to!int;\n\n int answer = 0;\n\n foreach(army; armies) {\n int xor = army^armies[m];\n int differ = 0;\n for(int bit = 0; bit < n; bit++)\n if((xor&(1< 0)\n differ += 1;\n if(differ <= k)\n answer += 1;\n }\n\n answer -= 1;\n answer.writeln;\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n int n, m, k; readf(\" %s %s %s\", &n, &m, &k);\n auto mask = new int [m];\n for (int i = 0; i < m; i++) {\n readf(\" %s\", &mask[i]);\n }\n int cur; readf(\" %s\", &cur);\n int ans = 0;\n for (int i = 0; i < m; i++) {\n int count = 0;\n for (int j = 0; j < n; j++) {\n if ((mask[i] & (1 << j)) != (cur & (1 << j))) {\n count++;\n }\n }\n ans += count <= k;\n }\n writeln(ans);\n}\n"}], "negative_code": [], "src_uid": "5ebb0ee239d68ea33d9dac2d0bdd5f4e"} {"source_code": "import std.stdio;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n long n, m, x;\r\n readf!\" %d %d %d\"(n, m, x);\r\n x--;\r\n long r = x % n, c = x / n;\r\n writeln(m * r + c + 1);\r\n }\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1506/problem/A\n// math\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n, m, x;\n readf(\"%s %s %s\\n\", &n, &m, &x);\n\n x -= 1;\n\n long row = x % n;\n long column = x / n;\n\n writefln(\"%s\", (row*m) + column + 1);\n}\n}\n\n"}], "negative_code": [], "src_uid": "e519e4495c9acef4c4a614aef73cb322"} {"source_code": "import std.stdio, std.algorithm, std.array, std.typecons, std.string, std.conv;\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 auto params = readln.split();\r\n int n = to!int(params[0]);\r\n string s = readln.strip();\r\n if (to!string(uniq(s)) == params[1]) {\r\n writeln(0);\r\n continue;\r\n }\r\n else {\r\n Nullable!(ulong) oneind;\r\n foreach(ind, el; s) {\r\n if ((el == to!char(params[1])) && (2*(ind + 1) > n))\r\n oneind = ind;\r\n }\r\n if (!oneind.isNull) {\r\n writeln(1);\r\n writeln(oneind + 1);\r\n }\r\n else {\r\n writeln(2);\r\n writeln(n-1, ' ', n);\r\n }\r\n }\r\n }\r\n}", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n ll n = scan;\n dchar c = scan!(dchar);\n auto word = scan!(dchar[]);\n ll cnt = 0;\n for(int i = 0; i < n; ++i){\n cnt += (word[i] == c);\n }\n if(cnt == n){\n writeln(0);\n writeln;\n return;\n }\n for(ll k = 1; k <= n; ++k){\n bool f = 1;\n for(ll m = k-1; m < n; m += k){\n if(word[to!int(m)] != c){ f = 0; break; }\n }\n if(f){\n writeln(1);\n writeln(k);\n return;\n }\n }\n writeln(2);\n writeln(n, \" \", n-1);\n}\n\nvoid main(){\n long tests = scan;\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\nvoid solve(){\n ll n = scan;\n dchar c = scan!(dchar);\n auto word = scan!(dchar[]);\n ll cnt = 0;\n for(int i = 0; i < n; ++i){\n cnt += (word[i] == c);\n }\n if(cnt == n){\n writeln(0);\n writeln;\n return;\n }\n for(ll k = 1; k < n; ++k){\n bool f = 1;\n for(ll m = k-1; m < n; m += k){\n if(word[to!int(m)] != c){ f = 0; break; }\n }\n if(f){\n writeln(1);\n writeln(k);\n return;\n }\n }\n writeln(2);\n writeln(n, \" \", n-1);\n}\n\nvoid main(){\n long tests = scan;\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\nvoid solve(){\n ll n = scan;\n dchar c = scan!(dchar);\n auto word = scan!(dchar[]);\n ll cnt = 0;\n for(int i = 0; i < n; ++i){\n cnt += (word[i] == c);\n }\n if(cnt == n){\n writeln(0);\n writeln;\n return;\n }\n for(ll k = 1; k < n; ++k){\n ll seen = 0;\n for(ll j = k; j < n; j += k){\n seen += (word[to!int(j)] == c);\n }\n if(seen == cnt){\n writeln(1);\n writeln(k);\n return;\n }\n if(k*cnt > n){\n break;\n }\n }\n writeln(2);\n writeln(n, \" \", n-1);\n}\n\nvoid main(){\n long tests = scan;\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, std.algorithm, std.array, std.typecons, std.string, std.conv;\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 auto params = readln.split();\r\n int n = to!int(params[0]);\r\n string s = readln.strip();\r\n if (to!string(uniq(s)) == params[1]) {\r\n writeln(0);\r\n continue;\r\n }\r\n else {\r\n Nullable!(ulong) oneind;\r\n foreach(ind, el; s) {\r\n if ((el == to!char(params[1])) && (2*(ind + 1) > n))\r\n oneind = ind;\r\n }\r\n if (!oneind.isNull) {\r\n writeln(1);\r\n writeln(oneind);\r\n }\r\n else {\r\n writeln(2);\r\n writeln(n-1, ' ', n);\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.array, std.typecons, std.string, std.conv;\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 auto params = readln.split();\r\n int n = to!int(params[0]);\r\n string s = readln.strip();\r\n if (to!string(uniq(s)) == params[1]) {\r\n writeln(0);\r\n continue;\r\n }\r\n else {\r\n if (s[n - 1] == to!char(params[1])) {\r\n writeln(1);\r\n writeln(n);\r\n }\r\n else {\r\n if (s[n - 2] == to!char(params[1])) {\r\n if (to!string(uniq(s[0..n - 2])) == params[1])\r\n {\r\n writeln(1);\r\n writeln(n - 1);\r\n }\r\n else {\r\n writeln(2);\r\n writeln(n-1, ' ', n);\r\n }\r\n }\r\n else {\r\n writeln(2);\r\n writeln(n-1, ' ', n);\r\n }\r\n }\r\n }\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.array, std.typecons, std.string, std.conv;\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 auto params = readln.split();\r\n int n = to!int(params[0]);\r\n string s = readln.strip();\r\n if (to!string(uniq(s)) == params[1]) {\r\n writeln(0);\r\n continue;\r\n }\r\n else {\r\n if (s[n - 1] == to!char(params[1])) {\r\n writeln(1);\r\n writeln(n);\r\n }\r\n else {\r\n writeln(2);\r\n writeln(n-1, ' ', n);\r\n }\r\n }\r\n }\r\n}"}], "src_uid": "3b8969f7f2051d559a1e375ce8275c73"} {"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, c;\n readf!\" %d %d %d \"(a, b, c);\n writeln(a + b == c || a + c == b || b + c == a ? \"YES\" : \"NO\");\n }\n}\n", "positive_code": [{"source_code": "import std;\r\n\r\nvoid main()\r\n{\r\n int w;\r\n scanf(\"%d\\n\", &w);\r\n foreach(_; 0..w)\r\n {\r\n int a,b,c;\r\n scanf(\"%d %d %d\\n\", &a, &b, &c);\r\n int max_el = max(a,b,c);\r\n if (a+b+c - max_el == max_el)\r\n writeln(\"YES\");\r\n else\r\n writeln(\"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\nvoid solve() {\r\n auto s = readarray!int;\r\n bool f() {\r\n int sum = s.reduce!\"a + b\";\r\n for (int i = 0; i < 3; i++) {\r\n if (sum - s[i] == s[i]) {\r\n return true;\r\n }\r\n }\r\n return false;\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"}], "negative_code": [], "src_uid": "1b8293c51d025940eb859b0e625ab588"} {"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\n\r\nvoid solve() {\r\n int Q = read!int;\r\n long[] s = new long[26], t = new long[26];\r\n s[0] = 1;\r\n t[0] = 1;\r\n\r\n bool cmp(long[] x, long[] y) {\r\n for (int i = 25; i >= 0; i--) {\r\n for (int j = 0; j < i; j++) {\r\n if (y[i] > 0 && x[j] > 0) return true;\r\n }\r\n }\r\n if (x.count!(c => c > 0) == 1 && y.count!(c => c > 0) == 1) {\r\n int i = 26 - x.find!(c => c > 0).length;\r\n int j = 26 - y.find!(c => c > 0).length;\r\n if (i == j) {\r\n return x[j] < y[j];\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n foreach (q; 0 .. Q) {\r\n int d, k; \r\n string x;\r\n readf(\"%d %d %s\\n\", &d, &k, &x);\r\n if (d == 1) {\r\n foreach (c; x) {\r\n int i = cast(int)(c - 'a');\r\n s[i] += k;\r\n }\r\n writeln(cmp(s, t) ? \"YES\" : \"NO\");\r\n } else {\r\n assert(d == 2);\r\n foreach (c; x) {\r\n int i = cast(int)(c - 'a');\r\n t[i] += k;\r\n }\r\n writeln(cmp(s, t) ? \"YES\" : \"NO\");\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, 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 q, d, k;\n string x;\n readf!\" %d \"(q);\n long[26] ft, fs;\n long totals = 1, totalt = 1;\n ft[0] = 1;\n fs[0] = 1;\n foreach (_ ; 0 .. q) {\n auto tmp = readln.splitter.array;\n d = tmp[0].to!long;\n k = tmp[1].to!long;\n x = tmp[2].strip;\n if (d == 1) {\n foreach (ch ; x) {\n fs[cast(size_t)(ch - 'a')] += k;\n totals += k;\n }\n } else {\n foreach (ch ; x) {\n ft[cast(size_t)(ch - 'a')] += k;\n totalt += k;\n }\n }\n\n if (totalt != ft[0]) {\n writeln(\"YES\");\n continue;\n }\n\n if (totals == fs[0]) {\n writeln(totals < totalt ? \"YES\" : \"NO\");\n continue;\n }\n\n writeln(\"NO\");\n }\n }\n}\n"}], "negative_code": [], "src_uid": "d40f0f3b577a1a5cfad2a657d6a1b90a"} {"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\n// T, S: monoid\n// opTT: T * T -> T\n// opST: S * T * int -> T\n// (s t_a) ... (s t_{b-1}) = opST(s, t_a ... t_{b-1}, b - a)\n// opSS: S * S -> S\n// query(a, b, s): t_a <- s t_a, ..., t_{b-1} <- s t_{b-1};\n// returns t_a ... t_{b-1}\nclass SegmentTree(T, S, alias opTT, alias opST, alias opSS) {\n import std.functional : binaryFun;\n alias opTTFun = binaryFun!opTT;\n alias opSTFun = opST;\n alias opSSFun = binaryFun!opSS;\n const(T) idT;\n const(S) idS;\n\n int n;\n T[] ts;\n S[] ss;\n this(int n_, const(T) idT, const(S) idS) {\n this.idT = idT;\n this.idS = idS;\n for (n = 1; n < n_; n <<= 1) {}\n ts = new T[n << 1];\n ss = new S[n << 1];\n ts[] = idT;\n ss[] = idS;\n }\n ref T at(int a) {\n return ts[n + a];\n }\n void build() {\n foreach_reverse (a; 1 .. n) ts[a] = opTTFun(ts[a << 1], ts[a << 1 | 1]);\n }\n T query(int a, int b, const(S) s) {\n return query(1, 0, n, a, b, s);\n }\n\n private:\n T query(int u, int l, int r, int a, int b, const(S) s) {\n if (a < l) a = l;\n if (b > r) b = r;\n if (a >= b) return idT;\n if (a == l && b == r) {\n ts[u] = opSTFun(s, ts[u], r - l);\n ss[u] = opSSFun(s, ss[u]);\n return ts[u];\n }\n const int uL = u << 1, uR = u << 1 | 1;\n const int mid = (l + r) >> 1;\n // speed-up: if (ss[u] != idS)\n {\n ts[uL] = opSTFun(ss[u], ts[uL], mid - l);\n ts[uR] = opSTFun(ss[u], ts[uR], r - mid);\n ss[uL] = opSSFun(ss[u], ss[uL]);\n ss[uR] = opSSFun(ss[u], ss[uR]);\n ss[u] = idS;\n }\n const T resL = query(uL, l, mid, a, b, s);\n const T resR = query(uR, mid, r, a, b, s);\n ts[u] = opTTFun(ts[uL], ts[uR]);\n return opTTFun(resL, resR);\n }\n}\n\n\nenum INF = 10^^9;\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 bit = new int[N];\n auto seg = new SegmentTree!(int, int, max, (s, t, sz) => (s + t), \"a + b\")(N, -INF, 0);\n foreach (i; 0 .. N) {\n seg.at(i) = 0;\n }\n seg.build;\n \n auto ans = new int[N];\n foreach_reverse (i; 0 .. N) {\n const j = bit.bSum(P[i]);\n bit.bAdd(P[i], +1);\n const now = seg.query(P[i], P[i] + 1, 0);\n debug {\n writeln(i, \" \", P[i], \" \", j, \" \", now);\n }\n seg.query(P[i], P[i] + 1, (P[i] - j) - now);\n seg.query(P[i] + 1, N, -1);\n ans[i] = max(seg.query(0, N, 0), 0);\n }\n \n foreach (i; 0 .. N) {\n write(ans[i] + 1, \" \");\n }\n writeln(1);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"B\"\n dependency \"dcomp\" version=\">=0.7.3\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n int n;\n sc.read(n);\n int[] a;\n sc.read(a); a[]-=1;\n bool[] used = new bool[n];\n int r = n-1;\n writeln(1);\n foreach (int i, d; a) {\n used[d] = true;\n while (r >= 0 && used[r]) r--;\n int s = 1 + (i+1) - (n-1-r);\n writeln(s);\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 /*\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": "b97eeaa66e91bbcc3b5e616cb480c7af"} {"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\n\nvoid main() {\n alias pii = Tuple!(int, \"k\", int, \"v\");\n pii[] a1, a2;\n int n = readln().strip().to!int;\n foreach (i; 0..n) {\n auto input = readln().split().map!(to!int).array;\n int k = input[0], v = input[1];\n if (k < 0) {\n a1 ~= pii(-k, v);\n } else {\n a2 ~= pii(k, v);\n }\n }\n a1.sort();\n a2.sort();\n int m = cast(int)min(a1.length, a2.length);\n auto b1 = a1.map!(t => t.v).array;\n auto b2 = a2.map!(t => t.v).array;\n b1 ~= 0;\n b2 ~= 0;\n writeln(sum(b1[0..m+1]) + sum(b2[0..m+1]));\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.format;\nimport std.stdio;\nimport std.range;\n\nstruct Tree {\n int pos, apples;\n}\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n auto trees = new Tree[n];\n foreach (ref tree; trees)\n readf(\" %d %d\", &tree.pos, &tree.apples);\n trees.sort!\"a.pos < b.pos\"();\n int mid = trees.length - trees.find!\"a.pos > b\"(0).length;\n int result = 0;\n int i, j;\n for (i = mid - 1, j = mid; i >= 0 && j < n; i--, j++)\n result += trees[i].apples + trees[j].apples;\n if (i >= 0)\n result += trees[i].apples;\n if (j < n)\n result += trees[j].apples;\n writeln(result);\n}\n"}], "negative_code": [], "src_uid": "bf573af345509b2364ada6e613b6f998"} {"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 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.map !(q{a - 'a'}).array;\r\n\t\tint hi = 0;\r\n\t\tauto trans = letters.iota.array;\r\n\t\tforeach (int i, c; s)\r\n\t\t{\r\n\t\t\twhile (k > 0 && trans[c] > 0)\r\n\t\t\t{\r\n\t\t\t\tint prev = trans[c];\r\n\t\t\t\tforeach (j; 0..letters)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (trans[j] == prev)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttrans[j] = trans[prev - 1];\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tk -= 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (s.map !(c => cast (char) (trans[c] + 'a')));\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// cheese-cracker [2022-05-05]\n\nvoid solve(){\n int n = scan!int;\n int k = scan!int;\n auto word = scan!(dchar[]);\n int[] w;\n for(int i = 0; i < n; ++i){\n w ~= (word[i] - 'a').to!int;\n }\n int cr = -1;\n int max2 = 0;\n int imax = n;\n for(int i = 0; i < n; ++i){\n if(w[i] > k){\n cr = w[i];\n imax = i;\n break;\n }\n max2 = max(max2, w[i]);\n }\n int kleft = k - max2;\n int low = max(cr - kleft, 0);\n\n for(int i = 0; i < n; ++i){\n if(w[i] <= max2){\n write('a');\n }else if(w[i] <= cr || cr == -1){\n write(min('a' + low, w[i] + 'a').to!dchar);\n }else{\n write((w[i] + 'a').to!dchar);\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"}], "negative_code": [{"source_code": "// cheese-cracker [2022-05-05]\n\nvoid solve(){\n int n = scan!int;\n int k = scan!int;\n auto word = scan!(dchar[]);\n int[] vis = new int[](26);\n int[] w;\n for(int i = 0; i < n; ++i){\n w ~= (word[i] - 'a').to!int;\n }\n int cr = -1;\n int max2 = 0;\n int imax = n;\n for(int i = 0; i < n; ++i){\n if(w[i] >= k){\n cr = w[i];\n imax = i;\n break;\n }\n max2 = max(max2, w[i]);\n }\n int kleft = k - max2;\n int low = max(cr - kleft, 0);\n int minchar = 'a';\n\n for(int i = 0; i < n; ++i){\n if(w[i] <= max2){\n write(min(minchar, w[i] + 'a').to!dchar);\n }else if(w[i] <= cr){\n write(min('a' + low, w[i] + 'a').to!dchar);\n }else{\n write((w[i] + 'a').to!dchar);\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"}, {"source_code": "// cheese-cracker [2022-05-05]\n\nvoid solve(){\n int n = scan!int;\n int k = scan!int;\n auto word = scan!(dchar[]);\n int[] vis = new int[](26);\n int[] w;\n for(int i = 0; i < n; ++i){\n w ~= (word[i] - 'a').to!int;\n }\n int cr = -1;\n int max2 = 0;\n int imax = n;\n for(int i = 0; i < n; ++i){\n if(w[i] >= k){\n cr = w[i];\n imax = i;\n break;\n }\n max2 = max(max2, w[i]);\n }\n int kleft = k - max2;\n int low = max(cr - kleft, 0);\n int minchar = 'a';\n if(imax == 0){ minchar = ('a' + low); }\n\n for(int i = 0; i < n; ++i){\n if(w[i] <= max2){\n write(min(minchar, w[i] + 'a').to!dchar);\n }else if(w[i] <= cr){\n write(min('a' + low, w[i] + 'a').to!dchar);\n }else{\n write((w[i] + 'a').to!dchar);\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"}, {"source_code": "// cheese-cracker [2022-05-05]\n\nvoid solve(){\n int n = scan!int;\n int k = scan!int;\n auto word = scan!(dchar[]);\n int[] vis = new int[](26);\n int[] w;\n for(int i = 0; i < n; ++i){\n w ~= (word[i] - 'a').to!int;\n }\n int cr = -1;\n int max2 = 0;\n int imax = n;\n for(int i = 0; i < n; ++i){\n if(w[i] >= k){\n cr = w[i];\n imax = i;\n break;\n }\n max2 = max(max2, w[i]);\n }\n int kleft = k - max2;\n int low = max(cr - kleft, 0);\n int minchar = 'a';\n if(imax == 0){ minchar = ('a' + low); }\n\n for(int i = 0; i < n; ++i){\n if(w[i] <= k){\n write(min(minchar, w[i] + 'a').to!dchar);\n }else if(w[i] <= cr){\n write(min('a' + low, w[i] + 'a').to!dchar);\n }else{\n write((w[i] + 'a').to!dchar);\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"}], "src_uid": "b86c1533fdfe68fd4dea2bf99cd9e111"} {"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 string[] arr;\n foreach (i; 0 .. n) {\n arr ~= readln.chomp;\n }\n \n auto byCol = new int[][] (n, m);\n foreach (rw; 0 .. n) {\n byCol[rw][m-1] = 1;\n foreach_reverse (c; 0 .. m-1) {\n byCol[rw][c] = arr[rw][c] == arr[rw][c+1] ? \n byCol[rw][c+1] + 1 : 1;\n }\n }\n \n auto byRow = new int[][] (n, m);\n foreach (c; 0 .. m) {\n byRow[n-1][c] = 1;\n foreach_reverse (rw; 0 .. n-1) {\n byRow[rw][c] = arr[rw][c] == arr[rw+1][c] ?\n byRow[rw+1][c] + 1 : 1;\n }\n }\n \n debug {\n byRow.each!writeln;\n byCol.each!writeln;\n }\n \n long ans = 0;\n foreach (rw; 0 .. n) {\n foreach (c; 0 .. m) {\n int reach1 = byRow[rw][c];\n \n if (rw + reach1 >= n) { continue; }\n \n int reach2 = byRow[rw + reach1][c];\n \n if (reach1 != reach2 || rw + reach1 + reach2 >= n) { continue; }\n \n int reach3 = min(reach1, byRow[rw + reach1 + reach2][c]);\n \n if (reach3 < reach1) { continue; }\n \n int rt = m;\n foreach (rwnxt; rw .. rw + reach1 + reach2 + reach3) {\n rt = min(rt, byCol[rwnxt][c]);\n }\n \n ans += rt;\n }\n }\n \n ans.writeln;\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;\nimport std.bigint;\n\nalias Tree = RBT!int;\nalias ll = long;\n\nvoid main() {\n GC.disable();\n\n int n, m;\n readf(\" %s %s\\n\", n, m);\n string[] A = new string[n];\n foreach(i; 0 .. n) {\n A[i] = readln.strip;\n }\n\n int[] ccl = new int[n];\n ccl[] =0;\n long ans = 0;\n\n foreach(j;0 .. m) {\n int[] co; //= new int[];\n char[] ch;// = new char[];\n int[] ml;// = new int[];\n co ~= 0;\n ch ~= A[0][j];\n ml ~= (n+m+100);\n \n foreach(i; 0 .. n) {\n if (j >= 1 && A[i][j] == A[i][j-1]) ccl[i]++; else ccl[i] = 1;\n\n if (A[i][j] == ch[$-1]) {\n co[$-1]++;\n ml[$-1] = min(ml[$-1], ccl[i]);\n } else {\n co ~= 1;\n ch ~= A[i][j];\n ml ~= ccl[i];\n }\n\n if (co.length >= 3) {\n if (co[$-1] == co[$-2] && co[$-1] <= co[$-3]) {\n long t= min(ml[$-1], ml[$-2]);\n int sss = co[$-1];\n t = min(t, minElement( ccl[ i - sss* 3 + 1 .. i - sss*2 + 1 ] ) );\n ans += t;\n }\n }\n }\n }\n\n writeln(ans);\n\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;\nimport std.bigint;\n\nalias Tree = RBT!int;\nalias ll = long;\n\nvoid main() {\n GC.disable();\n\n int n, m;\n readf(\" %s %s\\n\", n, m);\n string[] A = new string[n];\n foreach(i; 0 .. n) {\n A[i] = readln.strip;\n }\n\n int[] ccl = new int[n];\n ccl[] =0;\n long ans = 0;\n\n foreach(j;0 .. m) {\n int[] co; //= new int[];\n char[] ch;// = new char[];\n int[] ml;// = new int[];\n co ~= 0;\n ch ~= A[0][j];\n ml ~= (n+m+100);\n \n foreach(i; 0 .. n) {\n if (j >= 1 && A[i][j] == A[i][j-1]) { ccl[i]++;} else ccl[i] = 1;\n\n if (A[i][j] == ch[$-1]) {\n co[$-1]++;\n ml[$-1] = min(ml[$-1], ccl[i]);\n } else {\n co ~= 1;\n ch ~= A[i][j];\n ml ~= ccl[i];\n }\n\n if (co.length >= 3) {\n if (co[$-1] == co[$-2] && co[$-1] >= co[$-3]) {\n long t= min(ml[$-1], ml[$-2]);\n int sss = co[$-1];\n t = min(t, minElement( ccl[ i - sss* 3 + 1 .. i - sss*2 + 1 ] ) );\n ans += t;\n }\n }\n }\n }\n\n writeln(ans);\n\n\n}\n"}], "src_uid": "edc54435b62e76287da94836ad3aa86b"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto m = readInt!int;\n struct Adj\n {\n int value;\n int w;\n int index;\n }\n auto adj = new Adj[][](n);\n int getParity(int value)\n {\n int parity = 0;\n while (value)\n {\n\tparity ^= value&1;\n\tvalue >>= 1;\n }\n return parity;\n }\n auto edges = new int[3][](0);\n foreach(i; 0 .. n - 1)\n {\n auto x = readInt!int - 1;\n auto y = readInt!int - 1;\n auto v = readInt!int;\n adj[x] ~= Adj(v, y, i);\n adj[y] ~= Adj(v, x, i);\n edges ~= [x, y, v];\n }\n auto setAcc = new bool[](n);\n auto acc = new int[](n);\n auto rel = new Adj[][](n);\n foreach(i; 0 .. m)\n {\n auto a = readInt!int - 1;\n auto b = readInt!int - 1;\n auto p = readInt!int;\n rel[a] ~= Adj(p, b);\n rel[b] ~= Adj(p, a);\n }\n foreach(e; edges)\n {\n if (e[2] >= 0)\n\t{\n\t auto p = getParity(e[2]);\n\t rel[e[0]] ~= Adj(p, e[1]);\n\t rel[e[1]] ~= Adj(p, e[0]);\n\t}\n }\n bool possible = true;\n void fillAcc(int v, int color)\n {\n if (setAcc[v])\n {\n\tif (acc[v] != color) possible = false;\n\treturn;\n }\n else\n {\n\tsetAcc[v] = true;\n\tacc[v] = color;\n }\n foreach(a; rel[v])\n {\n\tfillAcc(a.w, color ^ a.value);\n }\n }\n foreach(i; 0 .. n) if (!setAcc[i]) fillAcc(i, 0);\n if (!possible) return writeln(\"NO\");\n writeln(\"YES\");\n void fillEdges(int v, int parent)\n {\n foreach(a; adj[v]) if (a.w != parent)\n {\n\tint diff = acc[a.w] ^ acc[v];\n\tif (a.value < 0)\n\t {\n\t assert(a.value == edges[a.index][2]);\n\t edges[a.index][2] = diff;\n\t }\n\tfillEdges(a.w, v);\n }\n }\n fillEdges(0, -1);\n foreach(edge; edges)\n {\n writeln(edge[0] + 1, \" \", edge[1] + 1, \" \", edge[2]);\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": "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 Value = int;\nint root(int[] ps, Value[] qs, int u) {\n if (ps[u] < 0) {\n return u;\n } else {\n int r = root(ps, qs, ps[u]);\n // qs[u] += qs[ps[u]];\n qs[u] ^= qs[ps[u]];\n return (ps[u] = r);\n }\n}\nbool connect(int[] ps, Value[] qs, int u, int v, Value c) {\n int ru = root(ps, qs, u);\n int rv = root(ps, qs, v);\n // Value cc = c + qs[u] - qs[v];\n Value cc = c ^ qs[u] ^ qs[v];\n if (ru == rv) return (cc == 0);\n // if (ps[ru] > ps[rv]) { swap(ru, rv); cc *= -1; }\n if (ps[ru] > ps[rv]) { swap(ru, rv); }\n ps[ru] += ps[rv]; ps[rv] = ru; qs[rv] = cc;\n return true;\n}\n\n\nint N, M;\nint[] A, B, C;\nint[] U, V, P;\n\nint[][] G;\nint[] ds;\n\nvoid dfs(int u, int p, int d) {\n ds[u] = d;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n const c = (~C[i]) ? (popcnt(C[i]) & 1) : 0;\n dfs(v, u, d ^ c);\n }\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[N - 1];\n B = new int[N - 1];\n C = new int[N - 1];\n foreach (i; 0 .. N - 1) {\n A[i] = readInt - 1;\n B[i] = readInt - 1;\n C[i] = readInt;\n }\n U = new int[M];\n V = new int[M];\n P = new int[M];\n foreach (m; 0 .. M) {\n U[m] = readInt - 1;\n V[m] = readInt - 1;\n P[m] = readInt;\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 ds = new int[N];\n dfs(0, -1, 0);\n debug {\n writeln(\"ds = \", ds);\n }\n \n auto ps = new int[N];\n ps[] = -1;\n auto qs = new int[N];\n foreach (i; 0 .. N - 1) {\n if (~C[i]) {\n if (!connect(ps, qs, A[i], B[i], popcnt(C[i]) & 1)) {\n assert(false);\n }\n }\n }\n bool ok = true;\n foreach (m; 0 .. M) {\n if (!connect(ps, qs, U[m], V[m], P[m])) {\n ok = false;\n }\n }\n if (ok) {\n foreach (u; 0 .. N) {\n root(ps, qs, u);\n }\n writeln(\"YES\");\n foreach (i; 0 .. N - 1) {\n int c = C[i];\n if (!~c) {\n c = qs[A[i]] ^ qs[B[i]];\n }\n writeln(A[i] + 1, \" \", B[i] + 1, \" \", c);\n }\n } else {\n writeln(\"NO\");\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "884e547e8ccb05e618ec80904b2ea107"} {"source_code": "immutable multi = true;\n\nvoid solve(int)\n{\n\tauto n = readInt!long;\n\tauto s = readInt!long;\n\tlong med = (n+1)/2;\n\tlong frommed = n - med +1;\n\treturn writeln(s / frommed);\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\tint n, s;\r\n\t\treadf !(\" %s %s\") (n, s);\r\n\t\tn /= 2;\r\n\t\tn += 1;\r\n\t\ts /= n;\r\n\t\twriteln (s);\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\t\tauto s = RD!int;\r\n\r\n\t\tauto cnt = n / 2 + 1;\r\n\t\tans[ti] = s / cnt;\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.string, std.algorithm, std.array;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(i; 0..t){\r\n\tint n, s;\r\n\tscanf(\"%d %d\", &n, &s);\r\n\tauto num_zero = (n - 1) / 2;\r\n\twriteln(s / (n - num_zero));\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 long t;\n readf!\" %d \"(t);\n while (t--) {\n long n, s;\n readf!\" %d %d \"(n, s);\n long cnt = n / 2 + 1;\n long ans = s / cnt;\n writeln(ans);\n }\n}\n"}], "negative_code": [], "src_uid": "0a05b11307fbb2536f868acf4e81c1e2"} {"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\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\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 Hero {\n int hp, maxHp, regen;\n int lastUpdated;\n}\n\nstruct Event {\n enum Type: ubyte {\n hpChanged,\n critPoint,\n }\n\n int time;\n Type type;\n Hero* h;\n union { int newHp, lastUpdated; }\n}\n\nint hcount, mcount;\nint baseBounty, kBounty, damage;\nHero[100_000] _heroes;\n\nlong calcBounty(int time) {\n return baseBounty + long(time) * kBounty;\n}\n\nvoid main() {\n Array!Event events;\n while (read(hcount, mcount, baseBounty, kBounty, damage)) {\n auto heroes = _heroes[0 .. hcount];\n version (LocalProject)\n heroes[ ] = Hero.init;\n events.clear();\n events.reserve(hcount + mcount);\n foreach (ref h; heroes) {\n read(h.maxHp, h.hp, h.regen);\n assert(h.hp <= h.maxHp);\n }\n foreach (i; 0 .. mcount) {\n int time, hindex, newHp;\n read(time, hindex, newHp);\n events ~= Event(time, Event.Type.hpChanged, &heroes[hindex - 1], newHp);\n }\n\n auto pq = events.heapify!((a, b) => tuple(a.time, a.type) > tuple(b.time, b.type));\n int curTime = 0, prevTime = 0;\n\n int getEffectiveHpAt(ref const Hero h, int time) {\n return cast(int)min(h.hp + long(time - h.lastUpdated) * h.regen, h.maxHp);\n }\n\n bool isVictimAt(ref const Hero h, int time) {\n if (h.maxHp <= damage)\n return true;\n const hp = getEffectiveHpAt(h, time);\n return hp < damage || (hp == damage && !h.regen);\n }\n\n bool isSemiVictimAt(ref const Hero h, int time) {\n return h.maxHp > damage && getEffectiveHpAt(h, time) == damage && h.regen;\n }\n\n int victims = cast(int)heroes[ ].count!(h => isVictimAt(h, 0));\n int semi = 0;\n long maxBounty = 0;\n\n void processHeroRegen(ref Hero h, int newHp) {\n if (isVictimAt(h, h.lastUpdated))\n victims--;\n assert(victims >= 0);\n\n h.hp = newHp;\n assert(h.hp <= h.maxHp);\n if (damage > h.hp && damage < h.maxHp && h.regen) {\n const timeToRegen = (damage - h.hp + h.regen - 1) / h.regen;\n assert(timeToRegen > 0);\n pq.insert(Event(curTime + timeToRegen, Event.Type.critPoint, &h, curTime));\n }\n\n h.lastUpdated = curTime;\n if (isVictimAt(h, curTime))\n victims++;\n else if (isSemiVictimAt(h, curTime))\n semi++;\n assert(victims + semi <= hcount);\n }\n\n foreach (ref h; heroes)\n processHeroRegen(h, h.hp);\n\n while (!pq.empty) {\n auto e = pq.front;\n pq.removeFront();\n curTime = e.time;\n if (curTime != prevTime) {\n const option1 = (victims + semi) * calcBounty(prevTime);\n const option2 = victims * calcBounty(curTime - 1);\n debug if (max(option1, option2) > maxBounty)\n writefln(\"%s | %s: v = %s, s = %s, bounty = %s | %s\",\n prevTime, curTime - 1, victims, semi, option1, option2);\n maxBounty = max(maxBounty, option1, option2);\n semi = 0;\n }\n\n final switch (e.type) with (Event.Type) {\n case hpChanged:\n processHeroRegen(*e.h, e.newHp);\n break;\n\n case critPoint:\n if (e.lastUpdated == e.h.lastUpdated)\n processHeroRegen(*e.h, getEffectiveHpAt(*e.h, curTime));\n break;\n }\n\n debug writefln(\"%s: stats = [%(%(%s/%), %)]\",\n curTime,\n heroes[ ].map!(h => [getEffectiveHpAt(h, curTime), h.maxHp]),\n );\n prevTime = curTime;\n }\n maxBounty = max(maxBounty, (victims + semi) * calcBounty(prevTime));\n if (kBounty && heroes[ ].any!(h => h.maxHp <= damage || (!h.regen && h.hp <= damage)))\n write(\"-1\\n\");\n else\n writeln(maxBounty);\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\n}\n", "positive_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 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\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 Hero {\n int hp, maxHp, regen;\n int lastUpdated;\n}\n\nstruct Event {\n enum Type: ubyte {\n hpChanged,\n critPoint,\n }\n\n int time;\n Type type;\n Hero* h;\n union { int newHp, lastUpdated; }\n}\n\nint hcount, mcount;\nint baseBounty, kBounty, damage;\nHero[100_000] _heroes;\n\nlong calcBounty(int time) {\n return baseBounty + long(time) * kBounty;\n}\n\nvoid main() {\n Array!Event events;\n while (read(hcount, mcount, baseBounty, kBounty, damage)) {\n auto heroes = _heroes[0 .. hcount];\n version (LocalProject)\n heroes[ ] = Hero.init;\n events.clear();\n events.reserve(hcount + mcount);\n foreach (ref h; heroes) {\n read(h.maxHp, h.hp, h.regen);\n assert(h.hp <= h.maxHp);\n }\n foreach (i; 0 .. mcount) {\n int time, hindex, newHp;\n read(time, hindex, newHp);\n events ~= Event(time, Event.Type.hpChanged, &heroes[hindex - 1], newHp);\n }\n\n auto pq = events.heapify!((a, b) => tuple(a.time, a.type) > tuple(b.time, b.type));\n int curTime = 0, prevTime = 0;\n\n int getEffectiveHpAt(ref const Hero h, int time) {\n return cast(int)min(h.hp + long(time - h.lastUpdated) * h.regen, h.maxHp);\n }\n\n bool isVictimAt(ref const Hero h, int time) {\n if (h.maxHp <= damage)\n return true;\n const hp = getEffectiveHpAt(h, time);\n return hp < damage || (hp == damage && !h.regen);\n }\n\n bool isSemiVictimAt(ref const Hero h, int time) {\n return h.maxHp > damage && getEffectiveHpAt(h, time) == damage && h.regen;\n }\n\n int victims = cast(int)heroes[ ].count!(h => isVictimAt(h, 0));\n int semi = 0;\n long maxBounty = 0;\n\n void processHeroRegen(ref Hero h, int newHp) {\n if (isVictimAt(h, h.lastUpdated))\n victims--;\n assert(victims >= 0);\n\n h.hp = newHp;\n assert(h.hp <= h.maxHp);\n if (damage > h.hp && damage < h.maxHp && h.regen) {\n const timeToRegen = (damage - h.hp + h.regen - 1) / h.regen;\n assert(timeToRegen > 0);\n pq.insert(Event(curTime + timeToRegen, Event.Type.critPoint, &h, curTime));\n }\n\n h.lastUpdated = curTime;\n if (isVictimAt(h, curTime))\n victims++;\n else if (isSemiVictimAt(h, curTime))\n semi++;\n assert(victims + semi <= hcount);\n }\n\n foreach (ref h; heroes)\n processHeroRegen(h, h.hp);\n\n while (!pq.empty) {\n auto e = pq.front;\n pq.removeFront();\n curTime = e.time;\n if (curTime != prevTime) {\n const option1 = (victims + semi) * calcBounty(prevTime);\n const option2 = victims * calcBounty(curTime - 1);\n debug if (max(option1, option2) > maxBounty)\n writefln(\"%s | %s: v = %s, s = %s, bounty = %s | %s\",\n prevTime, curTime - 1, victims, semi, option1, option2);\n maxBounty = max(maxBounty, option1, option2);\n semi = 0;\n }\n\n final switch (e.type) with (Event.Type) {\n case hpChanged:\n processHeroRegen(*e.h, e.newHp);\n break;\n\n case critPoint:\n if (e.lastUpdated == e.h.lastUpdated)\n processHeroRegen(*e.h, getEffectiveHpAt(*e.h, curTime));\n break;\n }\n\n debug writefln(\"%s: stats = [%(%(%s/%), %)]\",\n curTime,\n heroes[ ].map!(h => [getEffectiveHpAt(h, curTime), h.maxHp]),\n );\n prevTime = curTime;\n }\n maxBounty = max(maxBounty, (victims + semi) * calcBounty(prevTime));\n if (kBounty && heroes[ ].any!(h => h.maxHp <= damage || (!h.regen && h.hp <= damage)))\n write(\"-1\\n\");\n else\n writeln(maxBounty);\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\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 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\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 Hero {\n int hp, maxHp, regen;\n int lastUpdated;\n}\n\nstruct Event {\n enum Type: ubyte {\n hpChanged,\n critPoint,\n }\n\n int time;\n Type type;\n Hero* h;\n union { int newHp, lastUpdated; }\n}\n\nint hcount, mcount;\nint baseBounty, kBounty, damage;\nHero[100_000] _heroes;\n\nlong calcBounty(int time) {\n return baseBounty + long(time) * kBounty;\n}\n\nvoid main() {\n Array!Event events;\n while (read(hcount, mcount, baseBounty, kBounty, damage)) {\n auto heroes = _heroes[0 .. hcount];\n events.clear();\n events.reserve(hcount + mcount);\n foreach (ref h; heroes) {\n read(h.maxHp, h.hp, h.regen);\n assert(h.hp <= h.maxHp);\n }\n foreach (i; 0 .. mcount) {\n int time, hindex, newHp;\n read(time, hindex, newHp);\n events ~= Event(time, Event.Type.hpChanged, &heroes[hindex - 1], newHp);\n }\n\n auto pq = events.heapify!((a, b) => tuple(a.time, a.type) > tuple(b.time, b.type));\n int curTime = 0, prevTime = 0;\n\n int getEffectiveHpAt(ref const Hero h, int time) {\n return cast(int)min(h.hp + long(time - h.lastUpdated) * h.regen, h.maxHp);\n }\n\n bool isVictimAt(ref const Hero h, int time) {\n if (h.maxHp <= damage)\n return true;\n const hp = getEffectiveHpAt(h, time);\n return hp < damage || (hp == damage && !h.regen);\n }\n\n bool isSemiVictimAt(ref const Hero h, int time) {\n return h.maxHp > damage && getEffectiveHpAt(h, time) == damage && h.regen;\n }\n\n int victims = cast(int)heroes[ ].count!(h => isVictimAt(h, 0));\n int semi = cast(int)heroes[ ].count!(h => isSemiVictimAt(h, 0));\n long maxBounty = 0;\n\n void processHeroRegen(ref Hero h, int newHp, bool allowLoop = true) {\n if (isVictimAt(h, h.lastUpdated))\n victims--;\n assert(victims >= 0);\n\n h.hp = newHp;\n assert(h.hp <= h.maxHp);\n if (damage >= h.hp && damage < h.maxHp && h.regen && (damage > h.hp || allowLoop)) {\n const timeToRegen = (damage - h.hp + h.regen - 1) / h.regen;\n assert(timeToRegen >= 0);\n pq.insert(Event(curTime + timeToRegen, Event.Type.critPoint, &h, curTime));\n }\n\n h.lastUpdated = curTime;\n if (isVictimAt(h, curTime))\n victims++;\n else if (isSemiVictimAt(h, curTime))\n semi++;\n assert(victims + semi <= hcount);\n }\n\n foreach (ref h; heroes)\n processHeroRegen(h, h.hp);\n\n while (!pq.empty) {\n auto e = pq.front;\n pq.removeFront();\n curTime = e.time;\n if (curTime != prevTime) {\n const option1 = (victims + semi) * calcBounty(prevTime);\n const option2 = victims * calcBounty(curTime - 1);\n debug if (max(option1, option2) > maxBounty)\n writefln(\"%s | %s: v = %s, s = %s, bounty = %s | %s\",\n prevTime, curTime - 1, victims, semi, option1, option2);\n maxBounty = max(maxBounty, option1, option2);\n semi = 0;\n }\n\n final switch (e.type) with (Event.Type) {\n case hpChanged:\n processHeroRegen(*e.h, e.newHp);\n break;\n\n case critPoint:\n if (e.lastUpdated == e.h.lastUpdated)\n processHeroRegen(*e.h, getEffectiveHpAt(*e.h, curTime), false);\n break;\n }\n\n debug writefln(\"%s: stats = [%(%(%s/%), %)]\",\n curTime,\n heroes[ ].map!(h => [getEffectiveHpAt(h, curTime), h.maxHp]),\n );\n prevTime = curTime;\n }\n maxBounty = max(maxBounty, (victims + semi) * calcBounty(prevTime));\n if (heroes[ ].any!(h => h.maxHp <= damage || (!h.regen && h.hp <= damage)))\n write(\"-1\\n\");\n else\n writeln(maxBounty);\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\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 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\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 Hero {\n int hp, maxHp, regen;\n int lastUpdated;\n}\n\nstruct Event {\n enum Type: ubyte {\n hpChanged,\n critPoint,\n }\n\n int time;\n Type type;\n Hero* h;\n union { int newHp, lastUpdated; }\n}\n\nint hcount, mcount;\nint baseBounty, kBounty, damage;\nHero[100_000] _heroes;\n\nlong calcBounty(int time) {\n return baseBounty + long(time) * kBounty;\n}\n\nvoid main() {\n Array!Event events;\n while (read(hcount, mcount, baseBounty, kBounty, damage)) {\n auto heroes = _heroes[0 .. hcount];\n events.clear();\n events.reserve(hcount + mcount);\n foreach (ref h; heroes) {\n read(h.maxHp, h.hp, h.regen);\n assert(h.hp <= h.maxHp);\n }\n foreach (i; 0 .. mcount) {\n int time, hindex, newHp;\n read(time, hindex, newHp);\n events ~= Event(time, Event.Type.hpChanged, &heroes[hindex - 1], newHp);\n }\n if (kBounty && heroes[ ].any!(h => h.maxHp <= damage)) {\n write(\"-1\\n\");\n debug writeln();\n continue;\n }\n\n auto pq = events.heapify!((a, b) => tuple(a.time, a.type) > tuple(b.time, b.type));\n int curTime = 0, prevTime = 0;\n\n int getEffectiveHpAt(ref const Hero h, int time) {\n return cast(int)min(h.hp + long(time - h.lastUpdated) * h.regen, h.maxHp);\n }\n\n bool isVictimAt(ref const Hero h, int time) {\n if (h.maxHp <= damage)\n return true;\n const hp = getEffectiveHpAt(h, time);\n return hp < damage || (hp == damage && !h.regen);\n }\n\n bool isSemiVictimAt(ref const Hero h, int time) {\n return h.maxHp > damage && getEffectiveHpAt(h, time) == damage && h.regen;\n }\n\n int victims = cast(int)heroes[ ].count!(h => isVictimAt(h, 0));\n int semi = cast(int)heroes[ ].count!(h => isSemiVictimAt(h, 0));\n long maxBounty = 0;\n\n void processHeroRegen(ref Hero h, int newHp, bool allowLoop = true) {\n if (isVictimAt(h, h.lastUpdated))\n victims--;\n assert(victims >= 0);\n\n h.hp = newHp;\n assert(h.hp <= h.maxHp);\n if (damage >= h.hp && damage < h.maxHp && h.regen && (damage > h.hp || allowLoop)) {\n const timeToRegen = (damage - h.hp + h.regen - 1) / h.regen;\n assert(timeToRegen >= 0);\n pq.insert(Event(curTime + timeToRegen, Event.Type.critPoint, &h, curTime));\n }\n\n h.lastUpdated = curTime;\n if (isVictimAt(h, curTime))\n victims++;\n else if (isSemiVictimAt(h, curTime))\n semi++;\n assert(victims + semi <= hcount);\n }\n\n foreach (ref h; heroes)\n processHeroRegen(h, h.hp);\n\n while (!pq.empty) {\n auto e = pq.front;\n pq.removeFront();\n curTime = e.time;\n if (curTime != prevTime) {\n const option1 = (victims + semi) * calcBounty(prevTime);\n const option2 = victims * calcBounty(curTime - 1);\n debug if (max(option1, option2) > maxBounty)\n writefln(\"%s | %s: v = %s, s = %s, bounty = %s | %s\",\n prevTime, curTime - 1, victims, semi, option1, option2);\n maxBounty = max(maxBounty, option1, option2);\n semi = 0;\n }\n\n final switch (e.type) with (Event.Type) {\n case hpChanged:\n processHeroRegen(*e.h, e.newHp);\n break;\n\n case critPoint:\n if (e.lastUpdated == e.h.lastUpdated)\n processHeroRegen(*e.h, getEffectiveHpAt(*e.h, curTime), false);\n break;\n }\n\n debug writefln(\"%s: stats = [%(%(%s/%), %)]\",\n curTime,\n heroes[ ].map!(h => [getEffectiveHpAt(h, curTime), h.maxHp]),\n );\n prevTime = curTime;\n }\n maxBounty = max(maxBounty, (victims + semi) * calcBounty(prevTime));\n writeln(maxBounty);\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\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 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\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 Hero {\n int hp, maxHp, regen;\n int lastUpdated;\n}\n\nstruct Event {\n enum Type: ubyte {\n hpChanged,\n critPoint,\n }\n\n int time;\n Type type;\n Hero* h;\n union { int newHp, lastUpdated; }\n}\n\nint hcount, mcount;\nint baseBounty, kBounty, damage;\nHero[100_000] _heroes;\n\nlong calcBounty(int time) {\n return baseBounty + long(time) * kBounty;\n}\n\nvoid main() {\n Array!Event events;\n while (read(hcount, mcount, baseBounty, kBounty, damage)) {\n auto heroes = _heroes[0 .. hcount];\n version (LocalProject)\n heroes[ ] = Hero.init;\n events.clear();\n events.reserve(hcount + mcount);\n foreach (ref h; heroes) {\n read(h.maxHp, h.hp, h.regen);\n assert(h.hp <= h.maxHp);\n }\n foreach (i; 0 .. mcount) {\n int time, hindex, newHp;\n read(time, hindex, newHp);\n events ~= Event(time, Event.Type.hpChanged, &heroes[hindex - 1], newHp);\n }\n\n auto pq = events.heapify!((a, b) => tuple(a.time, a.type) > tuple(b.time, b.type));\n int curTime = 0, prevTime = 0;\n\n int getEffectiveHpAt(ref const Hero h, int time) {\n return cast(int)min(h.hp + long(time - h.lastUpdated) * h.regen, h.maxHp);\n }\n\n bool isVictimAt(ref const Hero h, int time) {\n if (h.maxHp <= damage)\n return true;\n const hp = getEffectiveHpAt(h, time);\n return hp < damage || (hp == damage && !h.regen);\n }\n\n bool isSemiVictimAt(ref const Hero h, int time) {\n return h.maxHp > damage && getEffectiveHpAt(h, time) == damage && h.regen;\n }\n\n int victims = cast(int)heroes[ ].count!(h => isVictimAt(h, 0));\n int semi = cast(int)heroes[ ].count!(h => isSemiVictimAt(h, 0));\n long maxBounty = 0;\n\n void processHeroRegen(ref Hero h, int newHp, bool allowLoop = true) {\n if (isVictimAt(h, h.lastUpdated))\n victims--;\n assert(victims >= 0);\n\n h.hp = newHp;\n assert(h.hp <= h.maxHp);\n if (damage >= h.hp && damage < h.maxHp && h.regen && (damage > h.hp || allowLoop)) {\n const timeToRegen = (damage - h.hp + h.regen - 1) / h.regen;\n assert(timeToRegen >= 0);\n pq.insert(Event(curTime + timeToRegen, Event.Type.critPoint, &h, curTime));\n }\n\n h.lastUpdated = curTime;\n if (isVictimAt(h, curTime))\n victims++;\n else if (isSemiVictimAt(h, curTime))\n semi++;\n assert(victims + semi <= hcount);\n }\n\n foreach (ref h; heroes)\n processHeroRegen(h, h.hp);\n\n while (!pq.empty) {\n auto e = pq.front;\n pq.removeFront();\n curTime = e.time;\n if (curTime != prevTime) {\n const option1 = (victims + semi) * calcBounty(prevTime);\n const option2 = victims * calcBounty(curTime - 1);\n debug if (max(option1, option2) > maxBounty)\n writefln(\"%s | %s: v = %s, s = %s, bounty = %s | %s\",\n prevTime, curTime - 1, victims, semi, option1, option2);\n maxBounty = max(maxBounty, option1, option2);\n semi = 0;\n }\n\n final switch (e.type) with (Event.Type) {\n case hpChanged:\n processHeroRegen(*e.h, e.newHp);\n break;\n\n case critPoint:\n if (e.lastUpdated == e.h.lastUpdated)\n processHeroRegen(*e.h, getEffectiveHpAt(*e.h, curTime), false);\n break;\n }\n\n debug writefln(\"%s: stats = [%(%(%s/%), %)]\",\n curTime,\n heroes[ ].map!(h => [getEffectiveHpAt(h, curTime), h.maxHp]),\n );\n prevTime = curTime;\n }\n maxBounty = max(maxBounty, (victims + semi) * calcBounty(prevTime));\n if (kBounty && heroes[ ].any!(h => h.maxHp <= damage || (!h.regen && h.hp <= damage)))\n write(\"-1\\n\");\n else\n writeln(maxBounty);\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\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 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\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 Hero {\n int hp, maxHp, regen;\n int lastUpdated;\n}\n\nstruct Event {\n enum Type: ubyte {\n hpChanged,\n critPoint,\n }\n\n int time;\n Type type;\n Hero* h;\n union { int newHp, lastUpdated; }\n}\n\nint hcount, mcount;\nint baseBounty, kBounty, damage;\nHero[100_000] _heroes;\n\nlong calcBounty(int time) {\n return baseBounty + long(time) * kBounty;\n}\n\nvoid main() {\n Array!Event events;\n while (read(hcount, mcount, baseBounty, kBounty, damage)) {\n auto heroes = _heroes[0 .. hcount];\n version (LocalProject)\n heroes[ ] = Hero.init;\n events.clear();\n events.reserve(hcount + mcount);\n foreach (ref h; heroes) {\n read(h.maxHp, h.hp, h.regen);\n assert(h.hp <= h.maxHp);\n }\n foreach (i; 0 .. mcount) {\n int time, hindex, newHp;\n read(time, hindex, newHp);\n events ~= Event(time, Event.Type.hpChanged, &heroes[hindex - 1], newHp);\n }\n\n auto pq = events.heapify!((a, b) => tuple(a.time, a.type) > tuple(b.time, b.type));\n int curTime = 0, prevTime = 0;\n\n int getEffectiveHpAt(ref const Hero h, int time) {\n return cast(int)min(h.hp + long(time - h.lastUpdated) * h.regen, h.maxHp);\n }\n\n bool isVictimAt(ref const Hero h, int time) {\n if (h.maxHp <= damage)\n return true;\n const hp = getEffectiveHpAt(h, time);\n return hp < damage || (hp == damage && !h.regen);\n }\n\n bool isSemiVictimAt(ref const Hero h, int time) {\n return h.maxHp > damage && getEffectiveHpAt(h, time) == damage && h.regen;\n }\n\n int victims = cast(int)heroes[ ].count!(h => isVictimAt(h, 0));\n int semi = cast(int)heroes[ ].count!(h => isSemiVictimAt(h, 0));\n long maxBounty = 0;\n\n void processHeroRegen(ref Hero h, int newHp) {\n if (isVictimAt(h, h.lastUpdated))\n victims--;\n assert(victims >= 0);\n\n h.hp = newHp;\n assert(h.hp <= h.maxHp);\n if (damage > h.hp && damage < h.maxHp && h.regen) {\n const timeToRegen = (damage - h.hp + h.regen - 1) / h.regen;\n assert(timeToRegen >= 0);\n pq.insert(Event(curTime + timeToRegen, Event.Type.critPoint, &h, curTime));\n }\n\n h.lastUpdated = curTime;\n if (isVictimAt(h, curTime))\n victims++;\n else if (isSemiVictimAt(h, curTime))\n semi++;\n assert(victims + semi <= hcount);\n }\n\n foreach (ref h; heroes)\n processHeroRegen(h, h.hp);\n\n while (!pq.empty) {\n auto e = pq.front;\n pq.removeFront();\n curTime = e.time;\n if (curTime != prevTime) {\n const option1 = (victims + semi) * calcBounty(prevTime);\n const option2 = victims * calcBounty(curTime - 1);\n debug if (max(option1, option2) > maxBounty)\n writefln(\"%s | %s: v = %s, s = %s, bounty = %s | %s\",\n prevTime, curTime - 1, victims, semi, option1, option2);\n maxBounty = max(maxBounty, option1, option2);\n semi = 0;\n }\n\n final switch (e.type) with (Event.Type) {\n case hpChanged:\n processHeroRegen(*e.h, e.newHp);\n break;\n\n case critPoint:\n if (e.lastUpdated == e.h.lastUpdated)\n processHeroRegen(*e.h, getEffectiveHpAt(*e.h, curTime));\n break;\n }\n\n debug writefln(\"%s: stats = [%(%(%s/%), %)]\",\n curTime,\n heroes[ ].map!(h => [getEffectiveHpAt(h, curTime), h.maxHp]),\n );\n prevTime = curTime;\n }\n maxBounty = max(maxBounty, (victims + semi) * calcBounty(prevTime));\n if (kBounty && heroes[ ].any!(h => h.maxHp <= damage || (!h.regen && h.hp <= damage)))\n write(\"-1\\n\");\n else\n writeln(maxBounty);\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\n}\n"}], "src_uid": "d05b6e11f051aa998296f63e3ecf2612"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, limit;\n\twhile (readf (\" %s %s\", &n, &limit) > 0)\n\t{\n\t\tlimit *= 8;\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tauto c = a.group.array;\n\t\tauto letters = c.length;\n\t\tauto s = [0];\n\t\ts.reserve (letters + 1);\n\t\tforeach (e; c)\n\t\t{\n\t\t\ts ~= s.back + e[1];\n\t\t}\n\t\tint res = n;\n\n\t\tint k = 0;\n\t\tint r = 1;\n\t\twhile (r <= letters)\n\t\t{\n\t\t\tfor (int i = 0, j = r; j <= letters; i++, j++)\n\t\t\t{\n\t\t\t\tif (n * 1L * k <= limit)\n\t\t\t\t{\n\t\t\t\t\tint cur = s[j] - s[i];\n\t\t\t\t\tres = min (res, n - cur);\n\t\t\t\t}\n\t\t\t}\n\t\t\tk += 1;\n\t\t\tr <<= 1;\n\t\t}\n\t\tif (n * 1L * k <= limit)\n\t\t{\n\t\t\tres = 0;\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math: pow;\n\nconst int MAX = 400005;\n\nint n, I;\nint[MAX] a;\nint[MAX] count;\nint[MAX] sum;\n\nvoid main() {\n readf(\" %s %s\", n, I);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n auto k = min(19, I * 8 / n);\n auto K = pow(2, k);\n\n sort(a[0..n]);\n auto m = 1;\n count[0] = 0;\n count[1] = 1;\n foreach(i; 1..n) {\n if (a[i] != a[i-1]) m++;\n count[m]++;\n }\n m++;\n\n foreach(i; 1..m) sum[i] = sum[i-1] + count[i];\n\n auto result = 0;\n foreach(i; 1..m) {\n auto j = max(0, i-K);\n result = max(result, sum[i] - sum[j]);\n }\n writeln(n - result);\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, el;\n readf(\"%s %s\", &n, &el);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n debug { int.max.writeln; }\n \n int space = el * 8 / n;\n int mx = space < 31 ? 2 ^^ space : int.max;\n \n debug { mx.writeln; }\n \n auto vals = arr.sort.group.map!(v => v[1]).array;\n \n debug { vals.writeln; }\n \n int ans = n, cur = vals[0 .. min(mx, vals.length)].sum;\n foreach (i; 0 .. vals.length) { \n ans = min(ans, n - cur);\n \n cur -= vals[i];\n if (i + mx < vals.length) { cur += vals[i + mx]; }\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.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, I;\nint[] A;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n I = readInt();\n A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n A.sort;\n \n int k;\n for (k = N; k >= 1; --k) {\n long logK = bsr(k);\n if (k & k - 1) {\n ++logK;\n }\n debug {\n writeln(k, \" \", logK);\n }\n if (N * logK <= 8 * I) {\n break;\n }\n }\n debug {\n writeln(\"k = \", k);\n }\n \n auto as = A.dup;\n as = as.sort.uniq.array;\n const asLen = cast(int)(as.length);\n auto cnt = new int[asLen];\n foreach (i; 0 .. N) {\n ++cnt[as.lowerBound(A[i])];\n }\n debug {\n writeln(\"cnt = \", cnt);\n }\n auto sum = new int[asLen + 1];\n foreach (j; 0 .. asLen) {\n sum[j + 1] = sum[j] + cnt[j];\n }\n \n int ans;\n foreach (j; 0 .. asLen) {\n chmax(ans, sum[min(j + k, asLen)] - sum[j]);\n }\n ans = N - ans;\n writeln(ans);\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, el;\n readf(\"%s %s\", &n, &el);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n debug { int.max.writeln; }\n \n int space = el * 8 / n;\n int mx = space < 31 ? 2 ^^ space : int.max;\n \n debug { mx.writeln; }\n \n auto vals = arr.sort.group.map!(v => v[1]).array;\n \n debug { vals.writeln; }\n \n int ans = n, cur = vals[0 .. min(mx, vals.length)].sum;\n foreach (i; 0 .. vals.length) { \n ans = min(ans, n - cur);\n \n cur -= vals[i];\n if (i + mx < vals.length) { cur += vals[i + mx - 1]; }\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.math: pow;\n\nconst int MAX = 400005;\n\nint n, I;\nint[MAX] a;\nint[MAX] count;\nint[MAX] sum;\n\nvoid main() {\n readf(\" %s %s\", n, I);\n foreach(i; 0..n) readf(\" %s\", a[i]);\n\n auto k = I * 8 / n;\n auto K = pow(2, k);\n\n sort(a[0..n]);\n auto m = 1;\n count[0] = 0;\n count[1] = 1;\n foreach(i; 1..n) {\n if (a[i] != a[i-1]) m++;\n count[m]++;\n }\n m++;\n\n foreach(i; 1..m) sum[i] = sum[i-1] + count[i];\n\n auto result = 0;\n foreach(i; 1..m) {\n auto j = max(0, i-K);\n result = max(result, sum[i] - sum[j]);\n }\n writeln(n - result);\n}\n"}], "src_uid": "ee4f345ac64f4444bd6e30d4818423a6"} {"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 ulong n, k;\n readf!\"%d %d\\n\"(n, k);\n\n ulong l = cast(ulong) ceil(log2(k));\n\n ulong c_i = pow(2, l+1) - (pow(2, l) - k);\n\n if (n <= c_i) {\n writeln(ceil(log2(n)));\n continue;\n }\n\n ulong c_a = n - c_i;\n ulong ceil = c_a / k + (c_a % k == 0 ? 0 : 1);\n writeln(l + ceil + 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\tlong n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\tlong cur = 1;\r\n\t\tlong res = 0;\r\n\t\twhile (cur < n && cur < k)\r\n\t\t{\r\n\t\t\tcur <<= 1;\r\n\t\t\tres += 1;\r\n\t\t}\r\n\t\twriteln (res + (n - cur + k - 1) / k);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "5df6eb50ead22b498bea69bb84341c06"} {"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 = readln.chomp.split.map!(to!int).array;\n \n long[] pows;\n if (k == 1) pows ~= 1;\n else if (k == -1) pows ~= [-1, 1];\n else {\n pows ~= [1, k];\n while (abs(pows.back) < 10L ^^ 9 * 10 ^^ 5) { pows ~= pows[$-1] * k; }\n }\n \n int[long] cnt;\n cnt[0] = 1;\n \n long ans = 0;\n long sm = 0;\n foreach (e; arr) {\n sm += e;\n \n foreach (p; pows) { ans += cnt.get(sm - p, 0); }\n \n cnt[sm] += 1;\n }\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 arr = readln.chomp.split.map!(to!int).array;\n \n long[] pows;\n if (k == 1) pows ~= 1;\n else if (k == -1) pows ~= [-1, 1];\n else {\n pows ~= [1, k];\n while (abs(pows.back) < 10L ^^ 9 * 10 ^^ 5) pows ~= pows[$-1] * k;\n }\n \n int[long] cnt;\n cnt[0] = 1;\n \n long ans = 0;\n long sm = 0;\n foreach (e; arr) {\n sm += e;\n \n foreach (p; pows) { ans += cnt.get(sm - p, 0); }\n \n cnt[sm] += 1;\n }\n \n ans.writeln;\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;\n\tlong 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\tlong total = a.map !(abs).sum (0L);\n\t\tlong q = 1;\n\t\tlong [] p;\n\t\twhile (!p.canFind (q) && abs (q) <= total)\n\t\t{\n\t\t\tp ~= q;\n\t\t\tq *= k;\n\t\t}\n\t\tdebug {writeln (p);}\n\n\t\tlong res = 0;\n\t\tint [long] s;\n\t\ts[0] += 1;\n\t\tlong cur = 0;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tcur += c;\n\t\t\tforeach (r; p)\n\t\t\t{\n\t\t\t\tdebug {writeln (\"? \", r - cur);}\n\t\t\t\tif ((cur - r) in s)\n\t\t\t\t{\n\t\t\t\t\tres += s[cur - r];\n\t\t\t\t}\n\t\t\t}\n\t\t\ts[cur] += 1;\n\t\t\tdebug {writeln (s);}\n\t\t}\n\t\twriteln (res);\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, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n long[] pows;\n pows ~= k;\n while (k != 1 && abs(pows.back) < 10L ^^ 9 * 10 ^^ 5) pows ~= pows[$-1] * k;\n\n int[long] cnt;\n cnt[0] = 1;\n \n long ans = 0;\n long sm = 0;\n foreach (e; arr) {\n sm += e;\n \n foreach (p; pows) { ans += cnt.get(sm - p, 0); }\n \n cnt[sm] += 1;\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;\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 long[] pows;\n if (k == 1) pows ~= 1;\n else if (k == -1) pows ~= [-1, 1];\n else {\n pows ~= k;\n while (abs(pows.back) < 10L ^^ 9 * 10 ^^ 5) pows ~= pows[$-1] * k;\n }\n \n int[long] cnt;\n cnt[0] = 1;\n \n long ans = 0;\n long sm = 0;\n foreach (e; arr) {\n sm += e;\n \n foreach (p; pows) { ans += cnt.get(sm - p, 0); }\n \n cnt[sm] += 1;\n }\n \n ans.writeln;\n}"}], "src_uid": "e4a2cfe3e76a7fafb8116c1972394c46"} {"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 int[] ls = scan!int(m);\n\n foreach(i; 0 .. m){\n if(i + ls[i] > n){\n \"-1\".writeln;\n return;\n }\n }\n\n long sum = ls.to!(long[]).sum;\n if(sum < n.to!long){\n \"-1\".writeln;\n return;\n }\n\n int[] ans;\n foreach(i; 0 .. m) ans ~= i + 1;\n \n ans[m - 1] = n - ls[m - 1] + 1;\n foreach_reverse(i; 0 .. m - 1){\n if(ans[i] + ls[i] < ans[i + 1]) ans[i] = ans[i + 1] - ls[i];\n }\n\n ans.unsplit.print;\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, m;\nmultitest_loop:\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\treadln;\n\t\tauto len = readln.splitter.map !(to !(int)).array;\n\t\tauto total = sum (len, 0L);\n\t\tif (total < n)\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue multitest_loop;\n\t\t}\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tif (len[i] > n - i)\n\t\t\t{\n\t\t\t\twriteln (-1);\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\n\t\tlong [] ans;\n\t\tans.reserve (m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tlong pos = max (i, n - total);\n\t\t\tans ~= pos + 1;\n\t\t\ttotal -= len[i];\n\t\t}\n\t\twritefln !(\"%(%s %)\") (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) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto l = RDA;\n\n\tauto len = l.sum;\n\tauto d = len - n;\n\tif (d < 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tbool ok = true;\n\t\tauto ans = new int[](m);\n\t\tint pos = 1;\n\t\tlong r;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tif (l[i] > n-i)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[i] = pos - cast(int)r;\n\t\t\tr = min(l[i]-1, d);\n\t\t\td -= r;\n\t\t\tpos = ans[i] + cast(int)l[i];\n\t\t\tif (pos > n+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\tdebug writeln(ans);\n\t\tif (ok)\n\t\t\tans.map!(to!string).join(\" \").writeln;\n\t\telse\n\t\t\twriteln(-1);\n\t}\n\t\n\tstdout.flush;\n\tdebug readln;\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 = readLong();\n const M = readInt();\n auto L = new long[M];\n foreach (i; 0 .. M) {\n L[i] = readLong();\n }\n \n auto LSum = new long[M + 1];\n foreach (i; 0 .. M) {\n LSum[i + 1] = LSum[i] + L[i];\n }\n \n long[] ans;\n if (LSum[M] >= N) {\n ans = new long[M];\n long bef = -1;\n foreach (i; 0 .. M) {\n /*\n bef < p\n p + L[i] <= N\n p + L[i] + ... + L[M - 1] >= N\n */\n ans[i] = max(bef + 1, N - (LSum[M] - LSum[i]));\n if (!(ans[i] + L[i] <= N)) {\n ans = [];\n break;\n }\n bef = ans[i];\n }\n }\n \n if (!ans.empty) {\n foreach (i; 0 .. M) {\n if (i > 0) write(\" \");\n write(ans[i] + 1);\n }\n writeln();\n } else {\n writeln(-1);\n }\n \n debug {\n long[] brt;\n foreach (h; 0 .. N^^M) {\n auto ps = iota(M).map!(i => (h / N^^i % N)).array;\n bool ok = true;\n auto col = new int[cast(int)(N)];\n col[] = -1;\n foreach (i; 0 .. M) {\n if (ps[i] + L[i] <= N) {\n col[cast(int)(ps[i]) .. cast(int)(ps[i] + L[i])] = i;\n } else {\n ok = false;\n break;\n }\n }\n ok = ok && (col.count(-1) == 0);\n foreach (i; 0 .. M) {\n ok = ok && (col.count(i) != 0);\n }\n if (ok) {\n brt = ps;\n break;\n }\n }\n writeln(\"brt = \", brt);\n assert((!ans.empty) == (!brt.empty));\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\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 n = RD!int;\n\tauto m = RD!int;\n\tauto l = RDA!int;\n\n\tauto len = l.sum;\n\tauto d = len - n;\n\tif (d < 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tauto ans = new int[](m);\n\t\tint pos = 1;\n\t\tint r;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tans[i] = pos - r;\n\t\t\tr = min(l[i]-1, d);\n\t\t\td -= r;\n\t\t\tpos = ans[i] + l[i];\n\t\t}\n\t\tans.map!(to!string).join(\" \").writeln;\n\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) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto l = RDA!int;\n\n\tauto len = l.sum;\n\tauto d = len - n;\n\tif (d < 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tbool ok = true;\n\t\tauto ans = new int[](m);\n\t\tint pos = 1;\n\t\tint r;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tans[i] = pos - r;\n\t\t\tr = min(l[i]-1, d);\n\t\t\td -= r;\n\t\t\tpos = ans[i] + l[i];\n\t\t\tif (pos > n+1)\n\t\t\t\tok = false;\n\t\t}\n\t\tdebug writeln(ans);\n\t\tif (ok)\n\t\t\tans.map!(to!string).join(\" \").writeln;\n\t\telse\n\t\t\twriteln(-1);\n\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) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto l = RDA!int;\n\n\tauto len = l.sum;\n\tauto d = len - n;\n\tif (d < 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tbool ok = true;\n\t\tauto ans = new int[](m);\n\t\tint pos = 1;\n\t\tint r;\n\t\tauto index = l.MAKE_IDX!\"a > b\"();\n\t\tforeach (i; index)\n\t\t{\n\t\t\tans[i] = pos - r;\n\t\t\tr = min(l[i]-1, d);\n\t\t\td -= r;\n\t\t\tpos = ans[i] + l[i];\n\t\t\tif (pos > n+1)\n\t\t\t\tok = false;\n\t\t}\n\t\tdebug writeln(ans);\n\t\tif (ok)\n\t\t\tans.map!(to!string).join(\" \").writeln;\n\t\telse\n\t\t\twriteln(-1);\n\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) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto l = RDA!int;\n\n\tauto len = l.sum;\n\tauto d = len - n;\n\tif (d < 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tbool ok = true;\n\t\tauto ans = new int[](m);\n\t\tint pos = 1;\n\t\tint r;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tans[i] = pos - r;\n\t\t\tr = min(l[i]-1, d);\n\t\t\td -= r;\n\t\t\tpos = ans[i] + l[i];\n\t\t\tif (pos > n)\n\t\t\t\tok = false;\n\t\t}\n\t\tif (ok)\n\t\t\tans.map!(to!string).join(\" \").writeln;\n\t\telse\n\t\t\twriteln(-1);\n\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) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto m = RD!int;\n\tauto l = RDA!int;\n\n\tauto len = l.sum;\n\tauto d = len - n;\n\tif (d < 0)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tbool ok = true;\n\t\tauto ans = new int[](m);\n\t\tint pos = 1;\n\t\tint r;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tif (l[i] > n-i)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[i] = pos - r;\n\t\t\tr = min(l[i]-1, d);\n\t\t\td -= r;\n\t\t\tpos = ans[i] + l[i];\n\t\t\tif (pos > n+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\tdebug writeln(ans);\n\t\tif (ok)\n\t\t\tans.map!(to!string).join(\" \").writeln;\n\t\telse\n\t\t\twriteln(-1);\n\t}\n\t\n\tstdout.flush;\n\tdebug readln;\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 M = readInt();\n auto L = new int[M];\n foreach (i; 0 .. M) {\n L[i] = readInt();\n }\n \n auto LSum = new int[M + 1];\n foreach (i; 0 .. M) {\n LSum[i + 1] = LSum[i] + L[i];\n }\n \n int[] ans;\n if (LSum[M] >= N) {\n ans = new int[M];\n int bef = -1;\n foreach (i; 0 .. M) {\n /*\n bef < p\n p + L[i] <= N\n p + L[i] + ... + L[M - 1] >= N\n */\n ans[i] = max(bef + 1, N - (LSum[M] - LSum[i]));\n if (!(ans[i] + L[i] <= N)) {\n ans = [];\n break;\n }\n bef = ans[i];\n }\n }\n \n if (!ans.empty) {\n foreach (i; 0 .. M) {\n if (i > 0) write(\" \");\n write(ans[i] + 1);\n }\n writeln();\n } else {\n writeln(-1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "90be8c6cf8f2cd626d41d2b0be2dfed3"} {"source_code": "import std.stdio, std.string;\nimport std.random;\n\nvoid solve(int[] a)\n{\n int[] one[40];\n int[] zero[40];\n foreach (int i; 0 .. 32)\n {\n foreach (int j; 0 .. a.length)\n {\n if ((a[j] & (1 << i)) == 0)\n {\n zero[i] ~= j;\n }\n else\n {\n one[i] ~= j;\n }\n }\n }\n int tar = -1;\n for (int pos = 30; pos >= 0; -- pos)\n {\n if (one[pos].length > 0)\n {\n int i;\n for (i = 0; i < pos; ++ i)\n {\n if (zero[i].length == 0)\n {\n break;\n }\n int j;\n for (j = 0; j < zero[i].length; ++ j)\n {\n if (a[zero[i][j]] & (1 << pos))\n {\n break;\n }\n }\n if (j == zero[i].length)\n {\n break;\n }\n }\n if (i == pos)\n {\n tar = pos;\n break;\n }\n }\n }\n if (tar == -1)\n {\n writefln(\"-1\");\n return;\n }\n bool[] flag = new bool[a.length];\n int k = 0;\n foreach (int i; 0 .. one[tar].length)\n {\n ++ k;\n flag[one[tar][i]] = true;\n }\n foreach (int i; 0 .. tar)\n {\n foreach (int j; 0 .. zero[i].length)\n {\n if ((a[zero[i][j]] & (1 << tar)) && flag[zero[i][j]] == false)\n {\n ++ k;\n flag[zero[i][j]] = true;\n }\n }\n }\n writefln(\"%d\", k);\n foreach (int i; 0 .. a.length)\n {\n if (flag[i] == true)\n {\n writef(\"%d \", a[i]);\n }\n }\n writefln(\"\");\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n int[] a = new int[n];\n foreach (int i; 0 .. n)\n {\n //a[i] = uniform(0, 1000000000) + 1;\n //a[i] = 1000000000 - i;\n scanf(\"%d\", &a[i]);\n }\n solve(a);\n }\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.random;\n\nint getPosition(T)(T[] arr, int[] index, T tar)\n{\n int l = 0, r = index.length - 1, idx = -1;\n while (l <= r)\n {\n int m = (l + r) >> 1;\n if (arr[index[m]] < tar)\n {\n l = m + 1;\n }\n else\n {\n idx = m;\n r = m - 1;\n }\n }\n if (idx == -1)\n {\n idx = index.length;\n }\n return idx;\n}\n\nvoid solve(int[] a)\n{\n int[] one[40];\n int[] zero[40];\n foreach (int i; 0 .. 32)\n {\n foreach (int j; 0 .. a.length)\n {\n if ((a[j] & (1 << i)) == 0)\n {\n zero[i] ~= j;\n }\n else\n {\n one[i] ~= j;\n }\n }\n }\n int tar = -1;\n for (int pos = 30; pos >= 0; -- pos)\n {\n if (one[pos].length > 0)\n {\n int i;\n for (i = 0; i < pos; ++ i)\n {\n if (zero[i].length == 0)\n {\n break;\n }\n int j;\n int idx = getPosition(a, zero[i], 1 << pos);\n for (j = idx; j < zero[i].length; ++ j)\n {\n if (a[zero[i][j]] & (1 << pos))\n {\n break;\n }\n }\n if (j == zero[i].length)\n {\n break;\n }\n }\n if (i == pos)\n {\n tar = pos;\n break;\n }\n }\n }\n if (tar == -1)\n {\n writefln(\"-1\");\n return;\n }\n bool[] flag = new bool[a.length];\n int k = 0;\n foreach (int i; 0 .. one[tar].length)\n {\n ++ k;\n flag[one[tar][i]] = true;\n }\n foreach (int i; 0 .. tar)\n {\n foreach (int j; 0 .. zero[i].length)\n {\n if ((a[zero[i][j]] & (1 << tar)) && flag[zero[i][j]] == false)\n {\n ++ k;\n flag[zero[i][j]] = true;\n }\n }\n }\n /*foreach (int i; 0 .. a.length)\n {\n if (flag[i] == false && (a[i] & (1 << tar)) != 0)\n {\n ++ k;\n flag[i] = true;\n }\n }*/\n writefln(\"%d\", k);\n foreach (int i; 0 .. a.length)\n {\n if (flag[i] == true)\n {\n writef(\"%d \", a[i]);\n }\n }\n writefln(\"\");\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n int[] a = new int[n];\n foreach (int i; 0 .. n)\n {\n //a[i] = uniform(0, 1000000000) + 1;\n //a[i] = 1000000000 - i;\n scanf(\"%d\", &a[i]);\n }\n solve(a);\n }\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.random;\n\nint getPosition(T)(T[] arr, int[] index, T tar)\n{\n int l = 0, r = index.length - 1, idx = -1;\n while (l <= r)\n {\n int m = (l + r) >> 1;\n if (arr[index[m]] < tar)\n {\n l = m + 1;\n }\n else\n {\n idx = m;\n r = m - 1;\n }\n }\n if (idx == -1)\n {\n idx = index.length;\n }\n return idx;\n}\n\nvoid solve(int[] a)\n{\n int[] one[40];\n int[] zero[40];\n foreach (int i; 0 .. 32)\n {\n foreach (int j; 0 .. a.length)\n {\n if ((a[j] & (1 << i)) == 0)\n {\n zero[i] ~= j;\n }\n else\n {\n one[i] ~= j;\n }\n }\n }\n int tar = -1;\n for (int pos = 30; pos >= 0; -- pos)\n {\n if (one[pos].length > 0)\n {\n int i;\n for (i = 0; i < pos; ++ i)\n {\n if (zero[i].length == 0)\n {\n break;\n }\n int j;\n int idx = getPosition(a, zero[i], 1 << pos);\n for (j = idx; j < zero[i].length; ++ j)\n {\n if (a[zero[i][j]] & (1 << pos))\n {\n break;\n }\n }\n if (j == zero[i].length)\n {\n break;\n }\n }\n if (i == pos)\n {\n tar = pos;\n break;\n }\n }\n }\n if (tar == -1)\n {\n writefln(\"-1\");\n return;\n }\n bool[] flag = new bool[a.length];\n int k = 0;\n foreach (int i; 0 .. one[tar].length)\n {\n ++ k;\n flag[one[tar][i]] = true;\n }\n foreach (int i; 0 .. tar)\n {\n foreach (int j; 0 .. zero[i].length)\n {\n if ((a[zero[i][j]] & (1 << tar)) && flag[zero[i][j]] == false)\n {\n ++ k;\n flag[zero[i][j]] = true;\n }\n }\n }\n foreach (int i; 0 .. a.length)\n {\n if (flag[i] == false && (a[i] & (1 << tar)) != 0)\n {\n ++ k;\n flag[i] = true;\n }\n }\n writefln(\"%d\", k);\n foreach (int i; 0 .. a.length)\n {\n if (flag[i] == true)\n {\n writef(\"%d \", a[i]);\n }\n }\n writefln(\"\");\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n int[] a = new int[n];\n foreach (int i; 0 .. n)\n {\n //a[i] = uniform(0, 1000000000) + 1;\n //a[i] = 1000000000 - i;\n scanf(\"%d\", &a[i]);\n }\n solve(a);\n }\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.random;\n\nvoid solve(int[] a)\n{\n\tint[] one[40];\n\tint[] zero[40];\n\tforeach (int i; 0 .. 32)\n\t{\n\t\tforeach (int j; 0 .. a.length)\n\t\t{\n\t\t\tif ((a[j] & (1 << i)) == 0)\n\t\t\t{\n\t\t\t\tzero[i] ~= j;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tone[i] ~= j;\n\t\t\t}\n\t\t}\n\t}\n\tint tar = -1;\n\tfor (int pos = 30; pos >= 0; -- pos)\n\t{\n\t\tif (one[pos].length > 0)\n\t\t{\n\t\t\tint i;\n\t\t\tfor (i = 0; i < pos; ++ i)\n\t\t\t{\n\t\t\t\tif (zero[i].length == 0)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tint j;\n\t\t\t\tfor (j = 0; j < zero[i].length; ++ j)\n\t\t\t\t{\n\t\t\t\t\tif (a[zero[i][j]] & (1 << pos))\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\tif (j == zero[i].length)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i == pos)\n\t\t\t{\n\t\t\t\ttar = pos;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tif (tar == -1)\n\t{\n\t\twritefln(\"-1\");\n\t\treturn;\n\t}\n\tbool[] flag = new bool[a.length];\n\tint k = 0;\n\tforeach (int i; 0 .. one[tar].length)\n\t{\n\t\t++ k;\n\t\tflag[one[tar][i]] = true;\n\t}\n\tforeach (int i; 0 .. tar)\n\t{\n\t\tforeach (int j; 0 .. zero[i].length)\n\t\t{\n\t\t\tif ((a[zero[i][j]] & (1 << tar)) && flag[zero[i][j]] == false)\n\t\t\t{\n\t\t\t\t++ k;\n\t\t\t\tflag[zero[i][j]] = true;\n\t\t\t}\n\t\t}\n\t}\n\tforeach (int i; 0 .. a.length)\n\t{\n\t\tif (flag[i] == false && (a[i] & (1 << tar)) != 0)\n\t\t{\n\t\t\t++ k;\n\t\t\tflag[i] = true;\n\t\t}\n\t}\n\twritefln(\"%d\", k);\n\tforeach (int i; 0 .. a.length)\n\t{\n\t\tif (flag[i] == true)\n\t\t{\n\t\t\twritef(\"%d \", a[i]);\n\t\t}\n\t}\n\twritefln(\"\");\n}\n\nvoid main(string[] args)\n{\n\tint n;\n\twhile (scanf(\"%d\", &n) == 1)\n\t{\n\t\tint[] a = new int[n];\n\t\tforeach (int i; 0 .. n)\n\t\t{\n\t\t\t//a[i] = uniform(0, 1000000000) + 1;\n\t\t\t//a[i] = 1000000000 - i;\n\t\t\tscanf(\"%d\", &a[i]);\n\t\t}\n\t\tsolve(a);\n\t}\n}"}], "negative_code": [], "src_uid": "54c23dda2aa1d58ecf22c03015dca55c"} {"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 !(int, q{x}, int, q{y}, int, q{t});\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s \", &n, &m) > 0)\n\t{\n\t\treadln ();\n\t\tauto p = new Point [n + m + 2];\n\t\tint xmax = int.min;\n\t\tint ymax = int.min;\n\t\tforeach (i; 0..n + m)\n\t\t{\n\t\t\treadf (\" %s %s\", &p[i].x, &p[i].y);\n\t\t\tp[i].t = (i >= n);\n\t\t\tif (i >= n)\n\t\t\t{\n\t\t\t\txmax = max (xmax, p[i].x);\n\t\t\t\tymax = max (ymax, p[i].y);\n\t\t\t}\n\t\t}\n\t\tp[n + m + 0] = Point (xmax, 0, 1);\n\t\tp[n + m + 1] = Point (0, ymax, 1);\n\t\tsort !((a, b) => (a.x * 1L * b.y < a.y * 1L * b.x) ||\n\t\t ((a.x * 1L * b.y == a.y * 1L * b.x) &&\n\t\t (a.x + a.y < b.x + b.y)),\n\t\t SwapStrategy.stable) (p);\n\n\t\tPoint [] q;\n\t\tforeach (c; p)\n\t\t{\n\t\t\tif (q.length > 0 &&\n\t\t\t c.x == q[$ - 1].x &&\n\t\t\t c.y == q[$ - 1].y)\n\t\t\t{\n\t\t\t\tq[$ - 1].t &= c.t;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tq ~= c;\n\t\t\t}\n\t\t}\n\t\tp = q;\n\t\tdebug {writeln (p.map !(to !(string)).join (\"\\n\"));}\n\t\tdebug {writeln ();}\n\n\t\tPoint [] s;\n\t\ts.reserve (n + m + 4);\n\t\tforeach (c; p)\n\t\t{\n\t\t\twhile (s.length > 1 &&\n\t\t\t (s[$ - 1].x - s[$ - 2].x) * 1L *\n\t\t\t (c.y - s[$ - 2].y) >\n\t\t\t (s[$ - 1].y - s[$ - 2].y) * 1L *\n\t\t\t (c.x - s[$ - 2].x))\n\t\t\t{\n\t\t\t\ts.length--;\n\t\t\t}\n\t\t\ts.assumeSafeAppend ();\n\t\t\ts ~= c;\n\t\t}\n\t\tdebug {writeln (s.map !(to !(string)).join (\"\\n\"));}\n\n\t\twriteln (all !(a => a.t == 1) (s) ? \"Min\" : \"Max\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.range, std.stdio, std.typecons;\nalias Point = Tuple !(long, q{x}, int, q{y}, int, q{t});\nvoid main ()\n{\n int n, m;\n readf (\" %s %s \", &n, &m);\n readln ();\n auto p = new Point [n + m];\n foreach (i, ref c; p)\n {\n readf (\" %s %s\", &c.x, &c.y);\n c.t = (i >= n);\n }\n p ~= Point (p[n..$].minPos!q{a.x > b.x}.front.x, 0, 1);\n p ~= Point (0, p[n..$].minPos!q{a.y > b.y}.front.y, 1);\n sort !((a, b) => (a.x * b.y < a.y * b.x) ||\n ((a.x * b.y == a.y * b.x) && (a.x + a.y < b.x + b.y))) (p);\n Point [] q, s;\n foreach (c; p)\n {\n if (q.length > 0 && c.x == q[$ - 1].x && c.y == q[$ - 1].y)\n q[$ - 1].t &= c.t;\n else\n q ~= c;\n }\n foreach (c; q)\n {\n while (s.length > 1 &&\n (s[$ - 1].x - s[$ - 2].x) * (c.y - s[$ - 2].y) >\n (s[$ - 1].y - s[$ - 2].y) * (c.x - s[$ - 2].x))\n s.length--;\n s.assumeSafeAppend ();\n s ~= c;\n }\n writeln (s.all!q{a.t == 1} ? \"Min\" : \"Max\");\n}\n"}], "negative_code": [], "src_uid": "9144a2386a8ca167e719d8305fa8a2fe"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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;\n\n\t\tauto cnt = new long[](30);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..30)\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\t++cnt[j];\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 1..n+1)\n\t\t{\n\t\t\tbool ok = true;\n\t\t\tforeach (j; 0..30)\n\t\t\t{\n\t\t\t\tif (cnt[j] % i)\n\t\t\t\t\tok = false;\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t\tans[ti] ~= 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}", "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\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 k = 0;\r\n\t\tforeach (z; 0..30)\r\n\t\t{\r\n\t\t\tint v = 0;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tv += (a[i] >> z) & 1;\r\n\t\t\t}\r\n\t\t\tk = gcd (k, v);\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (iota (1, n + 1)\r\n\t\t .filter !(c => k % c == 0));\r\n\t}\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\n// https://www.geeksforgeeks.org/find-divisors-natural-number-set-1/\nlong[] SortedDivisors(long n)\n{\n long[] ans;\n for (long i = 1; i * i <= n; i++) {\n if (n % i == 0) {\n // If divisors are equal, print only one\n if (n/i == i) {\n ans ~= i;\n } else { // Otherwise print both\n ans ~= i;\n ans ~= n / i;\n }\n }\n }\n ans.sort;\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.strip.split.map!(to!long).array;\n long tmp = long.max;\n long[32] cnt;\n foreach (x ; a) {\n foreach (i ; 0 .. 32) {\n if (x & (1L << i))\n cnt[i]++;\n }\n }\n long[] filtered_cnt;\n foreach (i ; 0 .. 32) {\n if (cnt[i] != 0)\n filtered_cnt ~= cnt[i];\n }\n if (filtered_cnt.length == 0) {\n writeln(iota(1, n + 1).map!text.join(\" \"));\n } else {\n long ans = filtered_cnt[0];\n foreach (x ; filtered_cnt)\n ans = gcd(ans, x);\n writeln(SortedDivisors(ans).map!text.join(\" \"));\n }\n }\n}\n"}, {"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 ans = 0;\n\tforeach(i; 0 .. 30)\n\t{\n\t\tint count = 0;\n\t\tforeach(ai; a) if (ai & (1 << i)) count++;\n\t\tans = gcd(ans, count);\n\t}\n\tif (ans == 0)\n\t{\n\t\tforeach(i; 1 .. n + 1) write(i, \" \");\n\t\twriteln;\n\t\treturn;\n\t}\n\tforeach(i; 1 .. ans + 1)\n\t{\n\t\tif (ans % i == 0) write(i, \" \");\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"}], "negative_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\n// https://www.geeksforgeeks.org/find-divisors-natural-number-set-1/\nlong[] SortedDivisors(long n)\n{\n long[] ans;\n for (long i = 1; i * i <= n; i++) {\n if (n % i == 0) {\n // If divisors are equal, print only one\n if (n/i == i) {\n ans ~= i;\n } else { // Otherwise print both\n ans ~= i;\n ans ~= n / i;\n }\n }\n }\n ans.sort;\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.strip.split.map!(to!long).array;\n long tmp = long.max;\n long[32] cnt;\n foreach (x ; a) {\n foreach (i ; 0 .. 32) {\n if (x & (1L << i))\n cnt[i]++;\n }\n }\n long[] filtered_cnt;\n foreach (i ; 0 .. 32) {\n if (cnt[i] != 0)\n filtered_cnt ~= cnt[i];\n }\n if (filtered_cnt.length == 0) {\n writeln(n);\n } else {\n long ans = filtered_cnt[0];\n foreach (x ; filtered_cnt)\n ans = gcd(ans, x);\n writeln(SortedDivisors(ans).map!text.join(\" \"));\n }\n }\n}\n"}], "src_uid": "81f4bc9ac72ed39da8614131954d0d99"} {"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 = RDA;\r\n\r\n\t\tauto score = new long[](n);\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tscore[i] = a[i];\r\n\t\t\tauto j = cast(int)(i + a[i]);\r\n\t\t\tif (j < n)\r\n\t\t\t{\r\n\t\t\t\tscore[i] += score[j];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tans[ti] = score.maxElement;\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\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 = new int [n];\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tauto j = i + a[i];\r\n\t\t\tv[i] = a[i] + (j >= n ? 0 : v[j]);\r\n\t\t}\r\n\t\twriteln (v.maxElement);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "ee8ca9b2c6104d1ff9ba1fc39e9df277"} {"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 string[] s;\n foreach (i; 0 .. 2) { s ~= readln.chomp; }\n \n debug { s.writeln; }\n \n int chk(int ix1) {\n int section = 1;\n int it1 = 0, it2 = 0;\n while (it1 < n && it2 < n) {\n if (s[ix1][it1] == s[1-ix1][it2]) { \n it1 += 1;\n it2 += 1;\n continue;\n }\n \n if (section == 1) { \n section += 1; \n it1 += 1;\n } else if (section == 2) {\n section += 1;\n it2 += 1;\n } else {\n return 0;\n }\n }\n \n return 1;\n }\n \n int ans = chk(0) + chk(1);\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import 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 s = readln ().strip ();\n\t\tauto t = readln ().strip ();\n\t\twhile (!s.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 && s.back == t.back)\n\t\t{\n\t\t\ts.popBack ();\n\t\t\tt.popBack ();\n\t\t}\n\t\twriteln ((s[1..$] == t[0..$ - 1]) + (s[0..$ - 1] == t[1..$]));\n\t}\n}\n"}], "negative_code": [], "src_uid": "a1c3876d705ac8e8b81394ba2be12ed7"} {"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 M = readInt();\n auto A = new int[M];\n auto B = new int[M];\n auto W = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n W[i] = readInt();\n }\n \n // incr w, incr val\n alias Entry = Tuple!(int, \"w\", int, \"val\");\n auto sets = new RedBlackTree!Entry[N];\n foreach (u; 0 .. N) {\n sets[u] = new RedBlackTree!Entry;\n }\n auto dp = new int[M];\n foreach (i; 0 .. M) {\n // w < W[i]\n auto ranA = sets[A[i]].lowerBound(Entry(W[i], -1));\n if (!ranA.empty) {\n dp[i] = ranA.back.val;\n }\n dp[i] += 1;\n // insert\n auto ranL = sets[B[i]].lowerBound(Entry(W[i], M + 1));\n if (!ranL.empty && ranL.back.val >= dp[i]) {\n continue;\n }\n auto ranR = sets[B[i]].upperBound(Entry(W[i], -1));\n Entry[] rems;\n foreach (e; ranR) {\n if (dp[i] >= e.val) {\n rems ~= e;\n } else {\n break;\n }\n }\n foreach (e; rems) {\n sets[B[i]].removeKey(e);\n }\n sets[B[i]].insert(Entry(W[i], dp[i]));\n }\n debug {\n writeln(\"dp = \", dp);\n }\n const ans = dp.maxElement;\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\nvoid main()\n{\n int n, m; readV(n, m);\n\n struct WL { int w, l; }\n alias rbt = RedBlackTree!(WL, \"a.w < b.w\");\n\n auto dp = new rbt[](n);\n foreach (i; 0..n) dp[i] = new rbt([WL(-1, 0)]);\n\n auto ans = 0;\n foreach (_; 0..m) {\n int u, v, w; readV(u, v, w); --u; --v;\n auto s = dp[u].lowerBound(WL(w, 0)).back, nl = s.l+1;\n ans = max(ans, nl);\n\n auto t = dp[v].lowerBound(WL(w+1, 0)).back;\n if (t.l >= nl) continue;\n\n dp[v].insert(WL(w, nl));\n dp[v].removeKey(dp[v].upperBound(WL(w, 0)).filter!(wl => wl.l < nl));\n }\n\n writeln(ans);\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, m; readV(n, m);\n\n struct WL { int w, l; }\n alias rbt = RedBlackTree!(WL, \"a.w < b.w\");\n\n auto dp = new rbt[](n);\n foreach (i; 0..n) dp[i] = new rbt([WL(-1, 0)]);\n\n auto ans = 0;\n foreach (_; 0..m) {\n int u, v, w; readV(u, v, w); --u; --v;\n auto s = dp[u].lowerBound(WL(w, 0)).back, nl = s.l+1;\n ans = max(ans, nl);\n\n auto t = dp[v].lowerBound(WL(w+1, 0)).back;\n if (t.l >= nl) continue;\n\n dp[v].insert(WL(w, nl));\n dp[v].removeKey(dp[v].upperBound(WL(w, 0)).filter!(wl => wl.l < nl));\n }\n\n writeln(ans);\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\nvoid main()\n{\n int n, m; readV(n, m);\n\n struct WL { int w, l; }\n alias rbt = RedBlackTree!(WL, \"a.w < b.w\");\n\n auto dp = new rbt[](n);\n foreach (i; 0..n) dp[i] = new rbt([WL(-1, 0)]);\n\n auto ans = 0;\n foreach (_; 0..m) {\n int u, v, w; readV(u, v, w); --u; --v;\n auto s = dp[u].lowerBound(WL(w, 0)).back, nl = s.l+1;\n ans = max(ans, nl);\n\n auto t = dp[v].lowerBound(WL(w+1, 0)).back;\n if (t.l >= nl) continue;\n\n dp[v].insert(WL(w, nl));\n }\n\n writeln(ans);\n}\n"}], "src_uid": "9c553e4745adefae68d4209fa8259918"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimport std.container;\nalias Edge = SList!int;\n\nvoid main() {\n int n, m, k, s;\n readf (\" %d %d %d %d\", &n, &m, &k, &s);\n auto a = new int[n];\n auto h = new Edge[k];\n foreach (i; 0 .. n) {\n readf (\" %d\", &a[i]);\n --a[i];\n h[a[i]].insert (i);\n }\n auto e = new Edge[n];\n foreach (t; 0 .. m) {\n int i, j;\n readf (\" %d %d\", &i, &j);\n --i; --j;\n e[i].insert(j);\n e[j].insert(i);\n }\n auto c = new int[][] (k, n);\n auto q = new int[n];\n auto age = new int[n];\n age[] = -1;\n foreach (t; 0 .. k) {\n int left, right;\n auto d = c[t];\n foreach (i; h[t]) {\n d[i] = 0;\n age[i] = t;\n q[right++] = i;\n }\n while (left != right) {\n auto i = q[left++];\n foreach (j; e[i]) {\n if (age[j] != t) {\n age[j] = t;\n d[j] = d[i] + 1;\n q[right++] = j;\n }\n }\n }\n }\n auto res = new int[n];\n auto g = new int[k];\n int r = k - s;\n foreach (i; 0 .. n) {\n foreach (j; 0 .. k) g[j] = c[j][i];\n if (s < r) {\n topN (g, s - 1);\n res[i] = g[0 .. s].sum;\n } else {\n if (r > 0) {\n topN! (\"a > b\") (g, r);\n }\n res[i] = g[r .. k].sum;\n }\n }\n writeln (res.map! (i => i.text).join(' '));\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, m, k, s;\n\twhile (readf (\" %s %s %s %s\", &n, &m, &k, &s) > 0)\n\t{\n\t\treadln;\n\t\tauto w = readln.splitter.map !(to !(int)).array;\n\t\tw[] -= 1;\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 q = new int [n];\n\t\tint qb, qe;\n\t\tauto d = new int [] [] (n, k);\n\t\tauto d0 = new int [] [] (k, n);\n\t\tforeach (ref line; d0)\n\t\t{\n\t\t\tline[] = int.max;\n\t\t}\n\n\t\tforeach (v; 0..k)\n\t\t{\n\t\t\tauto cd = d0[v];\n\t\t\tqb = 0;\n\t\t\tqe = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (w[i] == v)\n\t\t\t\t{\n\t\t\t\t\tcd[i] = 0;\n\t\t\t\t\tq[qe++] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (qb < qe)\n\t\t\t{\n\t\t\t\tint i = q[qb++];\n\t\t\t\tauto r = cd[i] + 1;\n\t\t\t\tforeach (j; a[i])\n\t\t\t\t{\n\t\t\t\t\tif (cd[j] == int.max)\n\t\t\t\t\t{\n\t\t\t\t\t\tcd[j] = r;\n\t\t\t\t\t\tq[qe++] = j;\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\tforeach (j; 0..k)\n\t\t\t{\n\t\t\t\td[i][j] = d0[j][i];\n\t\t\t}\n\t\t}\n\n\t\tauto ans = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ttopN (d[i], s - 1);\n\t\t\tans[i] = sum (d[i][0..s]);\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\n\t}\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, m, k, s;\n\treadln.chomp.split.tie(n, m, k, s);\n\tint[] a = readln.chomp.split.map!(to!int).map!(a => a -1).array;\n\tint[][] adj = new int[][](n);\n\tforeach (i; 0..m) {\n\t\tint u, v;\n\t\treadln.chomp.split.tie(u, v);\n\t\t--u;\n\t\t--v;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\tint[][] types = new int[][](k);\n\tforeach (int i, t; a) {\n\t\ttypes[t] ~= i;\n\t}\n\tint[][] dist = new int[][](k, n);\n\tforeach (i; 0..k) {\n\t\tdist[i] []= int.max;\n\t\tint[] queue;\n\t\tforeach (j; types[i]) {\n\t\t\tqueue ~= j;\n\t\t\tdist[i][j] = 0;\n\t\t}\n\t\twhile (queue.length) {\n\t\t\tint node = queue.front;\n\t\t\tqueue = queue[1..$];\n\t\t\tforeach (next; adj[node]) {\n\t\t\t\tif (dist[i][next] <= dist[i][node] + 1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdist[i][next] = dist[i][node] + 1;\n\t\t\t\tqueue ~= next;\n\t\t\t}\n\t\t}\n\t}\n\tforeach (i; 0..n) {\n\t\tint[] arr = new int[](k);\n\t\tforeach (j; 0..k) {\n\t\t\tarr[j] = dist[j][i];\n\t\t}\n\t\tstd.algorithm.sort(arr);\n\t\tint ans = arr[0..s].sum;\n\t\tif (i) write = \" \";\n\t\tans.write;\n\t}\n\twriteln;\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\nimport std.container;\nalias Edge = SList!int;\n\nvoid main() {\n int n, m, k, s;\n readf (\" %d %d %d %d\", &n, &m, &k, &s);\n auto a = new int[n];\n auto h = new Edge[k];\n foreach (i; 0 .. n) {\n readf (\" %d\", &a[i]);\n --a[i];\n h[a[i]].insert (i);\n }\n auto e = new Edge[n];\n foreach (t; 0 .. m) {\n int i, j;\n readf (\" %d %d\", &i, &j);\n --i; --j;\n e[i].insert(j);\n e[j].insert(i);\n }\n auto c = new int[][] (k, n);\n auto q = new int[n];\n auto age = new int[n];\n age[] = -1;\n foreach (t; 0 .. k) {\n int left, right;\n auto d = c[t];\n foreach (i; h[t]) {\n d[i] = 0;\n age[i] = t;\n q[right++] = i;\n }\n while (left != right) {\n auto i = q[left++];\n foreach (j; e[i]) {\n if (age[j] != t) {\n age[j] = t;\n d[j] = d[i] + 1;\n q[right++] = j;\n }\n }\n }\n }\n auto res = new int[n];\n auto g = new int[k];\n int r = k - s;\n foreach (i; 0 .. n) {\n foreach (j; 0 .. k) g[j] = c[j][i];\n if (s < r) {\n partialSort (g, s);\n res[i] = g[0 .. s].sum;\n } else {\n partialSort! (\"a > b\") (g, r);\n res[i] = g[r .. k].sum;\n }\n }\n writeln (res.map! (i => i.text).join(' '));\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 M = readInt();\n const K = readInt();\n const S = readInt();\n auto A = new int[N];\n foreach (u; 0 .. N) {\n A[u] = readInt() - 1;\n }\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 G = new int[][N];\n foreach (i; 0 .. M) {\n G[U[i]] ~= V[i];\n G[V[i]] ~= U[i];\n }\n \n auto ds = new int[][](N, K);\n auto que = new int[N];\n auto dist = new int[N];\n foreach (k; 0 .. K) {\n int qb, qe;\n dist[] = N;\n foreach (u; 0 .. N) {\n if (A[u] == k) {\n dist[u] = 0;\n que[qe++] = u;\n }\n }\n for (; qb != qe; ) {\n const u = que[qb++];\n foreach (v; G[u]) {\n if (chmin(dist[v], dist[u] + 1)) {\n que[qe++] = v;\n }\n }\n }\n foreach (u; 0 .. N) {\n ds[u][k] = dist[u];\n }\n }\n \n foreach (u; 0 .. N) {\n if (u > 0) write(\" \");\n ds[u].sort;\n const ans = ds[u][0 .. S].sum;\n write(ans);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "0c329a4e4b0bd5ef1686ed629a8b0573"} {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid main() {\n string a = stdin.readln.chop;\n long acc = 1;\n for (int i = 1; i < a.length; i++) {\n int x, y, c, j;\n for (j = 0; i + j < a.length; j++) {\n x = a[i+j-1] - '0';\n y = a[i+j] - '0';\n if (x + y == 9) {\n c++;\n } else {\n break;\n }\n }\n i += j;\n if (c % 2 == 0) {\n acc *= c / 2 + 1;\n }\n }\n acc.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n\tstring S =chomp(readln());\n\tint N =S.length;\n\tint poc[];\n\tlong pos[];\n\tpoc.length =pos.length =N+1;\n\tpos[0] =1, poc[0] =0;\n\t\n\tfor(int i =0; i < N; i++) {\n\t\tint a =poc[i], b =0, c =0, j =i;\n\t\twhile(true) {\n\t\t\tc +=cast(int)(S[j]-'0');\n\t\t\tif(c >= 9 || j == 0) break;\n\t\t\tj--;}\n\t\tb =poc[j];\n\t\tif(c == 9 && j == i-1) b++;\n\t\tpoc[i+1] =max(a,b);\n\t\tpos[i+1] =0;\n\t\tif(poc[i+1] == a) pos[i+1] +=pos[i];\n\t\tif(poc[i+1] == b && b > poc[j]) pos[i+1] +=pos[j];}\n//\t\twriteln(pos[i],\" \",poc[i]);}\n\t\n\twriteln(pos[N]);}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n\tstring S =chomp(readln());\n\tint N =S.length;\n\tint poc[];\n\tlong pos[];\n\tpoc.length =pos.length =N+1;\n\tpos[0] =1, poc[0] =0;\n\t\n\tfor(int i =0; i < N; i++) {\n\t\tint a =poc[i], b =0, c =0, j =i;\n\t\twhile(true) {\n\t\t\tc +=cast(int)(S[j]-'0');\n\t\t\tif(c >= 9 || j == 0) break;\n\t\t\tj--;}\n\t\tb =poc[j];\n\t\tif(c == 9) b++;\n\t\tpoc[i+1] =max(a,b);\n\t\tpos[i+1] =0;\n\t\tif(poc[i+1] == a) pos[i+1] +=pos[i];\n\t\tif(poc[i+1] == b && c == 9) pos[i+1] +=pos[j];}\n//\t\twriteln(pos[i],\" \",poc[i]);}\n\t\n\twriteln(pos[N]);}\n"}], "src_uid": "bb1e110a7f53e6f7d43ddced7407f3d1"} {"source_code": "/+ dub.sdl:\n name \"E\"\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.graph.maxflow;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, m, s, t;\n sc.read(n, m, s, t); s--; t--;\n\n struct E {\n int to, cap, rev;\n }\n void addEdge(E[][] g, int from, int to, int cap) {\n g[from] ~= E(to, cap, g[to].length.to!int);\n g[to] ~= E(from, 0, g[from].length.to!int-1);\n }\n\n E[][] g = new E[][](n);\n\n struct E2 {\n int to, id;\n }\n E2[][] gn = new E2[][](n);\n\n bool[] used = new bool[n];\n int[] pa;\n bool dfs(int p, int q) {\n if (used[p]) return false;\n if (p == q) return true;\n used[p] = true;\n foreach (e; gn[p]) {\n if (dfs(e.to, q)) {\n pa ~= e.id;\n return true;\n }\n }\n return false;\n }\n bool make(int p, int q) {\n used[] = false;\n pa = new int[0];\n return dfs(p, q);\n }\n\n int[] U = new int[m], V = new int[m], G = new int[m];\n foreach (i; 0..m) {\n int u, v, h; sc.read(u, v, h); u--; v--;\n U[i] = u; V[i] = v; G[i] = h;\n if (h == 0) {\n addEdge(g, u, v, 100000);\n } else {\n addEdge(g, u, v, 1);\n addEdge(g, v, u, 100000);\n gn[u] ~= E2(v, i);\n }\n }\n int[] sm = new int[m];\n foreach (i; 0..m) {\n int u = U[i], v = V[i];\n if (G[i] == 0) continue;\n sm[i]++;\n if (make(v, u)) {\n foreach (d; pa) {\n sm[d]++;\n }\n continue;\n }\n make(s, u);\n foreach (d; pa) {\n sm[d]++;\n } \n make(v, t);\n foreach (d; pa) {\n sm[d]++;\n }\n }\n auto mfI = maxFlow!(int, 0)(g, s, t);\n writeln(mfI.flow);\n foreach (i; 0..m) {\n int u = U[i], v = V[i];\n int di = 0;\n bool f;\n if (G[i] == 0) {\n f = false;\n } else {\n f = !mfI.dual[u] && mfI.dual[v];\n }\n writeln(sm[i], \" \", sm[i] + (f ? 0 : 1));\n }\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/maxflow.d */\n// module dcomp.graph.maxflow;\n\n// import dcomp.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, int s, int t) {\n assert(s != t);\n import std.algorithm : map;\n import std.range : array;\n import std.conv : to;\n int n = g.length.to!int;\n int[] level = new int[n];\n int[] iter = new int[n];\n\n void bfs() {\n level[] = -1; level[s] = 0;\n auto que = Deque!int(s);\n while (!que.empty) {\n int v = que.back; que.removeBack();\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, int t, C f) {\n import std.algorithm : min;\n if (v == t) return f;\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]) {\n C d = dfs(e.to, t, min(f, e.cap));\n if (d <= EPS) continue;\n e.cap -= d;\n g[e.to][e.rev].cap += d;\n return d;\n }\n iter[v]++;\n }\n return 0;\n }\n\n C flow = 0;\n while (true) {\n bfs();\n if (level[t] < 0) break;\n iter[] = 0;\n while (true) {\n C f = dfs(s, t, C.max);\n if (!f) break;\n flow += f;\n }\n }\n\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 \n\n\n \n\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/container/deque.d */\n// module dcomp.container.deque;\n\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 \n @property bool empty() const { return (!havePayload || p.empty); }\n \n @property size_t length() const { return (havePayload ? p.length : 0); }\n \n alias opDollar = length;\n ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }\n \n ref inout(T) front() inout {C; return (*p)[0]; }\n \n ref inout(T) back() inout {C; return (*p)[$-1]; }\n void clear() { if (p) p.clear(); }\n \n void insertFront(T v) {I; p.insertFront(v); }\n \n void insertBack(T v) {I; p.insertBack(v); }\n \n alias stableInsertBack = insertBack;\n \n void removeFront() {C; p.removeFront(); }\n \n void removeBack() {C; p.removeBack(); }\n \n Range opSlice() {I; return Range(p, 0, length); }\n}\n\n\n \n\n \n\n \n\n \n\n \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", "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\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\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const S = readInt() - 1;\n const T = readInt() - 1;\n auto A = new int[M];\n auto B = new int[M];\n auto G = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n G[i] = readInt();\n }\n \n auto mf0 = new MaxFlow!int(N);\n foreach (i; 0 .. M) {\n if (G[i] == 1) {\n mf0.addEdge(A[i], B[i], 1);\n mf0.addEdge(B[i], A[i], M + 1);\n } else {\n mf0.addEdge(A[i], B[i], M + 1);\n }\n }\n mf0.dinic(S, T);\n assert(mf0.tof <= M);\n auto d = new bool[][](N, N);\n foreach (u; 0 .. N) {\n d[u][u] = true;\n }\n foreach (i; 0 .. mf0.m) {\n if (mf0.capa[i] > 0) {\n d[mf0.zu[i ^ 1]][mf0.zu[i]] = true;\n }\n }\n foreach (w; 0 .. N) foreach (u; 0 .. N) foreach (v; 0 .. N) {\n if (d[u][w] && d[w][v]) {\n d[u][v] = true;\n }\n }\n \n auto ex = new int[N];\n foreach (i; 0 .. M) {\n if (G[i] == 1) {\n --ex[A[i]];\n ++ex[B[i]];\n }\n }\n debug {\n writeln(\"ex = \", ex);\n }\n auto mf1 = new MaxFlow!int(N);\n auto ids1 = new int[M];\n ids1[] = -1;\n foreach (u; 0 .. N) {\n if (u != S && u != T) {\n if (ex[u] < 0) {\n mf1.addEdge(S, u, -ex[u]);\n } else {\n mf1.addEdge(u, T, ex[u]);\n }\n }\n }\n foreach (i; 0 .. M) {\n if (G[i] == 1) {\n ids1[i] = mf1.m;\n mf1.addEdge(A[i], B[i], M);\n }\n }\n mf1.dinic(S, T);\n \n writeln(mf0.tof);\n foreach (i; 0 .. M) {\n int f, c;\n if (G[i] == 1) {\n f = 1 + mf1.capa[ids1[i] ^ 1];\n c = (d[S][A[i]] && !d[S][B[i]]) ? f : (f + 1);\n } else {\n f = 0;\n c = 1;\n }\n writeln(f, \" \", c);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "/+ dub.sdl:\n name \"E\"\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.graph.maxflow;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, m, s, t;\n sc.read(n, m, s, t); s--; t--;\n\n struct E {\n int to, cap, rev;\n }\n void addEdge(E[][] g, int from, int to, int cap) {\n g[from] ~= E(to, cap, g[to].length.to!int);\n g[to] ~= E(from, 0, g[from].length.to!int-1);\n }\n\n E[][] g = new E[][](n);\n\n struct E2 {\n int to, id;\n }\n E2[][] gn = new E2[][](n);\n\n bool[] used = new bool[n];\n int[] pa;\n bool dfs(int p, int q) {\n if (used[p]) return false;\n if (p == q) return true;\n used[p] = true;\n foreach (e; gn[p]) {\n if (dfs(e.to, q)) {\n pa ~= e.id;\n return true;\n }\n }\n return false;\n }\n bool make(int p, int q) {\n used[] = false;\n pa = new int[0];\n return dfs(p, q);\n }\n\n int[] U = new int[m], V = new int[m], G = new int[m];\n foreach (i; 0..m) {\n int u, v, h; sc.read(u, v, h); u--; v--;\n U[i] = u; V[i] = v; G[i] = h;\n if (h == 0) {\n addEdge(g, u, v, 100000);\n addEdge(g, v, u, 1);\n } else {\n addEdge(g, u, v, 1);\n addEdge(g, v, u, 100000);\n gn[u] ~= E2(v, i);\n }\n }\n int[] sm = new int[m];\n foreach (i; 0..m) {\n int u = U[i], v = V[i];\n if (G[i] == 0) continue;\n sm[i]++;\n if (make(v, u)) {\n foreach (d; pa) {\n sm[d]++;\n }\n continue;\n }\n make(s, u);\n foreach (d; pa) {\n sm[d]++;\n } \n make(v, t);\n foreach (d; pa) {\n sm[d]++;\n }\n }\n auto mfI = maxFlow!(int, 0)(g, s, t);\n writeln(mfI.flow);\n foreach (i; 0..m) {\n int u = U[i], v = V[i];\n int di = 0;\n bool f;\n if (G[i] == 0) {\n f = !mfI.dual[v] && mfI.dual[u];\n } else {\n f = !mfI.dual[u] && mfI.dual[v];\n }\n writeln(sm[i], \" \", sm[i] + (f ? 0 : 1));\n }\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/maxflow.d */\n// module dcomp.graph.maxflow;\n\n// import dcomp.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, int s, int t) {\n assert(s != t);\n import std.algorithm : map;\n import std.range : array;\n import std.conv : to;\n int n = g.length.to!int;\n int[] level = new int[n];\n int[] iter = new int[n];\n\n void bfs() {\n level[] = -1; level[s] = 0;\n auto que = Deque!int(s);\n while (!que.empty) {\n int v = que.back; que.removeBack();\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, int t, C f) {\n import std.algorithm : min;\n if (v == t) return f;\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]) {\n C d = dfs(e.to, t, min(f, e.cap));\n if (d <= EPS) continue;\n e.cap -= d;\n g[e.to][e.rev].cap += d;\n return d;\n }\n iter[v]++;\n }\n return 0;\n }\n\n C flow = 0;\n while (true) {\n bfs();\n if (level[t] < 0) break;\n iter[] = 0;\n while (true) {\n C f = dfs(s, t, C.max);\n if (!f) break;\n flow += f;\n }\n }\n\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 \n\n\n \n\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/container/deque.d */\n// module dcomp.container.deque;\n\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 \n @property bool empty() const { return (!havePayload || p.empty); }\n \n @property size_t length() const { return (havePayload ? p.length : 0); }\n \n alias opDollar = length;\n ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }\n \n ref inout(T) front() inout {C; return (*p)[0]; }\n \n ref inout(T) back() inout {C; return (*p)[$-1]; }\n void clear() { if (p) p.clear(); }\n \n void insertFront(T v) {I; p.insertFront(v); }\n \n void insertBack(T v) {I; p.insertBack(v); }\n \n alias stableInsertBack = insertBack;\n \n void removeFront() {C; p.removeFront(); }\n \n void removeBack() {C; p.removeBack(); }\n \n Range opSlice() {I; return Range(p, 0, length); }\n}\n\n\n \n\n \n\n \n\n \n\n \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"}, {"source_code": "/+ dub.sdl:\n name \"E\"\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.graph.maxflow;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, m, s, t;\n sc.read(n, m, s, t); s--; t--;\n\n struct E {\n int to, cap, rev;\n }\n void addEdge(E[][] g, int from, int to, int cap) {\n g[from] ~= E(to, cap, g[to].length.to!int);\n g[to] ~= E(from, 0, g[from].length.to!int-1);\n }\n\n E[][] g = new E[][](n);\n\n struct E2 {\n int to, id;\n }\n E2[][] gn = new E2[][](n);\n\n bool[] used = new bool[n];\n int[] pa;\n bool dfs(int p, int q) {\n if (used[p]) return false;\n if (p == q) return true;\n used[p] = true;\n foreach (e; gn[p]) {\n if (dfs(e.to, q)) {\n pa ~= e.id;\n return true;\n }\n }\n return false;\n }\n bool make(int p, int q) {\n used[] = false;\n pa = new int[0];\n return dfs(p, q);\n }\n\n int[] U = new int[m], V = new int[m], G = new int[m];\n foreach (i; 0..m) {\n int u, v, h; sc.read(u, v, h); u--; v--;\n U[i] = u; V[i] = v; G[i] = h;\n if (h == 0) {\n addEdge(g, u, v, 100000);\n addEdge(g, v, u, 1);\n } else {\n addEdge(g, u, v, 1);\n addEdge(g, v, u, 100000);\n gn[u] ~= E2(v, i);\n }\n }\n int[] sm = new int[m];\n foreach (i; 0..m) {\n int u = U[i], v = V[i];\n if (G[i] == 0) continue;\n sm[i]++;\n if (make(v, u)) {\n foreach (d; pa) {\n sm[d]++;\n }\n continue;\n }\n make(s, u);\n foreach (d; pa) {\n sm[d]++;\n } \n make(v, t);\n foreach (d; pa) {\n sm[d]++;\n }\n }\n auto mfI = maxFlow!(int, 0)(g, s, t);\n\n foreach (i; 0..m) {\n int u = U[i], v = V[i];\n int di = 0;\n bool f;\n if (G[i] == 0) {\n f = !mfI.dual[v] && mfI.dual[u];\n } else {\n f = !mfI.dual[u] && mfI.dual[v];\n }\n writeln(sm[i], \" \", sm[i] + (f ? 0 : 1));\n }\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/maxflow.d */\n// module dcomp.graph.maxflow;\n\n// import dcomp.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, int s, int t) {\n assert(s != t);\n import std.algorithm : map;\n import std.range : array;\n import std.conv : to;\n int n = g.length.to!int;\n int[] level = new int[n];\n int[] iter = new int[n];\n\n void bfs() {\n level[] = -1; level[s] = 0;\n auto que = Deque!int(s);\n while (!que.empty) {\n int v = que.back; que.removeBack();\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, int t, C f) {\n import std.algorithm : min;\n if (v == t) return f;\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]) {\n C d = dfs(e.to, t, min(f, e.cap));\n if (d <= EPS) continue;\n e.cap -= d;\n g[e.to][e.rev].cap += d;\n return d;\n }\n iter[v]++;\n }\n return 0;\n }\n\n C flow = 0;\n while (true) {\n bfs();\n if (level[t] < 0) break;\n iter[] = 0;\n while (true) {\n C f = dfs(s, t, C.max);\n if (!f) break;\n flow += f;\n }\n }\n\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 \n\n\n \n\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/container/deque.d */\n// module dcomp.container.deque;\n\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 \n @property bool empty() const { return (!havePayload || p.empty); }\n \n @property size_t length() const { return (havePayload ? p.length : 0); }\n \n alias opDollar = length;\n ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }\n \n ref inout(T) front() inout {C; return (*p)[0]; }\n \n ref inout(T) back() inout {C; return (*p)[$-1]; }\n void clear() { if (p) p.clear(); }\n \n void insertFront(T v) {I; p.insertFront(v); }\n \n void insertBack(T v) {I; p.insertBack(v); }\n \n alias stableInsertBack = insertBack;\n \n void removeFront() {C; p.removeFront(); }\n \n void removeBack() {C; p.removeBack(); }\n \n Range opSlice() {I; return Range(p, 0, length); }\n}\n\n\n \n\n \n\n \n\n \n\n \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"}, {"source_code": "/+ dub.sdl:\n name \"E\"\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.graph.maxflow;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, m, s, t;\n sc.read(n, m, s, t); s--; t--;\n\n struct E {\n int to, cap, rev;\n }\n void addEdge(E[][] g, int from, int to, int cap) {\n g[from] ~= E(to, cap, g[to].length.to!int);\n g[to] ~= E(from, 0, g[from].length.to!int-1);\n }\n\n E[][] g = new E[][](n);\n\n struct E2 {\n int to, id;\n }\n E2[][] gn = new E2[][](n);\n\n bool[] used = new bool[n];\n int[] pa;\n bool dfs(int p, int q) {\n if (used[p]) return false;\n if (p == q) return true;\n used[p] = true;\n foreach (e; gn[p]) {\n if (dfs(e.to, q)) {\n pa ~= e.id;\n return true;\n }\n }\n return false;\n }\n bool make(int p, int q) {\n used[] = false;\n pa = new int[0];\n return dfs(p, q);\n }\n\n int[] U = new int[m], V = new int[m], G = new int[m];\n foreach (i; 0..m) {\n int u, v, h; sc.read(u, v, h); u--; v--;\n U[i] = u; V[i] = v; G[i] = h;\n if (h == 0) {\n addEdge(g, u, v, 100000);\n } else {\n addEdge(g, u, v, 1);\n addEdge(g, v, u, 100000);\n gn[u] ~= E2(v, i);\n }\n }\n int[] sm = new int[m];\n foreach (i; 0..m) {\n int u = U[i], v = V[i];\n if (G[i] == 0) continue;\n sm[i]++;\n if (make(v, u)) {\n foreach (d; pa) {\n sm[d]++;\n }\n continue;\n }\n make(s, u);\n foreach (d; pa) {\n sm[d]++;\n } \n make(v, t);\n foreach (d; pa) {\n sm[d]++;\n }\n }\n auto mfI = maxFlow!(int, 0)(g, s, t);\n writeln(mfI.flow);\n foreach (i; 0..m) {\n int u = U[i], v = V[i];\n int di = 0;\n bool f;\n if (G[i] == 0) {\n f = true;\n } else {\n f = !mfI.dual[u] && mfI.dual[v];\n }\n writeln(sm[i], \" \", sm[i] + (f ? 0 : 1));\n }\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/maxflow.d */\n// module dcomp.graph.maxflow;\n\n// import dcomp.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, int s, int t) {\n assert(s != t);\n import std.algorithm : map;\n import std.range : array;\n import std.conv : to;\n int n = g.length.to!int;\n int[] level = new int[n];\n int[] iter = new int[n];\n\n void bfs() {\n level[] = -1; level[s] = 0;\n auto que = Deque!int(s);\n while (!que.empty) {\n int v = que.back; que.removeBack();\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, int t, C f) {\n import std.algorithm : min;\n if (v == t) return f;\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]) {\n C d = dfs(e.to, t, min(f, e.cap));\n if (d <= EPS) continue;\n e.cap -= d;\n g[e.to][e.rev].cap += d;\n return d;\n }\n iter[v]++;\n }\n return 0;\n }\n\n C flow = 0;\n while (true) {\n bfs();\n if (level[t] < 0) break;\n iter[] = 0;\n while (true) {\n C f = dfs(s, t, C.max);\n if (!f) break;\n flow += f;\n }\n }\n\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 \n\n\n \n\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/container/deque.d */\n// module dcomp.container.deque;\n\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 \n @property bool empty() const { return (!havePayload || p.empty); }\n \n @property size_t length() const { return (havePayload ? p.length : 0); }\n \n alias opDollar = length;\n ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }\n \n ref inout(T) front() inout {C; return (*p)[0]; }\n \n ref inout(T) back() inout {C; return (*p)[$-1]; }\n void clear() { if (p) p.clear(); }\n \n void insertFront(T v) {I; p.insertFront(v); }\n \n void insertBack(T v) {I; p.insertBack(v); }\n \n alias stableInsertBack = insertBack;\n \n void removeFront() {C; p.removeFront(); }\n \n void removeBack() {C; p.removeBack(); }\n \n Range opSlice() {I; return Range(p, 0, length); }\n}\n\n\n \n\n \n\n \n\n \n\n \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"}, {"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\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\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n const S = readInt() - 1;\n const T = readInt() - 1;\n auto A = new int[M];\n auto B = new int[M];\n auto G = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt() - 1;\n B[i] = readInt() - 1;\n G[i] = readInt();\n }\n \n auto mf0 = new MaxFlow!int(N);\n foreach (i; 0 .. M) {\n if (G[i] == 1) {\n mf0.addEdge(A[i], B[i], 1);\n mf0.addEdge(B[i], A[i], M + 1);\n } else {\n mf0.addEdge(A[i], B[i], M + 1);\n }\n }\n mf0.dinic(S, T);\n assert(mf0.tof <= M);\n auto d = new bool[][](N, N);\n foreach (u; 0 .. N) {\n d[u][u] = true;\n }\n foreach (i; 0 .. mf0.m) {\n if (mf0.capa[i] > 0) {\n d[mf0.zu[i ^ 1]][mf0.zu[i]] = true;\n }\n }\n foreach (w; 0 .. N) foreach (u; 0 .. N) foreach (v; 0 .. N) {\n if (d[u][w] && d[w][v]) {\n d[u][v] = true;\n }\n }\n \n auto ex = new int[N];\n foreach (i; 0 .. M) {\n if (G[i] == 1) {\n --ex[A[i]];\n ++ex[B[i]];\n }\n }\n debug {\n writeln(\"ex = \", ex);\n }\n auto mf1 = new MaxFlow!int(N);\n auto ids1 = new int[M];\n ids1[] = -1;\n foreach (u; 0 .. N) {\n if (u != S && u != T) {\n if (ex[u] < 0) {\n mf1.addEdge(S, u, -ex[u]);\n } else {\n mf1.addEdge(u, T, ex[u]);\n }\n }\n }\n foreach (i; 0 .. M) {\n if (G[i] == 1) {\n ids1[i] = mf1.m;\n mf1.addEdge(A[i], B[i], M);\n }\n }\n mf1.dinic(S, T);\n \n writeln(mf0.tof);\n foreach (i; 0 .. M) {\n int f, c;\n if (G[i] == 1) {\n f = 1 + mf1.capa[ids1[i] ^ 1];\n c = (d[S][A[i]] && !d[S][B[i]]) ? f : (f + 1);\n } else {\n f = c = 0;\n }\n writeln(f, \" \", c);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "92dde4bab1fccfc265ec575651aaa0b0"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1419/problem/A\n// greedy\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\n int n;\n string s;\n while(t--) {\n readf(\"%s\\n\", &n);\n readf(\"%s\\n\", &s);\n\n int even, odd;\n even = 0;\n odd = 0;\n\n for(int i = 1; i <= n; i++) {\n if(i % 2 == 1) {\n odd += (s[i - 1] - '0') % 2;\n } else {\n even += ((s[i - 1] - '0') + 1) % 2;\n }\n }\n\n //writefln(\"%s %s\", even, odd);\n\n int winner;\n if(n % 2 == 1) {\n if(odd > 0)\n winner = 1;\n else\n winner = 2;\n winner.writeln;\n continue;\n }\n\n if(even > 0)\n winner = 2;\n else\n winner = 1;\n winner.writeln;\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, std.container, std.range;\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!int;\n auto D = readln.chomp;\n if (N%2 == 1) {\n for (int i = 0; i < N; i+=2) {\n if ((D[i]-'0')%2 == 1) {\n writeln(1);\n goto end;\n }\n }\n writeln(2);\n } else {\n for (int i = 1; i < N; i += 2) {\n if ((D[i]-'0')%2 == 0) {\n writeln(2);\n goto end;\n }\n }\n writeln(1);\n }\n end:\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 main()\n{\n int T; get(T);\n foreach (_; 0..T) {\n int N; get(N);\n auto D = readln.chomp;\n if (N%2 == 1) {\n for (int i = 0; i < N; i+=2) {\n if ((D[i]-'0')%2 == 1) {\n writeln(1);\n goto end;\n }\n }\n writeln(2);\n } else {\n for (int i = 1; i < N; i += 2) {\n if ((D[i]-'0')%2 == 0) {\n writeln(2);\n goto end;\n }\n }\n writeln(1);\n }\n end:\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 = RD!string;\n\t\tif (n % 2)\n\t\t{\n\t\t\tbool ok;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (i % 2 == 0)\n\t\t\t\t{\n\t\t\t\t\tif ((s[i]-'0') % 2)\n\t\t\t\t\t\tok = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[ti] = ok ? 1 : 2;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbool ok;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (i % 2)\n\t\t\t\t{\n\t\t\t\t\tif ((s[i]-'0') % 2 == 0)\n\t\t\t\t\t\tok = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[ti] = ok ? 2 : 1;\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, 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"}], "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 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}\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 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 main()\n{\n int T; get(T);\n foreach (_; 0..T) {\n int N; get(N);\n string D; get(D);\n if (N%2 == 1) {\n for (int i = 0; i < N; i+=2) {\n if ((D[i]-'0')%2 == 1) {\n writeln(1);\n goto end;\n }\n }\n writeln(2);\n } else {\n for (int i = 1; i < N; i += 2) {\n if ((D[i]-'0')%2 == 0) {\n writeln(2);\n goto end;\n }\n }\n writeln(1);\n }\n end:\n }\n}"}], "src_uid": "c9225c915669e183cbd8c20b848d96e5"} {"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 = 9;\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 = new string [n];\r\n\t\tforeach (ref t; s)\r\n\t\t{\r\n\t\t\tt = readln.strip;\r\n\t\t}\r\n\r\n\t\tauto b = new bool [string] [limit];\r\n\t\tforeach (ref t; s)\r\n\t\t{\r\n\t\t\tb[t.length][t] = true;\r\n\t\t}\r\n\r\n\t\tauto answer = new bool [n];\r\n\t\tforeach (i, ref t; s)\r\n\t\t{\r\n\t\t\tforeach (lo; 1..t.length)\r\n\t\t\t{\r\n\t\t\t\tauto hi = t.length - lo;\r\n\t\t\t\tif (t[0..lo] in b[lo] && t[lo..$] in b[hi])\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[i] = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twritefln !(\"%(%d%)\") (answer);\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 s = new string [n];\r\n\t\tforeach (ref t; s)\r\n\t\t{\r\n\t\t\tt = readln.strip;\r\n\t\t}\r\n\r\n\t\tbool [string] b;\r\n\t\tforeach (ref t; s)\r\n\t\t{\r\n\t\t\tb[t] = true;\r\n\t\t}\r\n\r\n\t\tauto answer = new bool [n];\r\n\t\tforeach (i, ref t; s)\r\n\t\t{\r\n\t\t\tforeach (lo; 1..t.length)\r\n\t\t\t{\r\n\t\t\t\tauto hi = t.length - lo;\r\n\t\t\t\tif (t[0..lo] in b && t[lo..$] in b)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[i] = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twritefln !(\"%(%d%)\") (answer);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "9683d5960247359b6b9066e96897d6f9"} {"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.math;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto a00 = next!long;\n auto a01 = next!long;\n auto a10 = next!long;\n auto a11 = next!long;\n auto c0 = cast(long) (round((real(1.0) + sqrt(real(1.0) + 8.0 * a00)) / real(2.0)));\n auto c0p = cast(long) (round((real(1.0) - sqrt(real(1.0) + 8.0 * a00)) / real(2.0)));\n auto c1 = cast(long) (round((real(1.0) + sqrt(real(1.0) + 8.0 * a11)) / real(2.0)));\n auto c1p = cast(long) (round((real(1.0) - sqrt(real(1.0) + 8.0 * a11)) / real(2.0)));\n if (((c0 - 1) * c0) / 2 != a00 || ((c1 - 1) * c1) / 2 != a11)\n return writeln(\"Impossible\");\n \n string tryValues(long c0, long c1)\n {\n if (c0 < 0 || c1 < 0) return null;\n if (a00 + a01 + a10 + a11 != ((c0 + c1 - 1) * (c0 + c1) / 2))\n return null;\n if (c1 == 0)\n return \"0\".repeat(cast(int)c0).join;\n auto mul0 = a01 / c1;\n auto res0 = a01 % c1;\n assert(mul0 <= c0);\n if (res0 == 0)\n {\n\treturn chain(\"0\".repeat(cast(int)mul0),\n\t\t \"1\".repeat(cast(int)c1),\n\t\t \"0\".repeat(cast(int)(c0 - mul0))).join;\n }\n else\n {\n\treturn chain(\"0\".repeat(cast(int)mul0),\n\t\t \"1\".repeat(cast(int)(c1 - res0)),\n\t\t only(\"0\"),\n\t\t \"1\".repeat(cast(int)res0),\n\t\t \"0\".repeat(cast(int)(c0 - mul0 - 1))).join;\n }\n }\n foreach(tc0; [c0, c0p])\n foreach(tc1; [c1, c1p])\n if (string res = tryValues(tc0, tc1))\n\treturn res.writeln;\n writeln(\"Impossible\");\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.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.math;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto a00 = next!long;\n auto a01 = next!long;\n auto a10 = next!long;\n auto a11 = next!long;\n auto c0 = cast(long) (round((real(1.0) + sqrt(real(1.0) + 8.0 * a00)) / real(2.0)));\n auto c0p = cast(long) (round((real(1.0) - sqrt(real(1.0) + 8.0 * a00)) / real(2.0)));\n auto c1 = cast(long) (round((real(1.0) + sqrt(real(1.0) + 8.0 * a11)) / real(2.0)));\n auto c1p = cast(long) (round((real(1.0) - sqrt(real(1.0) + 8.0 * a11)) / real(2.0)));\n if (((c0 - 1) * c0) / 2 != a00 || ((c1 - 1) * c1) / 2 != a11)\n return writeln(\"Impossible\");\n \n string tryValues(long c0, long c1)\n {\n if (c0 < 0 || c1 < 0) return null;\n if (a00 + a01 + a10 + a11 != ((c0 + c1 - 1) * (c0 + c1) / 2))\n return null;\n if (c1 == 0)\n return iota(0, c0).map!(i => \"0\").join;\n auto mul0 = a01 / c1;\n auto res0 = a01 % c1;\n assert(mul0 <= c0);\n if (res0 == 0)\n {\n\treturn chain(iota(0, mul0).map!(i => \"0\"),\n\t\t iota(0, c1).map!(i => \"1\"),\n\t\t iota(0, c0 - mul0).map!(i => \"0\")).join;\n }\n else\n {\n\treturn chain(iota(0, mul0).map!(i => \"0\"),\n\t\t iota(0, c1 - res0).map!(i => \"1\"),\n\t\t only(\"0\"),\n\t\t iota(0, res0).map!(i => \"1\"),\n\t\t iota(0, c0 - mul0 - 1).map!(i => \"0\")).join;\n }\n }\n \n foreach(tc0; [c0, c0p])\n foreach(tc1; [c1, c1p])\n if (string res = tryValues(tc0, tc1))\n\treturn res.writeln;\n writeln(\"Impossible\");\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"}], "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.math;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto a00 = next!long;\n auto a01 = next!long;\n auto a10 = next!long;\n auto a11 = next!long;\n auto c0 = cast(long) (round((real(1.0) + sqrt(real(1.0) + 8.0 * a00)) / real(2.0)));\n auto c1 = cast(long) (round((real(1.0) + sqrt(real(1.0) + 8.0 * a11)) / real(2.0)));\n if (((c0 - 1) * c0) / 2 != a00 || ((c1 - 1) * c1) / 2 != a11\n || a00 + a01 + a10 + a11 != ((c0 + c1 - 1) * (c0 + c1)) / 2)\n return writeln(\"Impossible\");\n auto mul0 = a01 / c1;\n auto res0 = a01 % c1;\n assert(mul0 <= c0);\n if (res0 == 0)\n {\n chain(iota(0, mul0).map!(i => \"0\"),\n\t iota(0, c1).map!(i => \"1\"),\n\t iota(0, c0 - mul0).map!(i => \"0\")).join.writeln;\n }\n else\n {\n chain(iota(0, mul0).map!(i => \"0\"),\n\t iota(0, c1 - res0).map!(i => \"1\"),\n\t only(\"0\"),\n\t iota(0, res0).map!(i => \"1\"),\n\t iota(0, c0 - mul0 - 1).map!(i => \"0\")).join.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"}], "src_uid": "6893987b310c41efb269b63e865355d8"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 ok = new bool[](t);\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\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\tauto x = tot / n;\n\t\tok[ti] = true;\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] < i+1)\n\t\t\t{\n\t\t\t\tif (a[0]+a[i] >= i+1)\n\t\t\t\t{\n\t\t\t\t\tauto rem = i+1 - a[i];\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t\tans[ti] ~= [i+1, 1, 1];\n\t\t\t\t\ta[0] += a[i];\n\t\t\t\t\ta[i] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] -= cnt*(i+1);\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t\t}\n\t\t}\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach_reverse(i; 1..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t\ta[i] = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = (i+1) - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] -= cnt*(i+1);\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t\t}\n\t\t}\n\t\t/*if (n != 1)\n\t\t{\n\t\t\tif (a[1] != 0)\n\t\t\t\tans[ti].length = 0;\n\t\t}*/\n\t}\n\n\tforeach (ti; 0..t)\n\t{\n\t\tif (!ok[ti])\n\t\t\twriteln(-1);\n\t\telse\n\t\t{\n\t\t\twriteln(ans[ti].length);\n\t\t\tforeach (ee; ans[ti])\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\n\t\t}\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 = 0L ~ readln.splitter.map !(to !(long)).array;\n\t\tif (a.sum % n != 0)\n\t\t{\n\t\t\twriteln (-1);\n\t\t\tcontinue;\n\t\t}\n\t\talias Move = Tuple !(int, q{i}, int, q{j}, long, q{x});\n\t\tMove [] answer;\n\n\t\tvoid go (int i, int j, long x)\n\t\t{\n\t\t\ta[i] -= i * x;\n\t\t\ta[j] += i * x;\n\t\t\tanswer ~= Move (i, j, x);\n\t\t}\n\n\t\tforeach (j; 2..n + 1)\n\t\t{\n\t\t\tif (a[j] % j != 0)\n\t\t\t{\n\t\t\t\tgo (1, j, j - (a[j] % j));\n\t\t\t}\n\t\t\tassert (a[1] >= 0);\n\t\t\tassert (a[j] % j == 0);\n\t\t\tgo (j, 1, a[j] / j);\n\t\t}\n\t\tauto target = a.sum / n;\n\t\tforeach (j; 2..n + 1)\n\t\t{\n\t\t\tgo (1, j, target);\n\t\t}\n\n\t\twriteln (answer.length);\n\t\tforeach (ref c; answer)\n\t\t{\n\t\t\twriteln (c.i, \" \", c.j, \" \", c.x);\n\t\t}\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 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\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\t\n\t\tauto x = tot / n;\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach_reverse(i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = x - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] = 0;\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\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{\n\t\t\twriteln(e.length);\n\t\t\tforeach (ee; e)\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\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\t\tauto a = RDA!int;\n\t\n\t\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\tauto x = tot / n;\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] < i+1) continue;\n\t\t\tauto cnt = a[i] / (i+1);\n\t\t\ta[0] += cnt*(i+1);\n\t\t\ta[i] -= cnt*(i+1);\n\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t}\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach_reverse(i; 1..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t\ta[i] = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = (i+1) - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] -= cnt*(i+1);\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t\t}\n\t\t}\n\t\t/*if (n != 1)\n\t\t{\n\t\t\tif (a[1] != 0)\n\t\t\t\tans[ti].length = 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{\n\t\t\twriteln(e.length);\n\t\t\tforeach (ee; e)\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\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\t\tauto a = RDA!int;\n\t\n\t\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\t\n\t\tauto x = tot / n;\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i]-(i+1) < -x) continue;\n\t\t\tauto cnt = (a[i]+x) / (i+1);\n\t\t\ta[0] += cnt*(i+1);\n\t\t\ta[i] = 0;\n\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t}\n\n\t\tforeach_reverse(i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = x - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] = 0;\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\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{\n\t\t\twriteln(e.length);\n\t\t\tforeach (ee; e)\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\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\t\tauto a = RDA!int;\n\t\n\t\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\t\n\t\tauto x = tot / n;\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i]+x < i+1) continue;\n\t\t\tauto cnt = (a[i]+x) / (i+1);\n\t\t\ta[0] += cnt*(i+1);\n\t\t\ta[i] -= cnt*(i+1);\n\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t}\n\t\tdebug writeln(a);\n\n\t\tforeach_reverse(i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = x - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] = 0;\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t\t}\n\t\t}\n\t\tif (n != 1)\n\t\t{\n\t\t\tif (a[1] != 0)\n\t\t\t\tans[ti].length = 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{\n\t\t\twriteln(e.length);\n\t\t\tforeach (ee; e)\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\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\t\tauto a = RDA!int;\n\t\n\t\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\t\n\t\tauto x = tot / n;\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i]-(i+1) < -x) continue;\n\t\t\tauto cnt = (a[i]+x) / (i+1);\n\t\t\ta[0] += cnt*(i+1);\n\t\t\ta[i] -= cnt*(i+1);\n\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t}\n\t\tdebug writeln(a);\n\n\t\tforeach_reverse(i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = x - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] = 0;\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\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{\n\t\t\twriteln(e.length);\n\t\t\tforeach (ee; e)\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\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 ok = new bool[](t);\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\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\tauto x = tot / n;\n\t\tok[ti] = true;\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] < i+1) continue;\n\t\t\tauto cnt = a[i] / (i+1);\n\t\t\ta[0] += cnt*(i+1);\n\t\t\ta[i] -= cnt*(i+1);\n\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t}\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach_reverse(i; 1..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t\ta[i] = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = (i+1) - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] -= cnt*(i+1);\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t\t}\n\t\t}\n\t\t/*if (n != 1)\n\t\t{\n\t\t\tif (a[1] != 0)\n\t\t\t\tans[ti].length = 0;\n\t\t}*/\n\t}\n\n\tforeach (ti; 0..t)\n\t{\n\t\tif (!ok[ti])\n\t\t\twriteln(-1);\n\t\telse\n\t\t{\n\t\t\twriteln(ans[ti].length);\n\t\t\tforeach (ee; ans[ti])\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\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\t\tauto a = RDA!int;\n\t\n\t\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\t\n\t\tauto x = tot / n;\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i]+x < i+1) continue;\n\t\t\tauto cnt = (a[i]+x) / (i+1);\n\t\t\ta[0] += cnt*(i+1);\n\t\t\ta[i] -= cnt*(i+1);\n\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t}\n\t\tdebug writeln(a);\n\n\t\tforeach_reverse(i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = x - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] -= cnt*(i+1);\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t\t}\n\t\t}\n\t\tif (n != 1)\n\t\t{\n\t\t\tif (a[1] != 0)\n\t\t\t\tans[ti].length = 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{\n\t\t\twriteln(e.length);\n\t\t\tforeach (ee; e)\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\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\t\tauto a = RDA!int;\n\t\n\t\tauto tot = a.sum;\n\t\tif (tot % n) continue;\n\t\tauto x = tot / n;\n\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (a[i] < i+1) continue;\n\t\t\tauto cnt = a[i] / (i+1);\n\t\t\ta[0] += cnt*(i+1);\n\t\t\ta[i] -= cnt*(i+1);\n\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t}\n\t\ta[] -= x;\n\t\tdebug writeln(a);\n\n\t\tforeach_reverse(i; 1..n)\n\t\t{\n\t\t\tif (a[i] == 0) continue;\n\t\t\telse if (a[i] < 0)\n\t\t\t{\n\t\t\t\ta[0] += a[i];\n\t\t\t\tans[ti] ~= [1, i+1, -a[i]];\n\t\t\t\ta[i] = 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i]%(i+1))\n\t\t\t\t{\n\t\t\t\t\tauto rem = x - (a[i]%(i+1));\n\t\t\t\t\ta[0] -= rem;\n\t\t\t\t\ta[i] += rem;\n\t\t\t\t\tans[ti] ~= [1, i+1, rem];\n\t\t\t\t}\n\t\t\t\tauto cnt = a[i] / (i+1);\n\t\t\t\ta[0] += cnt*(i+1);\n\t\t\t\ta[i] -= cnt*(i+1);\n\t\t\t\tans[ti] ~= [i+1, 1, cnt];\n\t\t\t}\n\t\t}\n\t\t/*if (n != 1)\n\t\t{\n\t\t\tif (a[1] != 0)\n\t\t\t\tans[ti].length = 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{\n\t\t\twriteln(e.length);\n\t\t\tforeach (ee; e)\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "b6fb4d868e3f496466746f5e776ae2cc"} {"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\nint[] kmp(char[] s) {\n auto r = new int[s.length];\n foreach (i; 1 .. s.length) {\n int j = r[i - 1];\n while (j > 0 && s[i] != s[j]) j = r[j - 1];\n if (s[j] == s[i]) j++;\n r[i] = j;\n }\n \n return r;\n}\n\nvoid main() {\n int T;\n read(T);\n while (T--) {\n string s = readln.strip;\n string t = readln.strip;\n \n if (s == t) { writeln(\"Yes\"); continue; }\n \n bool yes = false;\n \n foreach (w; 0 .. s.length) {\n yes |= kmp(t ~ \"#\" ~ s[0 .. w + 1] ~ s[0 .. w].dup.reverse).canFind(t.length);\n }\n \n writeln(yes ? \"Yes\" : \"No\");\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.ascii;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint q = readInt!int;\n\twhile (q--)\n\t{\n\t\tauto s = cast(char[])readString; \n\t\tauto t = cast(char[])readString;\n\t\tbool can = false;\n\t\tforeach(i; 0 .. cast(int)s.length)\n\t\t{\n\t\t\tforeach(j; i .. cast(int)s.length)\n\t\t\t{\n\t\t\t\tint currLength = cast(int)(j - i + 1);\n\t\t\t\tauto str = s[i .. j + 1];\n\t\t\t\tint remLength = cast(int)t.length - currLength;\n\t\t\t\tif (remLength < 0) continue;\n\t\t\t\tif (remLength > j) continue;\n\t\t\t\tauto other = s[j - remLength .. j].dup;\n\t\t\t\tstr ~= other.reverse;\n\t\t\t\tif (str == t) { can = true; break; }\n\t\t\t}\n\t\t\tif (can) break;\n\t\t}\n\t\tif (can) 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": "// 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 string s, t;\r\n readf!\"%s\\n%s\\n\"(s, t);\r\n auto n = s.length, m = t.length;\r\n auto rs = s.dup.retro.to!string;\r\n bool ok = false;\r\n foreach(i; 0 .. n) {\r\n foreach(j; i .. n) {\r\n int l = j - i + 1;\r\n if (l > m || l + j < m) continue; \r\n if (s[i .. j + 1] == t[0 .. l] && rs[n - j .. n - j + m - l] == t[l .. $]) {\r\n ok = true;\r\n }\r\n }\r\n }\r\n (ok ? \"YES\" : \"NO\").writeln;\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 q;\n readf!\" %d \"(q);\n while (q--) {\n string s = readln.strip;\n string t = readln.strip;\n string[] a;\n foreach (i ; 1 .. s.length + 1) {\n string tmp = s[0 .. i];\n a ~= tmp ~ tmp.retro.text[1 .. $];\n }\n bool good = false;\n foreach (sx ; a) {\n if (sx.indexOf(t) != -1) {\n good = true;\n break;\n }\n }\n writeln(good ? \"YES\" : \"NO\");\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 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\t(){\r\n\t\tforeach (i; 0..s.length)\r\n\t\t{\r\n\t\t\tforeach (j; i..min(s.length, i+ss.length))\r\n\t\t\t{\r\n\t\t\t\tauto len = j - i + 1;\r\n\t\t\t\tbool ok = true;\r\n\t\t\t\tforeach (k; 0..len)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (s[i+k] != ss[k])\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}\r\n\t\t\t\tif (!ok) continue;\r\n\t\t\t\tforeach_reverse (k; 0..ss.length-len)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (j <= k)\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\tauto p = j - k - 1;\r\n\t\t\t\t\tif (s[p] != ss[len+k])\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}\r\n\t\t\t\tif (ok)\r\n\t\t\t\t{\r\n\t\t\t\t\tans[ti] = true;\r\n\t\t\t\t\treturn;\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 ? \"YES\" : \"NO\");\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\nbool solve (string s, string t)\r\n{\r\n\tauto n = s.length.to !(int);\r\n\tforeach (pos; 0..n)\r\n\t{\r\n\t\tforeach (next; pos..n)\r\n\t\t{\r\n\t\t\tforeach (prev; 0..next + 1)\r\n\t\t\t{\r\n\t\t\t\tif (equal (t, chain (s[pos..next + 1],\r\n\t\t\t\t s[prev..next].retro)))\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}\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": [], "src_uid": "d69e10bb05d119ec2ad4b5c0e4304336"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1397/problem/B\n// math\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n\n if(n >= 35) {\n long ans = 0;\n foreach(x; a)\n ans += x - 1;\n ans.writeln;\n return;\n }\n\n a.sort;\n\n long ans = 10L^^14;\n for(long c = 1L; c <= 10^^9; c++) {\n //writefln(\"c: %s\", c);\n long minima = 0L;\n for(int i = 0L; i < n; i++) {\n minima += abs(a[i] - c^^i);\n //writefln(\"i: %s\", i);\n }\n //writefln(\"minima: %s\", minima);\n if(minima > ans && ans != 10^^18)\n break;\n ans = min(ans,minima);\n }\n\n ans.writeln;\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 n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(real)).array;\n\t\tsort (a);\n\t\treal res = real.max;\n\t\tfor (real base = 1; log10 (base) * (n - 1) <= 12; base++)\n\t\t{\n\t\t\tres = min (res, n.iota.map !(i =>\n\t\t\t abs (a[i] - pow (base, i))).sum);\n\t\t}\n\t\twritefln !(\"%.0f\") (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.range;\nimport std.array;\nimport std.math;\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 readln;\n auto arr = readln.strip.split.map!(x => x.to!long).array.sort;\n debug writeln(\"length = \", arr.length);\n auto up = pow(10_000_000_001, 1.0/(n-1)).floor.to!long;\n \n long m = long.max;\n debug writeln(\"up = \", up);\n foreach (c; 1..up + 1)\n {\n\tlong t = arr[0] - 1;\n\tlong q = 1;\n\tdebug writeln(\"c = \", c);\n\tfor (int i = 1; i < n; i++)\n\t{\n\t q *= c;\n\t debug writeln(\"q = \", q);\n\t t += abs(q - arr[i]).to!long;\n\t}\n \n\tif (t < m)\n\t m = t;\n \n\tdebug writeln(t);\n }\n \n //debug writeln (\"c = \", c, \" m = \", m);\n writeln (m);\n \n return 0;\n}"}, {"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;\nimport std.experimental.checkedint;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!long();\n auto a = next!long(n);\n sort(a);\n bool admissibleC(long c)\n {\n auto p = checked!Saturate(long(1));\n foreach(i; 0 .. n)\n p *= c;\n return p != long.max;\n }\n long mincost = long.max;\n foreach(c; 0 .. 1_000_000_000)\n {\n if (!admissibleC(c))\n break;\n long cost = 0;\n long p = 1;\n foreach(i; 0 .. n)\n {\n cost += abs(a[cast(size_t)i] - p);\n p *= c;\n }\n mincost = min(mincost, cost);\n }\n writeln(mincost);\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 = 4096;\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": "// Vicfred\n// https://codeforces.com/contest/1397/problem/B\n// math\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n\n if(n >= 35) {\n long ans = 0;\n foreach(x; a)\n ans += x - 1;\n ans.writeln;\n return;\n }\n\n a.sort;\n\n long ans = 10L^^14;\n for(long c = 1L; c <= 10^^9; c++) {\n long minima = 0L;\n\n for(int i = 0; i < n; i++)\n minima += abs(a[i] - c^^i);\n\n if(minima > ans)\n break;\n\n ans = min(ans,minima);\n }\n\n ans.writeln;\n}\n\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1397/problem/B\n// math\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n\n if(n >= 30) {\n long ans = 0;\n foreach(x; a)\n ans += x - 1;\n ans.writeln;\n return;\n }\n\n a.sort;\n\n long ans = 10^^14;\n for(long c = 1; c <= 10^^9; ++c) {\n //writefln(\"c: %s\", c);\n long minima = 0;\n for(int i = 0; c^^i <= 10^^14; i++) {\n if(i >= n) break;\n minima += abs(a[i] - c^^i);\n //writefln(\"i: %s\", i);\n }\n //writefln(\"minima: %s\", minima);\n if(minima > ans)\n break;\n else\n ans = min(ans,minima);\n }\n\n ans.writeln;\n}\n\n"}, {"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\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!long();\n auto a = next!long(n);\n sort(a);\n bool admissibleC(long c)\n {\n long p = 1;\n foreach(i; 0 .. n)\n {\n if (p >= 2_000_000_000)\n {\n return false;\n }\n p *= c;\n }\n return true;\n }\n long mincost = long.max;\n foreach(c; 0 .. 1_000_000_000)\n {\n if (!admissibleC(c))\n break;\n long cost = 0;\n long p = 1;\n foreach(i; 0 .. n)\n {\n cost += abs(a[cast(size_t)i] - p);\n p *= c;\n }\n mincost = min(mincost, cost);\n }\n writeln(mincost);\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 = 4096;\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": "54e9c6f24c430c5124d840b5a65a1bc4"} {"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[] ss;\n\tforeach(i; 0 .. n) ss ~= read.to!long;\n\tlog(\"ss:\", ss);\n\t\n\tauto seg = new SegTree!long(0, n, ((x, y) => x + y), 0);\n\tforeach(i; 0 .. n) seg.setValue(i, n, i + 1);\n\tlog(\"seg:\", n.iota.map!(i => seg.getValue(i)));\n\t\n\tlong[] ans;\n\tforeach_reverse(s; ss){\n\t\tint j = uplimit!int(0, n - 1, (i => (seg.getValue(i) <= s))) + 1;\n\t\tlong an = j + 1;\n\t\tans ~= an;\n\t\tseg.setValue(j, n, -an);\n\t\tlog(\"seg:\", n.iota.map!(i => seg.getValue(i)));\n\t}\n\tlog(\"ans:\", ans);\n\t\n\tans.reverse.map!(to!string).join(\" \").writeln;\n\t\n}\n\n// a <= x <= c の中でfをみたす最大(二分探索; binary search) ※テンプレート版\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\n/*\nセグメント木 区分木 segtree segment tree\n範囲に書き込み、1点で読み出す。\nたとえば、 [l, r) の範囲に一律 x を足すクエリがくるなど。\n\n引数\na, b 添字の範囲。 この意味はa から b - 1 までなので注意。\napply (x, y) => すでに値 x があるところに y を加えるとどうなるか ※結合的な演算である必要がある\nneutral すべての x に対して apply(z, x) = apply(x, z) = x をみたす z\n\n*/\nclass SegTree(T){\n\tT delegate(T, T) apply;\n\tT neutral;\n\tint a, b; // a <= x < b を担当する\n\tbool isTerminal;\n\tSegTree left, right; // 左の子(a <= x < c)、右の子(c <= x < b)\n\tT value;\n\tthis(int a, int b, T delegate(T, T) apply, T neutral = T.init){\n\t\tthis.a = a, this.b = b;\n\t\tthis.apply = apply;\n\t\tthis.neutral = neutral;\n\t\tthis.value = neutral;\n\t\tif(b - a == 1){\n\t\t\tthis.isTerminal = 1;\n\t\t}\n\t\telse{\n\t\t\tint c = (a + b) / 2;\n\t\t\tthis.left = new SegTree(a, c, apply, neutral);\n\t\t\tthis.right = new SegTree(c, b, apply, neutral);\n\t\t}\n\t}\n\t\n\t// [a, b) に値を設定する ※[a, b) はこのノードの担当区間とかぶっていなくてもよい\n\tvoid setValue(int a, int b, T value){\n\t\tif(b <= this.a || this.b <= a) return;\n\t\tif(a <= this.a && this.b <= b){\n\t\t\tthis.value = apply(this.value, value);\n\t\t}\n\t\telse{\n\t\t\tdivideValue();\n\t\t\tleft.setValue(a, b, value);\n\t\t\tright.setValue(a, b, value);\n\t\t}\n\t}\n\t\n\t// 自分の持っていた値を子に引き継ぐ\n\tvoid divideValue(){\n\t\tleft.value = apply(left.value, this.value);\n\t\tright.value = apply(right.value, this.value);\n\t\tthis.value = neutral;\n\t}\n\t\n\t// iにおける値 ※iは必ずこのノードの担当区間内である前提\n\tT getValue(int i){\n\t\tassert(a <= i && i < b);\n\t\tif(this.isTerminal) return this.value;\n\t\telse divideValue();\n\t\tif(i < left.b) return left.getValue(i);\n\t\telse return right.getValue(i);\n\t}\n\t\n\t// 配列に変換したもの(デバッグ用)\n\tT[] array(){\n\t\tT[] res;\n\t\tforeach(i; a .. b) res ~= this.value;\n\t\treturn res;\n\t}\n\t\n\t// 文字列に変換したもの(デバッグ用)\n\toverride string toString(){\n\t\tif(this.isTerminal) return this.array.to!string;\n\t\telse\treturn this.array.to!string ~ \"\\n\" ~ left.toString ~ right.toString ~ \"\\n\";\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\nenum INF = 10L^^18;\nalias Entry = Tuple!(long, \"val\", int, \"key\");\n\nclass SegmentTree {\n int n;\n Entry[] mx;\n long[] add;\n this(long[] ini) {\n const n_ = cast(int)(ini.length);\n for (n = 1; n < n_; n <<= 1) {}\n mx = new Entry[n << 1];\n add = new long[n << 1];\n mx[] = Entry(-INF, -1);\n add[] = 0;\n foreach (i; 0 .. n_) {\n mx[n + i] = Entry(ini[i], i);\n }\n foreach_reverse (a; 1 .. n) {\n mx[a] = max(mx[a << 1], mx[a << 1 | 1]);\n }\n }\n // [a, b)\n private Entry query(int u, int x, int y, int a, int b, long val) {\n chmax(a, x);\n chmin(b, y);\n if (a >= b) {\n return Entry(-INF, -1);\n }\n if (a == x && b == y) {\n mx[u].val += val;\n add[u] += val;\n return mx[u];\n }\n assert(u < n);\n const uL = u << 1 | 0;\n const uR = u << 1 | 1;\n const mid = (x + y) >> 1;\n if (add[u] != 0) {\n mx[uL].val += add[u];\n mx[uR].val += add[u];\n add[uL] += add[u];\n add[uR] += add[u];\n add[u] = 0;\n }\n const resL = query(uL, x, mid, a, b, val);\n const resR = query(uR, mid, y, a, b, val);\n mx[u] = max(mx[uL], mx[uR]);\n return max(resL, resR);\n }\n // [a, b)\n Entry query(int a, int b, long val) {\n return query(1, 0, n, a, b, val);\n }\n}\n\n\nint N;\nlong[] S;\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 \n S[] *= -1;\n debug {\n writeln(\"S = \", S);\n }\n auto seg = new SegmentTree(S);\n auto ans = new int[N];\n \n foreach (x; 1 .. N + 1) {\n const e = seg.query(0, N, 0);\n debug {\n writefln(\"x = %s: e = %s\", x, e);\n }\n assert(e.val == 0);\n ans[e.key] = x;\n seg.query(e.key, e.key + 1, -INF);\n seg.query(e.key + 1, N, x);\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 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 struct fwtr {\n int mx;\n long[] arr;\n this(int n) {\n mx = n;\n arr = new long[] (n+1);\n }\n \n void add(int p, int v) {\n while (p <= mx) {\n arr[p] += v;\n p += (p & (-p)); \n }\n }\n \n long sm(int p) {\n long ret = 0;\n while (p > 0) {\n ret += arr[p];\n p -= (p & (-p));\n }\n \n return ret;\n }\n }\n \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!long).array;\n auto sums = (n+1).iota.dropOne.cumulativeFold!((a, b) => a + b);\n \n debug { sums.writeln; }\n \n auto f = new fwtr(n);\n \n int binS(long sm) {\n long getSm(int idx) {\n return (idx.to!long * (idx + 1)) / 2 - f.sm(idx);\n }\n \n int le = 1, r = n;\n while (le < r) {\n int m = (le + r) / 2 + 1;\n if (getSm(m-1) <= sm) { le = m; }\n else { r = m - 1; }\n }\n \n return le;\n }\n \n auto ans = new int[] (n);\n \n foreach_reverse (i, sm; arr) {\n int val = binS(sm);\n f.add(val, val);\n ans[i] = val;\n }\n \n ans.map!(to!string).join(\" \").writeln;\n}"}], "negative_code": [], "src_uid": "c994ae45ac126c3ee16e77617b4554fc"} {"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\tint [int] b;\n\t\treadln.splitter.map !(to !(int)).filter !(x => x % k > 0)\n\t\t .map !(x => k - x % k).each !(x => b[x + 1] += 1);\n\t\tb.byKeyValue.map !(s => s.key + k * (s.value - 1L))\n\t\t .maxElement (0L).writeln;\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);\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\ta[] = (k - a[] % k) % k;\n\t\tsort (a);\n\t\tlong res = 0;\n\t\tlong cur = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i > 0 && a[i] == a[i - 1])\n\t\t\t{\n\t\t\t\tcur += k;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcur = 0;\n\t\t\t}\n\t\t\tif (a[i] > 0)\n\t\t\t{\n\t\t\t\tres = max (res, cur + a[i] + 1);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\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, k;\n @Dim(\"n\") long[] a;\n\n void solve(long tc = -1)\n {\n long[long] cnt;\n foreach(ai; a)\n if (ai % k != 0)\n {\n cnt.require((-ai%k + k)%k, 0)++;\n }\n if (cnt.length == 0)\n {\n writeln(0);\n return;\n }\n long ops = 0;\n foreach(m, c; cnt)\n {\n ops = max(ops, m + (c - 1) * k);\n }\n writeln(ops + 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;\nimport std.string : split, strip;\nimport std.conv : to;\nimport std.algorithm : map;\nimport std.array;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int n;\n long k;\n readf!\"%d %d\\n\"(n, k);\n\n auto a = readln.strip.split.map!(to!long);\n auto d = a.map!(a => a % k == 0 ? 0 : k - a % k);\n \n int[long] f;\n foreach (e; d) {\n f[e]++;\n }\n f.remove(0);\n\n long m = 0;\n int c;\n foreach (key, occ; f) {\n if (m == 0 || occ > c || (occ == c && key > m)) {\n m = key;\n c = occ;\n }\n }\n\n if (m == 0) {\n writeln(0);\n } else {\n writeln(k * (c - 1) + m + 1);\n }\n }\n}"}, {"source_code": "import std.algorithm, std.conv, std.stdio;\nvoid main () {\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0) {\n\t\treadln;\n\t\tint [int] b;\n\t\treadln.splitter.map !(to !(int)).filter !(x => x % k > 0).map !(x => k - x % k).each !(x => b[x + 1] += 1);\n\t\tb.byKeyValue.map !(s => s.key + k * (s.value - 1L)).maxElement (0L).writeln;\n\t}\n}\n"}], "negative_code": [], "src_uid": "a8b4c115bedda3847e7c2e3620e3e19b"} {"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 auto X = new bool[](10^^6+10);\n int[] Y;\n auto zero = 0;\n auto one = 0;\n int last = 0;\n int[] ans;\n\n foreach (i, a; A) {\n if (a > 0) {\n if (X[a]) {\n writeln(-1);\n return;\n }\n X[a] = true;\n zero -= 1;\n one += 1;\n } else {\n a *= -1;\n if (!X[a]) {\n writeln(-1);\n return;\n }\n Y ~= a;\n zero += 1;\n one -= 1;\n if (one == 0) {\n ans ~= (i.to!int + 1) - last;\n last = i.to!int + 1;\n foreach (y; Y) X[y] = false;\n Y = [];\n }\n }\n }\n\n if (X.any) {\n writeln(-1);\n return;\n }\n\n writeln(ans.length.to!int);\n ans.map!(to!string).join(\" \").writeln;\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;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint n = rint;\n\tint[] as = rint(n);\n\t\n\tint[] xs = new int[](1_000_999);\n\tlong[] ys = new long[](1_000_999);\n\tint cnt = 0;\n\tint[] ans;\n\t\n\tint an = 0;\n\tforeach(a; as){\n\t\tan += 1;\n\t\tif(a > 0){\n\t\t\tif(xs[a] > 0){\n\t\t\t\t\"-1\".writeln;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\txs[a] = 1;\n\t\t\tif(ys[a] == ans.length + 1){\n\t\t\t\t\"-1\".writeln;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tys[a] = ans.length + 1;\n\t\t\tcnt += 1;\n\t\t}\n\t\telse{\n\t\t\tif(xs[-a] == 0){\n\t\t\t\t\"-1\".writeln;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\txs[-a] = 0;\n\t\t\tcnt -= 1;\n\t\t\tif(cnt == 0){\n\t\t\t\tans ~= an;\n\t\t\t\tan = 0;\n\t\t\t}\n\t\t}\n\t\tlog(\"a:\", a, \"cnt:\", cnt, \"an:\", an, \"ans:\", ans);\n\t\tlog(\"xs:\", xs[0..10]);\n\t\tlog(\"ys:\", ys[0..10]);\n\t}\n\t\n\tif(cnt > 0){\n\t\t\"-1\".writeln;\n\t\treturn;\n\t}\n\t\n\tans.length.writeln;\n\tans.map!(to!string).array.join(\" \").writeln;\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 N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto X = new bool[](10^^6+10);\n int[] Y;\n auto zero = 0;\n auto one = 0;\n int last = 0;\n int[] ans;\n\n foreach (i, a; A) {\n if (a > 0) {\n if (X[a]) {\n writeln(-1);\n return;\n }\n X[a] = true;\n zero -= 1;\n one += 1;\n } else {\n a *= -1;\n if (!X[a]) {\n writeln(-1);\n return;\n }\n Y ~= a;\n zero += 1;\n one -= 1;\n if (one == 0) {\n ans ~= (i.to!int + 1) - last;\n last = i.to!int + 1;\n foreach (y; Y) X[y] = false;\n Y = [];\n }\n }\n }\n\n writeln(ans.length.to!int);\n ans.map!(to!string).join(\" \").writeln;\n}\n"}], "src_uid": "17f73ae0347b551fb5e287322785c8a4"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto mat = ma(n, readString.map!(c => c == '0'? int(0) : int(1)).array);\n\tauto rowSum = new int[][](m, n);\n\tauto colSum = new int[][](n, m);\n\tforeach(j; 0 .. m)\n\t{\n\t\trowSum[j][0] = mat[0][j];\n\t}\n\tforeach(j; 0 .. m)\n\t{\n\t\t\t\n\t\tforeach(i; 1 .. n)\n\t\t{\n\t\t\trowSum[j][i] = rowSum[j][i-1] + mat[i][j];\n\t\t}\n\t}\n\tforeach(i; 0 .. n)\n\t{\n\t\tcolSum[i][0] = mat[i][0];\n\t}\n\tforeach(i; 0 .. n)\n\t{\n\t\tforeach(j; 1 .. m)\n\t\t{\n\t\t\tcolSum[i][j] = colSum[i][j-1] + mat[i][j];\n\t\t}\n\t}\n\tauto ans = int.max;\n\tforeach(i1; 0 .. n)\n\t{\n\t\tforeach(i2; i1 + 4 .. n)\n\t\t{\n\t\t\tauto minTail = int.max;\n\t\t\tauto height = i2 - i1 - 1;\n\t\t\tauto railsSum = new int[](m);\n\t\t\tauto bodySum = new int[](m);\n\t\t\tauto pileRemove = new int[](m);\n\t\t\t\n\t\t\trailsSum[0] = (1-mat[i1][0]) + (1-mat[i2][0]);\n\t\t\tbodySum[0] = rowSum[0][i2-1] - rowSum[0][i1];\n\t\t\tpileRemove[0] = height - (rowSum[0][i2-1] - rowSum[0][i1]);\n\t\t\tforeach(j; 1 .. m)\n\t\t\t{\n\t\t\t\trailsSum[j] = (1-mat[i1][j]) + (1-mat[i2][j]) + railsSum[j-1];\n\t\t\t\tbodySum[j] = (rowSum[j][i2-1] - rowSum[j][i1]) + bodySum[j-1];\n\t\t\t\tpileRemove[j] = height - (rowSum[j][i2-1] - rowSum[j][i1]);\n\t\t\t\t\n\t\t\t\tdebug writeln(\"body sum \", i1, \" \", i2, \" \", j, \" = \", bodySum[j]);\n\t\t\t\tdebug writeln(\"pile remove \", i1, \" \", i2, \" \", j, \" = \", pileRemove[j]);\n\t\t\t}\n\n\t\t\tforeach(j; 3 .. m)\n\t\t\t{\n\t\t\t\tminTail = min(minTail, -railsSum[j-3]+pileRemove[j-3]-bodySum[j-3]);\n\t\t\t\tauto localOperations = minTail + pileRemove[j] + railsSum[j-1] + bodySum[j-1];\n\t\t\t\tans = min(ans, localOperations);\n\t\t\t}\n\t\t}\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": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto mat = ma(n, readString.map!(c => c == '0'? int(0) : int(1)).array);\n\tauto rowSum = new int[][](m, n);\n\tauto colSum = new int[][](n, m);\n\tforeach(j; 0 .. m)\n\t{\n\t\trowSum[j][0] = mat[0][j];\n\t}\n\tforeach(j; 0 .. m)\n\t{\n\t\t\t\n\t\tforeach(i; 1 .. n)\n\t\t{\n\t\t\trowSum[j][i] = rowSum[j][i-1] + mat[i][j];\n\t\t}\n\t}\n\tforeach(i; 0 .. n)\n\t{\n\t\tcolSum[i][0] = mat[i][0];\n\t}\n\tforeach(i; 0 .. n)\n\t{\n\t\tforeach(j; 1 .. m)\n\t\t{\n\t\t\tcolSum[i][j] = colSum[i][j-1] + mat[i][j];\n\t\t}\n\t}\n\tauto railsSum = new int[](m);\n\tauto bodySum = new int[](m);\n\tauto pileRemove = new int[](m);\n\tauto ans = int.max;\n\tforeach(i1; 0 .. n)\n\t{\n\t\tforeach(i2; i1 + 4 .. n)\n\t\t{\n\t\t\tauto minTail = int.max;\n\t\t\tauto height = i2 - i1 - 1;\n\t\t\trailsSum[0] = (1-mat[i1][0]) + (1-mat[i2][0]);\n\t\t\tbodySum[0] = rowSum[0][i2-1] - rowSum[0][i1];\n\t\t\tpileRemove[0] = height - (rowSum[0][i2-1] - rowSum[0][i1]);\n\t\t\tforeach(j; 1 .. m)\n\t\t\t{\n\t\t\t\trailsSum[j] = (1-mat[i1][j]) + (1-mat[i2][j]) + railsSum[j-1];\n\t\t\t\tbodySum[j] = (rowSum[j][i2-1] - rowSum[j][i1]) + bodySum[j-1];\n\t\t\t\tpileRemove[j] = height - (rowSum[j][i2-1] - rowSum[j][i1]);\n\t\t\t}\n\t\t\tforeach(j; 3 .. m)\n\t\t\t{\n\t\t\t\tminTail = min(minTail, -railsSum[j-3]+pileRemove[j-3]-bodySum[j-3]);\n\t\t\t\tauto localOperations = minTail + pileRemove[j] + railsSum[j-1] + bodySum[j-1];\n\t\t\t\tans = min(ans, localOperations);\n\t\t\t}\n\t\t}\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"}, {"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 numCases = readInt();\n foreach (caseId; 0 .. numCases) {\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 ASums = new int[][](M, N + 1);\n foreach (x; 0 .. M) {\n foreach (y; 0 .. N) {\n ASums[x][y + 1] = ASums[x][y] + (A[x][y] - '0');\n }\n }\n \n int ans = INF;\n auto fs = new int[M + 1];\n foreach (y0; 0 .. N) foreach (y1; y0 + 3 .. N) {\n foreach (x; 0 .. M) {\n fs[x + 1] = fs[x];\n fs[x + 1] += 1 - (A[x][y0] - '0');\n fs[x + 1] += 1 - (A[x][y1] - '0');\n fs[x + 1] += (ASums[x][y1] - ASums[x][y0 + 1]);\n }\n int mn = INF;\n foreach (x; 0 .. M) {\n if (x >= 4) {\n int cost;\n cost += (y1 - y0 - 1) - (ASums[x - 4][y1] - ASums[x - 4][y0 + 1]);\n cost -= fs[x - 4 + 1];\n chmin(mn, cost);\n }\n {\n int cost = mn;\n cost += (y1 - y0 - 1) - (ASums[x][y1] - ASums[x][y0 + 1]);\n cost += fs[x];\n chmin(ans, cost);\n }\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "immutable multi = true;\n\nint[400][400] mat, rowSum;\nint[400] railsSum, bodySum, pileRemove;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tforeach(i; 0 .. n)\n\t{\n\t\tauto str = readString;\n\t\tforeach(j; 0 .. m)\n\t\t\tmat[i][j] = int(str[j] == '1');\n\t}\n\tforeach(j; 0 .. m)\n\t{\n\t\trowSum[j][0] = mat[0][j];\n\t}\n\tforeach(j; 0 .. m)\n\t{\n\t\t\t\n\t\tforeach(i; 1 .. n)\n\t\t{\n\t\t\trowSum[j][i] = rowSum[j][i-1] + mat[i][j];\n\t\t}\n\t}\n\tauto ans = int.max;\n\tforeach(i1; 0 .. n)\n\t{\n\t\tforeach(i2; i1 + 4 .. n)\n\t\t{\n\t\t\tauto minTail = int.max;\n\t\t\tauto height = i2 - i1 - 1;\n\t\t\trailsSum[0] = (1-mat[i1][0]) + (1-mat[i2][0]);\n\t\t\tbodySum[0] = rowSum[0][i2-1] - rowSum[0][i1];\n\t\t\tpileRemove[0] = height - (rowSum[0][i2-1] - rowSum[0][i1]);\n\t\t\tforeach(j; 1 .. m)\n\t\t\t{\n\t\t\t\trailsSum[j] = (1-mat[i1][j]) + (1-mat[i2][j]) + railsSum[j-1];\n\t\t\t\tbodySum[j] = (rowSum[j][i2-1] - rowSum[j][i1]) + bodySum[j-1];\n\t\t\t\tpileRemove[j] = height - (rowSum[j][i2-1] - rowSum[j][i1]);\n\t\t\t}\n\t\t\tforeach(j; 3 .. m)\n\t\t\t{\n\t\t\t\tminTail = min(minTail, -railsSum[j-3]+pileRemove[j-3]-bodySum[j-3]);\n\t\t\t\tauto localOperations = minTail + pileRemove[j] + railsSum[j-1] + bodySum[j-1];\n\t\t\t\tans = min(ans, localOperations);\n\t\t\t}\n\t\t}\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"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto mat = ma(n, readString.map!(c => c == '0'? int(0) : int(1)).array);\n\tauto rowSum = new int[][](m, n);\n\tforeach(j; 0 .. m)\n\t{\n\t\trowSum[j][0] = mat[0][j];\n\t}\n\tforeach(j; 0 .. m)\n\t{\n\t\t\t\n\t\tforeach(i; 1 .. n)\n\t\t{\n\t\t\trowSum[j][i] = rowSum[j][i-1] + mat[i][j];\n\t\t}\n\t}\n\tauto railsSum = new int[](m);\n\tauto bodySum = new int[](m);\n\tauto pileRemove = new int[](m);\n\tauto ans = int.max;\n\tforeach(i1; 0 .. n)\n\t{\n\t\tforeach(i2; i1 + 4 .. n)\n\t\t{\n\t\t\tauto minTail = int.max;\n\t\t\tauto height = i2 - i1 - 1;\n\t\t\trailsSum[0] = (1-mat[i1][0]) + (1-mat[i2][0]);\n\t\t\tbodySum[0] = rowSum[0][i2-1] - rowSum[0][i1];\n\t\t\tpileRemove[0] = height - (rowSum[0][i2-1] - rowSum[0][i1]);\n\t\t\tforeach(j; 1 .. m)\n\t\t\t{\n\t\t\t\trailsSum[j] = (1-mat[i1][j]) + (1-mat[i2][j]) + railsSum[j-1];\n\t\t\t\tbodySum[j] = (rowSum[j][i2-1] - rowSum[j][i1]) + bodySum[j-1];\n\t\t\t\tpileRemove[j] = height - (rowSum[j][i2-1] - rowSum[j][i1]);\n\t\t\t}\n\t\t\tforeach(j; 3 .. m)\n\t\t\t{\n\t\t\t\tminTail = min(minTail, -railsSum[j-3]+pileRemove[j-3]-bodySum[j-3]);\n\t\t\t\tauto localOperations = minTail + pileRemove[j] + railsSum[j-1] + bodySum[j-1];\n\t\t\t\tans = min(ans, localOperations);\n\t\t\t}\n\t\t}\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"}], "negative_code": [], "src_uid": "c789584f0a4b5d1cca1d6168e8261379"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 n = RD!int;\n\t\tauto k1 = RD!int;\n\t\tauto k2 = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = RDA;\n\t\tforeach (i; 0..k1)\n\t\t{\n\t\t\tif (a[i] == n)\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}\n", "positive_code": [{"source_code": "void main() {\n\tauto t = ri;\n\tforeach(_; 0..t) {\n\t\tauto ip = readAs!(int[]);\n\t\tauto a = readAs!(int[]);\n\t\tauto b = readAs!(int[]);\n\t\ta.sort!\"a > b\"();\n\t\tb.sort!\"a > b\"();\n\t\tif(a[0] > b[0]) writeln(\"YES\");\n\t\telse 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}"}, {"source_code": "import std.stdio;\nimport std.algorithm : map, maxElement;\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, k1, k2;\n readf!\"%d %d %d\\n\"(n, k1, k2);\n\n auto maxa = readln.strip.split.map!(to!int).maxElement;\n auto maxb = readln.strip.split.map!(to!int).maxElement;\n\n writeln(maxa > maxb ? \"YES\" : \"NO\");\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\tint n, k1, k2;\n\t\treadf !(\" %s %s %s\") (n, k1, k2);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int));\n\t\tauto b = readln.splitter.map !(to !(int));\n\t\twriteln (a.maxElement > b.maxElement ? \"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\tforeach(_; 0 .. rint){\n\t\tint n = rint, k1 = rint, k2 = rint;\n\t\tint[] as = rint(k1);\n\t\tint[] bs = rint(k2);\n\n\t\tstring ans = \"NO\";\n\t\tforeach(a; as) if(a == n) ans = \"YES\";\n\t\t\n\t\tans.writeln;\n\t}\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; imax1)\n\t\t\t{\n\t\t\t\tmax1=d;\n\t\t\t}\n\t\t}\n\t\tfor (int j=0; jmax2)\n\t\t\t{\n\t\t\t\tmax2=d;\n\t\t\t}\n\t\t}\n\t\tif (max1>max2)\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(\"NO\");\n\t\t}\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "3ef23f114be223255bd10131b2375b86"} {"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 nom = n / m;\n auto a = next!int(n);\n auto cnt = new int[](m);\n auto byclass = new int[][](m);\n foreach(i, ai; a)\n {\n auto aim = ai % m;\n cnt[aim]++;\n byclass[aim] ~= cast(int) i;\n }\n auto toFill = redBlackTree!int();\n foreach(i; 0 .. m)\n if (cnt[i] < nom)\n toFill.insert(cast(int)i);\n long moves = 0;\n foreach(mclass; 0 .. m)\n {\n if (cnt[mclass] < nom) continue;\n auto tomove = cnt[mclass] - nom;\n foreach(i; 0 .. tomove)\n\t{\n\t auto index = byclass[mclass][i];\n\t auto upper = toFill.upperBound(mclass);\n\t int fill = upper.empty? toFill.upperBound(-1).front : upper.front;\n\t int delta = fill - mclass + int(fill < mclass) * m;\n\t moves += delta;\n\t a[index] = a[index] + delta;\n\t assert(a[index] % m == fill);\n\t assert(cnt[fill] < nom);\n\t cnt[fill]++;\n\t if (cnt[fill] == nom)\n\t toFill.removeKey(fill);\n\t}\n }\n writeln(moves);\n foreach(ai; a)\n write(ai, \" \");\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", "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 arr = readln.chomp.split.map!(to!int).array;\n \n auto rm = new int[][] (m);\n \n foreach (i, e; arr) { rm[e % m] ~= i.to!int; }\n \n debug { rm.each!writeln; }\n \n long ans = 0;\n int[] totake;\n foreach (i; 0 .. 2 * m) {\n int cr = i % m;\n while (rm[cr].length < n / m && !totake.empty()) {\n int idx = totake.back;\n totake.popBack();\n \n int newval = (arr[idx] / m) * m + cr;\n if (newval <= arr[idx]) { newval += m; }\n ans += newval - arr[idx];\n arr[idx] = newval;\n rm[cr] ~= idx;\n }\n \n while (rm[cr].length > n / m) {\n totake ~= rm[cr].back;\n rm[cr].popBack();\n }\n }\n \n ans.writeln;\n arr.map!(to!string).join(\" \").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 m = next!int;\n auto a = next!int(n);\n auto cnt = new int[](m);\n auto byclass = new int[][](m);\n foreach(i, ai; a)\n {\n auto aim = ai % m;\n cnt[aim]++;\n byclass[aim] ~= cast(int) i;\n }\n auto toFill = redBlackTree!int();\n foreach(i; 0 .. m)\n if (cnt[i] < n / m)\n toFill.insert(cast(int)i);\n long moves = 0;\n foreach(mclass; 0 .. m)\n {\n debug writeln(\"working with class \", mclass, \" with indices \", byclass[mclass]);\n if (cnt[mclass] < n / m) continue;\n auto tomove = cnt[mclass] - n / m;\n debug writeln(\"will move \", tomove);\n foreach(i; 0 .. tomove)\n\t{\n\t auto index = byclass[mclass][i];\n\t int fill;\n\t auto upper = toFill.upperBound(mclass);\n\t if (upper.empty)\n\t {\n\t fill = toFill.upperBound(-1).front;\n\t }\n\t else\n\t {\n\t fill = upper.front;\n\t }\n\t int delta;\n\t if (fill > mclass)\n\t {\n\t delta = fill - mclass;\n\t }\n\t else\n\t {\n\t delta = m - mclass + fill;\n\t }\n\t moves += delta;\n\t a[index] = a[index] + delta;\n\t assert(a[index] % m == fill);\n\t assert(cnt[fill] < n / m);\n\t cnt[fill]++;\n\t if (cnt[fill] >= n / m)\n\t toFill.removeKey(fill);\n\t}\n }\n writeln(moves);\n foreach(ai; a)\n write(ai, \" \");\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 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 = readln.chomp.split.map!(to!int).array;\n \n auto rm = new int[][] (m);\n \n foreach (i, e; arr) { rm[e % m] ~= i.to!int; }\n \n debug { rm.each!writeln; }\n \n int ans = 0;\n int[] totake;\n foreach (i; 0 .. 3 * m) {\n int cr = i % m;\n while (rm[cr].length < n / m && !totake.empty()) {\n int idx = totake.back;\n totake.popBack();\n \n int newval = (arr[idx] / m) * m + cr;\n if (newval <= arr[idx]) { newval += m; }\n ans += newval - arr[idx];\n arr[idx] = newval;\n rm[cr] ~= idx;\n }\n \n while (rm[cr].length > n / m) {\n totake ~= rm[cr].back;\n rm[cr].popBack();\n }\n }\n \n ans.writeln;\n arr.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, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto rm = new int[][] (m);\n \n foreach (i, e; arr) { rm[e % m] ~= i.to!int; }\n \n debug { rm.each!writeln; }\n \n int ans = 0;\n int[] totake;\n foreach (i; 0 .. 2 * m) {\n int cr = i % m;\n while (rm[cr].length < n / m && !totake.empty()) {\n int idx = totake.back;\n totake.popBack();\n \n int newval = (arr[idx] / m) * m + cr;\n ans += newval - arr[idx];\n arr[idx] = newval;\n rm[cr] ~= idx;\n }\n \n while (rm[cr].length > n / m) {\n totake ~= rm[cr].back;\n rm[cr].popBack();\n }\n }\n \n ans.writeln;\n arr.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, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto rm = new int[][] (m);\n \n foreach (i, e; arr) { rm[e % m] ~= i.to!int; }\n \n debug { rm.each!writeln; }\n \n int ans = 0;\n int[] totake;\n foreach (i; 0 .. 3 * m) {\n int cr = i % m;\n while (rm[cr].length < n / m && !totake.empty()) {\n int idx = totake.back;\n totake.popBack();\n \n int newval = (arr[idx] / m) * m + cr;\n ans += newval - arr[idx];\n arr[idx] = newval;\n rm[cr] ~= idx;\n }\n \n while (rm[cr].length > n / m) {\n totake ~= rm[cr].back;\n rm[cr].popBack();\n }\n }\n \n ans.writeln;\n arr.map!(to!string).join(\" \").writeln;\n}"}], "src_uid": "4a7c2e32e29734476fa40bced7ddc4e8"} {"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!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA;\n\t\tlong[] tmp;\n\t\tlong cnt;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tcnt += a[j];\n\t\t\tif (tmp.length == k-1) continue;\n\t\t\tif (cnt % 2 == 1)\n\t\t\t{\n\t\t\t\ttmp ~= j + 1;\n\t\t\t\tcnt = 0;\n\t\t\t}\n\t\t}\n\t\tif (cnt != 0)\n\t\t{\n\t\t\tif (cnt % 2 == 1)\n\t\t\t\ttmp ~= n;\n\t\t\telse\n\t\t\t\ttmp.length = 0;\n\t\t}\n\t\tif (tmp.length != k)\n\t\t{\n\t\t\ttmp.length = 0;\n\t\t}\n\t\tans[i] = tmp;\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\te.map!(to!string).join(\" \").writeln();\n\t\t}\n\t}\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "import std.stdio;\nvoid main()\n{\n int q;\n readf(\" %s\", &q);\n \n for(int i = 0; i < q; i++){\n \tint k = 0;\n \tint n = 0;\n \treadf(\" %s %s\", &n, &k);\n \tlong[] array = new long[] (n);\n \tint totalParity = 0;\n \tint numOdd = 0;\n\n \tfor(int j = 0; j < n; j++){\n \t\treadf(\" %s\", &array[j]);\n \t\ttotalParity += array[j];\n \t\ttotalParity %= 2;\n \t\tif(array[j] % 2 == 1)\n \t\t\tnumOdd++;\n \t}\n\n \tif(totalParity == (k % 2) && numOdd >= k){\n \t\twrite(\"YES\\n\");\n \t\tint currentParity = 0;\n \t\tint numSegments = 1;\n\n \t\tfor(int j = 0; j < n && numSegments < k; j++){\n \t\t\tcurrentParity += array[j];\n \t\t\tcurrentParity %= 2;\n \t\t\tif(currentParity % 2 == 1){\n \t\t\t\twrite(j + 1);\n \t\t\t\twrite(\" \");\n \t\t\t\tcurrentParity = 0;\n \t\t\t\tnumSegments++;\n \t\t\t}\n \t\t}\n \t\twrite((n));\n \t\twrite(\"\\n\");\n \t}else{\n \t\twrite(\"NO\\n\");\n \t}\n }\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid solve() {\n int n, k;\n readf(\" %s %s\", n, k);\n\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n readf(\" %s\", a[i]);\n }\n\n auto numOfOdds = fold!((s, x) => s + x % 2)(a, 0);\n if ((numOfOdds - k) % 2 == 0 && numOfOdds >= k) {\n writeln(\"YES\");\n for (int i = 0, j = 1; i < n; i++) {\n if (a[i] % 2 == 1) {\n if (j == k) {\n write(n);\n break;\n } else {\n write(i+1, \" \");\n j += 1;\n }\n }\n }\n writeln();\n } else {\n writeln(\"NO\");\n }\n}\n\nvoid main(){\n int numOfTests;\n readf(\" %s\", numOfTests);\n for (int i = 0; i < numOfTests; i++) {\n solve();\n }\n}\n\n"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.container.array;\n\nvoid main(string[] args){\n long n, a, b, sum, input;\n scanf(\"%lld\", &n);\n while (n--) {\n auto arr = Array!int();\n scanf(\"%lld %lld\", &a, &b);\n sum = 0;\n for (int i = 0; i < a; i++) {\n scanf(\"%lld\", &input);\n sum += input;\n if (sum & 1) {\n arr.insertBack(i + 1);\n sum = 0;\n } else if (i == a - 1) {\n if (!arr.empty()) {\n arr.back() = i + 1;\n }\n }\n }\n int len = arr.length;\n int start = 0;\n while (len > b) {\n len -= 2;\n start += 2;\n }\n if (len == b) {\n printf(\"YES\\n\");\n for (int i = start; i < arr.length; i++ ) {\n printf(\"%d \", arr[i]);\n }\n printf(\"\\n\");\n } else {\n printf(\"NO\\n\");\n }\n }\n}\n"}], "negative_code": [{"source_code": "module main;\n\nimport std.stdio;\nimport std.container.array;\n\nvoid main(string[] args){\n long n, a, b, sum, input;\n scanf(\"%lld\", &n);\n while (n--) {\n auto arr = Array!int();\n scanf(\"%lld %lld\", &a, &b);\n sum = 0;\n for (int i = 0; i < a; i++) {\n scanf(\"%lld\", &input);\n sum += input;\n if (sum & 1) {\n arr.insertBack(i + 1);\n sum = 0;\n }\n }\n int len = arr.length;\n while (len > b) {\n len -= 2;\n }\n if (len == b) {\n printf(\"YES\\n\");\n for (int i =0; i < b; i++ ) {\n printf(\"%d \", arr[i]);\n }\n printf(\"\\n\");\n } else {\n printf(\"NO\\n\");\n }\n }\n}\n"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int q;\n readf(\" %s\", &q);\n \n for(int i = 0; i < q; i++){\n \tint k = 0;\n \tint n = 0;\n \treadf(\" %s %s\", &n, &k);\n \tint[] array = new int[] (n);\n \tint totalParity = 0;\n\n \tfor(int j = 0; j < n; j++){\n \t\treadf(\" %s\", &array[j]);\n \t\ttotalParity += array[j];\n \t\ttotalParity %= 2;\n \t}\n\n \tif(totalParity == (k % 2)){\n \t\twrite(\"YES\\n\");\n \t\tint currentParity = 0;\n \t\tint numSegments = 1;\n\n \t\tfor(int j = 0; j < n && numSegments < k; j++){\n \t\t\tcurrentParity += array[j];\n \t\t\tcurrentParity %= 2;\n \t\t\tif(currentParity % 2 == 1){\n \t\t\t\twrite(j);\n \t\t\t\twrite(\" \");\n \t\t\t}\n \t\t}\n \t\twrite((n - 1));\n \t\twrite(\"\\n\");\n \t}else{\n \t\twrite(\"NO\\n\");\n \t}\n }\n}"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int q;\n readf(\" %s\", &q);\n \n for(int i = 0; i < q; i++){\n \tint k = 0;\n \tint n = 0;\n \treadf(\" %s %s\", &n, &k);\n \tint[] array = new int[] (n);\n \tint totalParity = 0;\n\n \tfor(int j = 0; j < n; j++){\n \t\treadf(\" %s\", &array[j]);\n \t\ttotalParity += array[j];\n \t\ttotalParity %= 2;\n \t}\n\n \tif(totalParity == (k % 2)){\n \t\twrite(\"YES\\n\");\n \t\tint currentParity = 0;\n \t\tint numSegments = 1;\n\n \t\tfor(int j = 0; j < n && numSegments < k; j++){\n \t\t\tcurrentParity += array[j];\n \t\t\tcurrentParity %= 2;\n \t\t\tif(currentParity % 2 == 1){\n \t\t\t\twrite(j + 1);\n \t\t\t\twrite(\" \");\n \t\t\t\tcurrentParity = 0;\n \t\t\t\tnumSegments++;\n \t\t\t}\n \t\t}\n \t\twrite((n));\n \t\twrite(\"\\n\");\n \t}else{\n \t\twrite(\"NO\\n\");\n \t}\n }\n}"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int q;\n readf(\" %s\", &q);\n \n for(int i = 0; i < q; i++){\n \tint k = 0;\n \tint n = 0;\n \treadf(\" %s %s\", &n, &k);\n \tlong[] array = new long[] (n);\n \tint totalParity = 0;\n\n \tfor(int j = 0; j < n; j++){\n \t\treadf(\" %s\", &array[j]);\n \t\ttotalParity += array[j];\n \t\ttotalParity %= 2;\n \t}\n\n \tif(totalParity == (k % 2)){\n \t\twrite(\"YES\\n\");\n \t\tint currentParity = 0;\n \t\tint numSegments = 1;\n\n \t\tfor(int j = 0; j < n && numSegments < k; j++){\n \t\t\tcurrentParity += array[j];\n \t\t\tcurrentParity %= 2;\n \t\t\tif(currentParity % 2 == 1){\n \t\t\t\twrite(j + 1);\n \t\t\t\twrite(\" \");\n \t\t\t\tcurrentParity = 0;\n \t\t\t\tnumSegments++;\n \t\t\t}\n \t\t}\n \t\twrite((n));\n \t\twrite(\"\\n\");\n \t}else{\n \t\twrite(\"NO\\n\");\n \t}\n }\n}"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int q;\n readf(\" %s\", &q);\n \n for(int i = 0; i < q; i++){\n \tint k = 0;\n \tint n = 0;\n \treadf(\" %s %s\", &n, &k);\n \tint[] array = new int[] (n);\n \tint totalParity = 0;\n\n \tfor(int j = 0; j < n; j++){\n \t\treadf(\" %s\", &array[j]);\n \t\ttotalParity += array[j];\n \t\ttotalParity %= 2;\n \t}\n\n \tif(totalParity == (k % 2)){\n \t\twriteln(\"YES\\n\");\n \t\tint currentParity = 0;\n \t\tint numSegments = 1;\n\n \t\tfor(int j = 0; j < n && numSegments < k; j++){\n \t\t\tcurrentParity += array[j];\n \t\t\tcurrentParity %= 2;\n \t\t\tif(currentParity % 2 == 1){\n \t\t\t\twrite(j);\n \t\t\t\twrite(\" \");\n \t\t\t}\n \t\t}\n \t\twrite((n - 1));\n \t\twrite(\"\\n\");\n \t}else{\n \t\twrite(\"NO\\n\");\n \t}\n }\n}"}], "src_uid": "7f5269f3357827b9d8682d70befd3de1"} {"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 d = cin.read_int;\n\n char[][] att = new char[][d];\n \n int beat_streak = 0;\n int count = 0;\n for (int i = 0; i < d; i++) {\n att[i] = new char[n];\n att[i] = cin.read_string.dup;\n if (canFind(att[i][0..n], '0')) count++;\n else count = 0;\n beat_streak = max(beat_streak, count);\n }\n writeln(beat_streak);\n } \n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n\n auto nd = readln.split.map!(to!int).array;\n\n int max_ans1, max_ans2;\n foreach (idx; 0 .. nd[1]) {\n bool d_idx = readln.strip.map!(to!char).array.any!(d => d == '0');\n if (d_idx) {\n ++max_ans1;\n if (max_ans1 > max_ans2) {\n max_ans2 = max_ans1;\n }\n } else {\n max_ans1 = 0;\n }\n }\n\n writeln(max_ans2);\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\n\nvoid main()\n{\n auto n = split(strip(readln()));\n auto d = to!int(n[1]);\n int maxi;\n int count;\n foreach (i; 0 .. d)\n {\n auto x = strip(readln());\n if (indexOf(x, '0') >= 0)\n count++;\n else\n {\n maxi = max(maxi, count);\n count = 0;\n }\n }\n maxi = max(maxi, count);\n writeln(maxi);\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\n\nvoid main()\n{\n auto n = split(strip(readln()));\n auto d = to!int(n[1]);\n int maxi;\n int count;\n foreach (i; 0 .. d)\n {\n auto x = strip(readln());\n if (indexOf(x, '0') >= 0)\n count++;\n else\n {\n maxi = max(maxi, count);\n count = 0;\n }\n }\n writeln(maxi);\n}\n\n"}], "src_uid": "a6ee741df426fd2d06fdfda4ca369397"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\t\n\t\tans[ti] = (b - (a % b)) % b;\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 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 uint h = r.next!uint ();\n const uint w = r.next!uint ();\n auto a = new char[][](h, w);\n foreach (j; 0 .. h) {\n foreach (i; 0 .. w) {\n if (i || j) write ('B'); else write('W');\n }\n writeln;\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(); } 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 foreach(i; 0 .. n){\n if(i == 0) \"W\".write;\n else \"B\".write;\n foreach(j; 0 .. m - 1) \"B\".write;\n \"\".writeln;\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\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 string[][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tans[ti].length = n;\n\t\tforeach (y; 0..n-1)\n\t\t{\n\t\t\tforeach (x; 0..m-1)\n\t\t\t{\n\t\t\t\tans[ti][y] ~= 'W';\n\t\t\t}\n\t\t\tans[ti][y] ~= 'B';\n\t\t}\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tans[ti][$-1] ~= 'B';\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (ee; e)\n\t\t\twriteln(ee);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "2b37f27a98ec8f80d0bff3f7ae8f2cff"} {"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 d = scan!long, m = scan!long;\n long u = 1;\n long ans = 0;\n long tmp = 1;\n int i = 0;\n d += 1;\n while(u <= d){\n tmp *= u / 2 + 1, tmp %= m;\n ans += tmp * u, ans %= m;\n i += 1;\n u *= 2;\n }\n ans += m - tmp * (u - d) % m, ans %= m;\n tmp *= u / 2 + 1, tmp %= m;\n ans.print;\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\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\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const D = readLong();\n ModInt.M = readInt();\n \n ModInt ans = 1;\n for (int e = 0; ; ++e) {\n long lb = 1 << e, ub = 1 << (e + 1);\n chmin(ub, D + 1);\n debug {\n writeln(e, \": \", lb, \" \", ub);\n }\n if (lb < ub) {\n ans *= (1 + (ub - lb));\n } else {\n break;\n }\n }\n ans -= 1;\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;\nimport std.typecons;\n\nvoid main ()\n{\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint d, m;\n\t\treadf !(\" %s %s\") (d, m);\n\n\t\tlong res = 1;\n\t\tfor (long p = 1; p <= d; p <<= 1)\n\t\t{\n\t\t\tlong hi = min ((p << 1) - 1, d);\n\t\t\tlong total = hi - p + 2;\n\t\t\tres = (res * total) % m;\n\t\t}\n\t\tres = (res + m - 1) % m;\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\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 d = r.next!uint;\n const m = r.next!uint;\n uint add (uint x, uint y) {\n x += y;\n if (x >= m) x -= m;\n return x;\n }\n uint sub (uint x, uint y) {\n if (x < y) x += m;\n x -= y;\n return x;\n }\n uint mul (uint x, uint y) {\n ulong z = x.to!ulong * y;\n return (z % m).to!uint;\n }\n auto deg = new uint[32];\n int last = 1;\n foreach (i; 1 .. 32) {\n uint l = min (d + 1, 1U << i);\n debug stderr.writeln (\"l = \", l);\n if (l == last) break;\n uint dt = l - last;\n debug stderr.writeln (\"dt = \", dt);\n deg[i] = dt % m;\n last = l;\n }\n debug stderr.writeln (deg);\n auto u = new uint[32];\n u[0] = 1;\n uint res; \n while (u.any!(\"a != 0\")) {\n auto e = new uint[32];\n foreach (i; 0 .. 32) {\n foreach (j; i + 1 .. 32) {\n e[j] = add (e[j], mul (u[i], deg[j]));\n }\n }\n debug stderr.writeln (\"e = \", e);\n u = e;\n foreach (i; u) {\n res = add (res, i);\n }\n }\n writeln (res);\n }\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;\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 d = r.next!uint;\n const m = r.next!uint;\n uint add (uint x, uint y) {\n x += y;\n if (x >= m) x -= m;\n return x;\n }\n uint sub (uint x, uint y) {\n if (x < y) x += m;\n x -= y;\n return x;\n }\n uint mul (uint x, uint y) {\n ulong z = x.to!ulong * y;\n return (z % m).to!uint;\n }\n auto deg = new uint[32];\n int last = 1;\n foreach (i; 1 .. 32) {\n int l = min (d + 1, 1 << i);\n debug stderr.writeln (\"l = \", l);\n int dt = l - last;\n debug stderr.writeln (\"dt = \", dt);\n if (dt == 0) break;\n deg[i] = dt % m;\n last = l;\n }\n debug stderr.writeln (deg);\n auto cum = new uint[32];\n cum[0] = 0;\n foreach (i; 1 .. 32) {\n cum[i] = cum[i-1] + deg[i];\n }\n debug stderr.writeln (\"cum = \", cum);\n auto u = new uint[32];\n u[0] = 1;\n uint res; \n while (u.any!(\"a != 0\")) {\n auto e = new uint[32];\n foreach (i; 0 .. 32) {\n foreach (j; i + 1 .. 32) {\n e[j] = add (e[j], mul (u[i], deg[j]));\n }\n }\n debug stderr.writeln (\"e = \", e);\n u = e;\n foreach (i; u) {\n res = add (res, i);\n }\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(); } 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 d = scan!long, m = scan!long;\n long u = 1;\n long ans = 0;\n long tmp = 1;\n int i = 0;\n d += 1;\n while(u <= d){\n tmp *= primes[i], tmp %= m;\n ans += tmp * u, ans %= m;\n i += 1;\n u *= 2;\n }\n ans += m - tmp * (u - d) % m, ans %= m;\n tmp *= primes[i], tmp %= m;\n ans.print;\n }\n \n}\n\nlong[] primes = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, \n 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,\n 131, 137, 139, 149, 151, 157, 163, 167, 173];\n"}], "src_uid": "12157ec4a71f0763a898172b38ff1ef2"} {"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\nvoid solve() {\r\n long b, q, y; readf(\"%d %d %d\\n\", &b, &q, &y);\r\n long c, r, z; readf(\"%d %d %d\\n\", &c, &r, &z);\r\n\r\n bool check_invalid() {\r\n if ( (c - b) % q != 0 ) return true; // invalid\r\n if (r % q != 0) return true;\r\n if (c - b < 0) return true;\r\n if (c + r * (z - 1) - b > q * (y - 1)) return true;\r\n return false;\r\n }\r\n\r\n bool check_infinite() {\r\n if (c - r < b) return true;\r\n if (c + r * z > b + q * (y - 1)) return true;\r\n return false;\r\n }\r\n\r\n if (check_invalid()) {\r\n writeln(0);\r\n } else if (check_infinite()) {\r\n writeln(-1);\r\n } else {\r\n long ans = 0;\r\n auto ms = divisors(q);\r\n foreach (m; ms) {\r\n long p = r / q * m;\r\n if (lcm(p, q) != r) continue;\r\n long s = r / p;\r\n ans += s * s;\r\n ans %= mod;\r\n //writefln(\"(%s, %s) -> %s\", p, q, s);\r\n }\r\n writeln(ans);\r\n }\r\n}\r\n\r\nlong[] divisors(long x) {\r\n long[] ret;\r\n for (long k = 1; k * k <= x; k++) {\r\n if (x % k == 0) {\r\n ret ~= k;\r\n ret ~= x / k;\r\n }\r\n }\r\n return ret.sort.uniq.array;\r\n}\r\nlong lcm(long a, long b) {\r\n return a / gcd(a, b) * b;\r\n}\r\n\r\nenum long mod = cast(long)(1e9+7);\r\n", "positive_code": [{"source_code": "// cheese-cracker [2022-05-03]\n\nconst long MOD = 1_000_000_007;\n\n\nvoid solve(){\n long b = scan; long q = scan;\n long y = scan;\n\n long c = scan;\n long r = scan;\n long z = scan;\n\n long lo = c - b;\n long B = b + q*(y-1);\n long C = c + r*(z-1);\n long remb = ((b % q) + q) % q;\n long remc = ((c % q) + q) % q;\n\n /* show(B, C, B-C); */\n if(r % q != 0 || B < C || lo < 0 || remc != remb){\n writeln(0);\n }else if(lo < r || B < C + r){\n writeln(-1);\n }else{\n long res = 0;\n for(long div = 1; div * div <= q; ++div){\n if(q % div == 0){\n long p = div * (r / q);\n if(p / gcd(p, q) == r / q){\n res += (r / p) * (r / p) % MOD;\n res %= MOD;\n }\n if(div * div != q){\n p = r / div;\n if(p / gcd(p, q) == r / q){\n res += (r / p) * (r / p) % MOD;\n res %= MOD;\n }\n }\n }\n }\n writeln(res);\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": [{"source_code": "// cheese-cracker [2022-05-03]\n\nconst long MOD = 1_000_000_007;\n\n\nvoid solve(){\n long b = scan; long q = scan;\n long y = scan;\n\n long c = scan;\n long r = scan;\n long z = scan;\n\n long lo = c - b;\n long B = b + q*y;\n long C = c + r*z;\n long remb = ((b % q) + q) % q;\n long remc = ((c % q) + q) % q;\n\n /* show(B, C, B-C); */\n if(r % q != 0 || B < C || lo < 0 || remc != remb){\n writeln(0);\n }else if(lo < r || B < C + r){\n writeln(-1);\n }else{\n long res = 0;\n for(long div = 1; div * div <= q; ++div){\n if(q % div == 0){\n long p = div * (r / q);\n if(p * q == r * gcd(p, q)){\n res += (r / p) * (r / p) % MOD;\n res %= MOD;\n }\n if(div * div != q){\n p = (q/div) * (r/q);\n if(p * q == r * gcd(p, q)){\n res += (r / p) * (r / p) % MOD;\n res %= MOD;\n }\n }\n }\n }\n writeln(res);\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"}, {"source_code": "// cheese-cracker [2022-05-03]\n\nconst long MOD = 1_000_000_007;\n\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\n// Modulo Inverse\nll modinv(ll num){ return modexp(num, MOD-2); }\n\nlong[] primes;\nvoid prime_sieve(){\n size_t sz =100_000;\n auto isPrime = new bool[](sz + 1);\n isPrime[] = 1;\n foreach(p; 2..10_000){\n if(isPrime[p]){\n for(int divi = p*p; divi <= sz; divi += p){ isPrime[divi] = 0; }\n }\n }\n primes = isPrime[2..$].enumerate.filter!(a => a[1]).map!(a => (a[0] + 2).to!(long)).array;\n}\n\nvoid solve(){\n long b = scan;\n long q = scan;\n long y = scan;\n\n long c = scan;\n long r = scan;\n long z = scan;\n\n long lo = c - b;\n long B = b + q*y;\n long C = c + r*z;\n long remb = ((b % q) + q) % q;\n long remc = ((c % q) + q) % q;\n\n if(r % q != 0 || B < C || lo < 0 || remc != remb){\n writeln(0);\n }else if(lo < r || B < C + r){\n writeln(-1);\n }else{\n long num = q;\n long res = 1;\n foreach(p; primes){\n long cnt = 1;\n while(num % p == 0){\n num /= p;\n ++cnt;\n }\n res *= ((modexp(p*p, cnt) - 1) + MOD) % MOD;\n res %= MOD;\n res *= modinv(p*p - 1);\n res %= MOD;\n }\n if(num != 1){\n long p = num;\n res *= (1 + p*p) % MOD;\n res %= MOD;\n }\n writeln(res);\n }\n}\n\n\nvoid main(){\n prime_sieve;\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; } }\nalias ll = long;\n"}, {"source_code": "// cheese-cracker [2022-05-03]\n\nconst long MOD = 1_000_000_007;\n\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\n// Modulo Inverse\nll modinv(ll num){ return modexp(num, MOD-2); }\n\nlong[] primes;\nvoid prime_sieve(){\n size_t sz =100_000;\n auto isPrime = new bool[](sz + 1);\n isPrime[] = 1;\n foreach(p; 2..10_000){\n if(isPrime[p]){\n for(int divi = p*p; divi <= sz; divi += p){ isPrime[divi] = 0; }\n }\n }\n primes = isPrime[2..$].enumerate.filter!(a => a[1]).map!(a => (a[0] + 2).to!(long)).array;\n}\n\nvoid solve(){\n long b = scan;\n long q = scan;\n long y = scan;\n\n long c = scan;\n long r = scan;\n long z = scan;\n\n long lo = c - b;\n long hi = (b + q*y) - (c + r*z);\n long remb = ((b % q) + q) % q;\n long remc = ((c % q) + q) % q;\n\n if(r % q != 0 || hi < 0 || lo < 0 || remc != remb){\n writeln(0);\n }else if(lo < r || hi < r){\n writeln(-1);\n }else{\n long num = q;\n long res = 1;\n foreach(p; primes){\n long cnt = 1;\n while(num % p == 0){\n num /= p;\n ++cnt;\n }\n res *= ((modexp(p*p, cnt) - 1) + MOD) % MOD;\n res %= MOD;\n res *= modinv(p*p - 1);\n res %= MOD;\n }\n if(num != 1){\n long p = num;\n res *= (1 + p*p) % MOD;\n res %= MOD;\n }\n writeln(res);\n }\n}\n\n\nvoid main(){\n prime_sieve;\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; } }\nalias ll = long;\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\nvoid solve() {\r\n long b, q, y; readf(\"%d %d %d\\n\", &b, &q, &y);\r\n long c, r, z; readf(\"%d %d %d\\n\", &c, &r, &z);\r\n\r\n bool check_invalid() {\r\n if ( (c - b) % q != 0 ) return true; // invalid\r\n if (r % q != 0) return true;\r\n if (c - b < 0) return true;\r\n if (c + r * (z - 1) - b > q * (y - 1)) return true;\r\n return false;\r\n }\r\n\r\n bool check_infinite() {\r\n if (c - r < b) return true;\r\n if (c + r * z > b + q * (y - 1)) return true;\r\n return false;\r\n }\r\n\r\n if (check_invalid()) {\r\n writeln(0);\r\n } else if (check_infinite()) {\r\n writeln(-1);\r\n } else {\r\n long ans = 0;\r\n auto ms = divisors(q);\r\n foreach (m; ms) {\r\n long p = r / q * m;\r\n long s = r / p;\r\n ans += s * s;\r\n ans %= mod;\r\n }\r\n writeln(ans);\r\n }\r\n}\r\n\r\nlong[] divisors(long x) {\r\n long[] ret;\r\n for (long k = 1; k * k <= x; k++) {\r\n if (x % k == 0) {\r\n ret ~= k;\r\n ret ~= x / k;\r\n }\r\n }\r\n return ret.sort.uniq.array;\r\n}\r\n\r\nenum long mod = cast(long)(1e9+7);\r\n"}], "src_uid": "3035265a44fcc3bb6317bf1b9662fc76"} {"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.strip.splitter(\"\").map!(to!int).array;\n auto b = readln.strip.splitter(\"\").map!(to!int).array;\n auto cnt1 = a.count(1);\n Tuple!(int, int)[] ans;\n foreach (i ; 0 .. n) {\n if (a[i] == 1) {\n ans ~= tuple(i + 1, i + 1);\n }\n b[i] ^= (cnt1 % 2) ^ a[i];\n }\n auto cnt1b = b.count(1);\n if (cnt1b == 0) {\n writeln(\"YES\");\n } else if (cnt1b == b.length) {\n writeln(\"YES\");\n ans ~= tuple(1, n);\n ans ~= tuple(1, 1);\n ans ~= tuple(2, n);\n } else {\n writeln(\"NO\");\n continue;\n }\n writeln(ans.length);\n foreach (x ; ans) {\n writefln(\"%d %d\", x[0], x[1]);\n }\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.strip.map !(q{a - '0'}).array;\r\n\t\tauto b = readln.strip.map !(q{a - '0'}).array;\r\n\t\tint [] [] answer;\r\n\t\tif (a != b)\r\n\t\t{\r\n\t\t\tanswer ~= [0, n];\r\n\t\t\ta[] = 1 - a[];\r\n\t\t}\r\n\t\tif (a != b)\r\n\t\t{\r\n\t\t\twriteln (\"NO\");\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\twriteln (\"YES\");\r\n\t\tint k = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i])\r\n\t\t\t{\r\n\t\t\t\tanswer ~= [i, i + 1];\r\n\t\t\t\tk += 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif ((k - 1) % 2 == 0)\r\n\t\t{\r\n\t\t\tanswer ~= [0, n];\r\n\t\t\tanswer ~= [0, 1];\r\n\t\t\tanswer ~= [1, n];\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\twriteln (line[0] + 1, \" \", line[1]);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "cc9abcff3224118b533881335e4c582b"} {"source_code": "import std.stdio;\nimport std.algorithm : max, min;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int a, b;\n readf!\"%d %d\\n\"(a, b);\n auto c = min(max(2*a, b), max(2*b, a));\n writeln(c*c);\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 = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long a, b;\n\n void solve(long tc = -1)\n {\n if (a > b)\n swap(a, b);\n writeln(max(2 * a, b) * max(2 * a, b));\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 long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tans[ti] = max(min(a, b)*2, max(a, b))^^2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "3bb093fb17d6b76ae340fab44b08fcb8"} {"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!int;\r\n\t\tauto x = new int[](k);\r\n\t\tauto y = new int[](k);\r\n\t\tauto used = new bool[](n*2);\r\n\t\tforeach (i; 0..k)\r\n\t\t{\r\n\t\t\tx[i] = RD!int-1;\r\n\t\t\ty[i] = RD!int-1;\r\n\t\t\tused[x[i]] = true;\r\n\t\t\tused[y[i]] = true;\r\n\t\t}\r\n\r\n\t\tint[] arr;\r\n\t\tforeach (i; 0..n*2)\r\n\t\t{\r\n\t\t\tif (used[i]) continue;\r\n\t\t\tarr ~= i;\r\n\t\t}\r\n\t\tforeach (i; 0..n-k)\r\n\t\t{\r\n\t\t\tx ~= arr[i];\r\n\t\t\ty ~= arr[n-k+i];\r\n\t\t}\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[][] tmp = [[x[i], 0], [y[i], 0], [x[j], 1], [y[j], 1]];\r\n\t\t\t\ttmp.sort!\"a[0] < b[0]\";\r\n\t\t\t\tif (tmp[0][1] != tmp[1][1] && tmp[1][1] != tmp[2][1])\r\n\t\t\t\t\t++ans[ti];\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\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 m = n * 2;\r\n\t\tauto p = new int [2] [n];\r\n\t\tauto used = new bool [m];\r\n\t\tforeach (int i, ref c; p[0..k])\r\n\t\t{\r\n\t\t\tc = readln.splitter.map !(to !(int)).array;\r\n\t\t\tc[] -= 1;\r\n\t\t\tforeach (ref x; c)\r\n\t\t\t{\r\n\t\t\t\tused[x] = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint cur = 0;\r\n\t\tforeach (z; 0..2)\r\n\t\t{\r\n\t\t\tforeach (i; k..n)\r\n\t\t\t{\r\n\t\t\t\twhile (used[cur])\r\n\t\t\t\t{\r\n\t\t\t\t\tcur += 1;\r\n\t\t\t\t}\r\n\t\t\t\tused[cur] = true;\r\n\t\t\t\tp[i][z] = cur;\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\tsort (p[i][]);\r\n\t\t}\r\n\t\tsort (p);\r\n\t\tdebug {writeln (p);}\r\n\r\n\t\tint res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..i)\r\n\t\t\t{\r\n\t\t\t\tif (p[i][0] < p[j][1] && p[j][1] < p[i][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\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\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 X = new int[K];\n auto Y = new int[K];\n foreach (k; 0 .. K) {\n X[k] = readInt() - 1;\n Y[k] = readInt() - 1;\n if (X[k] > Y[k]) {\n swap(X[k], Y[k]);\n }\n }\n \n auto used = new bool[2 * N];\n foreach (k; 0 .. K) {\n used[X[k]] = true;\n used[Y[k]] = true;\n }\n auto xs = X.dup, ys = Y.dup;\n foreach (u; 0 .. 2 * N) {\n if (!used[u]) {\n ((xs.length < N) ? xs : ys) ~= u;\n }\n }\n \n int ans;\n foreach (i; 0 .. N) foreach (j; 0 .. N) {\n if (xs[i] < xs[j] && xs[j] < ys[i] && ys[i] < ys[j]) {\n ++ans;\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "9ca9df1ab3760edb8e7adc3be533c576"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1519/problem/C\n// data structures, sorting\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 long[] u = readln.split.map!(to!long).array;\n long[] s = readln.split.map!(to!long).array;\n\n long[][] universities = new long[][](n);\n\n for(int i = 0; i < n; ++i) {\n u[i] -= 1;\n }\n\n for(int i = 0; i < n; ++i) {\n universities[cast(uint)u[i]] ~= s[i];\n }\n\n for(int i = 0; i < n; ++i) {\n universities[i].sort;\n universities[i].reverse;\n }\n\n long[][] cumulative = new long[][](n + 1,1);\n\n for(int i = 0; i < n; i++) {\n foreach(x; universities[i]) {\n cumulative[i] ~= (cumulative[i][$- 1] + x);\n }\n }\n\n long[] ans = new long[n];\n for(int i = 0; i < n; ++i) {\n for(int k = 1; k <= universities[i].length; k++) {\n ans[k - 1] += cumulative[i][universities[i].length/k*k];\n }\n }\n for(int i = 0; i < n; ++i)\n writef(\"%s \", ans[i]);\n \"\".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\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 u = RDA(-1);\r\n\t\tauto s = RDA;\r\n\r\n\t\tauto list = new long[][](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tlist[u[i]] ~= s[i];\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tlist[i].sort!\"a > b\";\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 1..list[i].length)\r\n\t\t\t{\r\n\t\t\t\tlist[i][j] += list[i][j-1];\r\n\t\t\t}\r\n\t\t}\r\n\t\tdebug writeln(list);\r\n\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..list[i].length)\r\n\t\t\t{\r\n\t\t\t\tauto rem = list[i].length % (j+1);\r\n\t\t\t\tans[ti][j] += list[i][$-1-rem];\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": "// Vicfred\n// https://codeforces.com/contest/1519/problem/C\n// data structures, sorting\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 long[] u = readln.split.map!(to!long).array;\n long[] s = readln.split.map!(to!long).array;\n\n long[][] universities = new long[][](n);\n\n for(int i = 0; i < n; ++i) {\n u[i] -= 1;\n }\n\n for(int i = 0; i < n; ++i) {\n universities[cast(uint)u[i]] ~= s[i];\n }\n\n for(int i = 0; i < n; ++i) {\n universities[i].sort;\n universities[i].reverse;\n }\n\n long[][] cumulative = new long[][](n + 1,1);\n\n for(int i = 0; i < n; i++) {\n foreach(x; universities[i]) {\n cumulative[i] ~= (cumulative[i][$- 1] + x);\n }\n }\n\n int[] ans = new int[n];\n for(int i = 0; i < n; ++i) {\n for(int k = 1; k <= universities[i].length; k++) {\n ans[k - 1] += cumulative[i][universities[i].length/k*k];\n }\n }\n for(int i = 0; i < n; ++i)\n writef(\"%s \", ans[i]);\n \"\".writeln;\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1519/problem/C\n// data structures, sorting\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[] u = readln.split.map!(to!int).array;\n int[] s = readln.split.map!(to!int).array;\n\n int[][] universities = new int[][](n);\n\n for(int i = 0; i < n; ++i) {\n u[i] -= 1;\n }\n\n for(int i = 0; i < n; ++i) {\n universities[u[i]] ~= s[i];\n }\n\n for(int i = 0; i < n; ++i) {\n universities[i].sort;\n universities[i].reverse;\n }\n\n long[][] cumulative = new long[][](n + 1,1);\n\n for(int i = 0; i < n; i++) {\n foreach(x; universities[i]) {\n cumulative[i] ~= (cumulative[i][$- 1] + x);\n }\n }\n\n int[] ans = new int[n];\n for(int i = 0; i < n; ++i) {\n for(int k = 1; k <= universities[i].length; k++) {\n ans[k - 1] += cumulative[i][universities[i].length/k*k];\n }\n }\n for(int i = 0; i < n; ++i)\n writef(\"%s \", ans[i]);\n \"\".writeln;\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1519/problem/C\n// data structures, sorting\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[] u = readln.split.map!(to!int).array;\n int[] s = readln.split.map!(to!int).array;\n\n int[][] universities = new int[][](n);\n\n for(int i = 0; i < n; ++i) {\n u[i] -= 1;\n }\n\n for(int i = 0; i < n; ++i) {\n universities[u[i]] ~= s[i];\n }\n\n for(int i = 0; i < n; ++i) {\n universities[i].sort;\n universities[i].reverse;\n }\n\n int[][] cumulative = new int[][](n + 1,1);\n\n for(int i = 0; i < n; i++) {\n foreach(x; universities[i]) {\n cumulative[i] ~= (cumulative[i][$- 1] + x);\n }\n }\n\n int[] ans = new int[n];\n for(int i = 0; i < n; ++i) {\n for(int k = 1; k <= universities[i].length; k++) {\n ans[k - 1] += cumulative[i][universities[i].length/k*k];\n }\n }\n for(int i = 0; i < n; ++i)\n writef(\"%s \", ans[i]);\n \"\".writeln;\n}\n}\n"}], "src_uid": "437ab04bd029db32ceba31becbe06722"} {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv;\n\nvoid main() {\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[] x = new string[n];\n foreach (i; 0 .. n) { x[i] = stdin.readln; }\n bool[] f = new bool[n];\n f.fill(false);\n foreach (j; 0 .. m) {\n int mx = 0;\n foreach (i; 0 .. n) {\n mx = max(x[i][j].to!int, mx);\n }\n foreach (i; 0 .. n) {\n if (x[i][j].to!int == mx) {\n f[i] = true;\n }\n }\n }\n writeln(f.count(true));\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.functional, std.array;\n\nvoid main() {\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n string[] x = new string[n];\n foreach (i; 0 .. n) { x[i] = stdin.readln.chomp; }\n uint[][] y = x.map!(pipe!(map!(\"a-'0'\"), array)).array;\n bool[] f = new bool[n]; f.fill(false);\n foreach (j; 0 .. m) {\n int mx = 0;\n foreach (i; 0 .. n) {\n mx = max(y[i][j], mx);\n }\n foreach (i; 0 .. n) {\n if (y[i][j] == mx) {\n f[i] = true;\n }\n }\n }\n writeln(f.count(true));\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 m = cin.readInt;\n\n int[][] g = new int[][](n, m);\n string[] mat = new string[n];\n for (int i = 0; i < n; i++) {\n mat[i] = cin.readString;\n for (int j = 0; j < m; j++) \n g[i][j] = mat[i][j] - 48;\n }\n \n int[] subMax;\n for (int i = 0; i < m; i++) {\n int maxx = -9999;\n for (int j = 0; j < n; j++) {\n maxx = max(maxx, g[j][i]);\n }\n subMax ~= maxx;\n }\n\n int ans = 0;\n int[] best = new int[n];\n for (int i = 0; i < m; i++) {\n int maxCount = 0;\n for (int j = 0; j < n; j++) {\n if (g[j][i] == subMax[i])\n best[j] = 1;\n }\n }\n writeln(best.count(1));\n } \n}"}], "negative_code": [], "src_uid": "41bdb08253cf5706573f5d469ab0a7b3"} {"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 while (n--) {\n long q;\n read(q);\n \n auto t = q / 3;\n auto r = q - 2 * t;\n \n while (r - t > 1) {\n t++;\n r -= 2;\n }\n \n writeln(r, \" \", t);\n }\n}\n\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1551/problem/A\n// math, greedy\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n;\n readf(\"%s\\n\", &n);\n\n long c1, c2;\n c1 = n / 3L;\n c2 = n / 3L;\n\n if(n % 3 == 1) {\n c1 += 1;\n } else if (n % 3 == 2) {\n c2 += 1;\n }\n\n writefln(\"%s %s\", c1, c2);\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;\n\twhile (t--)\n\t{\n\t\tint n = readInt!int;\n\t\tif (n % 3 == 0)\n\t\t{\n\t\t\twriteln(n/3, \" \", n/3);\n\t\t}\n\t\telse if (n % 3 == 1)\n\t\t{\n\t\t\twriteln(n/3+1, \" \", n/3);\n\t\t}\n\t\telse \n\t\t{\n\t\t\twriteln(n/3, \" \", n/3+1);\n\t\t}\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\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readf!\" %d \"(n);\n long c2 = (n + 1) / 3;\n long c1 = n - c2 * 2;\n writefln(\"%d %d\", c1, c2);\n }\n}\n"}], "negative_code": [], "src_uid": "71335a9489f0985f4e16435b14d6a34a"} {"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\nint n, q;\n\n\nstruct SqrtDecomposition {\n alias Entry = Tuple!(long, \"val\", int, \"idx\");\n alias MinMax = Tuple!(int, \"min\", int, \"max\");\n struct Bucket {\n long added;\n Entry[] vs;\n void add(int l, int r, long x) {\n long prevAdded = added;\n added = 0;\n foreach(ref e; vs) {\n e.val += prevAdded;\n if (l <= e.idx && e.idx < r) e.val += x;\n }\n vs.sort();\n }\n\n int min(long x) {\n int lb = -1, ub = cast(int)vs.length;\n while (ub - lb > 1) {\n int mid = (ub + lb) / 2;\n if (vs[mid].val < x) {\n lb = mid;\n } else {\n ub = mid;\n }\n }\n if (ub == vs.length || vs[ub].val != x) {\n return -1;\n } else {\n return vs[ub].idx;\n }\n }\n\n int max(long x) {\n int lb = -1, ub = cast(int)vs.length;\n while (ub - lb > 1) {\n int mid = (ub + lb) / 2;\n if (vs[mid].val > x) {\n ub = mid;\n } else {\n lb = mid;\n }\n }\n if (lb == -1 || vs[lb].val != x) {\n return -1;\n } else {\n return vs[lb].idx;\n }\n }\n }\n \n int n, m, bsize;\n Bucket[] bs;\n this(int[] a) {\n n = cast(int)a.length;\n bsize = cast(int)(sqrt(real(n)) + 1);\n m = (n - 1) / bsize + 1;\n bs = new Bucket[m];\n foreach (i; 0..m) {\n int l = i * bsize;\n int r = min(n, (i + 1) * bsize);\n bs[i].added = 0;\n foreach(j; l..r) {\n bs[i].vs ~= Entry(a[j], j);\n }\n bs[i].vs.sort();\n }\n }\n\n void add(int l, int r, long x) {\n int lb = l / bsize;\n int rb = (r - 1) / bsize;\n if (lb == rb) {\n bs[lb].add(l, r, x);\n } else {\n bs[lb].add(l, r, x);\n foreach(i; lb+1..rb) {\n bs[i].added += x;\n }\n bs[rb].add(l, r, x);\n }\n }\n\n MinMax query(long x) {\n MinMax ans = MinMax(n, -1);\n foreach(b; bs) {\n int minIdx = b.min(x - b.added);\n int maxIdx = b.max(x - b.added);\n if (minIdx != -1) {\n assert(maxIdx != -1);\n ans.min = min(minIdx, ans.min);\n ans.max = max(maxIdx, ans.max);\n } else {\n assert(maxIdx == -1);\n }\n }\n return ans;\n }\n}\n\nvoid main() {\n scanf(\"%d%d\", &n, &q);\n int[] a = new int[n];\n foreach (i; 0..n) {\n scanf(\"%d\", &a[i]);\n }\n auto sq = SqrtDecomposition(a); \n while (q--) {\n int t;\n scanf(\"%d\", &t);\n if (t == 1) {\n int l, r, x;\n scanf(\"%d%d%d\", &l, &r, &x);\n l--;\n sq.add(l, r, x);\n } else if (t == 2) {\n int y;\n scanf(\"%d\", &y);\n auto ans = sq.query(y);\n if (ans.max == -1) {\n writeln(-1);\n } else {\n writeln(ans.max - ans.min);\n }\n } else {\n assert(false);\n }\n }\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\nint n, q;\n\n\nstruct SqrtDecomposition {\n alias Entry = Tuple!(long, \"val\", int, \"idx\");\n alias MinMax = Tuple!(int, \"min\", int, \"max\");\n struct Bucket {\n long added;\n Entry[] vs;\n void add(int l, int r, long x) {\n long prevAdded = added;\n added = 0;\n Entry[] newvs = new Entry[vs.length];\n foreach(i,e; vs) {\n e.val += prevAdded;\n if (l <= e.idx && e.idx < r) e.val += x;\n newvs[i] = e;\n }\n newvs.sort();\n vs = newvs;\n }\n\n int min(long x) {\n int lb = -1, ub = cast(int)vs.length;\n while (ub - lb > 1) {\n int mid = (ub + lb) / 2;\n if (vs[mid].val < x) {\n lb = mid;\n } else {\n ub = mid;\n }\n }\n if (ub == vs.length || vs[ub].val != x) {\n return -1;\n } else {\n return vs[ub].idx;\n }\n }\n\n int max(long x) {\n int lb = -1, ub = cast(int)vs.length;\n while (ub - lb > 1) {\n int mid = (ub + lb) / 2;\n if (vs[mid].val > x) {\n ub = mid;\n } else {\n lb = mid;\n }\n }\n if (lb == -1 || vs[lb].val != x) {\n return -1;\n } else {\n return vs[lb].idx;\n }\n }\n }\n \n int n, m, bsize;\n Bucket[] bs;\n this(int[] a) {\n n = cast(int)a.length;\n bsize = cast(int)(sqrt(real(n)) + 1);\n m = (n - 1) / bsize + 1;\n bs = new Bucket[m];\n foreach (i; 0..m) {\n int l = i * bsize;\n int r = min(n, (i + 1) * bsize);\n bs[i].added = 0;\n foreach(j; l..r) {\n bs[i].vs ~= Entry(a[j], j);\n }\n bs[i].vs.sort();\n }\n }\n\n void add(int l, int r, long x) {\n int lb = l / bsize;\n int rb = (r - 1) / bsize;\n if (lb == rb) {\n bs[lb].add(l, r, x);\n } else {\n bs[lb].add(l, r, x);\n foreach(i; lb+1..rb) {\n bs[i].added += x;\n }\n bs[rb].add(l, r, x);\n }\n }\n\n MinMax query(long x) {\n MinMax ans = MinMax(n, -1);\n foreach(b; bs) {\n int minIdx = b.min(x - b.added);\n int maxIdx = b.max(x - b.added);\n if (minIdx != -1) {\n assert(maxIdx != -1);\n ans.min = min(minIdx, ans.min);\n ans.max = max(maxIdx, ans.max);\n } else {\n assert(maxIdx == -1);\n }\n }\n return ans;\n }\n}\n\nvoid main() {\n scanf(\"%d%d\", &n, &q);\n int[] a = new int[n];\n foreach (i; 0..n) {\n scanf(\"%d\", &a[i]);\n }\n auto sq = SqrtDecomposition(a); \n while (q--) {\n int t;\n scanf(\"%d\", &t);\n if (t == 1) {\n int l, r, x;\n scanf(\"%d%d%d\", &l, &r, &x);\n l--;\n sq.add(l, r, x);\n } else if (t == 2) {\n int y;\n scanf(\"%d\", &y);\n auto ans = sq.query(y);\n if (ans.max == -1) {\n writeln(-1);\n } else {\n writeln(ans.max - ans.min);\n }\n } else {\n assert(false);\n }\n }\n}\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\nint n, q;\n\n\nstruct SqrtDecomposition {\n alias Entry = Tuple!(long, \"val\", int, \"idx\");\n alias MinMax = Tuple!(int, \"min\", int, \"max\");\n struct Bucket {\n long added;\n Entry[] vs;\n void add(int l, int r, long x) {\n long prevAdded = added;\n added = 0;\n Entry[] newvs = new Entry[vs.length];\n foreach(i,e; vs) {\n e.val += prevAdded;\n if (l <= e.idx && e.idx < r) e.val += x;\n newvs[i] = e;\n }\n newvs.sort();\n vs = newvs;\n }\n\n int min(long x) {\n int lb = -1, ub = cast(int)vs.length;\n while (ub - lb > 1) {\n int mid = (ub + lb) / 2;\n if (vs[mid].val < x) {\n lb = mid;\n } else {\n ub = mid;\n }\n }\n if (ub == vs.length || vs[ub].val != x) {\n return -1;\n } else {\n return vs[ub].idx;\n }\n }\n\n int max(long x) {\n int lb = -1, ub = cast(int)vs.length;\n while (ub - lb > 1) {\n int mid = (ub + lb) / 2;\n if (vs[mid].val > x) {\n ub = mid;\n } else {\n lb = mid;\n }\n }\n if (lb == -1 || vs[lb].val != x) {\n return -1;\n } else {\n return vs[lb].idx;\n }\n }\n }\n \n int n, m, bsize;\n Bucket[] bs;\n this(int[] a) {\n n = cast(int)a.length;\n bsize = cast(int)(sqrt(real(n)) + 1);\n m = (n - 1) / bsize + 1;\n bs = new Bucket[m];\n foreach (i; 0..m) {\n int l = i * bsize;\n int r = min(n, (i + 1) * bsize);\n bs[i].added = 0;\n foreach(j; l..r) {\n bs[i].vs ~= Entry(a[j], j);\n }\n bs[i].vs.sort();\n }\n }\n\n void add(int l, int r, long x) {\n int lb = l / bsize;\n int rb = (r - 1) / bsize;\n if (lb == rb) {\n bs[lb].add(l, r, x);\n } else {\n bs[lb].add(l, r, x);\n foreach(i; lb+1..rb) {\n bs[i].added += 1;\n }\n bs[rb].add(l, r, x);\n }\n }\n\n MinMax query(long x) {\n MinMax ans = MinMax(n, -1);\n foreach(b; bs) {\n int minIdx = b.min(x - b.added);\n int maxIdx = b.max(x - b.added);\n if (minIdx != -1) {\n assert(maxIdx != -1);\n ans.min = min(minIdx, ans.min);\n ans.max = max(maxIdx, ans.max);\n } else {\n assert(maxIdx == -1);\n }\n }\n return ans;\n }\n}\n\nvoid main() {\n scanf(\"%d%d\", &n, &q);\n int[] a = new int[n];\n foreach (i; 0..n) {\n scanf(\"%d\", &a[i]);\n }\n auto sq = SqrtDecomposition(a); \n while (q--) {\n int t;\n scanf(\"%d\", &t);\n if (t == 1) {\n int l, r, x;\n scanf(\"%d%d%d\", &l, &r, &x);\n l--;\n sq.add(l, r, x);\n } else if (t == 2) {\n int y;\n scanf(\"%d\", &y);\n auto ans = sq.query(y);\n if (ans.max == -1) {\n writeln(-1);\n } else {\n writeln(ans.max - ans.min);\n }\n } else {\n assert(false);\n }\n }\n}\n"}], "src_uid": "7f91216cfb2568367f5e5ef058b8c2db"} {"source_code": "import 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\nint[] a, b, c;\n\nvoid main() {\n\n\tint n;\n\n\treadf(\" %s\", &n);\n\n\tint k;\n\tforeach (i; 0 .. n) {\n\t\tscanf(\"%d\", &k);\n\t\ta ~= k;\n\t}\n\n\tforeach (i; 0 .. n - 1) {\n\t\tscanf(\"%d\", &k);\n\t\tb ~= k;\n\t}\n\n\tforeach (i; 0 .. n - 2) {\n\t\tscanf(\"%d\", &k);\n\t\tc ~= k;\n\t}\n\n\tsort(a);\n\tsort(b);\n\tsort(c);\n\n\tbool flag = 1;\n\tforeach (i; 0 .. n - 1)\n\t\tif (a[i] != b[i]) {\n\t\t\twriteln(a[i]);\n\t\t\tflag = 0;\n\t\t\tbreak;\n\t\t}\n\n\tif (flag)\n\t\twriteln(a[n - 1]);\n\n\tflag = 1;\n\tforeach (i; 0 .. n - 2)\n\t\tif (b[i] != c[i]) {\n\t\t\twriteln(b[i]);\n\t\t\tflag = 0;\n\t\t\tbreak;\n\t\t}\n\n\tif (flag)\n\t\twriteln(b[n - 2]);\n}", "positive_code": [{"source_code": "import std.algorithm,std.conv,std.range,std.stdio;\n\nvoid main()\n{\n\treadln;\n\tauto f=()=>readln.split.map!(to!int).reduce!\"a^b\";\n\tauto x=f(),y=f(),z=f();\n\twriteln(x^y,'\\n',y^z);\n}\n"}, {"source_code": "import 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\nint a, b, c;\n\nvoid main() {\n\n\tint n;\n\n\treadf(\" %s\", &n);\n\n\tint k;\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %s\", &k);\n\t\ta ^= k;\n\t}\n\n\tforeach (i; 0 .. n - 1) {\n\t\treadf(\" %s\", &k);\n\t\tb ^= k;\n\t}\n\n\tforeach (i; 0 .. n - 2) {\n\t\treadf(\" %s\", &k);\n\t\tc ^= k;\n\t}\n\n\twriteln(a ^ b, '\\n', b ^ c);\n}"}, {"source_code": "import 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\nlong a, b, c;\n\nvoid main() {\n\t\n\tint n;\n\t\n\treadf(\" %s\", &n);\n\t\n\tint k;\n\tforeach (i; 0 .. n) {\n\t\tscanf(\"%d\", &k);\n\t\ta += k;\n\t}\n\t\n\tforeach (i; 0 .. n - 1) {\n\t\tscanf(\"%d\", &k);\n\t\tb += k;\n\t}\n\t\n\tforeach (i; 0 .. n - 2) {\n\t\tscanf(\"%d\", &k);\n\t\tc += k;\n\t}\n\n\twriteln(a - b, '\\n', b - c);\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;\n\tscanf(\"%d\", &n);\n\tint[int] ce1;\n\tforeach (int i; 0..n)\n\t{\n\t\tint error;\n\t\tscanf(\"%d\", &error); \n\t\tce1[error]++;\n\t}\n\tint[int] ce2;\n\tforeach (int i; 0..(n-1))\n\t{\n\t\tint error;\n\t\tscanf(\"%d\", &error);\n\t\tce2[error]++;\n\t}\n\tforeach (int key; ce1.byKey)\n\t{\n\t\tif (!(key in ce2) || ce1[key] != ce2[key])\n\t\t{\n\t\t\tprintf(\"%d\\n\", key);\n\t\t\tbreak;\n\t\t}\n\t}\n\tint[int] ce3;\n\tforeach (int i; 0..(n-2))\n\t{\n\t\tint error;\n\t\tscanf(\"%d\", &error);\n\t\tce3[error]++;\n\t}\n\n\tforeach (int key; ce2.byKey)\n\t{\t\n\t\tif (!(key in ce3) || ce2[key] != ce3[key])\n\t\t{\n\t\t\tprintf(\"%d\", key);\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import 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\nint a, b, c;\n\nvoid main() {\n\n\tint n;\n\n\treadf(\" %s\", &n);\n\n\tint k;\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %s\", &k);\n\t\ta ^= k;\n\t}\n\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %s\", &k);\n\t\tb ^= k;\n\t}\n\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %s\", &k);\n\t\tc ^= k;\n\t}\n\n\twriteln(a ^ b, '\\n', b ^ c);\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;\n\tscanf(\"%d\", &n);\n\tint[int] ce;\n\tforeach (int i; 0..(3*n - 3))\n\t{\n\t\tint error;\n\t\tscanf(\"%d\", &error); \n\t\tce[error]++;\n\t}\n\tint ak;\n\tint bk;\n\tforeach (int key; ce.byKey)\n\t{\n\t\tif (ce[key] < 3)\n\t\t{\n\t\t\tak = (ak == 0 && ce[key] == 1) ? key : ak;\n\t\t\tbk = (bk == 0 && ce[key] == 2) ? key : bk;\n\t\t}\n\t}\n\tprintf(\"%d\\n%d\", ak, bk);\n\treturn 0;\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;\n\tscanf(\"%d\", &n);\n\tint[int] ce;\n\tforeach (int i; 0..(3*n - 3))\n\t{\n\t\tint error;\n\t\tscanf(\"%d\", &error); \n\t\tce[error]++;\n\t}\n\tint ak;\n\tint bk;\n\tforeach (int key; ce.byKey)\n\t{\n\t\tif (ce[key] % 3 != 0)\n\t\t{\n\t\t\tak = (ak == 0 && ce[key] % 3 == 1) ? key : ak;\n\t\t\tbk = (bk == 0 && ce[key] % 3 == 2) ? key : bk;\n\t\t}\n\t}\n\tprintf(\"%d\\n%d\", ak, bk);\n\treturn 0;\n}"}], "src_uid": "1985566215ea5a7f22ef729bac7205ed"} {"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, k;\n @Dim(\"n\") string[] maze;\n\n void solve(long tc = -1)\n {\n char[][] mmaze = maze.map!(row => row.dup).array;\n enum long[2][] deltas = [[+1, 0],\n [-1, 0],\n [0, +1],\n [0, -1]];\n const initialPosition = delegate long[2]() {\n foreach(i; 0 .. n)\n foreach(j; 0 .. m)\n if (maze.at(i).at(j) == '.')\n return [i, j];\n assert(0);\n } ();\n auto dist = makeSlice!long(n, m);\n auto visited = makeSlice!bool(n, m);\n long[2][][long] withdist;\n auto maxdist = long(0);\n DList!(long[2]) queue;\n queue.insertFront(initialPosition);\n dist.at(initialPosition[0]).at(initialPosition[1]) = 0;\n visited.at(initialPosition[0]).at(initialPosition[1]) = true;\n withdist.require(0, null);\n withdist.at(0) = [initialPosition];\n while(!queue.empty)\n {\n auto node = queue.front;\n queue.removeFront;\n foreach(delta; deltas)\n {\n long[2] neighbour;\n neighbour[] = node[] + delta[];\n if (neighbour[0] >= 0 && neighbour[0] < n\n && neighbour[1] >= 0 && neighbour[1] < m\n && maze.at(neighbour[0]).at(neighbour[1]) == '.'\n && !visited.at(neighbour[0]).at(neighbour[1]))\n {\n dist.at(neighbour[0]).at(neighbour[1]) = dist.at(node[0]).at(node[1]) + 1;\n require(withdist, dist.at(neighbour[0]).at(neighbour[1]), null);\n withdist.at(dist.at(neighbour[0]).at(neighbour[1])) ~= neighbour;\n visited.at(neighbour[0]).at(neighbour[1]) = true;\n maxdist = max(maxdist, dist.at(neighbour[0]).at(neighbour[1]));\n queue.insertBack(neighbour);\n }\n }\n }\n auto inserted = long(0);\n auto disttoinsert = maxdist;\n while(inserted < k)\n {\n if (withdist.at(disttoinsert).empty)\n {\n disttoinsert--;\n }\n auto toinsert = withdist.at(disttoinsert)[$ - 1];\n mmaze.at(toinsert[0]).at(toinsert[1]) = 'X';\n withdist.at(disttoinsert).length--;\n inserted++;\n }\n foreach(row; mmaze)\n {\n writeln(row);\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.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 / 4;\nimmutable int DIRS = 4;\nimmutable int [DIRS] DR = [-1, 0, +1, 0];\nimmutable int [DIRS] DC = [ 0, -1, 0, +1];\n\nvoid main ()\n{\n\tint n, m, k;\n\twhile (readf (\" %s %s %s \", &n, &m, &k) > 0)\n\t{\n\t\tchar [] [] a;\n\t\tchar [] t1;\n\t\tforeach (j; 0..m + 2)\n\t\t{\n\t\t\tt1 ~= '#';\n\t\t}\n\t\ta ~= t1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tchar [] t2 = cast (char []) readln.strip;\n\t\t\ta ~= ('#' ~ t2 ~ '#');\n\t\t}\n\t\ta ~= t1;\n\n\t\talias Tuple !(int, \"r\", int, \"c\") coord;\n\t\tauto s = coord (-1, -1);\niloop:\t\tforeach (i; 0..n + 2)\n\t\t{\n\t\t\tforeach (j; 0..m + 2)\n\t\t\t{\n\t\t\t\tif (a[i][j] == '.')\n\t\t\t\t{\n\t\t\t\t\ts = coord (i, j);\n\t\t\t\t\tbreak iloop;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tenforce (s != coord (-1, -1));\n\n\t\tauto d = new int [] [] (n + 2, m + 2);\n\t\tforeach (ref e; d)\n\t\t{\n\t\t\te[] = INF;\n\t\t}\n\t\td[s.r][s.c] = 0;\n\t\tcoord [] q;\n\t\tq.reserve ((n + 2) * (m + 2));\n\t\tcoord [] r = q;\n\t\tq.assumeSafeAppend;\n\t\tq ~= s;\n\t\tint p = 0;\n\t\twhile (p < q.length)\n\t\t{\n\t\t\tauto cur = q[p];\n\t\t\tp++;\n\t\t\tforeach (dir; 0..DIRS)\n\t\t\t{\n\t\t\t\tauto next = coord (cur.r + DR[dir],\n\t\t\t\t cur.c + DC[dir]);\n\t\t\t\tif (a[next.r][next.c] != '.')\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (d[next.r][next.c] == INF)\n\t\t\t\t{\n\t\t\t\t\td[next.r][next.c] =\n\t\t\t\t\t d[cur.r][cur.c] + 1;\n\t\t\t\t\tq.assumeSafeAppend;\n\t\t\t\t\tq ~= next;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tq = q[$ - k..$];\n\t\tforeach (cur; q)\n\t\t{\n\t\t\ta[cur.r][cur.c] = 'X';\n\t\t}\n\n\t\tforeach (b; a[1..n + 1])\n\t\t{\n\t\t\twriteln (b[1..m + 1]);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "3aba4a129e24ca2f06f5f3ef13415b8b"} {"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, d;\r\n\twhile (readf !(\" %s %s\") (n, d) > 0)\r\n\t{\r\n\t\tauto p = n.iota.array;\r\n\t\tauto s = 1.repeat (n).array;\r\n\r\n\t\tint root (int v)\r\n\t\t{\r\n\t\t\tif (p[v] != v)\r\n\t\t\t{\r\n\t\t\t\tp[v] = root (p[v]);\r\n\t\t\t}\r\n\t\t\treturn p[v];\r\n\t\t}\r\n\r\n\t\tbool unite (int u, int v)\r\n\t\t{\r\n\t\t\tu = root (u);\r\n\t\t\tv = root (v);\r\n\t\t\tif (u == v)\r\n\t\t\t{\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\tif (s[u] > s[v])\r\n\t\t\t{\r\n\t\t\t\tswap (u, v);\r\n\t\t\t}\r\n\t\t\tp[u] = v;\r\n\t\t\ts[v] += s[u];\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tint add = 0;\r\n\t\tforeach (j; 0..d)\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\tauto cur = unite (u, v);\r\n\t\t\tadd += !cur;\r\n\r\n\t\t\tauto t = n.iota.filter !(v => p[v] == v)\r\n\t\t\t .map !(v => s[v]).array;\r\n\t\t\tsort (t);\r\n\t\t\tforeach (k; 0..add)\r\n\t\t\t{\r\n\t\t\t\tt[$ - 2] += t.back;\r\n\t\t\t\tt.popBack ();\r\n\t\t\t}\r\n\t\t\twriteln (t.back - 1);\r\n\t\t}\r\n\t}\r\n}\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 int n, d, saved = 0;\n readf(\" %d %d \", &n, &d);\n\n auto uf = Dsu(n);\n\n while (d--) {\n int u, v;\n readf(\" %d %d \", &u, &v);\n u--;\n v--;\n if (!uf.same(u, v)) {\n uf.merge(u, v);\n } else {\n saved++;\n }\n writeln(uf.groups.map!(x => x.length).array.sort!\"a>b\".take(saved + 1).sum - 1);\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"}, {"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 n, d;\n readf(\" %d %d \", &n, &d);\n\n auto largest = redBlackTree!(\"a > b\", true, int)();\n auto remaining = redBlackTree!(\"a > b\", true, int)();\n\n Dsu uf;\n uf = Dsu(n);\n\n long ans;\n long saved;\n while (d--) {\n int u, v;\n readf(\" %d %d \", &u, &v);\n u--;\n v--;\n if (!uf.same(u, v)) {\n if (largest.removeKey(uf.size(u)) == 0)\n remaining.removeKey(uf.size(u));\n else\n ans -= uf.size(u);\n if (largest.removeKey(uf.size(v)) == 0)\n remaining.removeKey(uf.size(v));\n else\n ans -= uf.size(v);\n uf.merge(u, v);\n remaining.insert(uf.size(v));\n } else {\n saved++;\n }\n while (largest.length > 0 && remaining.length > 0 && largest.back < remaining.front) {\n auto tmp = largest.back;\n largest.removeBack;\n ans -= tmp;\n remaining.insert(tmp);\n }\n while (largest.length < saved + 1 && remaining.length > 0) {\n auto tmp = remaining.front;\n remaining.removeFront;\n largest.insert(tmp);\n ans += tmp;\n }\n writeln(ans - 1 + saved - (largest.length - 1));\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"}, {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto d = readInt!int;\n auto parent = iota(n).array;\n auto size = ma(n, 1);\n int getParent(int i)\n {\n if (parent[i] == i) return i;\n return parent[i] = getParent(parent[i]);\n }\n bool unite(int i, int j)\n {\n i = getParent(i);\n j = getParent(j);\n if (i == j) return false;\n if (size[i] > size[j]) swap(i, j);\n parent[i] = j;\n size[j] += size[i];\n return true;\n }\n int redundant = 0;\n foreach(i; 0 .. d)\n {\n redundant += int(!unite(readInt!int - 1, readInt!int - 1));\n (iota(n).filter!(j => parent[j] == j)\n .map!(j => size[j])\n .array\n .sort!((a, b) => a > b)\n .take(redundant + 1)\n .sum - 1).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": "immutable multi = false;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto d = readInt!int;\n auto parent = iota(n).array;\n auto size = ma(n, 1);\n foreach(i; 0 .. n) { parent[i] = i; size[i] = 1; }\n int getParent(int i)\n {\n if (parent[i] == i) return i;\n return parent[i] = getParent(parent[i]);\n }\n bool unite(int i, int j)\n {\n i = getParent(i);\n j = getParent(j);\n if (i == j) return false;\n if (size[i] > size[j]) swap(i, j);\n parent[i] = j;\n size[j] += size[i];\n return true;\n }\n int redundant = 0;\n foreach(i; 0 .. d)\n {\n redundant += int(!unite(readInt!int - 1, readInt!int - 1));\n (iota(n).filter!(j => parent[j] == j)\n .map!(j => size[j])\n .array\n .sort!((a, b) => a > b)\n .take(redundant + 1)\n .sum - 1).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": "immutable multi = false;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto d = readInt!int;\n auto parent = new int[](n);\n auto size = new int[](n);\n foreach(i; 0 .. n) { parent[i] = i; size[i] = 1; }\n int getParent(int i)\n {\n if (parent[i] == i) return i;\n return parent[i] = getParent(parent[i]);\n }\n bool unite(int i, int j)\n {\n i = getParent(i);\n j = getParent(j);\n if (i == j) return false;\n if (size[i] > size[j]) swap(i, j);\n parent[i] = j;\n size[j] += size[i];\n return true;\n }\n int redundant = 0;\n foreach(i; 0 .. d)\n {\n redundant += int(!unite(readInt!int - 1, readInt!int - 1));\n (iota(n).filter!(j => parent[j] == j)\n .map!(j => size[j])\n .array\n .sort!((a, b) => a > b)\n .take(redundant + 1)\n .sum - 1).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": "immutable multi = false;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto d = readInt!int;\n auto parent = new int[](n);\n auto size = new int[](n);\n foreach(i; 0 .. n) { parent[i] = i; size[i] = 1; }\n int getParent(int i)\n {\n if (parent[i] == i) return i;\n return parent[i] = getParent(parent[i]);\n }\n bool unite(int i, int j)\n {\n i = getParent(i);\n j = getParent(j);\n if (i == j) return false;\n if (size[i] > size[j]) swap(i, j);\n parent[i] = j;\n size[j] += size[i];\n return true;\n }\n int redundant = 0;\n foreach(i; 0 .. d)\n {\n auto x = readInt!int - 1;\n auto y = readInt!int - 1;\n auto newE = unite(x, y);\n redundant += int(!newE);\n int[] sizes;\n foreach(j; 0 .. n)\n\t{\n\t if (parent[j] == j)\n\t sizes ~= size[j];\n\t}\n sort(sizes);\n int ans = 0;\n foreach(k; 0 .. redundant + 1)\n\t{\n\t ans += sizes[$ - 1 - k];\n\t}\n (ans-1).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"}], "negative_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 int n, d;\n readf(\" %d %d \", &n, &d);\n\n auto largest = redBlackTree!(\"a > b\", true, int)();\n auto remaining = redBlackTree!(\"a > b\", true, int)();\n\n Dsu uf;\n uf = Dsu(n);\n\n long ans;\n long saved;\n long req = 0;\n while (d--) {\n req++;\n int u, v;\n readf(\" %d %d \", &u, &v);\n u--;\n v--;\n if (!uf.same(u, v)) {\n if (largest.removeKey(uf.size(u)) == 0)\n remaining.removeKey(uf.size(u));\n else\n ans -= uf.size(u);\n if (largest.removeKey(uf.size(v)) == 0)\n remaining.removeKey(uf.size(v));\n else\n ans -= uf.size(v);\n uf.merge(u, v);\n remaining.insert(uf.size(v));\n } else {\n saved++;\n }\n while (largest.length < saved + 1 && remaining.length > 0) {\n auto tmp = remaining.front;\n remaining.removeFront;\n largest.insert(tmp);\n ans += tmp;\n }\n writeln(min(req, ans + (saved + 1 - largest.length) - 1));\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"}, {"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 n, d;\n readf(\" %d %d \", &n, &d);\n\n auto largest = redBlackTree!(\"a > b\", true, int)();\n auto remaining = redBlackTree!(\"a > b\", true, int)();\n\n Dsu uf;\n uf = Dsu(n);\n\n long ans;\n long saved;\n while (d--) {\n int u, v;\n readf(\" %d %d \", &u, &v);\n u--;\n v--;\n if (!uf.same(u, v)) {\n if (largest.removeKey(uf.size(u)) == 0)\n remaining.removeKey(uf.size(u));\n else\n ans -= uf.size(u);\n if (largest.removeKey(uf.size(v)) == 0)\n remaining.removeKey(uf.size(v));\n else\n ans -= uf.size(v);\n uf.merge(u, v);\n remaining.insert(uf.size(v));\n } else {\n saved++;\n }\n while (largest.length < saved + 1 && remaining.length > 0) {\n auto tmp = remaining.front;\n remaining.removeFront;\n largest.insert(tmp);\n ans += tmp;\n }\n writeln(min(n - 1, ans + (saved + 1 - largest.length) - 1));\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"}, {"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\nstruct edge { int u, v; };\n\nvoid main()\n{\n int n, d;\n readf(\" %d %d \", &n, &d);\n\n auto largest = redBlackTree!(\"a > b\", true, int)();\n auto remaining = redBlackTree!(\"a > b\", true, int)();\n\n int[][] adj = new int[][](n, 0);\n Dsu uf;\n uf = Dsu(n);\n\n long ans;\n long saved;\n while (d--) {\n int u, v;\n readf(\" %d %d \", &u, &v);\n u--;\n v--;\n if (!uf.same(u, v)) {\n if (largest.removeKey(uf.size(u)) == 0)\n remaining.removeKey(uf.size(u));\n else\n ans -= uf.size(u);\n if (largest.removeKey(uf.size(v)) == 0)\n remaining.removeKey(uf.size(v));\n else\n ans -= uf.size(v);\n uf.merge(u, v);\n adj[u] ~= v;\n adj[v] ~= u;\n remaining.insert(uf.size(v));\n } else {\n saved++;\n }\n while (largest.length < saved + 1 && remaining.length > 0) {\n auto tmp = remaining.front;\n remaining.removeFront;\n largest.insert(tmp);\n ans += tmp;\n }\n writeln(ans - 1 + saved - (largest.length - 1));\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"}], "src_uid": "29bc7a22baa3dc6bb508b00048e50114"} {"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 [] a, int n)\r\n{\r\n\tif (a[1..$ - 1].all !(q{a == 0}))\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\tif (a[1..$ - 1].all !(q{a <= 1}))\r\n\t{\r\n\t\treturn -1;\r\n\t}\r\n\tif (n == 3 && a[1] % 2 == 1)\r\n\t{\r\n\t\treturn -1;\r\n\t}\r\n\tlong res = 0;\r\n\tforeach (i; 1..n - 1)\r\n\t{\r\n\t\tres += a[i] / 2 + (a[i] & 1);\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\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.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\tbool ok;\r\n\t\tforeach (i; 1..n-1)\r\n\t\t{\r\n\t\t\tif (a[i] >= 2)\r\n\t\t\t\tok = true;\r\n\t\t}\r\n\t\tif (n == 3 && a[1] % 2)\r\n\t\t\tok = false;\r\n\t\tif (!ok)\r\n\t\t\tans[ti] = -1;\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (i; 1..n-1)\r\n\t\t\t\tans[ti] += (a[i]+1) / 2;\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": "// cheese-cracker [2022-02-12]\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n long summ = 0;\n bool f = 0;\n for(int i = 1; i < n-1; ++i){\n if(arr[i] >= 2){\n f = 1;\n }\n summ += arr[i]/2 + (arr[i] % 2 != 0);\n }\n if(f && !(n == 3 && arr[1] % 2 != 0) ){\n writeln(summ);\n }else{\n writeln(-1);\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"}, {"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 bool good;\n if (N == 3) {\n good = (A[1] % 2 == 0);\n } else {\n foreach (i; 1 .. N - 1) {\n good = good || (A[i] >= 2);\n }\n }\n \n long ans;\n if (good) {\n foreach (i; 1 .. N - 1) {\n ans += (A[i] + 1) / 2;\n }\n } else {\n ans = -1;\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "// cheese-cracker [2022-02-12]\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n long summ = 0;\n bool f = 0;\n for(int i = 1; i < n-1; ++i){\n if(arr[i] >= 2){\n f = 1;\n }\n summ += arr[i];\n }\n if(f && !(n == 3 && arr[1] % 2 != 0) ){\n writeln(summ/2 + (summ % 2 != 0));\n }else{\n writeln(-1);\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"}, {"source_code": "// cheese-cracker [2022-02-12]\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n long summ = 0;\n bool f = 0;\n for(int i = 1; i < n-1; ++i){\n if(arr[i] % 2 == 0){\n f = 1;\n }\n summ += arr[i];\n }\n if(f){\n writeln(summ/2 + (summ % 2 != 0));\n }else{\n writeln(-1);\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"}, {"source_code": "// cheese-cracker [2022-02-12]\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n long[] opp, ops;\n long oper = 0;\n opp ~= 0;\n for(int i = 1; i < n-1; ++i){\n opp ~= oper;\n oper += arr[i] / 2;\n }\n ops ~= 0;\n oper = 0;\n for(int i = n-2; i > 0; --i){\n ops ~= oper;\n oper += arr[i] / 2;\n }\n ops ~= 0;\n ops.reverse;\n show(ops, opp);\n long ocnt = 0;\n for(int i = 1; i < n-1; ++i){\n ocnt = (arr[i] % 2 != 0);\n if(opp[i] + ops[i] >= ocnt){\n oper += ocnt;\n }else{\n writeln(-1);\n return;\n }\n }\n writeln(oper);\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"}, {"source_code": "// cheese-cracker [2022-02-12]\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n long[] opp, ops;\n long oper = 0;\n opp ~= 0;\n for(int i = 1; i < n-1; ++i){\n opp ~= oper;\n oper += arr[i] / 2;\n }\n ops ~= 0;\n oper = 0;\n for(int i = n-2; i > 0; --i){\n ops ~= oper;\n oper += arr[i] / 2;\n }\n long ocnt = 0;\n for(int i = 1; i < n-1; ++i){\n ocnt = (arr[i] % 2 != 0);\n if(opp[i] + ops[i] >= ocnt){\n oper += ocnt;\n }else{\n writeln(-1);\n return;\n }\n }\n writeln(oper);\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"}, {"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\tbool ok;\r\n\t\tforeach (i; 1..n-1)\r\n\t\t{\r\n\t\t\tif (a[i] % 2 == 0)\r\n\t\t\t\tok = true;\r\n\t\t}\r\n\t\tif (!ok)\r\n\t\t\tans[ti] = -1;\r\n\t\telse\r\n\t\t{\r\n\t\t\tforeach (i; 1..n-1)\r\n\t\t\t\tans[ti] += (a[i]+1) / 2;\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": "5b99775142b4a28b6b1069367602448f"} {"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;\nalias ln = long;\nln pmod(ln a, ln m)\n{\n return ((a%m+m)%m);\n}\n\nint main()\n{\n ln t; get(t);\n while(t--)\n {\n ln a, b, c, d, k; get(a, b, c, d, k);\n ln rp = (a + pmod(-a, c)) / c;\n ln rpc = (b + pmod(-b, d)) / d;\n if (rp + rpc <= k)\n\t{\n\t w(rp, \" \", rpc);\n\t}\n else\n\t{\n\t w(-1);\n\t}\n }\n return 0;\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=a && (e-j)*d>=b)\n\t\t\t{\n\t\t\t\twriteln(j,\" \", (e-j));\n\t\t\t\tflag=true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (flag==false)\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.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[2][](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 d = RD;\n\t\tauto k = RD;\n\t\tauto x = (a+c-1)/c;\n\t\tauto y = (b+d-1)/d;\n\t\tif (x+y <= k)\n\t\t\tans[i] = [x, y];\n\t\telse\n\t\t\tans[i] = [-1, -1];\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e[0] == -1)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\twriteln(e[0], \" \", e[1]);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "17cf2d6f59773925b228188b5a47b710"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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!string;\n\t\tbool start;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == '1')\n\t\t\t\tstart = true;\n\t\t\telse if (start)\n\t\t\t\t++ans[ti];\n\t\t}\n\t\tforeach_reverse (c; s)\n\t\t{\n\t\t\tif (c == '1')\n\t\t\t\tstart = false;\n\t\t\telse if (start)\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 : 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\nint solve(string s) {\n int n = cast(int) s.length;\n int i = 0;\n while (i < n && s[i] == '0') {\n i++;\n }\n if (i == n) {\n return 0;\n }\n int j = n - 1;\n while (s[j] == '0') {\n j--;\n }\n int result = 0;\n for (; j > i; j--) {\n result += s[j] == '0';\n }\n return result;\n}\n\nvoid main() {\n IO io;\n int T = io.readInt;\n while (T--) {\n writeln(solve(io.readToken));\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\tstring s = readln.chomp;\n\t\tint a = -1, b = -1;\n\t\tforeach(int i, c; s){\n\t\t\tif(c == '1'){\n\t\t\t\tif(a < 0) a = i;\n\t\t\t\tb = i;\n\t\t\t}\n\t\t}\n\t\tif(a < -1) \"0\".writeln;\n\t\telse{\n\t\t\tint ans = 0;\n\t\t\tforeach(int i, c; s){\n\t\t\t\tif(a <= i && i <= b && c == '0') ans += 1;\n\t\t\t}\n\t\t\tans.writeln;\n\t\t}\n\n\t}\n}"}], "negative_code": [], "src_uid": "5de66fbb594bb317654366fd2290c4d3"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.random;\n\nbool is_good(long x, long A, long B)\n{\n if (x < 1)\n return false;\n return x % (A * B) == 0;\n}\n\nbool is_nearly_good(long x, long A, long B)\n{\n if (x < 1)\n return false;\n return (x % (A * B) != 0) && (x % A == 0);\n}\n\nvoid main()\n{\n int t;\n readf!\" %d\"(t);\n while (t--) {\n long A, B;\n readf!\" %d %d\"(A, B);\n long x, y, z;\n bool done = false;\n foreach (c1 ; 1 .. 10) {\n if (done)\n break;\n foreach (c2 ; 1 .. 10) {\n if (done)\n break;\n x = A * (B * c1 + 1);\n y = A * (B * c2 - 1);\n z = A * B * (c1 + c2);\n if (x != y && is_good(z, A, B) && is_nearly_good(x, A, B) && is_nearly_good(y, A, B)) {\n writeln(\"YES\\n\" ~ [x, y, z].map!text.joiner(\" \").text);\n done = true;\n }\n }\n }\n if (!done)\n writeln(\"NO\");\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.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 arr = readln().chomp.splitter(\" \").map!(to!long).array;\r\n long a = arr[0];\r\n long b = arr[1];\r\n \r\n if(b == 1) \r\n {\r\n writeln(\"NO\");\r\n continue OUTER;\r\n }\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", a*b, a*b+a, a*b*2+a));\r\n }\r\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.random;\n\nbool is_good(long x, long A, long B)\n{\n if (x < 1)\n return false;\n return x % (A * B) == 0;\n}\n\nbool is_nearly_good(long x, long A, long B)\n{\n if (x < 1)\n return false;\n return (x % (A * B) != 0) && (x % A == 0);\n}\n\nvoid main()\n{\n int t;\n readf!\" %d\"(t);\n while (t--) {\n long A, B;\n readf!\" %d %d\"(A, B);\n long x, y, z;\n bool done = false;\n foreach (c1 ; 1 .. 10) {\n if (done)\n break;\n foreach (c2 ; 1 .. 10) {\n if (done)\n break;\n x = A * (B * c1 + 1);\n y = A * (B * c2 - 1);\n z = A * B * (c1 + c2);\n if (is_good(z, A, B) && is_nearly_good(x, A, B) && is_nearly_good(y, A, B)) {\n writeln(\"YES\\n\" ~ [x, y, z].map!text.joiner(\" \").text);\n done = true;\n }\n }\n }\n if (!done)\n writeln(\"NO\");\n }\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1521/problem/A\n// math\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\n if(B == 1L) {\n \"NO\".writeln;\n continue;\n }\n\n long x = A;\n long y = A*B;\n long z = A*(B + 1L);\n \"YES\".writeln;\n writefln(\"%s %s %s\", x, y, z);\n}\n}\n\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 a, b;\r\n readf!\"%d %d\\n\"(a, b);\r\n if (b == 1)\r\n writeln(\"NO\");\r\n else\r\n writefln!\"YES\\n%d %d %d\"(a, a * b, a * (b + 1));\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.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 arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int a = arr[0];\r\n int b = arr[1];\r\n int m = max(a,b);\r\n \r\n if(b == 1) \r\n {\r\n writeln(\"NO\");\r\n continue OUTER;\r\n }\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", a*b, a*b+a, a*b*2+a));\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 arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int a = arr[0];\r\n int b = arr[1];\r\n int m = max(a,b);\r\n \r\n if(b == 1) writeln(\"NO\");\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", a*b, a*b+a, a*b*2+a));\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 arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int a = arr[0];\r\n int b = arr[1];\r\n \r\n for(int i = a; i <= a*b*a; i+= a)\r\n {\r\n for(int j = a; j <= a*b*a; j+=a)\r\n {\r\n if(i == j) continue;\r\n int z = i+j;\r\n if(z % (a*b) == 0 || ((i % (a*b) == 0) != (j % (a*b) == 0)))\r\n {\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", i, j, z));\r\n continue OUTER;\r\n }\r\n }\r\n }\r\n \r\n writeln(\"NO\");\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 arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int a = arr[0];\r\n int b = arr[1];\r\n \r\n for(int i = a; i <= a*b*a; i+= a)\r\n {\r\n for(int j = a; j <= a*b*a; j+=a)\r\n {\r\n if(i == j || (i+j)%a != 0) continue;\r\n int z = i+j;\r\n if(((i % (a*b) == 0) != (j % (a*b) == 0)) != (z % (a*b) == 0))\r\n {\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", i, j, z));\r\n continue OUTER;\r\n }\r\n }\r\n }\r\n \r\n writeln(\"NO\");\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 arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int a = arr[0];\r\n int b = arr[1];\r\n \r\n for(int i = a; i <= int.max; i+= a)\r\n {\r\n for(int j = a; j <= int.max; j+=a)\r\n {\r\n if(i == j) continue;\r\n int z = i+j;\r\n if(((i % (a*b) == 0) != (j % (a*b) == 0)) != (z % (a*b) == 0))\r\n {\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", i, j, z));\r\n continue OUTER;\r\n }\r\n }\r\n }\r\n \r\n writeln(\"NO\");\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 arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int a = arr[0];\r\n int b = arr[1];\r\n \r\n for(int i = a; i <= a*b*a; i+= a)\r\n {\r\n for(int j = a; j <= a*b*a; j+=a)\r\n {\r\n if(i == j) continue;\r\n int z = i+j;\r\n if((i % (a*b) == 0) != (j % (a*b) == 0))\r\n {\r\n if(z % (a*b) == 0) continue;\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", i, j, z));\r\n continue OUTER;\r\n }\r\n else if(z % (a*b) == 0)\r\n {\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", i, j, z));\r\n continue OUTER;\r\n }\r\n }\r\n }\r\n \r\n writeln(\"NO\");\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 arr = readln().chomp.splitter(\" \").map!(to!int).array;\r\n int a = arr[0];\r\n int b = arr[1];\r\n \r\n for(int i = a; i <= a*b*a; i+= a)\r\n {\r\n for(int j = a; j <= a*b*a; j+=a)\r\n {\r\n if(i == j) continue;\r\n \r\n if(i % (a*b) == 0 || j % (a*b) == 0)\r\n {\r\n int z = i+j;\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", i, j, z));\r\n continue OUTER;\r\n }\r\n else\r\n {\r\n if((i+j) % (a*b) == 0)\r\n {\r\n writeln(\"YES\");\r\n writeln(format(\"%d %d %d\", i, j, i+j));\r\n continue OUTER;\r\n }\r\n }\r\n }\r\n }\r\n \r\n writeln(\"NO\");\r\n }\r\n}"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1521/problem/A\n// math\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\n if(B == 1L) {\n \"NO\".writeln;\n continue;\n }\n\n long x = A;\n long y = A*B;\n long z = A*(B + 1L);\n writefln(\"%s %s %s\", x, y, z);\n}\n}\n\n"}], "src_uid": "f10aa45956e930df3df0e23f2592c8f1"} {"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\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 t = readln.strip;\r\n\t\tauto lo = n.iota.filter !(i => t[i] == 'B')\r\n\t\t .map !(i => a[i]).array;\r\n\t\tauto hi = n.iota.filter !(i => t[i] == 'R')\r\n\t\t .map !(i => a[i]).array;\r\n\t\tsort !(q{a < b}) (lo);\r\n\t\tsort !(q{a > b}) (hi);\r\n\t\tauto okLo = lo.length.iota.all !((int i) => lo[i] >= i + 1);\r\n\t\tauto okHi = hi.length.iota.all !((int i) => hi[i] <= n - i);\r\n\t\twriteln (okLo && okHi ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_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 = 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 int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n if (i == n-1) readf!\"%d\\n\"(a[i]);\n else readf!\"%d \"(a[i]);\n }\n\n int[] up = new int[0];\n int[] down = new int[0];\n for (int i = 0; i < n; i++) {\n char c;\n if (i == n-1) readf!\"%c\\n\"(c);\n else readf!\"%c\"(c);\n\n if (c == 'R') up ~= [a[i]];\n else down ~= [a[i]];\n }\n\n up.sort!(\"a > b\");\n down.sort!(\"a < b\");\n\n bool possible = true;\n int upper = n;\n for (int i = 0; i < up.length; i++) {\n if (up[i] > upper) possible = false;\n upper --;\n }\n\n int lower = 1;\n for (int i = 0; i < down.length; i++) {\n if (down[i] < lower) possible = false;\n lower ++;\n }\n\n if (possible) writeln(\"YES\");\n else writeln(\"NO\");\n\n }\n}\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 = 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 int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n if (i == n-1) readf!\"%d\\n\"(a[i]);\n else readf!\"%d \"(a[i]);\n }\n\n int[] up = new int[0];\n int[] down = new int[0];\n for (int i = 0; i < n; i++) {\n char c;\n if (i == n-1) readf!\"%c\\n\"(c);\n else readf!\"%c\"(c);\n\n if (c == 'R') up ~= [a[i]];\n else down ~= [a[i]];\n }\n\n up.sort!(\"a > b\");\n down.sort!(\"a < b\");\n\n bool possible = true;\n int upper = n;\n for (int i = 0; i < up.length; i++) {\n if (up[i] > upper) possible = false;\n upper --;\n }\n\n int lower = 0;\n for (int i = 0; i < down.length; i++) {\n if (down[i] < lower) possible = false;\n lower ++;\n }\n\n if (possible) writeln(\"YES\");\n else writeln(\"NO\");\n\n }\n}\n"}], "src_uid": "c3df88e22a17492d4eb0f3239a27d404"} {"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 a = RD;\n\t\tauto b = RD;\n\t\tauto n = RD;\n\t\tlong x, y;\n\t\tif (n == 0)\n\t\t{\n\t\t\tx = a;\n\t\t}\n\t\telse if ((n-1) % 3 != 0)\n\t\t{\n\t\t\tx = a;\n\t\t}\n\t\tif (n % 3 != 0)\n\t\t{\n\t\t\ty = b;\n\t\t}\n\t\tans[i] = x^y;\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; }\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tint t = read.to!int;\n\tforeach(_; 0 .. t){\n\t\tlong a = read.to!long;\n\t\tlong b = read.to!long;\n\t\tlong n = read.to!long;\n\t\t\n\t\tif(n % 3 == 0) a.writeln;\n\t\tif(n % 3 == 1) b.writeln;\n\t\tif(n % 3 == 2) (a ^b).writeln;\n\t}\n\t\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 numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const A = readLong();\n const B = readLong();\n const N = readLong();\n long ans;\n switch (N % 3) {\n case 0: ans = A; break;\n case 1: ans = B; break;\n case 2: ans = A ^ B; break;\n default: assert(false);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "64a375c7c49591c676dbdb039c93d218"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main()\n{\n\tint n;\n\treadf(\"%d\", &n);\n\t\n\tint[] res = new int[2 * n];\n\tfill(res, n);\n\tfor (int i = 1, j = 0, k = n - 1; i < n; i += 2, j++, k--)\n\t\tres[j] = res[k] = i;\n\tfor (int i = 2, j = n, k = 2 * n - 2; i < n; i += 2, j++, k--)\n\t\tres[j] = res[k] = i;\n\n\twritefln(\"%(%d %)\", res);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main()\n{\n\tint n;\n\treadf(\"%d\", &n);\n\t\n\tint[] res = new int[2 * n];\n\tfill(res, n);\n\tfor (int i = 1, j = 0, k = n - 1; i < n; i += 2, j++, k--)\n\t\tres[j] = res[k] = i;\n\tfor (int i = 2, j = n, k = 2 * n - 2; i < n; i += 2, j++, k--)\n\t\tres[j] = res[k] = i;\n\n\tfor (int i = 0; i < res.length; i++)\n\t\tprintf(\"%d%c\", res[i], i == res.length - 1 ? '\\n' : ' ');\n}\n"}], "negative_code": [], "src_uid": "c234cb0321e2bd235cd539a63364b152"} {"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.chomp;\n auto T = readln.chomp;\n\n long hatena = 0;\n foreach (s; S) if (s == '?') hatena += 1;\n auto cnt2 = new long[](26);\n foreach (s; S) if (s != '?') cnt2[s - 'a'] += 1;\n\n auto cnt = new long[](26);\n foreach (t; T) cnt[t - 'a'] += 1;\n\n long hi = 10^^7;\n long lo = 0;\n auto hoge = new long[](26);\n long h;\n\n while (hi - lo > 1) {\n long mid = (hi + lo) / 2;\n foreach (i; 0..26) hoge[i] = cnt[i] * mid - cnt2[i];\n h = hatena;\n foreach (i; 0..26) h -= max(0, hoge[i]);\n if (h >= 0) lo = mid;\n else hi = mid;\n }\n\n foreach (i; 0..26) cnt[i] = cnt[i] * lo - cnt2[i];\n int p = 0;\n while (p < 26 && cnt[p] <= 0) p += 1;\n auto ans = new char[](S.length);\n\n foreach (i; 0..S.length) {\n if (S[i] == '?' && p < 26) {\n ans[i] = (p.to!char + 'a').to!char;\n cnt[p] -= 1;\n while (p < 26 && cnt[p] <= 0) p += 1;\n } else if (S[i] == '?' && p >= 26){\n ans[i] = 'z';\n } else {\n ans[i] = S[i];\n }\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\n\nvoid main(){\n\tauto s=readln.strip, t=readln.strip;\n\tint w=0;\n\tint[26] f,g;\n\tforeach(c;s) ++('a'<=c&&c<='z'?f[c-'a']:w);\n\tforeach(c;t) ++g[c-'a'];\n\tauto ns=s.dup;\n\tint i=0;\n\twhile(f[].all!(c=>c>=0)){\n\t\tf[]-=g[];\n\t\tforeach(k,ref c;f){\n\t\t\tif(c>=0) continue;\n\t\t\tint d=min(-c,w);\n\t\t\tc+=d,w-=d;\n\t\t\tforeach(j;0..d){\n\t\t\t\twhile(ns[i]!='?') i++;\n\t\t\t\tns[i]=cast(char)('a'+k);\n\t\t\t}\n\t\t}\n\t}\n\twriteln(ns.to!string);\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.chomp;\n auto T = readln.chomp;\n\n long hatena = 0;\n foreach (s; S) if (s == '?') hatena += 1;\n auto cnt2 = new long[](26);\n foreach (s; S) if (s != '?') cnt2[s - 'a'] += 1;\n\n auto cnt = new long[](26);\n foreach (t; T) cnt[t - 'a'] += 1;\n\n int hi = 10^^7;\n int lo = 0;\n auto hoge = new long[](26);\n long h;\n\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n foreach (i; 0..26) hoge[i] = cnt[i] * mid - cnt2[i];\n h = hatena;\n foreach (i; 0..26) h -= max(0, hoge[i]);\n if (h >= 0) lo = mid;\n else hi = mid;\n }\n\n foreach (i; 0..26) cnt[i] = cnt[i] * lo - cnt2[i];\n int p = 0;\n while (p < 26 && cnt[p] <= 0) p += 1;\n auto ans = new char[](S.length);\n\n foreach (i; 0..S.length) {\n if (S[i] == '?' && p < 26) {\n ans[i] = (p.to!char + 'a').to!char;\n cnt[i] -= 1;\n while (p < 26 && cnt[p] <= 0) p += 1;\n } else if (S[i] == '?' && p >= 26){\n ans[i] = 'z';\n } else {\n ans[i] = S[i];\n }\n }\n\n ans.writeln;\n}\n"}], "src_uid": "fb96c841b1973a04becf7a5d1392eab3"} {"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;\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) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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---------------------------------------\nauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\tif(is(typeof(exp&1)))\n{\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*=base;\n\t\tif(res>=mm)res%=mm;\n\t\tbase*=base;\n\t\tif(base>=mm)base%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\nlong base=131;\nlong rb=binpow(131L,mod-2,mod);\nvoid main()\n{\n\t/*int n;\n\tloop:while(read(&n))\n\t{\n\n\t}*/\n\tdebug writeln(cast(int)('C'));\n\tauto s=readln.strip;\n\tauto h1=new int[s.length];\n\tauto st=new int[s.length];\n\tauto h2=h1.dup;\n\tlong p=base;\n\th1[0]=s[0];\n\tforeach(i;1..s.length)\n\t{\n\t\th1[i]=(h1[i-1]+s[i]*p)%mod;\n\t\tp=(p*base)%mod;\n\t}\n\tp=base;\n\th2[$-1]=s[$-1];\n\tforeach_reverse(i;0..s.length-1)\n\t{\n\t\th2[i]=(h2[i+1]+s[i]*p)%mod;\n\t\tp=(p*base)%mod;\n\t}\n\tst[0]=1;\n\tforeach(i;1..st.length)\n\t{\n\t\tst[i]=(st[i-1]*rb)%mod;\n\t}\n\tdebug writeln(st);\n\tlong hsub(int r)\n\t{\n\t\tlong ans=h2[0];\n\t\tif(r!=s.length-1)ans-=h2[r+1];\n\t\tif(ans<0)ans+=mod;\n\t\tans*=st[s.length-1-r];\n\t\tif(ans>=mod)ans%=mod;\n\t\treturn ans;\n\t}\n\tauto ans=new int[s.length];\n\tdebug writeln(h1,'\\n',h2);\n\tdebug writeln(hsub(0)==h1[0]);\n\tforeach(i;0..s.length)\n\t{\n\t\tif(hsub(i)==h1[i])\n\t\t{\n\t\t\tif(i==0)ans[i]=1;\n\t\t\telse ans[i]=ans[(i-1)/2]+1;\n\t\t}\n\t\telse ans[i]=0;\n\t}\n\tdebug writeln(ans);\n\twriteln(ans.sum);\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;\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) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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---------------------------------------\nauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\tif(is(typeof(exp&1)))\n{\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*=base;\n\t\tif(res>=mm)res%=mm;\n\t\tbase*=base;\n\t\tif(base>=mm)base%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\nlong base=151;\nlong rb=binpow(151L,mod-2,mod);\nchar[] s;\nvoid main()\n{\n\t/*int n;\n\tloop:while(read(&n))\n\t{\n\n\t}*/\n\ts.length=5000000;\n\tdebug writeln(cast(int)('C'));\n\treadln(s);\n\ts=s[0..$-1];\n\tauto h1=new int[s.length];\n\tauto st=new int[s.length];\n\tauto h2=h1.dup;\n\tlong p=base;\n\th1[0]=s[0];\n\tforeach(i;1..s.length)\n\t{\n\t\th1[i]=(h1[i-1]+s[i]*p)%mod;\n\t\tp=(p*base)%mod;\n\t}\n\tp=base;\n\th2[$-1]=s[$-1];\n\tforeach_reverse(i;0..s.length-1)\n\t{\n\t\th2[i]=(h2[i+1]+s[i]*p)%mod;\n\t\tp=(p*base)%mod;\n\t}\n\tst[0]=1;\n\tforeach(i;1..st.length)\n\t{\n\t\tst[i]=(st[i-1]*rb)%mod;\n\t}\n\tdebug writeln(st);\n\tlong hsub(int r)\n\t{\n\t\tlong ans=h2[0];\n\t\tif(r!=s.length-1)ans-=h2[r+1];\n\t\tif(ans<0)ans+=mod;\n\t\tans*=st[s.length-1-r];\n\t\tif(ans>=mod)ans%=mod;\n\t\treturn ans;\n\t}\n\tauto ans=new int[s.length];\n\tdebug writeln(h1,'\\n',h2);\n\tdebug writeln(hsub(0)==h1[0]);\n\tforeach(i;0..s.length)\n\t{\n\t\tif(hsub(i)==h1[i])\n\t\t{\n\t\t\tif(i==0)ans[i]=1;\n\t\t\telse ans[i]=ans[(i-1)/2]+1;\n\t\t}\n\t\telse ans[i]=0;\n\t}\n\tdebug writeln(ans);\n\twriteln(ans.sum);\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 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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\nauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\tif(is(typeof(exp&1)))\n{\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=mulmod(res,base,mm);\n\t\tbase=mulmod(base,base,mm);\n\t\t//base%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\nlong mulmod(long a,long b,in long m=hashmod)\n{\n\tlong res;\n\twhile(b)\n\t{\n\t\tif(b&1)\n\t\t{\n\t\t\tres+=a;\n\t\t\tif(res>=m)res-=m;\n\t\t}\n\t\ta<<=1;\n\t\tb>>=1;\n\t\tif(a>=m)a-=m;\n\t}\n\treturn res;\n}\nlong base=997;\nlong rb=binpow(997L,hashmod-2,hashmod);\n\nvoid main()\n{\n\t/*int n;\n\tloop:while(read(&n))\n\t{\n\n\t}*/\n\tauto s=readln.strip;\n\tauto h1=new long[s.length];\n\tauto st=new long[s.length];\n\tauto h2=h1.dup;\n\tlong p=base;\n\th1[0]=s[0];\n\tforeach(i;1..s.length)\n\t{\n\t\th1[i]=(h1[i-1]+mulmod(s[i],p,hashmod))%hashmod;\n\t\tp=mulmod(p,base,hashmod);\n\t}\n\tp=base;\n\th2[$-1]=s[$-1];\n\tforeach_reverse(i;0..s.length-1)\n\t{\n\t\th2[i]=(h2[i+1]+mulmod(s[i],p,hashmod))%hashmod;\n\t\tp=mulmod(p,base,hashmod);\n\t}\n\tst[0]=1;\n\tforeach(i;1..st.length)\n\t{\n\t\tst[i]=mulmod(st[i-1],rb);\n\t}\n\tlong hsub(int r)\n\t{\n\t\tlong ans=h2[0];\n\t\tif(r!=s.length-1)ans-=h2[r+1];\n\t\tans=mulmod(ans,st[s.length-1-r]);\n\t\tans=(ans+hashmod)%hashmod;\n\t\treturn ans;\n\t}\n\tauto ans=new long[s.length];\n\tforeach(i;0..s.length)\n\t{\n\t\tif(hsub(i)==h1[i])\n\t\t{\n\t\t\tif(i==0)ans[i]=1;\n\t\t\telse ans[i]=ans[(i-1)/2]+1;\n\t\t}\n\t\telse ans[i]=0;\n\t}\n\twriteln(ans.sum);\n}"}], "src_uid": "0090979443c294ef6aed7cd09201c9ef"} {"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto mat = ma(n, readString);\n\tauto unknowable = new bool[][](n, m);\n\tbool isKnowable(int i, int j)\n\t{\n\t\tif (mat[i][j] == '.') return true;\n\t\tif (i == 0 || mat[i-1][j] == '.') return true;\n\t\tif (j == 0 || mat[i][j-1] == '.') return true;\n\t\treturn false;\n\t}\n\tforeach(i; 0 .. n)\n\t\tforeach(j; 0 .. m)\n\t\t{\n\t\t\tunknowable[i][j] = !isKnowable(i, j);\n\t\t}\n\tauto hasUnknowable = new bool[](m);\n\tforeach(j; 0 .. m)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\thasUnknowable[j] = hasUnknowable[j] || unknowable[i][j];\n\t}\n\tauto compatible = new bool[](m);\n\tcompatible[m-1] = true;\n\tforeach(j; 0 .. m-1)\n\t{\n\t\tauto exitable = new bool[](n);\n\t\tcompatible[j] = true;\n\t\texitable[0] = mat[0][j+1] == '.';\n\t\tforeach(i; 1 .. n)\n\t\t{\n\t\t\tif (mat[i][j+1] == '.')\n\t\t\t{\n\t\t\t\texitable[i] = exitable[i-1] || mat[i][j] == '.';\n\t\t\t\tif (!exitable[i]) compatible[j] = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\texitable[i] = false;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"for \", j);\n\t\tdebug writeln(exitable);\n\t}\n\tauto pair = new int[](m);\n\tint j = m - 1;\n\tpair[m-1] = m-1;\n\tforeach_reverse(i; 0 .. m-1)\n\t{\n\t\tif (compatible[i] && !hasUnknowable[i+1])\n\t\t{\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"not compatible\");\n\t\t\tj = i;\n\t\t}\n\t\tpair[i] = j;\n\t}\n\tdebug writeln(compatible);\n\tdebug writeln(hasUnknowable);\n\tdebug writeln(pair);\n\tint q = readInt!int;\n\tforeach(i; 0 .. q)\n\t{\n\t\tint x = readInt!int-1;\n\t\tint y = readInt!int-1;\n\t\tif (y <= pair[x]) writeln(\"Yes\");\n\t\telse writeln(\"No\");\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\nvoid main()\r\n{\r\n int n, m;\r\n readf!\"%s %s\"(n, m);\r\n readln;\r\n \r\n string[] arr;\r\n foreach (i; 0 .. n) {\r\n arr ~= readln.chomp;\r\n }\r\n \r\n int[] cols;\r\n outer: foreach (j; 0 .. m-1) {\r\n foreach (i; 1 .. n) {\r\n if (arr[i][j] == 'X' && arr[i-1][j+1] == 'X') { \r\n cols ~= j+1; \r\n continue outer;\r\n }\r\n }\r\n }\r\n \r\n auto sorted = assumeSorted(cols);\r\n \r\n debug { sorted.writeln; }\r\n \r\n int q;\r\n readf!\"%s\"(q);\r\n readln;\r\n while (q--) {\r\n int x1, x2;\r\n readf!\"%s %s\"(x1, x2);\r\n readln;\r\n \r\n auto bigger = sorted.upperBound(x1-1);\r\n auto ambiguous = x1 < x2 && bigger.any() && bigger.front < x2;\r\n \r\n debug { writeln(bigger, ' ', x1, ' ', x2); }\r\n \r\n writeln(ambiguous ? \"NO\" : \"YES\");\r\n }\r\n}"}], "negative_code": [{"source_code": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto mat = ma(n, readString);\n\tauto unknowable = new bool[][](n, m);\n\tbool isKnowable(int i, int j)\n\t{\n\t\tif (mat[i][j] == '.') return true;\n\t\tif (i == 0 || mat[i-1][j] == '.') return true;\n\t\tif (j == 0 || mat[i][j-1] == '.') return true;\n\t\treturn false;\n\t}\n\tforeach(i; 0 .. n)\n\t\tforeach(j; 0 .. m)\n\t\t{\n\t\t\tunknowable[i][j] = !isKnowable(i, j);\n\t\t}\n\tauto hasUnknowable = new bool[](m);\n\tforeach(j; 0 .. m)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\thasUnknowable[j] = hasUnknowable[j] || unknowable[i][j];\n\t}\n\tauto compatible = new bool[](m);\n\tcompatible[m-1] = true;\n\tforeach(j; 0 .. m-1)\n\t{\n\t\tauto exitable = new bool[](n);\n\t\tcompatible[j] = true;\n\t\texitable[0] = mat[0][j+1] == '.';\n\t\tforeach(i; 1 .. n)\n\t\t{\n\t\t\tif (mat[i][j+1] == '.')\n\t\t\t{\n\t\t\t\texitable[i] = exitable[i-1] || mat[i][j] == '.';\n\t\t\t\tif (!exitable[i]) compatible[j] = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\texitable[i] = false;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"for \", j);\n\t\tdebug writeln(exitable);\n\t}\n\tauto pair = new int[](m);\n\tint j = m - 1;\n\tforeach_reverse(i; 0 .. m)\n\t{\n\t\tif (compatible[i])\n\t\t{\n//\t\t\twhile (j > i && hasUnknowable[j]) j--;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"not compatible\");\n\t\t\tj = i;\n\t\t}\n\t\tpair[i] = j;\n\t}\n\tdebug writeln(compatible);\n\tdebug writeln(hasUnknowable);\n\tdebug writeln(pair);\n\tint q = readInt!int;\n\tforeach(i; 0 .. q)\n\t{\n\t\tint x = readInt!int-1;\n\t\tint y = readInt!int-1;\n\t\tif (y <= pair[x]) writeln(\"Yes\");\n\t\telse writeln(\"No\");\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": "immutable multi = false;\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto mat = ma(n, readString);\n\tauto unknowable = new bool[][](n, m);\n\tbool isKnowable(int i, int j)\n\t{\n\t\tif (mat[i][j] == '.') return true;\n\t\tif (i == 0 || mat[i-1][j] == '.') return true;\n\t\tif (j == 0 || mat[i][j-1] == '.') return true;\n\t\treturn false;\n\t}\n\tforeach(i; 0 .. n)\n\t\tforeach(j; 0 .. m)\n\t\t{\n\t\t\tunknowable[i][j] = !isKnowable(i, j);\n\t\t}\n\tauto hasUnknowable = new bool[](m);\n\tforeach(j; 0 .. m)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t\thasUnknowable[j] = hasUnknowable[j] || unknowable[i][j];\n\t}\n\tauto compatible = new bool[](m);\n\tcompatible[m-1] = true;\n\tforeach(j; 0 .. m-1)\n\t{\n\t\tauto exitable = new bool[](n);\n\t\tcompatible[j] = true;\n\t\texitable[0] = mat[0][j+1] == '.';\n\t\tforeach(i; 1 .. n)\n\t\t{\n\t\t\tif (mat[i][j+1] == '.')\n\t\t\t{\n\t\t\t\texitable[i] = exitable[i-1] || mat[i][j] == '.';\n\t\t\t\tif (!exitable[i]) compatible[j] = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\texitable[i] = false;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"for \", j);\n\t\tdebug writeln(exitable);\n\t}\n\tauto pair = new int[](m);\n\tint j = m - 1;\n\tforeach_reverse(i; 0 .. m)\n\t{\n\t\tif (compatible[i])\n\t\t{\n\t\t\twhile (j > i && hasUnknowable[j]) j--;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tdebug writeln(\"not compatible\");\n\t\t\tj = i;\n\t\t}\n\t\tpair[i] = j;\n\t}\n\tdebug writeln(compatible);\n\tdebug writeln(hasUnknowable);\n\tdebug writeln(pair);\n\tint q = readInt!int;\n\tforeach(i; 0 .. q)\n\t{\n\t\tint x = readInt!int-1;\n\t\tint y = readInt!int-1;\n\t\tif (y <= pair[x]) writeln(\"Yes\");\n\t\telse writeln(\"No\");\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"}], "src_uid": "03004aeeccc23ada1788c7d4d706ed10"} {"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 n = io.readInt;\n int g = io.readInt;\n int b = io.readInt;\n int req = n + 1 >> 1;\n int k = (req - 1) / g;\n writeln(max(cast(long) k * (g + b) + (req - k * g), n));\n }\n}\n", "positive_code": [{"source_code": "/// https://codeforces.com/problemset/problem/1303/B\n/// PS> dmd cf.d; if($?) {cat in.txt | .\\cf.exe}\nimport std.stdio : stdin, writeln;\nimport std.algorithm : max;\n\nlong ceilDiv(long a, long b) {\n return a/b + (a%b > 0);\n}\n\nvoid main()\n{\n int t, n, g, b;\n long k, m;\n stdin.readf!\"%d\\n\"(t);\n while (t--) {\n stdin.readf!\"%d %d %d\\n\"(n, g, b);\n k = (n+1)/2;\n m = ceilDiv(k, g);\n writeln((m-1)*b + k + max(n - k - b*(m-1), 0));\n }\n}"}, {"source_code": "/// https://codeforces.com/problemset/problem/1303/B\n/// PS> dmd cf.d; if($?) {cat in.txt | .\\cf.exe}\nimport std.stdio : stdin, writeln;\nimport std.algorithm : max;\n\nvoid main()\n{\n int t, n, g, b;\n long k, m;\n stdin.readf!\"%d\\n\"(t);\n while (t--) {\n stdin.readf!\"%d %d %d\\n\"(n, g, b);\n k = (n + 1) >> 1;\n m = (k/g + (k%g > 0) - 1)*b + k;\n writeln(max(n, m));\n }\n}"}, {"source_code": "/// https://codeforces.com/problemset/problem/1303/B\n/// PS> dmd cf.d; if($?) {cat in.txt | .\\cf.exe}\nimport std.stdio : stdin, writeln;\nimport std.algorithm : max;\n\nvoid main()\n{\n int t, n, g, b;\n long k, m;\n stdin.readf!\"%d\\n\"(t);\n while (t--) {\n stdin.readf!\"%d %d %d\\n\"(n, g, b);\n k = (n + 1) >> 1;\n m = (k/g + (k%g > 0) - 1)*b + k;\n writeln(m + max(n - m, 0));\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\tlong n = rlong, g = rlong, b = rlong;\n\n\t\tlong n1 = (n + 1) / 2; // minimum good pavement\n\t\tlong n2 = n - n1; // maximum bad pavement\n\t\t\n\t\tlong ans;\n\t\tlong x = n2 / b;\n\t\tif((x + 1) * g >= n1){\n\t\t\tans = n;\n\t\t}\n\t\telse{\n\t\t\tlong n3 = n1 - (x + 1) * g;\n\t\t\tif(n3 % g == 0) ans = x * (g + b) + g + (n3 / g) * (g + b);\n\t\t\telse ans = x * (g + b) + g + (n3 / g) * (g + b) + b + (n3 % g);\n\t\t}\n\t\t\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; }\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 g = RD!int;\n\t\tauto b = RD!int;\n\n\t\tlong need = (n+1) / 2;\n\t\tlong cnt = need / g * (g+b) - b;\n\t\tlong r = need % g;\n\t\tif (r != 0)\n\t\t\tcnt += b + r;\n\t\tans[ti] = max(n, cnt);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "be9138aca8e1b8a5d722f99fcd70b685"} {"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 G = new int[][](N);\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 auto ans = new int[](N);\n int p = 0;\n\n auto used = new bool[](N);\n auto pq = new BinaryHeap!(Array!int, \"a > b\");\n pq.insert(0);\n\n while (!pq.empty) {\n auto n = pq.front;\n pq.popFront;\n if (used[n]) continue;\n used[n] = true;\n ans[p++] = n + 1;\n foreach (m; G[n]) {\n if (used[m]) continue;\n pq.insert(m);\n }\n }\n\n ans.map!(to!string).join(\" \").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, m;\n scan(n, m);\n\n auto adj = new int[][](n, 0);\n foreach (i ; 0 .. m) {\n int u, v;\n scan(u, v);\n u--, v--;\n adj[u] ~= v;\n adj[v] ~= u;\n }\n\n auto bh = new BinaryHeap!(Array!int, \"a > b\")();\n bh.insert(0);\n\n auto visited = new bool[](n);\n visited[0] = true;\n auto ans = new int[](n);\n\n foreach (i ; 0 .. n) {\n auto v = bh.front; bh.popFront();\n ans[i] = v + 1;\n\n foreach (u ; adj[v]) {\n if (visited[u]) continue;\n visited[u] = true;\n bh.insert(u);\n }\n }\n\n writefln(\"%(%s %)\", 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": "157630371c4f6c3bcc6355d96c86a626"} {"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;\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;\nT lcm (T)(T a,T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow X binpow(X,Y)(X base,Y exp)\n\tif(!isFloatingPoint!Y && !is(typeof(exp.im)))\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)\n\tif(!isFloatingPoint!Y && !is(typeof(exp.im)))\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);}\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}\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\tint opCmp(ref const pair!(X,Y) s_) const pure nothrow\n\t{\n\t\tint cmp=0-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in 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)(in X a_) pure nothrow @property @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @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,in X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]m1.fi)\n\t\t\t\t{\n\t\t\t\t\tm2=m1;\n\t\t\t\t\tm1=mp(d[i],i*1L);\n\t\t\t\t}\n\t\t\t\telse if(d[i]>m2.fi)\n\t\t\t\t{\n\t\t\t\t\tm2=mp(d[i],i*1L);\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach(i;g[v])\n\t\t\t{\n\t\t\t\tif(i==pr)continue;\n\t\t\t\tlong cur= (m1.se==i?m2.fi:m1.fi);\n\t\t\t\tdfs2(i,v,max(h,cur));\n\t\t\t}\n\n\t\t}\n\t\tdfs2(1,1,long.min);\n\t\tif(ans==long.min)writeln(\"Impossible\");\n\t\telse writeln(ans);\n\t}\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\nlong result;\n\nstruct Node {\n int niceness;\n Node*[ ] children;\n\n Tuple!(long, long) recurse(const(Node)* prev) const {\n long max1 = long.min, max2 = long.min;\n long sum = niceness, curmax = long.min;\n foreach (node; children)\n if (node !is prev) {\n long nextSum, nextMax;\n AliasSeq!(nextSum, nextMax) = node.recurse(&this);\n sum += nextSum;\n curmax = max(curmax, nextMax);\n if (nextMax > max1) {\n max2 = max1;\n max1 = nextMax;\n } else if (nextMax > max2)\n max2 = nextMax;\n }\n if (max2 != long.min)\n result = max(result, max1 + max2);\n return tuple(sum, max(sum, curmax));\n }\n}\n\nNode[200_000] _nodes;\n\nvoid main() {\n int n;\n while (read(&n)) {\n auto nodes = _nodes[0 .. n];\n foreach (ref node; nodes) {\n read(&node.niceness);\n node.children = null;\n }\n foreach (i; 1 .. n) {\n int a, b;\n read(&a, &b);\n a--;\n b--;\n nodes[a].children ~= &nodes[b];\n nodes[b].children ~= &nodes[a];\n }\n result = long.min;\n nodes[0].recurse(null);\n if (result != long.min)\n writeln(result);\n else\n writeln(\"Impossible\");\n }\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;\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;\nT lcm (T)(T a,T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow X binpow(X,Y)(X base,Y exp)\n\tif(!isFloatingPoint!Y && !is(typeof(exp.im)))\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)\n\tif(!isFloatingPoint!Y && !is(typeof(exp.im)))\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);}\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}\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\tint opCmp(ref const pair!(X,Y) s_) const pure nothrow\n\t{\n\t\tint cmp=0-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in 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)(in X a_) pure nothrow @property @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @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,in X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m] max(b.length,a))(g,0);\n\t\tif((f==2 && g[1].length<2) || n==1){writeln(\"Impossible\");continue;}\n\t\tlong[] s,d;\n\t\ts.length=d.length=n+1;\n\t\tfill(d,long.min);\n\t\tdebug\n\t\t{\n\t\t\tforeach(i;g)\n\t\t\t{\n\t\t\t\tforeach(j;i)write(j,' ');\n\t\t\t\twriteln;\n\t\t\t}\n\t\t}\n\t\tvoid dfs1(int v,int pr)\n\t\t{\n\t\t\ts[v]+=a[v-1];\n\t\t\tforeach(i;g[v])\n\t\t\t{\n\t\t\t\tif(i!=pr)\n\t\t\t\t{\n\t\t\t\t\tdfs1(i,v);\n\t\t\t\t\td[v]=max(d[v],d[i]);\n\t\t\t\t\ts[v]+=s[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\td[v]=max(d[v],s[v]);\n\t\t}\n\n\t\tdfs1(1,1);\n\t\tdebug putarr(d);\n\t\tdebug writeln;\n\t\tlong ans=long.min;\n\t\tlong dfs2(int v,int pr)\n\t\t{\n\t\t\tuint ans1,ans2;\n\t\t\tforeach(i;g[v])\n\t\t\t{\n\t\t\t\tif(i==pr)continue;\n\t\t\t\tif(d[i]>d[ans1]){ans2=ans1;ans1=i;}\n\t\t\t\telse if(d[i]>d[ans2])ans2=i;\n\t\t\t}\n\t\t\tdebug writeln(d[ans1]);\n\t\t\tforeach(i;g[v])\n\t\t\t{\n\t\t\t\tif(i==pr )continue;\n\t\t\t\tif(i!=ans1)ans=max(ans,dfs2(i,v)+d[ans1]);\n\t\t\t\telse ans=max(ans,dfs2(i,v)+d[ans2]);\n\t\t\t}\n\t\t\treturn d[ans1];\n\t\t}\n\t\tdfs2(1,1);\n\t\twriteln(ans);\n\n\t}\n}"}], "src_uid": "14b65af01caf1f3971a2f671589b86a8"} {"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 auto a = readln.chomp.split.map!(to!int).array;\n \n auto ans = 0;\n \n foreach (p; a.length.iota.stride(2)) {\n auto k = a[p];\n debug { writeln(p, ' ', k, ' ', a[p+1..$]); }\n auto i = a.length - a[p+1..$].find(k).length;\n debug { i.writeln; }\n while (a[i-1] != k) {\n ++ans;\n a[i] = a[i-1];\n a[i-1] = k;\n --i;\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;\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\tlong res = 0;\n\t\tfor (int i = 0; i < 2 * n; i += 2)\n\t\t{\n\t\t\tint j = i + 1;\n\t\t\twhile (a[j] != a[i])\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\twhile (j > i + 1)\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t\tswap (a[j], a[j - 1]);\n\t\t\t\tj -= 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\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new int[2 * N];\n foreach (i; 0 .. 2 * N) {\n A[i] = readInt();\n }\n \n auto as = A.dup;\n int ans;\n for (int i = 0; i < 2 * N; i += 2) {\n foreach (j; i + 1 .. 2 * N) {\n if (as[i] == as[j]) {\n for (; i + 1 < j; --j) {\n swap(as[j], as[j - 1]);\n ++ans;\n }\n goto done;\n }\n }\n assert(false);\n done:\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "194bc63b192a4e24220b36984901fb3b"} {"source_code": "import std.stdio, std.algorithm;\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n\n auto a = new int[](n);\n\n foreach(i; 0..n) {\n readf(\" %d\", &a[i]);\n }\n\n int k = a.reduce!(max), ix;\n auto ans = new char[](k * 3 * n);\n foreach(i; 0..k) {\n foreach(j; 0..n) {\n if (a[j] > i) ans[ix++] = 'P';\n if (j < n-1) ans[ix++] = 'R';\n }\n foreach(j; 0..n) {\n if (j < n-1) ans[ix++] = 'L';\n }\n }\n\n writeln(ans[0..ix]);\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 (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tstring res;\n\t\tforeach (i, x; a)\n\t\t{\n\t\t\tforeach (j; 0..x)\n\t\t\t{\n\t\t\t\tres ~= 'P';\n\t\t\t\tif (j + 1 < x)\n\t\t\t\t{\n\t\t\t\t\tif (i == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tres ~= \"RL\";\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tres ~= \"LR\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i + 1 < n)\n\t\t\t{\n\t\t\t\tres ~= 'R';\n\t\t\t}\n\t\t}\n\t\twriteln (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;\n\nvoid main() {\n int n = stdin.readln.chop.to!int;\n int[] a = stdin.readln.chop.split.map!(to!int).array;\n char prev = 'X';\n int c = 0;\n while (true) {\n if (a[c] > 0) {\n if (prev == 'P') {\n if (c == 0) {\n write(\"RL\");\n prev = 'L';\n } else {\n write(\"LR\");\n prev = 'R';\n }\n } else {\n a[c]--;\n write('P');\n prev = 'P';\n }\n } else {\n if (c == n - 1) {\n break;\n }\n write('R');\n prev = 'R';\n c++;\n }\n }\n write('\\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\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\tstring [] res;\n\t\tforeach (x; a)\n\t\t{\n\t\t\tstring temp;\n\t\t\tforeach (i; 0..x)\n\t\t\t{\n\t\t\t\ttemp ~= 'P';\n\t\t\t}\n\t\t\tres ~= temp;\n\t\t}\n\t\twritef (\"%(%(%c%)R%)\", res);\n\t\tbreak;\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 a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tstring [] res;\n\t\tforeach (x; a)\n\t\t{\n\t\t\tstring temp;\n\t\t\tforeach (i; 0..x)\n\t\t\t{\n\t\t\t\ttemp ~= \"P\";\n\t\t\t}\n\t\t\tres ~= temp;\n\t\t}\n\t\twritefln (\"%(%(%c%)R%)\", res);\n\t}\n}\n"}], "src_uid": "50e88225d8b081d63eebe446f48057f4"} {"source_code": "import std.algorithm, std.array, std.stdio;\nvoid main ()\n{\n\tint n, a, b;\n\tscanf (\"%d\", &n);\n\tauto x = new int [n];\n\tforeach (i; 0..n)\n\t\tscanf (\"%d\", &x[i]);\n\tx = x.sort.uniq.array;\n\tscanf (\"%d%d\", &a, &b);\n\tint res = 0;\n\twhile (a > b)\n\t{\n\t\tres++;\n\t\tint c = a - 1;\n\t\tint [] y;\n\t\tforeach (d; x)\n\t\t{\n\t\t\tint e = a - (a % d);\n\t\t\tif (e >= b)\n\t\t\t{\n\t\t\t\ty ~= d;\n\t\t\t\tc = min (c, e);\n\t\t\t}\n\t\t}\n\t\ta = c;\n\t\tx = y;\n\t}\n\twriteln (res);\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 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\tx = x.sort !(\"a < b\", SwapStrategy.stable).uniq.array;\n\t\tint a, b;\n\t\treadf (\" %s %s\", &a, &b);\n\n\t\tint res = 0;\n\t\twhile (a > b)\n\t\t{\n\t\t\tres++;\n\t\t\tint c = a - 1;\n\t\t\tint [] y;\n\t\t\tforeach (d; x)\n\t\t\t{\n\t\t\t\tint e = a - (a % d);\n\t\t\t\tif (e >= b)\n\t\t\t\t{\n\t\t\t\t\ty ~= d;\n\t\t\t\t\tc = min (c, e);\n\t\t\t\t}\n\t\t\t}\n\t\t\ta = c;\n\t\t\tx = y;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.stdio;\nvoid main ()\n{\n\tint n, a, b;\n\treadf (\" %s\", &n);\n\tauto x = new int [n];\n\tforeach (i; 0..n)\n\t\treadf (\" %s\", &x[i]);\n\tx = x.sort.uniq.array;\n\treadf (\" %s %s\", &a, &b);\n\tint res = 0;\n\twhile (a > b)\n\t{\n\t\tres++;\n\t\tint c = a - 1;\n\t\tint [] y;\n\t\tforeach (d; x)\n\t\t{\n\t\t\tint e = a - (a % d);\n\t\t\tif (e >= b)\n\t\t\t{\n\t\t\t\ty ~= d;\n\t\t\t\tc = min (c, e);\n\t\t\t}\n\t\t}\n\t\ta = c;\n\t\tx = y;\n\t}\n\twriteln (res);\n}\n"}], "negative_code": [], "src_uid": "b4c96c9c0fa10612a06cfd2a6a5cc417"} {"source_code": "import std.math;\nimport std.stdio;\n\nimport std.algorithm;\nimport std.stdio;\n\nimmutable int MAX_N = 1_000_000;\n\nbool [] bool_primes (int n)\n{\n auto a = new bool [n + 1];\n a[] = true;\n a[0] = a[1] = false;\n for (int i = 2; i * i <= n; i++)\n if (a[i])\n for (int j = i * i; j <= n; j += i)\n a[j] = false;\n return a;\n}\n\nvoid main ()\n{\n bool [] p = bool_primes (MAX_N);\n \n\n int n;\n while (readf (\" %s\", &n) > 0)\n {\n foreach (i; 0..n)\n {\n long t;\n readf (\" %s\", &t);\n long s = cast (long) sqrt (cast (real) t);\n writef (\"%s\\n\", t > 1 && s * s == t &&\n p[cast (int) s] ? \"YES\" : \"NO\");\n }\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv: parse;\nimport std.array: split, join;\nimport std.algorithm: map;\nimport std.string: chop;\nimport std.math: sqrt;\nimport std.parallelism: taskPool;\n\nvoid main() {\n readln;\n readln.chop.split(\" \").map!yesno.join(\"\\n\").writeln;\n}\nstring yesno(string a) {\n auto n = sqrt(cast(real)a.parse!long);\n if(n == 1) return \"NO\";\n if(n % 1 == 0 && isPrime(cast(long)n)) return \"YES\";\n return \"NO\";\n}\nbool isPrime(long n) {\n foreach(i; 2..cast(long)sqrt(cast(real)n) + 1) if(n % i == 0) return false;\n return true;\n}"}, {"source_code": "import std.stdio;\nimport std.conv: parse;\nimport std.array: split, join;\nimport std.algorithm: map;\nimport std.string: chop;\nimport std.math: sqrt;\nimport std.parallelism: taskPool;\n\nvoid main() {\n readln;\n readln.chop.split(\" \").map!yesno.join(\"\\n\").writeln;\n}\nstring yesno(string a) {\n auto n = sqrt(cast(real)a.parse!long);\n if(n == 1) return \"NO\";\n if(n % 1 == 0 && isPrime(cast(long)n)) return \"YES\";\n return \"NO\";\n}\nbool isPrime(long n) {\n foreach(i; 2..cast(long)sqrt(cast(real)n) + 1) if(n % i == 0) return false;\n return true;\n}\n"}, {"source_code": "import std.math;\nimport std.stdio;\n\nimport std.algorithm;\nimport std.stdio;\n\nimmutable int MAX_N = 1_000_000;\n\nbool [] bool_primes (int n)\n{\n auto a = new bool [n + 1];\n a[] = true;\n a[0] = a[1] = false;\n for (int i = 2; i * i <= n; i++)\n if (a[i])\n for (int j = i * i; j <= n; j += i)\n a[j] = false;\n return a;\n}\n\nimmutable bool [] p = bool_primes (MAX_N);\n\nvoid main ()\n{\n int n;\n while (readf (\" %s\", &n) > 0)\n {\n foreach (i; 0..n)\n {\n long t;\n readf (\" %s\", &t);\n long s = cast (long) sqrt (cast (real) t);\n writef (\"%s\\n\", t > 1 && s * s == t &&\n p[cast (int) s] ? \"YES\" : \"NO\");\n }\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\nimport std.stdio;\nimport std.conv;\nimport std.math;\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 CFBETA142B()\n{\n auto n = ni();\n int[] LinearEratosphene(int N)\n {\n int[] lp = new int[N + 1];\n int[] pr = [];\n for (int i = 2; i <= N; ++i)\n {\n if (lp[i] == 0)\n {\n lp[i] = i;\n pr ~= i;\n }\n for (int j = 0; (j < pr.length) && (pr[j] <= lp[i]) && (i * pr[j] <= N); ++j)\n lp[i * pr[j]] = pr[j];\n }\n return lp;\n }\n int[1000001] lp = LinearEratosphene(1000000);\n for (int i=0; i 2 && number % 2 == 0) {\n\t\treturn false;\n\t}\n\n\tfor (auto i = 3; i * i <= number; i += 2) {\n\t\tif (number % i == 0) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\nvoid main() {\n\tint n;\n\tlong number;\n\n\treadf(\"%d\", &n);\n\tfor (auto i = 0; i < n; ++i) {\n\t\treadf(\" %d\", &number);\n\n\t\tdouble sqrtNumber = sqrt(cast(double) number);\n\t\tif (sqrtNumber - cast(long)sqrtNumber > 0) {\n\t\t\twriteln(\"NO\");\n\t\t} else {\n\t\t\tisPrime(cast(long) sqrtNumber)? writeln(\"YES\"): writeln(\"NO\");\n\t\t}\n\t}\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 x = readln.split.to!(long[]);\n\n auto primes = eratos(10^^6);\n\n foreach (xi ; x) {\n long v = nibutan(primes, xi);\n\n debug {\n writeln(v);\n }\n\n if (v^^2 == xi) {\n writeln(\"YES\");\n }\n else {\n writeln(\"NO\");\n }\n }\n}\n\nlong nibutan(int[] primes, long xi)\n{\n int btm = -1, top = primes.length.to!int, mid;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (primes[mid] <= xi / primes[mid]) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n return btm > -1 ? primes[btm] : 0;\n}\n\nint[] eratos(int n)\n{\n bool[] s = new bool[](n);\n fill(s, true);\n s[0] = s[1] = false;\n\n for (int p = 2; p*p < n; ++p) {\n if (s[p]) {\n for (int q = p*p; q < n; q += p) {\n s[q] = false;\n }\n }\n }\n\n return iota(n).filter!(a => s[a]).array;\n}\n\nbool is_prime(long x) {\n if (x < 2) return false;\n\n for (int p = 2; p*p <= x; ++p) {\n if (x % p == 0) return false;\n }\n\n return true;\n}\n\nlong root(long x) {\n long top = x, btm = 0, mid;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (mid <= x/mid) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n return btm;\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 = readln.chomp.to!int;\n auto x = readln.chomp.split.to!(long[]);\n\n foreach(xi; x) {\n long rx = root(xi);\n\n debug {\n writeln(rx);\n writeln(is_prime(rx));\n }\n\n if(xi > 1 && (rx^^2 == xi) && is_prime(rx)){\n writeln(\"YES\");\n }\n else {\n writeln(\"NO\");\n }\n }\n}\n\nbool is_prime(long x) {\n if (x < 2) return false;\n\n for (int p = 2; p*p <= x; ++p) {\n if (x % p == 0) return false;\n }\n\n return true;\n}\n\nlong root(long x) {\n long top = x, btm = 0, mid;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (mid <= x/mid) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n return btm;\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;\nimport std.conv: parse;\nimport std.array: split, join;\nimport std.algorithm: map;\nimport std.string: chop;\nimport std.math: sqrt;\n\nvoid main()\n{\n readln;\n readln.chop.split(\" \").map!yesno.join(\"\\n\").writeln;\n}\nstring yesno(string a) {\n auto n = sqrt(cast(float)a.parse!int);\n if(n % 1 == 0 && isPrime(cast(int)n)) return \"YES\";\n return \"NO\";\n}\nbool isPrime(int n) {\n foreach(i; 2..n) if(n % i == 0) return false;\n return true;\n}"}, {"source_code": "import std.stdio;\nimport std.conv: parse;\nimport std.array: split, join;\nimport std.algorithm: map;\nimport std.string: chop;\nimport std.math: sqrt;\n\nvoid main()\n{\n readln;\n readln.chop.split(\" \").map!yesno.join(\"\\n\").writeln;\n}\nstring yesno(string a) {\n auto n = sqrt(cast(float)a.parse!long);\n if(n % 1 == 0 && isPrime(cast(int)n)) return \"YES\";\n return \"NO\";\n}\nbool isPrime(int n) {\n foreach(i; 2..n) if(n % i == 0) return false;\n return true;\n}"}, {"source_code": "import std.stdio;\nimport std.conv: parse;\nimport std.array: split, join;\nimport std.algorithm: map;\nimport std.string: chop;\nimport std.math: sqrt;\n\nvoid main()\n{\n readln;\n readln.chop.split(\" \").map!yesno.join(\"\\n\").writeln;\n}\nstring yesno(string a) {\n auto n = sqrt(cast(float)a.parse!long);\n if(n == 1) return \"NO\";\n if(n % 1 == 0 && isPrime(cast(int)n)) return \"YES\";\n return \"NO\";\n}\nbool isPrime(int n) {\n foreach(i; 2..n) if(n % i == 0) return false;\n return true;\n}"}, {"source_code": "import std.stdio;\nimport std.conv: parse;\nimport std.array: split, join;\nimport std.algorithm: map;\nimport std.string: chop;\nimport std.math: sqrt;\n\nvoid main()\n{\n readln;\n readln.chop.split(\" \").map!yesno.join(\"\\n\").writeln;\n}\nstring yesno(string a) {\n auto n = sqrt(cast(float)a.parse!int);\n if(n % 1 == 0 && isPrime(cast(int)n)) return \"YES\";\n return \"NO\";\n}\nbool isPrime(int n) {\n foreach(i; 2..n) if(n % i != 0) return false;\n return true;\n}"}, {"source_code": "import std.stdio;\n\nbool [long] squares (int n)\n{\n bool [long] res;\n foreach (i; 1..n + 1)\n {\n long s = i;\n s *= i;\n res[s] = true;\n }\n return res;\n}\n\nimmutable bool [long] f;\n\nvoid main ()\n{\n int n;\n while (readf (\" %s \", &n) > 0)\n {\n foreach (i; 0..n)\n {\n long t;\n readf (\" %s \", &t);\n writef (\"%s\\n\", t in f ? \"YES\" : \"NO\");\n }\n }\n}\n"}, {"source_code": "import std.math;\nimport std.stdio;\n\nvoid main ()\n{\n int n;\n while (readf (\" %s\", &n) > 0)\n {\n foreach (i; 0..n)\n {\n long t;\n readf (\" %s\", &t);\n long s = cast (long) sqrt (cast (real) t);\n writef (\"%s\\n\", s * s == t ? \"YES\" : \"NO\");\n }\n }\n}\n"}, {"source_code": "import std.stdio;\n\nbool [long] squares (int n)\n{\n bool [long] res;\n foreach (i; 1..n + 1)\n {\n long s = i;\n s *= i;\n res[s] = true;\n }\n return res;\n}\n\nimmutable bool [long] f;\n\nvoid main ()\n{\n int n;\n while (readf (\" %s \", &n) > 0)\n {\n foreach (i; 0..n)\n {\n long t;\n readf (\" %s \", &t);\n writef (\"%s\\n\", f.get (t, false) ? \"YES\" : \"NO\");\n }\n }\n}\n"}, {"source_code": "import std.math;\nimport std.stdio;\n\nvoid main ()\n{\n int n;\n while (readf (\" %s\", &n) > 0)\n {\n foreach (i; 0..n)\n {\n long t;\n readf (\" %s\", &t);\n long s = cast (long) sqrt (cast (real) t);\n writef (\"%s\\n\", t > 1 && s * s == t ? \"YES\" : \"NO\");\n }\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.c.stdio;\nimport std.stdio;\nimport std.conv;\nimport std.math;\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 CFBETA142B()\n{\n auto n = ni();\n long[] x = new long[n];\n long m=0;\n for (int i=0; i 1 && (root(xi)^^2 == xi)){\n writeln(\"YES\");\n }\n else {\n writeln(\"NO\");\n }\n }\n}\n\nlong root(long x) {\n long top = x, btm = 0, mid;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (mid*mid <= x) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n return btm;\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 = readln.chomp.to!int;\n auto x = readln.chomp.split.to!(long[]);\n\n foreach(xi; x) {\n long rx = root(xi);\n\n if(xi > 1 && (rx^^2 == xi) && is_prime(rx)){\n writeln(\"YES\");\n }\n else {\n writeln(\"NO\");\n }\n }\n}\n\nbool is_prime(long x) {\n if (x < 2) return false;\n\n for (int p = 2; p*p <= x; ++p) {\n if (x % p == 0) return false;\n }\n\n return true;\n}\n\nlong root(long x) {\n long top = x, btm = 0, mid;\n\n while (top - btm > 1) {\n mid = btm + (top - btm) / 2;\n\n if (mid*mid <= x) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n return btm;\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}"}], "src_uid": "6cebf9af5cfbb949f22e8b336bf07044"} {"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 foreach (i; 0..N) write(i + 5000001, \" \");\n writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\n\nvoid main() {\n int n; readf(\"%d\", &n);\n writef(\"%d\", 10000000 - n);\n for (int i = 10000000 - n + 1; i < 10000000; i++) {\n writef(\" %d\", i);\n }\n writeln;\n}\n"}], "negative_code": [], "src_uid": "c047040426e736e9085395ed9666135f"} {"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 enum T = \"abacaba\";\n int t;\n read(t);\n testCase:while(t--)\n {\n int n;\n string istr;\n read(n);\n read(istr);\n char[] str = istr.dup;\n for(size_t i = 0; i + T.length - 1 < istr.length; i++)\n {\n if (iota(0, T.length).all!(j => str[i + j] == '?' || str[i + j] == T[j]))\n {\n auto saved = str[i .. i + T.length].dup;\n str[i .. i + T.length] = T[];\n if (iota(0, str.length - T.length + 1).filter!(k => k != i).all!(k => str[k .. k + T.length] != T[]))\n {\n str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n str[i .. i + T.length] = saved;\n }\n }\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\nimmutable string pattern = \"abacaba\";\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 = s.dup;\n\t\tforeach (ref c; t)\n\t\t{\n\t\t\tif (c == '?')\n\t\t\t{\n\t\t\t\tc = 'z';\n\t\t\t}\n\t\t}\n\t\tforeach (start; 0..n - 6)\n\t\t{\n\t\t\tif (zip (s[start..start + 7], pattern).any\n\t\t\t !(p => p[0] != '?' && p[0] != p[1]))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto r = t.dup;\n\t\t\tr[start..start + 7] = pattern;\n\t\t\tif (r.find (pattern).drop (1).find (pattern).empty)\n\t\t\t{\n\t\t\t\twriteln (\"YES\");\n\t\t\t\twriteln (r);\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.container: DList;\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 int n;\n string istr;\n read(n);\n read(istr);\n enum wantedString = \"abacaba\";\n for(size_t i = 0; i + wantedString.length - 1 < istr.length; i++)\n {\n char[] str = istr.dup;\n import std.algorithm: all, map, count, min;\n import std.range: iota;\n import std.array: array;\n if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))\n {\n str[i .. i + wantedString.length] = wantedString[];\n auto appearances = iota(0, str.length).count!(k => str[k .. min(k + wantedString.length, $)] == wantedString[]);\n assert(appearances >= 1);\n if (appearances == 1)\n {\n import std.utf;\n str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;\n import std.stdio;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n }\n }\n import std.stdio;\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.container: DList;\nimport std.algorithm: all, map, count;\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 enum T = \"abacaba\";\n int t;\n read(t);\n testCase:while(t--)\n {\n int n;\n string istr;\n read(n);\n read(istr);\n char[] str = istr.dup;\n for(size_t i = 0; i + T.length - 1 < istr.length; i++)\n {\n if (iota(0, T.length).all!(j => str[i + j] == '?' || str[i + j] == T[j]))\n {\n auto saved = str[i .. i + T.length].dup;\n str[i .. i + T.length] = T[];\n if (iota(0, str.length - T.length + 1).all!(k => k == i || str[k .. k + T.length] != T[]))\n {\n str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n str[i .. i + T.length] = saved;\n }\n }\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.container: DList;\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 int n;\n string istr;\n read(n);\n read(istr);\n enum wantedString = \"abacaba\";\n for(size_t i = 0; i + wantedString.length - 1 < istr.length; i++)\n {\n char[] str = istr.dup;\n import std.algorithm: all, map, count, min;\n import std.range: iota;\n import std.array: array;\n if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))\n {\n str[i .. i + wantedString.length] = wantedString[];\n import std.utf;\n str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;\n auto appearances = iota(0, str.length).count!(k => str[k .. min(k + wantedString.length, $)] == wantedString[]);\n assert(appearances >= 1);\n if (appearances == 1)\n {\n import std.stdio;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n }\n }\n import std.stdio;\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.container: DList;\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 int n;\n string istr;\n read(n);\n read(istr);\n enum wantedString = \"abacaba\";\n char[] str = istr.dup;\n for(size_t i = 0; i + wantedString.length - 1 < istr.length; i++)\n {\n import std.algorithm: all, map, count;\n import std.range: iota;\n import std.array: array;\n if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))\n {\n auto saved = str[i .. i + wantedString.length].dup;\n str[i .. i + wantedString.length] = wantedString[];\n if (iota(0, str.length - wantedString.length + 1).all!(k => k == i || str[k .. k + wantedString.length] != wantedString[]))\n {\n import std.stdio;\n import std.utf;\n str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n str[i .. i + wantedString.length] = saved;\n }\n }\n import std.stdio;\n writeln(\"No\");\n }\n}\n"}], "negative_code": [{"source_code": "import std.container: DList;\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 int n;\n string istr;\n read(n);\n read(istr);\n char[] str = istr.dup;\n enum wantedString = \"abacaba\";\n for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)\n {\n import std.algorithm: all, map, count;\n import std.range: iota;\n import std.array: array;\n if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))\n {\n auto saved = str[i .. i + wantedString.length].dup;\n str[i .. i + wantedString.length] = wantedString[];\n import std.utf;\n str = str.map!(c => c == '?'? 'x' : c).array.toUTF8.dup;\n auto appearances = iota(0, str.length - wantedString.length + 1).count!(k => str[k .. k + wantedString.length] == wantedString[]);\n assert(appearances >= 1);\n if (iota(0, str.length - wantedString.length + 1).count!(k => str[k .. k + wantedString.length] == wantedString[]) == 1)\n {\n import std.stdio;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n str[i .. i + wantedString.length] = saved;\n }\n }\n import std.stdio;\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.container: DList;\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 int n;\n string istr;\n read(n);\n read(istr);\n char[] str = istr.dup;\n enum wantedString = \"abacaba\";\n for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)\n {\n import std.algorithm: all, map, count;\n import std.range: iota;\n import std.array: array;\n if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))\n {\n auto saved = str[i .. i + wantedString.length].dup;\n str[i .. i + wantedString.length] = wantedString[];\n import std.utf;\n str = str.map!(c => c == '?'? 'x' : c).array.toUTF8.dup;\n if (iota(0, str.length - wantedString.length + 1).count!(k => str[k .. k + wantedString.length] == wantedString[]) == 1)\n {\n import std.stdio;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n str[i .. i + wantedString.length] = saved;\n }\n }\n import std.stdio;\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.container: DList;\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 int n;\n string istr;\n read(n);\n read(istr);\n char[] str = istr.dup;\n enum wantedString = \"abacaba\";\n for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)\n {\n import std.algorithm: all, map;\n import std.range: iota;\n import std.array: array;\n if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))\n {\n auto saved = str[i .. i + wantedString.length].dup;\n str[i .. i + wantedString.length] = wantedString[];\n import std.utf;\n str = str.map!(c => c == '?'? 'x' : c).array.toUTF8.dup;\n if (iota(0, str.length - wantedString.length + 1).all!(k => k == i || str[k .. k + wantedString.length] != wantedString[]))\n {\n import std.stdio;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n str[i .. i + wantedString.length] = saved;\n }\n }\n import std.stdio;\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.container: DList;\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 int n;\n string istr;\n read(n);\n read(istr);\n char[] str = istr.dup;\n enum wantedString = \"abacaba\";\n for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)\n {\n import std.algorithm: all, map;\n import std.range: iota;\n import std.array: array;\n if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))\n {\n auto saved = str[i .. i + wantedString.length].dup;\n str[i .. i + wantedString.length] = wantedString[];\n import std.utf;\n str = str.map!(c => c == '?'? 'x' : c).array.toUTF8.dup;\n if (iota(0, str.length - wantedString.length + 1).all!(k => k == i || str[k .. k + wantedString.length] != wantedString[]))\n {\n import std.stdio;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n }\n }\n import std.stdio;\n writeln(\"No\");\n }\n}\n"}, {"source_code": "import std.container: DList;\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 int n;\n string istr;\n read(n);\n read(istr);\n char[] str = istr.dup;\n enum wantedString = \"abacaba\";\n for(size_t i = 0; i + wantedString.length - 1 < str.length; i++)\n {\n import std.algorithm: all, map, count, min;\n import std.range: iota;\n import std.array: array;\n if (iota(0, wantedString.length).all!(j => str[i + j] == '?' || str[i + j] == wantedString[j]))\n {\n auto saved = str[i .. i + wantedString.length].dup;\n str[i .. i + wantedString.length] = wantedString[];\n import std.utf;\n str = str.map!(c => c == '?'? 'z' : c).array.toUTF8.dup;\n auto appearances = iota(0, str.length).count!(k => str[k .. min(k + wantedString.length, $)] == wantedString[]);\n assert(appearances >= 1);\n if (appearances == 1)\n {\n import std.stdio;\n writeln(\"Yes\");\n writeln(str.idup);\n continue testCase;\n }\n str[i .. i + wantedString.length] = saved[];\n }\n }\n import std.stdio;\n writeln(\"No\");\n }\n}\n"}], "src_uid": "f6b7ad10382135b293bd3f2f3257d4d3"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1437/problem/C\n// \nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int q = readln.chomp.to!int;\n\n int n;\n int[] t;\n while(q--) {\n n = readln.chomp.to!int;\n t = readln.split.map!(to!int).array;\n\n t = t.map!(x => x - 1).array;\n\n t.sort;\n\n // dp\n // number of dishes\n // at time t\n int[][] dp = new int[][](n + 1, 2*n);\n for(int i = 0; i < n + 1; i++) {\n for(int j = 0; j < 2*n; j++) {\n dp[i][j] = int.max;\n }\n }\n\n dp[0][0] = 0L;\n for(int i = 0; i < n + 1; i++) {\n for(int j = 0; j + 1 < 2*n; j++) {\n if(dp[i][j] < int.max) {\n if(i + 1 <= n)\n dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + abs(t[i] - j));\n // dont take the dish and move to the next minute\n dp[i][j + 1] = min(dp[i][j], dp[i][j + 1]);\n }\n }\n }\n\n dp[n][2 * n - 1].writeln;\n }\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\nimmutable int infinity = int.max / 2;\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\tauto f = new int [] [] (2, n + 1);\n\t\tint b = 0;\n\t\tf[b][] = infinity;\n\t\tf[b][0] = 0;\n\t\tforeach (i; 1..n * 2 + 1)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tf[b][] = f[!b][];\n\t\t\tforeach_reverse (k; 1..n + 1)\n\t\t\t{\n\t\t\t\tf[b][k] = min (f[b][k], f[!b][k - 1] +\n\t\t\t\t abs (i - a[k - 1]));\n\t\t\t}\n\t\t}\n\t\twriteln (f[b][n]);\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\nimmutable int infinity = int.max / 2;\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\tauto f = new int [n + 1];\n\t\tf[] = infinity;\n\t\tf[0] = 0;\n\t\tforeach (i; 1..n * 2 + 1)\n\t\t{\n\t\t\tforeach_reverse (k; 1..n + 1)\n\t\t\t{\n\t\t\t\tf[k] = min (f[k], f[k - 1] +\n\t\t\t\t abs (i - a[k - 1]));\n\t\t\t}\n\t\t}\n\t\twriteln (f[n]);\n\t}\n}\n"}], "negative_code": [], "src_uid": "27998621de63e50a7d89cb1c1e30f67c"} {"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 auto s = readln.chomp;\n \n auto rooms = new bool[10];\n \n foreach (e; s) {\n if (e == 'L') {\n int i = 0;\n while (rooms[i]) { ++i; }\n rooms[i] = true;\n } else if (e == 'R') {\n int i = 9;\n while (rooms[i]) { --i; }\n rooms[i] = true;\n } else {\n rooms[e - '0'] = false;\n }\n }\n \n foreach (e; rooms) {\n write(e ? '1' : '0');\n }\n 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\tchar[] cs = readln.chomp.to!(char[]);\n\t\n\tchar[] ans = \"0000000000\".to!(char[]);\n\tforeach(c; cs){\n\t\tif(c == 'L'){\n\t\t\tforeach(i; 0 .. 10) if(ans[i] == '0'){\n\t\t\t\tans[i] = '1';\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse if(c == 'R'){\n\t\t\tforeach_reverse(i; 0 .. 10) if(ans[i] == '0'){\n\t\t\t\tans[i] = '1';\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tint i = (c - '0').to!int;\n\t\t\tans[i] = '0';\n\t\t}\n\t}\n\t\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.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;\n\tauto s = RD!string;\n\tauto ans = new long[](10);\n\tforeach (c; s)\n\t{\n\t\tif (c == 'L')\n\t\t{\n\t\t\tforeach (i; 0..10)\n\t\t\t{\n\t\t\t\tif (ans[i] == 0)\n\t\t\t\t{\n\t\t\t\t\tans[i] = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (c == 'R')\n\t\t{\n\t\t\tforeach_reverse (i; 0..10)\n\t\t\t{\n\t\t\t\tif (ans[i] == 0)\n\t\t\t\t{\n\t\t\t\t\tans[i] = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto pos = [c].to!int;\n\t\t\tans[pos] = 0;\n\t\t}\n\n\t}\n\t\n\tans.map!(to!string).join(\"\").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "a6cbf01d72d607ca95fe16df4fb16693"} {"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\tint n, k;\r\n\twhile (readf !(\" %s %s\") (n, k) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta[] -= 1;\r\n\r\n\t\tauto x = (n + k - 2) / (k - 1);\r\n\t\tauto pos = new int [n];\r\n\t\tpos[] = NA;\r\n\t\tauto used = new bool [n];\r\n\r\n\t\tint [] [] answer;\r\n\t\tforeach (int i, ref cur; a)\r\n\t\t{\r\n\t\t\tif (pos[cur] != NA)\r\n\t\t\t{\r\n\t\t\t\tanswer ~= [pos[cur], i];\r\n\t\t\t\tpos[cur] = NA;\r\n\t\t\t\tused[cur] = true;\r\n\t\t\t\tif (answer.length % x == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tpos[] = NA;\r\n\t\t\t\t}\r\n\t\t\t\tif (answer.length >= n)\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\telse if (!used[cur])\r\n\t\t\t{\r\n\t\t\t\tpos[cur] = i;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tanswer.schwartzSort !(c => a[c.front]);\r\n\r\n\t\twritefln !(\"%(%(%s %)\\n%)\") (answer.map !(map !(q{a + 1})));\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 N = readInt();\n const K = readInt();\n auto C = new int[N * K];\n foreach (i; 0 .. N * K) {\n C[i] = readInt() - 1;\n }\n \n auto xss = new int[][N];\n foreach (i; 0 .. N * K) {\n xss[C[i]] ~= i;\n }\n \n auto as = new int[N];\n auto bs = new int[N];\n as[] = -1;\n bs[] = -1;\n auto nums = new int[K - 1];\n foreach (c; 0 .. N) {\n ++nums[c % (K - 1)];\n }\n foreach (k; 0 .. K - 1) {\n alias Entry = Tuple!(int, \"x\", int, \"c\");\n Entry[] es;\n foreach (c; 0 .. N) {\n if (as[c] == -1) {\n es ~= Entry(xss[c][k + 1], c);\n }\n }\n es.sort;\n foreach (j; 0 .. nums[k]) {\n const c = es[j].c;\n as[c] = xss[c][k];\n bs[c] = xss[c][k + 1];\n }\n }\n \n foreach (c; 0 .. N) {\n writeln(as[c] + 1, \" \", bs[c] + 1);\n }\n }\n } catch (EOFException e) {\n }\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\nimmutable int NA = -1;\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\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta[] -= 1;\r\n\r\n\t\tauto x = (n + k - 2) / (k - 1);\r\n\t\tauto pos = new int [n];\r\n\t\tpos[] = NA;\r\n\r\n\t\tint [] [] answer;\r\n\t\tforeach (int i, ref cur; a)\r\n\t\t{\r\n\t\t\tif (pos[cur] == NA)\r\n\t\t\t{\r\n\t\t\t\tpos[cur] = i;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tanswer ~= [pos[cur] + 1, i + 1];\r\n\t\t\t\tpos[cur] = NA;\r\n\t\t\t\tif (answer.length % x == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tpos[] = NA;\r\n\t\t\t\t}\r\n\t\t\t\tif (answer.length >= n)\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}\r\n\r\n\t\twritefln !(\"%(%(%s %)\\n%)\") (answer);\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// Dijkstra\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 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 K = readInt();\n auto C = new int[N * K];\n foreach (i; 0 .. N * K) {\n C[i] = readInt() - 1;\n }\n \n auto app = new int[N];\n app[] = -1;\n auto nxt = new int[N * K];\n foreach_reverse (i; 0 .. N * K) {\n nxt[i] = app[C[i]];\n app[C[i]] = i;\n }\n \n const lim = (N + (K - 1) - 1) / (K - 1);\n auto mcf = new MinCostFlow!(int, int)(N * K + 1);\n foreach (i; 0 .. N * K) {\n mcf.addEdge(i, i + 1, lim, 0);\n }\n auto ids = new int[N * K];\n ids[] = -1;\n foreach (i; 0 .. N * K) {\n if (nxt[i] != -1) {\n ids[i] = mcf.addEdge(i, nxt[i] + 1, 1, -1);\n }\n }\n mcf.solve(0, N * K, lim);\n assert(mcf.toc <= -N);\n \n int cnt;\n foreach (i; 0 .. N * K) {\n if (ids[i] != -1 && mcf.capa[ids[i]] == 0) {\n writeln(i + 1, \" \", nxt[i] + 1);\n if (++cnt >= N) {\n break;\n }\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "ada7340984ca02702146e7b2ab71f194"} {"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 = RD!int;\r\n\t\tauto a = RDA(-1);\r\n\t\tauto b = RDA(-1);\r\n\t\t\r\n\t\tauto cnt_a = new long[](n);\r\n\t\tauto cnt_b = new long[](m);\r\n\t\tforeach (i; 0..k)\r\n\t\t{\r\n\t\t\tans[ti] += i - cnt_a[a[i]] - cnt_b[b[i]];\r\n\t\t\t++cnt_a[a[i]];\r\n\t\t\t++cnt_b[b[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}", "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, K; get(A, B, K);\r\n int[] AA; get(AA);\r\n int[] BB; get(BB);\r\n long res;\r\n auto ac = new int[](A + 1);\r\n auto bc = new int[](B + 1);\r\n int[Tuple!(int, int)] ps;\r\n foreach_reverse (i; 0..K) {\r\n int a = AA[i], b = BB[i], p;\r\n auto t = tuple(a, b);\r\n if (t in ps) p = ps[t];\r\n res += (K - i - 1) - ac[a] - bc[b] + p;\r\n ac[a] += 1;\r\n bc[b] += 1;\r\n ps[t] += 1;\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 p, q, k;\r\n\t\treadf !(\" %s %s %s\") (p, q, k);\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\ta[] -= 1;\r\n\t\tb[] -= 1;\r\n\t\tauto da = new int [p];\r\n\t\tauto db = new int [q];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tda[c] += 1;\r\n\t\t}\r\n\t\tforeach (ref c; b)\r\n\t\t{\r\n\t\t\tdb[c] += 1;\r\n\t\t}\r\n\t\tlong res = 0;\r\n\t\tforeach (i; 0..p)\r\n\t\t{\r\n\t\t\tres += da[i] * (da[i] - 1L);\r\n\t\t}\r\n\t\tforeach (j; 0..q)\r\n\t\t{\r\n\t\t\tres += db[j] * (db[j] - 1L);\r\n\t\t}\r\n\t\twriteln ((k * (k - 1L) - res) / 2);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "14ce451a31c0dbc2b2f4e04a939b199d"} {"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.chomp;\n auto T = readln.chomp;\n auto N = S.length.to!int;\n auto M = T.length.to!int;\n auto A = readln.split.map!(to!int).array;\n auto B = new int[](N);\n foreach (i; 0..N) {\n B[A[i]-1] = i;\n }\n\n int hi = N;\n int lo = M - 1;\n while (hi - lo > 1) {\n int mid = (hi + lo) / 2;\n int cnt = 0;\n int del = N - mid;\n foreach (i; 0..N) {\n if (B[i] < del)\n continue;\n if (S[i] == T[cnt])\n cnt += 1;\n if (cnt >= M)\n break;\n }\n if (cnt >= M)\n hi = mid;\n else\n lo = mid;\n }\n\n (N-hi).writeln;\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\twhile (true)\n\t{\n\t\tauto s = readln.strip;\n\t\tif (s is null)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tauto t = readln.strip;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tint n = cast (int) s.length;\n\t\tp[] -= 1;\n\n\t\tbool ok (int k)\n\t\t{\n\t\t\tauto cur = s.dup;\n\t\t\tforeach (i; 0..k)\n\t\t\t{\n\t\t\t\tcur[p[i]] = '-';\n\t\t\t}\n\t\t\tcur = cur.filter !(c => c != '-').text.dup;\n\t\t\tint pos = 0;\n\t\t\tforeach (c; cur)\n\t\t\t{\n\t\t\t\tif (c == t[pos])\n\t\t\t\t{\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif (pos >= t.length)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn true;\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\tint lo = 0;\n\t\tint hi = n;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tint me = (lo + hi + 1) >> 1;\n\t\t\tif (ok (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 (lo);\n\t}\n}\n"}], "negative_code": [], "src_uid": "0aed14262c135d1624df9814078031ae"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m;\n long k;\n rd(n, m, k);\n auto a = readln.split.to!(long[]);\n\n for (auto i = n - 1, r = k; i >= 0; i--) {\n if ((r -= a[i]) < 0) {\n if ((--m) == 0) {\n writeln(n - i - 1);\n return;\n }\n r = k - a[i];\n }\n }\n\n writeln(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, std.string;\nimport std.algorithm;\n\nbool ok(int[] a, int m, int k)\n{\n auto n = cast(int)a.length;\n auto i = 0, j = 0;\n auto c = k;\n while (i < n && j < m)\n {\n if (a[i] > c)\n {\n ++ j;\n c = k;\n }\n else\n {\n c -= a[i];\n ++ i;\n }\n }\n return i == n ? true : false;\n}\n\nvoid solve(int[] a, int n, int m, int k)\n{\n auto ans = 0;\n auto left = 0, right = n - 1;\n while (left <= right)\n {\n auto mid = (left + right) >> 1;\n if (!ok(a[mid .. n], m, k))\n {\n left = mid + 1;\n }\n else\n {\n ans = n - mid;\n right = mid - 1;\n }\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n, m, k;\n while (readf(\"%d %d %d\\n\", &n, &m, &k) == 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, n, m, k);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "869f8763211a7771ecd73d56b5c34479"} {"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\tp[] -= 1;\n\t\tauto a = new int [] [n];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\ta[p[i]] ~= i;\n\t\t}\n\n\t\tauto d = new int [n];\n\n\t\tvoid recur (int v, int h)\n\t\t{\n\t\t\td[h] ^= 1;\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\trecur (u, h + 1);\n\t\t\t}\n\t\t}\n\n\t\trecur (0, 0);\n\t\twriteln (sum (d));\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 P = new int[N];\n foreach (u; 1 .. N) {\n P[u] = readInt() - 1;\n }\n P[0] = -1;\n \n auto dep = new int[N];\n dep[0] = 0;\n foreach (u; 1 .. N) {\n dep[u] = 1 + dep[P[u]];\n }\n \n auto cnt = new int[N];\n foreach (u; 0 .. N) {\n ++cnt[dep[u]];\n }\n int ans;\n foreach (d; 0 .. N) {\n ans += cnt[d] % 2;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "a4563e6aea9126e20e7a33df664e3171"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 a = RD!int;\n\tauto b = RD!int;\n\tauto k = RD!int;\n\tauto h = RDA(-1);\n\n\tauto cnt = new int[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto r = h[i] % (a+b);\n\t\tcnt[i] = r / a;\n\t}\n\tcnt.sort();\n\n\tint ans;\n\tforeach (i; 0..n)\n\t{\n\t\tif (cnt[i] <= k)\n\t\t{\n\t\t\t++ans;\n\t\t\tk -= cnt[i];\n\t\t}\n\t}\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.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 n = readInt;\n int a = readInt;\n int b = readInt;\n int k = readInt;\n int[] need = new int[n];\n for (int i = 0; i < n; ++i)\n {\n int hp = readInt;\n int s = a + b;\n int rounds = (hp + s - 1) / s;\n hp -= (rounds - 1) * s;\n need[i] = (hp + a - 1) / a - 1;\n }\n sort(need);\n int result = 0;\n for (int i = 0; i < n; ++i)\n {\n if (need[i] <= k)\n {\n k -= need[i], result++;\n }\n }\n writeln(result);\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\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 mixin(input(q{n, a, b, k}));\n auto h = new long[n.ind];\n read(h);\n auto rk = h\n .map!((hi)\n {\n auto r = (hi % (a + b) == 0)? (a + b) : (hi % (a + b));\n // a * x >= r\n // x >= r / a\n return (r + pmod(-r, a)) / a - 1;\n })\n .array;\n sort(rk);\n auto points = long(0);\n foreach(rki; rk)\n {\n if (k < rki)\n break;\n k -= rki;\n points++;\n }\n writeln(points);\n}\n"}], "negative_code": [], "src_uid": "ada28bbbd92e0e7c6381bb9a4b56e7f9"} {"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv, std.range, std.bigint;\r\n\r\nvoid main()\r\n{\r\n\tint n;\r\n\tscanf(\"%d\", &n);\r\n\tgetchar();\r\n\tauto heroes = readln.split().to!(BigInt[]);\r\n\tint m;\r\n\tscanf(\"%d\", &m);\r\n\tgetchar();\r\n\theroes.sort();\r\n\tBigInt[] res = new BigInt[m];\r\n\tBigInt total = to!BigInt(heroes.sum());\r\n\tforeach(i;0..m)\r\n\t{\r\n\t\tauto dragon = readln.split().to!(BigInt[]);\r\n\t\tsize_t send = 0;\r\n\t\tif (heroes[n - 1] < dragon[0])\r\n\t\t\tsend = n - 1;\r\n\t\telse\r\n\t\t{\r\n\t\t\tsize_t ok = n - 1;\r\n\t\t\tsize_t ng = -1;\r\n\t\t\twhile (ok - ng > 1)\r\n\t\t\t{\r\n\t\t\t\tsize_t center = (ng + ok) / 2;\r\n\t\t\t\tif (heroes[center] >= dragon[0])\r\n\t\t\t\t\tok = center;\r\n\t\t\t\telse\r\n\t\t\t\t\tng = center;\r\n\t\t\t}\r\n\t\t\tsend = ok;\r\n\t\t}\r\n\t\tres[i] = max(BigInt(0), dragon[0] - heroes[send]) + max(BigInt(0), dragon[1] - total + heroes[send]);\r\n\t\tif (send > 0)\r\n\t\t\tres[i] = min(res[i], max(BigInt(0), dragon[0] - heroes[send - 1] + max(BigInt(0), dragon[1] - total + heroes[send - 1])));\r\n\t}\r\n\tres.each!(a => writeln(a));\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv, std.range;\r\n \r\nvoid main()\r\n{\r\n\tint n;\r\n\tscanf(\"%d\", &n);\r\n\tgetchar();\r\n\tauto heroes = readln.split().to!(long[]);\r\n\tint m;\r\n\tscanf(\"%d\", &m);\r\n\tgetchar();\r\n\theroes.sort();\r\n\tlong[] res = new long[m];\r\n\tlong total = to!long(heroes.sum());\r\n\tforeach(i;0..m)\r\n\t{\r\n\t\tauto dragon = readln.split().to!(long[]);\r\n\t\tsize_t send = 0;\r\n\t\tif (heroes[n - 1] < dragon[0])\r\n\t\t\tsend = n - 1;\r\n\t\telse\r\n\t\t{\r\n\t\t\tsize_t ok = n - 1;\r\n\t\t\tsize_t ng = -1;\r\n\t\t\twhile (ok - ng > 1)\r\n\t\t\t{\r\n\t\t\t\tsize_t center = (ng + ok) / 2;\r\n\t\t\t\tif (heroes[center] >= dragon[0])\r\n\t\t\t\t\tok = center;\r\n\t\t\t\telse\r\n\t\t\t\t\tng = center;\r\n\t\t\t}\r\n\t\t\tsend = ok;\r\n\t\t}\r\n\t\tres[i] = max(long(0), dragon[0] - heroes[send]) + max(long(0), dragon[1] - total + heroes[send]);\r\n\t\tif (send > 0)\r\n\t\t\tres[i] = min(res[i], max(long(0), dragon[0] - heroes[send - 1] + max(long(0), dragon[1] - total + heroes[send - 1])));\r\n\t}\r\n\tres.each!(a => writeln(a));\r\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv;\r\n\r\nvoid main()\r\n{\r\n\tint n;\r\n\tscanf(\"%d\", &n);\r\n\tgetchar();\r\n\tauto heroes = readln.split().to!(ulong[]);\r\n\tint m;\r\n\tscanf(\"%d\", &m);\r\n\tgetchar();\r\n\theroes.sort();\r\n\tforeach(_;0..m)\r\n\t{\r\n\t\tauto dragon = readln.split().to!(ulong[]);\r\n\t\tauto atack = heroes.find!((a,b) => a >= b)(dragon[0]);\r\n\t\tif (atack.empty)\r\n\t\t{\r\n\t\t\tif (dragon[1] > heroes.sum() - heroes.maxElement)\r\n\t\t\t\twriteln(dragon[0] - heroes.maxElement + max(0, dragon[1] - heroes.sum() + heroes.maxElement));\r\n\t\t\telse\r\n\t\t\t\twriteln(dragon[0] - heroes.maxElement);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tulong[] weak = heroes.find!((a,b) => a < b)(dragon[0]);\r\n\t\t\tulong atacker = atack.minElement();\r\n\t\t\tif (!weak.empty)\r\n\t\t\t{\r\n\t\t\t\tulong weaker = weak.maxElement();\r\n\t\t\t\tif (dragon[1] > heroes.sum() - weaker)\r\n\t\t\t\t\tif (dragon[1] > heroes.sum() - atacker)\r\n\t\t\t\t\t\twriteln(min(dragon[0] - weaker + dragon[1] - heroes.sum() + weaker, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\twriteln(min(dragon[0] - weaker + dragon[1] - heroes.sum() + weaker, 0));\r\n\t\t\t\telse\r\n\t\t\t\t\tif (dragon[1] > heroes.sum() - atacker)\r\n\t\t\t\t\t\twriteln(min(dragon[0] - weaker, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\twriteln(min(dragon[0] - weaker, 0));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (dragon[1] > heroes.sum() - atacker)\r\n\t\t\t\t\twriteln(max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\telse\r\n\t\t\t\t\twriteln(0);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv;\r\n\r\nvoid main()\r\n{\r\n\tint n;\r\n\tscanf(\"%d\", &n);\r\n\tgetchar();\r\n\tauto heroes = readln.split().to!(ulong[]);\r\n\tint m;\r\n\tscanf(\"%d\", &m);\r\n\tgetchar();\r\n\theroes.sort();\r\n\tforeach(_;0..m)\r\n\t{\r\n\t\tauto dragon = readln.split().to!(ulong[]);\r\n\t\tauto atack = heroes.find!((a,b) => a >= b)(dragon[0]);\r\n\t\tif (atack.empty)\r\n\t\t{\r\n\t\t\twriteln(dragon[0] - heroes.maxElement() + max(0, dragon[1] - heroes.sum() + heroes.maxElement));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tulong[] weak = heroes.find!((a,b) => a < b)(dragon[0]);\r\n\t\t\tulong atacker = atack.minElement();\r\n\t\t\tif (!weak.empty)\r\n\t\t\t{\r\n\t\t\t\tulong weaker = weak.maxElement();\r\n\t\t\t\tif (dragon[1] > heroes.sum() - weaker)\r\n\t\t\t\t\tif (dragon[1] > heroes.sum() - atacker)\r\n\t\t\t\t\t\twriteln(min(dragon[0] - weaker + dragon[1] - heroes.sum() + weaker, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\twriteln(min(dragon[0] - weaker + dragon[1] - heroes.sum() + weaker, 0));\r\n\t\t\t\telse\r\n\t\t\t\t\tif (dragon[1] > heroes.sum() - atacker)\r\n\t\t\t\t\t\twriteln(min(dragon[0] - weaker, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\twriteln(min(dragon[0] - weaker, 0));\r\n//\t\t\t\twriteln(min(dragon[0] - weaker + max(0, dragon[1] - heroes.sum() + weaker), max(0, dragon[1] - heroes.sum() + atacker)));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (dragon[1] > heroes.sum() - atacker)\r\n\t\t\t\t\twriteln(max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\telse\r\n\t\t\t\t\twriteln(0);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv;\r\n\r\nvoid main()\r\n{\r\n\tint n;\r\n\tscanf(\"%d\", &n);\r\n\tgetchar();\r\n\tauto heroes = readln.split().to!(long[]);\r\n\tint m;\r\n\tscanf(\"%d\", &m);\r\n\tgetchar();\r\n\theroes.sort();\r\n\tforeach(_;0..m)\r\n\t{\r\n\t\tauto dragon = readln.split().to!(long[]);\r\n\t\tauto atack = heroes.find!((a,b) => a >= b)(dragon[0]);\r\n\t\tif (atack.empty)\r\n\t\t{\r\n\t\t\twriteln(dragon[0] - heroes.maxElement() + max(0, dragon[1] - heroes.sum() + heroes.maxElement));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong[] weak = heroes.find!((a,b) => a < b)(dragon[0]);\r\n\t\t\tlong atacker = atack.minElement();\r\n\t\t\tif (!weak.empty)\r\n\t\t\t{\r\n\t\t\t\tlong weaker = weak.maxElement();\r\n\t\t\t\twriteln(min(dragon[0] - weaker + max(0, dragon[1] - heroes.sum() + weaker), max(0, dragon[1] - heroes.sum() + atacker)));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t\twriteln(max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv;\r\n\r\nvoid main()\r\n{\r\n\tint n;\r\n\tscanf(\"%d\", &n);\r\n\tgetchar();\r\n\tauto heroes = readln.split().to!(long[]);\r\n\tint m;\r\n\tscanf(\"%d\", &m);\r\n\tgetchar();\r\n\theroes.sort();\r\n\tforeach(_;0..m)\r\n\t{\r\n\t\tauto dragon = readln.split().to!(long[]);\r\n\t\tauto atack = heroes.find!((a,b) => a >= b)(dragon[0]);\r\n\t\tif (atack.empty)\r\n\t\t{\r\n\t\t\twriteln(dragon[0] - heroes.maxElement() + max(0, dragon[1] - heroes.sum() + heroes.maxElement));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong[] weak = heroes.find!((a,b) => a < b)(dragon[0]);\r\n\t\t\tlong atacker = atack.minElement();\r\n\t\t\tif (!weak.empty)\r\n\t\t\t{\r\n\t\t\t\tlong weaker = weak.maxElement();\r\n\t\t\t\tif (dragon[0] - weaker > atacker - dragon[0])\r\n\t\t\t\t\twriteln(max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\telse\r\n\t\t\t\t\twriteln(dragon[0] - weaker + max(0, dragon[1] - heroes.sum() + weaker));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t\twriteln(max(0, dragon[1] - heroes.sum()));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv;\r\n\r\nvoid main()\r\n{\r\n\tint n;\r\n\tscanf(\"%d\", &n);\r\n\tgetchar();\r\n\tauto heroes = readln.split().to!(long[]);\r\n\tint m;\r\n\tscanf(\"%d\", &m);\r\n\tgetchar();\r\n\theroes.sort();\r\n\tforeach(_;0..m)\r\n\t{\r\n\t\tauto dragon = readln.split().to!(long[]);\r\n\t\tauto atack = heroes.find!((a,b) => a >= b)(dragon[0]);\r\n\t\tif (atack.empty)\r\n\t\t{\r\n\t\t\twriteln(dragon[0] - heroes.maxElement() + max(0, dragon[1] - heroes.sum() + heroes.maxElement));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong[] weak = heroes.find!((a,b) => a < b)(dragon[0]);\r\n\t\t\tlong atacker = atack.minElement();\r\n\t\t\tif (!weak.empty)\r\n\t\t\t{\r\n\t\t\t\tlong weaker = weak.maxElement();\r\n\t\t\t\tif (dragon[0] - weaker > atacker - dragon[0])\r\n\t\t\t\t\twriteln(max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\telse\r\n\t\t\t\t\twriteln(dragon[0] - weaker + max(0, dragon[1] - heroes.sum() + weaker));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t\twriteln(max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.array, std.conv;\r\n\r\nvoid main()\r\n{\r\n\tint n;\r\n\tscanf(\"%d\", &n);\r\n\tgetchar();\r\n\tauto heroes = readln.split().to!(long[]);\r\n\tint m;\r\n\tscanf(\"%d\", &m);\r\n\tgetchar();\r\n\theroes.sort();\r\n\tforeach(_;0..m)\r\n\t{\r\n\t\tauto dragon = readln.split().to!(long[]);\r\n\t\tauto atack = heroes.find!((a,b) => a >= b)(dragon[0]);\r\n\t\tif (atack.empty)\r\n\t\t{\r\n\t\t\twriteln(dragon[0] - heroes.maxElement() + max(0, dragon[1] - heroes.sum() + heroes.maxElement));\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong[] weak = heroes.find!((a,b) => a < b)(dragon[0]);\r\n\t\t\tlong atacker = atack.minElement();\r\n\t\t\tif (!weak.empty)\r\n\t\t\t{\r\n\t\t\t\tlong weaker = weak.maxElement();\r\n\t\t\t\tif (dragon[0] - weaker > atacker - dragon[0])\r\n\t\t\t\t\twriteln(atacker - dragon[0] + max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\telse\r\n\t\t\t\t\twriteln(dragon[0] - weaker + max(0, dragon[1] - heroes.sum() + weaker));\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t\twriteln(atacker - dragon[0] + max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\t\tdebug{\r\n\t\t\t\t\t\twriteln(max(0, dragon[1] - heroes.sum() + atacker));\r\n\t\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"}], "src_uid": "8827e14bcba5689118f393442280d2ba"} {"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 m = next!int;\n struct VarDef\n {\n int varname;\n enum ExpType\n {\n\tvalue, and, or, xor\n }\n ExpType type;\n int v1 = -1, v2 = -1;\n string s1, s2;\n }\n auto vdefs = new VarDef[](n);\n int[string] indexof;\n int lastindex = 0;\n foreach(i; 0 .. n)\n {\n auto line = inputFile.readln;\n auto words = line.split;\n indexof[words[0]] = lastindex++;\n if (words.length == 5)\n\t{\n\t vdefs[i].varname = indexof[words[0]];\n\t \n\t if (words[2][0] == '0' || words[2][0] == '1') vdefs[i].s1 = words[2];\n\t else if (words[2][0] == '?') {}\n\t else vdefs[i].v1 = indexof[words[2]];\n\t \n\t final switch(words[3])\n\t {\n\t case \"AND\":\n\t vdefs[i].type = VarDef.ExpType.and;\n\t break;\n\t case \"XOR\":\n\t vdefs[i].type = VarDef.ExpType.xor;\n\t break;\n\t case \"OR\":\n\t vdefs[i].type = VarDef.ExpType.or;\n\t break;\n\t }\n\t if (words[4][0] == '0' || words[4][0] == '1') vdefs[i].s2 = words[4];\n\t else if (words[4][0] == '?') {}\n\t else vdefs[i].v2 = indexof[words[4]];\n\t \n\t}\n else\n\t{\n\t debug assert(words.length == 3);\n\t vdefs[i].varname = indexof[words[0]];\n\t vdefs[i].type = VarDef.ExpType.value;\n\t if (words[2][0] == '0' || words[2][0] == '1') vdefs[i].s1 = words[2];\n\t else if (words[2][0] == '?') {}\n\t else vdefs[i].v1 = indexof[words[2]];\n\t}\n }\n debug writeln(vdefs);\n int evalbit(int bitpos, int bitval)\n {\n int[] varval = new int[](n);\n int expval(int v, string exp)\n {\n if (v != -1) return varval[v];\n if (exp !is null) return cast(int)(exp[bitpos] - '0');\n return bitval;\n }\n void eval(VarDef vdef)\n {\n final switch(vdef.type)\n\t{\n\tcase VarDef.ExpType.value:\n\t varval[vdef.varname] = expval(vdef.v1, vdef.s1);\n\t break;\n\tcase VarDef.ExpType.and:\n\t varval[vdef.varname] = expval(vdef.v1, vdef.s1) & expval(vdef.v2, vdef.s2);\n\t break;\n\tcase VarDef.ExpType.xor:\n\t varval[vdef.varname] = expval(vdef.v1, vdef.s1) ^ expval(vdef.v2, vdef.s2);\n\t break;\n\tcase VarDef.ExpType.or:\n\t varval[vdef.varname] = expval(vdef.v1, vdef.s1) | expval(vdef.v2, vdef.s2);\n\t break;\n\t}\n }\n foreach(vdef; vdefs)\n eval(vdef);\n return cast(int)(varval.sum);\n }\n auto ansmax = new char[](m);\n auto ansmin = new char[](m);\n foreach(bitpos; 0 .. m)\n {\n ansmax[bitpos] = '0';\n ansmin[bitpos] = '0';\n auto r0 = evalbit(cast(int)bitpos, 0);\n auto r1 = evalbit(cast(int)bitpos, 1);\n if (r1 < r0)\n\tansmin[bitpos] = '1';\n if (r1 > r0)\n\tansmax[bitpos] = '1';\n }\n ansmin.idup.writeln;\n ansmax.idup.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;\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 int n;\n int m;\n while (readf (\" %s %s\", &n, &m) > 0)\n {\n readln;\n auto expr = new string [] [n];\n int [string] num;\n auto op1 = new int [n];\n auto op2 = new int [n];\n\n int operand (int i, string s)\n {\n if (s == \"?\")\n {\n return -1;\n }\n else if ('0' <= s[0] && s[0] <= '1')\n {\n return -2;\n }\n else\n {\n assert (s in num);\n return num[s];\n }\n }\n\n foreach (i; 0..n)\n {\n expr[i] = readln.split;\n num[expr[i][0]] = i;\n op1[i] = operand (i, expr[i][2]);\n if (expr[i].length == 3)\n {\n continue;\n }\n op2[i] = operand (i, expr[i][4]);\n }\n\n int calc (int j, int b)\n {\n auto v = new int [n];\n\n int value (int i, int k, int cur)\n {\n if (cur == -1)\n {\n return b;\n }\n if (cur == -2)\n {\n return expr[i][k][j] - '0';\n }\n assert (cur < i);\n return v[cur];\n }\n\n foreach (i; 0..n)\n {\n v[i] = value (i, 2, op1[i]);\n if (expr[i].length == 5)\n {\n if (expr[i][3] == \"OR\")\n {\n v[i] |= value (i, 4, op2[i]);\n }\n if (expr[i][3] == \"XOR\")\n {\n v[i] ^= value (i, 4, op2[i]);\n }\n if (expr[i][3] == \"AND\")\n {\n v[i] &= value (i, 4, op2[i]);\n }\n }\n }\n\n return sum (v);\n }\n\n string resMin;\n string resMax;\n foreach (j; 0..m)\n {\n int u = calc (j, 0);\n int v = calc (j, 1);\n if (u == v)\n {\n resMin ~= '0';\n resMax ~= '0';\n }\n if (u > v)\n {\n resMin ~= '1';\n resMax ~= '0';\n }\n if (u < v)\n {\n resMin ~= '0';\n resMax ~= '1';\n }\n }\n writeln (resMin);\n writeln (resMax);\n }\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;\n\tint m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\treadln;\n\t\tauto expr = new string [] [n];\n\t\tint [string] num;\n\t\tauto op1 = new int [n];\n\t\tauto op2 = new int [n];\n\n\t\tint operand (int i, string s)\n\t\t{\n\t\t\tif (s == \"?\")\n\t\t\t{\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\telse if ('0' <= s[0] && s[0] <= '1')\n\t\t\t{\n\t\t\t\treturn -2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (s in num);\n\t\t\t\treturn num[s];\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\texpr[i] = readln.split;\n\t\t\tnum[expr[i][0]] = i;\n\t\t\top1[i] = operand (i, expr[i][2]);\n\t\t\tif (expr[i].length == 3)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\top2[i] = operand (i, expr[i][4]);\n\t\t}\n\n\t\tint calc (int j, int b)\n\t\t{\n\t\t\tauto v = new int [n];\n\n\t\t\tint value (int i, int k, int cur)\n\t\t\t{\n\t\t\t\tif (cur == -1)\n\t\t\t\t{\n\t\t\t\t\treturn b;\n\t\t\t\t}\n\t\t\t\tif (cur == -2)\n\t\t\t\t{\n\t\t\t\t\treturn expr[i][k][j] - '0';\n\t\t\t\t}\n\t\t\t\tassert (cur < i);\n\t\t\t\treturn v[cur];\n\t\t\t}\n\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tv[i] = value (i, 2, op1[i]);\n\t\t\t\tif (expr[i].length == 5)\n\t\t\t\t{\n\t\t\t\t\tif (expr[i][3] == \"OR\")\n\t\t\t\t\t{\n\t\t\t\t\t\tv[i] |= value (i, 4, op2[i]);\n\t\t\t\t\t}\n\t\t\t\t\tif (expr[i][3] == \"XOR\")\n\t\t\t\t\t{\n\t\t\t\t\t\tv[i] ^= value (i, 4, op2[i]);\n\t\t\t\t\t}\n\t\t\t\t\tif (expr[i][3] == \"AND\")\n\t\t\t\t\t{\n\t\t\t\t\t\tv[i] &= value (i, 4, op2[i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn sum (v);\n\t\t}\n\n\t\tstring resMin;\n\t\tstring resMax;\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u = calc (j, 0);\n\t\t\tint v = calc (j, 1);\n\t\t\tif (u == v)\n\t\t\t{\n\t\t\t\tresMin ~= '0';\n\t\t\t\tresMax ~= '0';\n\t\t\t}\n\t\t\tif (u > v)\n\t\t\t{\n\t\t\t\tresMin ~= '1';\n\t\t\t\tresMax ~= '0';\n\t\t\t}\n\t\t\tif (u < v)\n\t\t\t{\n\t\t\t\tresMin ~= '0';\n\t\t\t\tresMax ~= '1';\n\t\t\t}\n\t\t}\n\t\twriteln (resMin);\n\t\twriteln (resMax);\n\t}\n}\n"}], "negative_code": [], "src_uid": "318295e4c986a920c57bfc8a2a7860ed"} {"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\tauto a = new int [] [n];\n\t\tauto d = 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\n\t\tint root = 0;\n\t\twhile (d[root] != 1)\n\t\t{\n\t\t\troot += 1;\n\t\t}\n\n\t\tauto depth = new int [n];\n\n\t\tvoid recur (int v, int p)\n\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\tdepth[u] = depth[v] + 1;\n\t\t\t\t\trecur (u, v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdepth[root] = 0;\n\t\trecur (root, -1);\n\n\t\tint res = n - 1;\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\tauto numLeaves = a[v].count !(u => d[u] == 1);\n\t\t\tif (numLeaves > 1)\n\t\t\t{\n\t\t\t\tres -= numLeaves - 1;\n\t\t\t}\n\t\t}\n\t\tauto haveOdd = n.iota\n\t\t .filter !(v => d[v] == 1)\n\t\t .map !(v => depth[v])\n\t\t .any !(x => x % 2 != 0);\n\t\twriteln (haveOdd ? 3 : 1, \" \", 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;\nint[] A, B;\n\nint[][] G;\nint[] dep;\n\nvoid dfs(int u, int p) {\n dep[u] = (p == -1) ? 0 : (dep[p] + 1);\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ 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 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 int rt = -1;\n foreach (u; 0 .. N) {\n if (G[u].length == 1) {\n rt = u;\n break;\n }\n }\n dep = new int[N];\n dfs(rt, -1);\n \n int ansMin = 1;\n foreach (u; 0 .. N) {\n if (G[u].length == 1) {\n if (dep[u] % 2 != 0) {\n ansMin = 3;\n }\n }\n }\n \n int ansMax;\n auto used = new bool[N];\n foreach (i; 0 .. N - 1) {\n if (G[A[i]].length == 1) {\n used[B[i]] = true;\n } else if (G[B[i]].length == 1) {\n used[A[i]] = true;\n } else {\n ++ansMax;\n }\n }\n foreach (u; 0 .. N) {\n if (used[u]) {\n ++ansMax;\n }\n }\n \n writeln(ansMin, \" \", ansMax);\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) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto edges = new int[][](n);\n\tforeach (i; 0..n-1)\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\tdebug writeln(edges);\n\n\tbool odds;\n\t{\n\t\tint[][] open;\n\t\tauto dist = new int[](n);\n\t\tdist[] = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (edges[i].length == 1)\n\t\t\t{\n\t\t\t\topen ~= [i, -1];\n\t\t\t\tdist[i] = 0;\n\t\t\t}\n\t\t}\n\t\t\n\t\t(){\n\t\twhile (!open.empty)\n\t\t{\n\t\t\tauto nd = open.front; open.popFront;\n\t\t\tauto from = nd[0];\n\t\t\tauto par = nd[1];\n\t\t\tauto d = dist[from]^1;\n\t\t\tforeach (to; edges[from])\n\t\t\t{\n\t\t\t\tif (to == par) continue;\n\t\t\t\tif (dist[to] == -1)\n\t\t\t\t{\n\t\t\t\t\tdist[to] = d;\n\t\t\t\t\topen ~= [to, from];\n\t\t\t\t}\n\t\t\t\telse if (dist[to] != d)\n\t\t\t\t{\n\t\t\t\t\todds = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}}();\n\t}\n\n\tlong cnt;\n\t{\n\t\tint[][] open;\n\t\tauto dist = new int[](n);\n\t\tdist[] = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (edges[i].length == 1)\n\t\t\t{\n\t\t\t\topen ~= [i, -1];\n\t\t\t\tdist[i] = 0;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"open:\", open);\n\t\tforeach (e; open)\n\t\t{\n\t\t\tint[][] op = [e];\n\t\t\twhile (!op.empty)\n\t\t\t{\n\t\t\t\tauto nd = op.front; op.popFront;\n\t\t\t\tauto from = nd[0];\n\t\t\t\tauto par = nd[1];\n\t\t\t\tauto d = dist[from]+1;\n\t\t\t\tif (d == 3) continue;\n\t\t\t\tforeach (to; edges[from])\n\t\t\t\t{\n\t\t\t\t\tif (to == par) continue;\n\t\t\t\t\tif (dist[to] == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tdebug writeln(from, \":\", to);\n\t\t\t\t\t}\n\t\t\t\t\telse if (dist[to] == -1 && d != 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[to] = d;\n\t\t\t\t\t\top ~= [to, from];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tdebug writeln(\"cnt:\", cnt);\n\n\tlong ans1 = odds ? 3 : 1;\n\tlong ans2 = n-1-cnt;\n\twriteln(ans1, \" \", ans2);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "e65b974a85067500f20b316275dc5821"} {"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 !(long)).array;\r\n\r\n\t\tlong p = 1;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\twhile (c % 2 == 0)\r\n\t\t\t{\r\n\t\t\t\tc /= 2;\r\n\t\t\t\tp *= 2;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tsort (a);\r\n\t\ta.back *= p;\r\n\t\twriteln (a.sum);\r\n\t}\r\n}\r\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!int);\n long maxA = long.min;\n long sumA = 0;\n auto powers = 0;\n foreach(ref ai; a)\n {\n while ((ai & 1) == 0)\n\t{\n\t powers++;\n\t ai >>= 1;\n\t}\n sumA += ai;\n maxA = max(maxA, ai);\n }\n long power = (1L << powers);\n long ans = power * (cast(long)maxA) + (sumA - maxA);\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 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 mulcnt = 0;\n long sum = 0;\n foreach (ref x ; a) {\n while (x % 2 == 0) {\n mulcnt++;\n x /= 2;\n }\n sum += x;\n }\n a.sort;\n sum -= a.back;\n while (mulcnt-- > 0) {\n a.back *= 2;\n }\n sum += a.back;\n writeln(sum);\n }\n}\n"}], "negative_code": [], "src_uid": "f5de1e9b059bddf8f8dd46c18ce12683"} {"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 maxN = 200_000;\nint[maxN] parent = -1;\nint[maxN] setSize = 0;\nvoid makeSet(int i)\n{\n assert(parent[i] == -1);\n parent[i] = i;\n setSize[i] = 1;\n}\nint findParent(int i)\n{\n auto pi = parent[i];\n if (pi == -1 || pi == i) return pi;\n return parent[i] = findParent(pi);\n}\nint join(int i, int j)\n{\n assert(findParent(i) != -1);\n assert(findParent(j) != -1);\n i = findParent(i);\n j = findParent(j);\n if (setSize[i] < setSize[j]) swap(i, j);\n parent[j] = i;\n setSize[i] += setSize[j];\n return i;\n}\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto a = next!int(n);\n auto sortedIndices = iota(0, n).array.sort!((i, j) => a[i] > a[j]);\n auto sol = new int[](n + 1);\n int soli = 1;\n int mx = 1;\n foreach(i; sortedIndices)\n {\n makeSet(i);\n if (i + 1 < n && parent[i + 1] != -1)\n\tmx = max(setSize[join(i, i + 1)], mx);\n if (i - 1 >= 0 && parent[i - 1] != -1)\n\tmx = max(setSize[join(i, i - 1)], mx);\n for(; soli <= mx; soli++)\n\tsol[soli] = a[i];\n }\n println(sol[1 .. $]);\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, std.conv, std.range, std.stdio, std.string; \nvoid main ()\n{\n int n;\n while (readf (\" %s \", &n) > 0)\n {\n auto a = readln.split.map !(to !(int)).array;\n auto p = n.iota.array;\n auto prev = (n + 2).iota.array;\n auto next = prev.dup;\n --prev[];\n ++next[];\n p.sort !((x, y) => a[x] > a[y]);\n ++p[];\n auto ans = new int [n];\n int v = 0;\n foreach (x; p)\n {\n prev[next[x]] = prev[x];\n next[prev[x]] = next[x];\n while (v < next[x] - prev[x] - 1)\n {\n ans[v] = a[x - 1];\n v++;\n }\n }\n writefln (\"%(%s %)\", ans);\n }\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.range;\nimport std.array;\nimport std.conv;\nimport std.complex;\nimport std.math;\nimport std.ascii;\nimport std.bigint;\nimport std.container;\nimport std.typecons;\n\nauto readInt() {\n\treturn readInts()[0];\n}\nauto readInts() {\n\treturn array(map!(to!int)(readln().strip().split()));\n}\nauto readLong() { \n\treturn readLongs()[0];\n}\nauto readLongs() {\n\treturn array(map!(to!long)(readln().strip().split()));\n}\n\nvoid main() {\n\tauto n = readInt();\n\tauto a = readLongs();\n\tauto arev = a.dup;\n\tarev.reverse;\n\ta = -1 ~ a;\n\tarev = -1 ~ arev;\n\tint[] s = [0];\n\tauto t = new int[](n);\n\tauto u = new int[](n);\n\tforeach(i; 0..n) {\n\t\twhile(!(a[s[$-1]] < a[i+1])) {\n\t\t\ts = s[0..$-1];\n\t\t}\n\t\tt[i] = i-s[$-1];\n\t\ts ~= i+1;\n\t}\n\ts = [0];\n\tforeach(i; 0..n) {\n\t\twhile(!(arev[s[$-1]] < arev[i+1])) {\n\t\t\ts = s[0..$-1];\n\t\t}\n\t\tu[n-i-1] = i-s[$-1];\n\t\ts ~= i+1;\n\t}\n\tauto si = new long[](n);\n\tforeach(i; 0..n) {\n\t\tauto l = t[i]+u[i]+1;\n\t\tsi[l-1] = max(si[l-1], a[i+1]);\n\t}\n\tforeach_reverse(i; 0..n-1) {\n\t\tsi[i] = max(si[i+1], si[i]);\n\t}\n\tforeach(i; 0..n) {\n\t\twriteln(si[i]);\n\t}\n}\n\n\n\n\n\n\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main ()\n{\n int n;\n while (readf (\" %s \", &n) > 0)\n {\n auto a = readln.split.map !(to !(int)).array;\n auto p = n.iota.array;\n auto prev = (n + 2).iota.array;\n auto next = prev.dup;\n --prev[];\n ++next[];\n p.sort !((x, y) => a[x] > a[y]);\n ++p[];\n auto ans = new int [n];\n int v = 0;\n foreach (x; p)\n {\n prev[next[x]] = prev[x];\n next[prev[x]] = next[x];\n while (v < next[x] - prev[x] - 1)\n {\n ans[v] = a[x - 1];\n v++;\n }\n }\n writefln (\"%(%s %)\", ans);\n }\n}"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\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\tauto p = n.iota.array;\n\t\tauto prev = (n + 2).iota.array;\n\t\tauto next = prev.dup;\n\t\t--prev[];\n\t\t++next[];\n\t\tp.sort !((x, y) => a[x] > a[y]);\n\t\t++p[];\n\t\tauto ans = new int [n];\n\t\tint v = 0;\n\t\tforeach (x; p)\n\t\t{\n\t\t\tprev[next[x]] = prev[x];\n\t\t\tnext[prev[x]] = next[x];\n\t\t\twhile (v < next[x] - prev[x] - 1)\n\t\t\t{\n\t\t\t\tans[v] = a[x - 1];\n\t\t\t\tv++;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\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 a = readln.split.map !(to !(int)).array;\n\t\tauto p = n.iota.array;\n\t\tauto prev = (n + 2).iota.array;\n\t\tprev[] -= 1;\n\t\tauto next = (n + 2).iota.array;\n\t\tnext[] += 1;\n\t\tsort !((x, y) => a[x] > a[y], SwapStrategy.stable) (p);\n\t\tp[] += 1;\n\t\tauto ans = new int [n];\n\t\tint v = 0;\n\t\tforeach (x; p)\n\t\t{\n\t\t\tprev[next[x]] = prev[x];\n\t\t\tnext[prev[x]] = next[x];\n\t\t\tint u = next[x] - prev[x] - 1;\n\t\t\twhile (v < u)\n\t\t\t{\n\t\t\t\tans[v] = a[x - 1];\n\t\t\t\tv++;\n\t\t\t}\n\t\t}\n\n\t\tans.map !(text).join (\" \").writeln;\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\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\tauto p = n.iota.array;\n\t\tauto prev = (n + 2).iota.array;\n\t\tauto next = prev.dup;\n\t\t++prev[];\n\t\t--next[];\n\t\tp.sort !((x, y) => a[x] > a[y]);\n\t\t++p[];\n\t\tauto ans = new int [n];\n\t\tint v = 0;\n\t\tforeach (x; p)\n\t\t{\n\t\t\tprev[next[x]] = prev[x];\n\t\t\tnext[prev[x]] = next[x];\n\t\t\twhile (v < next[x] - prev[x] - 1)\n\t\t\t{\n\t\t\t\tans[v] = a[x - 1];\n\t\t\t\tv++;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "src_uid": "5cf25cd4a02ce8020258115639c0ee64"} {"source_code": "import std.stdio;\r\nimport std.math;\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\nalias S = Tuple!(int, \"y\", int, \"x\", int, \"c\");\r\n\r\nvoid solve() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto F = N.iota.map!(_ => readln.chomp.split(\" \").map!(to!int).array).array;\r\n\r\n bool C() {\r\n if ( (N + M - 1) % 2 == 1 ) return false;\r\n auto f = new int[][][](2, N, M);\r\n foreach (i; 0 .. N) {\r\n f[0][i][] = int.min;\r\n f[1][i][] = int.max;\r\n }\r\n f[0][0][0] = F[0][0];\r\n f[1][0][0] = F[0][0];\r\n for (int i = 0; i < N; i++) {\r\n for (int j = 0; j < M; j++) {\r\n if (i + 1 < N) {\r\n f[0][i+1][j] = max(f[0][i+1][j], f[0][i][j] + F[i+1][j]);\r\n f[1][i+1][j] = min(f[0][i+1][j], f[1][i][j] + F[i+1][j]);\r\n }\r\n if (j + 1 < M) {\r\n f[0][i][j+1] = max(f[0][i][j+1], f[0][i][j] + F[i][j+1]);\r\n f[1][i][j+1] = min(f[1][i][j+1], f[1][i][j] + F[i][j+1]);\r\n }\r\n }\r\n }\r\n return f[1][N-1][M-1] <= 0 && 0 <= f[0][N-1][M-1];\r\n }\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": "// cheese-cracker [2022-07-01]\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n long[][] arr;\n auto dp = new long[][](n, m);\n for(int i = 0; i < n; ++i){\n arr ~= scanArray;\n }\n long num = n + m - 1;\n if(num % 2){\n writeln(\"NO\");\n return;\n }\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n if(i > 0 && j > 0){\n dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + arr[i][j];\n }else if(i > 0){\n dp[i][j] = dp[i-1][j] + arr[i][j];\n }else if(j > 0){\n dp[i][j] = dp[i][j-1] + arr[i][j];\n }else{\n dp[i][j] = arr[i][j];\n }\n }\n }\n /* show(dp); */\n long maxx = dp[n-1][m-1];\n for(int i = 0; i < n; ++i){\n dp[i][] = 0;\n }\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n if(i > 0 && j > 0){\n dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + arr[i][j];\n }else if(i > 0){\n dp[i][j] = dp[i-1][j] + arr[i][j];\n }else if(j > 0){\n dp[i][j] = dp[i][j-1] + arr[i][j];\n }else{\n dp[i][j] = arr[i][j];\n }\n }\n }\n /* show(dp); */\n long minn = dp[n-1][m-1];\n show(minn, maxx);\n assert(minn <= maxx);\n if(minn <= 0 && maxx >= 0){\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": [{"source_code": "import std.stdio;\r\nimport std.math;\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\nalias S = Tuple!(int, \"y\", int, \"x\", int, \"c\");\r\n\r\nvoid solve() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto F = N.iota.map!(_ => readln.chomp.split(\" \").map!(to!int).array).array;\r\n\r\n bool C() {\r\n if ( (N + M - 1) % 2 == 1 ) return false;\r\n auto f = new int[][][](2, N, M);\r\n f[0][0][0] = F[0][0];\r\n f[1][0][0] = F[0][0];\r\n for (int i = 0; i < N; i++) {\r\n for (int j = 0; j < M; j++) {\r\n if (i + 1 < N) {\r\n f[0][i+1][j] = max(f[0][i+1][j], f[0][i][j] + F[i+1][j]);\r\n f[1][i+1][j] = min(f[0][i+1][j], f[1][i][j] + F[i+1][j]);\r\n }\r\n if (j + 1 < M) {\r\n f[0][i][j+1] = max(f[0][i][j+1], f[0][i][j] + F[i][j+1]);\r\n f[1][i][j+1] = min(f[1][i][j+1], f[1][i][j] + F[i][j+1]);\r\n }\r\n }\r\n }\r\n return f[0][N-1][M-1] <= 0 && 0 <= f[1][N-1][M-1];\r\n }\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": "// cheese-cracker [2022-07-01]\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n long[][] arr;\n auto dp = new long[][](n, m);\n for(int i = 0; i < n; ++i){\n auto ray = scanArray;\n arr ~= ray;\n }\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n if(i > 0 && j > 0){\n dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + arr[i][j];\n }else if(i > 0){\n dp[i][j] = dp[i-1][j] + arr[i][j];\n }else if(j > 0){\n dp[i][j] = dp[i][j-1] + arr[i][j];\n }else{\n dp[i][j] = arr[i][j];\n }\n }\n }\n show(dp);\n long maxx = dp[n-1][m-1];\n for(int i = 0; i < n; ++i){\n dp[i][] = 0;\n }\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n if(i > 0 && j > 0){\n dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + arr[i][j];\n }else if(i > 0){\n dp[i][j] = dp[i-1][j] + arr[i][j];\n }else if(j > 0){\n dp[i][j] = dp[i][j-1] + arr[i][j];\n }else{\n dp[i][j] = arr[i][j];\n }\n }\n }\n show(dp);\n long minn = dp[n-1][m-1];\n show(minn, maxx);\n assert(minn <= maxx);\n if(minn <= 0 && maxx >= 0){\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"}, {"source_code": "// cheese-cracker [2022-07-01]\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n long[][] arr;\n auto dp = new long[][](n, m);\n for(int i = 0; i < n; ++i){\n auto ray = scanArray;\n arr ~= ray;\n }\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n if(i > 0 && j > 0){\n dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + arr[i][j];\n }else if(i > 0){\n dp[i][j] = dp[i-1][j] + arr[i][j];\n }else if(j > 0){\n dp[i][j] = dp[i][j-1] + arr[i][j];\n }else{\n dp[i][j] = arr[i][j];\n }\n }\n }\n show(dp);\n long maxx = dp[n-1][m-1];\n /* for(int i = 0; i < n; ++i){ */\n /* dp[i][] = 0; */\n /* } */\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n if(i > 0 && j > 0){\n dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + arr[i][j];\n }else if(i > 0){\n dp[i][j] = dp[i-1][j] + arr[i][j];\n }else if(j > 0){\n dp[i][j] = dp[i][j-1] + arr[i][j];\n }else{\n dp[i][j] = arr[i][j];\n }\n }\n }\n show(dp);\n long minn = dp[n-1][m-1];\n show(minn, maxx);\n assert(minn <= maxx);\n if(minn <= 0 && maxx >= 0){\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"}, {"source_code": "// cheese-cracker [2022-07-01]\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n long[][] arr;\n auto dp = new long[][](n, m);\n for(int i = 0; i < n; ++i){\n auto ray = scanArray;\n arr ~= ray;\n }\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n if(i > 0 && j > 0){\n dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + arr[i][j];\n }else if(i > 0){\n dp[i][j] = dp[i-1][j] + arr[i][j];\n }else if(j > 0){\n dp[i][j] = dp[i][j-1] + arr[i][j];\n }else{\n dp[i][j] = arr[i][j];\n }\n }\n }\n /* show(dp); */\n long maxx = dp[n-1][m-1];\n for(int i = 0; i < n; ++i){\n for(int j = 0; j < m; ++j){\n if(i > 0 && j > 0){\n dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + arr[i][j];\n }else if(i > 0){\n dp[i][j] = dp[i-1][j] + arr[i][j];\n }else if(j > 0){\n dp[i][j] = dp[i][j-1] + arr[i][j];\n }else{\n dp[i][j] = arr[i][j];\n }\n }\n }\n /* show(dp); */\n long minn = dp[n-1][m-1];\n show(maxx, minn);\n if(minn <= 0 && maxx >= 0){\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"}], "src_uid": "7d6d1c5af6e3faefe67f585a5130d6bd"} {"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 s = RD!string;\n\tlong ans = 1;\n\tint cnt;\n\tchar last = '?';\n\tauto fib = new long[](10^^5+1);\n\tfib[0] = 1;\n\tfib[1] = 1;\n\tforeach (i; 2..fib.length)\n\t{\n\t\tfib[i] = fib[i-1];\n\t\tfib[i].moda(fib[i-2]);\n\t}\n\tforeach (c; s)\n\t{\n\t\tif (c == 'w' || c == 'm')\n\t\t{\n\t\t\tans = 0;\n\t\t\tbreak;\n\t\t}\n\t\t\n\t\tif (c == last)\n\t\t\t++cnt;\n\t\telse\n\t\t{\n\t\t\tans.modm(fib[cnt]);\n\t\t\tlast = '?';\n\t\t\tcnt = 0;\n\t\t\tif (c == 'u' || c == 'n')\n\t\t\t{\n\t\t\t\tlast = c;\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t}\n\t}\n\tif (cnt != 0)\n\t{\n\t\tans.modm(fib[cnt]);\n\t}\n\n\twriteln(ans);\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\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto S = readln.chomp;\n auto N = S.length.to!int;\n\n if (S.canFind('m') || S.canFind('w')) {\n writeln(0);\n return;\n }\n\n auto dp = new long[][](N+1, 2);\n dp[0][1] = 1;\n\n foreach (i; 0..N) {\n (dp[i+1][0] += dp[i][0] + dp[i][1]) %= MOD;\n (dp[i+1][1] += dp[i][0]) %= MOD;\n }\n\n long ans = 1;\n char prev = '*';\n int tmp = 0;\n\n foreach (i; 0..N) {\n if (S[i] == prev) {\n tmp += 1;\n continue;\n }\n if (prev == 'n' || prev == 'u') {\n ans = ans * (dp[tmp].sum % MOD) % MOD;\n }\n prev = S[i];\n tmp = 1;\n }\n\n if (S.back == 'n' || S.back == 'u') {\n ans = ans * (dp[tmp].sum % MOD) % MOD;\n }\n\n ans.writeln;\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\nstruct IntM(int q = 1_000_000_007) {\n alias N = IntM!q;\n private:\n int v;\n invariant () { assert (v >= 0 && v < q); }\n pure nothrow @nogc\n void fromInt (int m) {\n v = m % q;\n if (v < 0) {\n v += q;\n }\n }\n public:\n pure nothrow @nogc\n this (int m) {\n fromInt (m);\n }\n pure nothrow @nogc\n N opAssign (int m) {\n fromInt (m);\n return this;\n }\n pure nothrow @nogc\n N opUnary (string op : \"-\")() const {\n return N (-v);\n }\n pure nothrow @nogc\n ref N opUnary (string op : \"++\")() {\n if (++v >= q) {\n v -= q;\n }\n return this;\n }\n pure nothrow @nogc\n ref N opUnary (string op : \"--\")() {\n if (--v < 0) {\n v += q;\n }\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"+\")(in N rhs) {\n v = (v + rhs.v) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"-\")(in N rhs) {\n v = (v - rhs.v + q) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"*\")(in N rhs) {\n v = (v.to!(long) * rhs.v) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"/\")(in N rhs) {\n return this *= rhs.inversion ();\n }\n pure nothrow @nogc\n ref N opOpAssign (string op)(in int rhs) if (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\") {\n mixin (\"return this \" ~ op ~ \"= N(rhs);\");\n }\n pure nothrow @nogc\n N opBinary (string op)(in N rhs) const if (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\") {\n N t = this;\n mixin (\"t \" ~ op ~ \"= rhs;\");\n return t;\n }\n pure nothrow @nogc\n N opBinary (string op)(in int rhs) const if (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\") {\n mixin (\"return this \" ~ op ~ \" N(rhs);\");\n }\n pure nothrow @nogc\n N opBinaryRight (string op)(in int rhs) const if (op == \"+\" || op == \"*\") {\n mixin (\"return this \" ~ op ~ \" N(rhs);\");\n }\n pure nothrow @nogc\n int opCast(T : int)() const { return v; }\n pure nothrow @nogc\n int opCmp (const N rhs) const {\n if (v < rhs.v) {\n return -1;\n }\n if (v > rhs.v) {\n return 1;\n }\n return 0;\n }\n pure nothrow\n string toString() const { return v.text; }\n //a ^ x = this (mod q)\n}\nalias N = IntM!1_000_000_007;\n\nvoid main() {\n auto s = readln.strip;\n debug stderr.writeln (s);\n immutable n = s.length;\n debug stderr.writeln (n);\n auto d = new N[n+1];\n d[n] = N (1);\n bool sol = true;\n foreach_reverse (i; 0 .. n) {\n d[i] = d[i+1];\n if (i + 1 < n && s[i] == s[i+1] && (s[i] == 'u' || s[i] == 'n')) {\n d[i] += d[i + 2];\n }\n if (s[i] == 'm' || s[i] == 'w') {\n sol = false;\n }\n }\n debug stderr.writeln (d);\n if (!sol) {\n d[0] = N (0);\n }\n writeln (d[0]);\n}\n\n"}], "negative_code": [], "src_uid": "12c223c903544899638e47bcab88999a"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m; rd(n, m);\n auto x=readln.split.to!(long[]);\n auto y=readln.split.to!(long[]);\n\n int cnt=0;\n for(int i=0, j=0, sx=0, sy=0; i= hedef )\n\t\t{\n\t\t\tif ( küçükDizi.empty() || büyükDizi.empty() ) \n\t\t\t{\n\t\t\t\tkacKere++;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\tif ( toplam > hedef)\n\t\t\t\t\tküçükDizi.front() = toplam - hedef;\n\t\t\t\telse\n\t\t\t\t\tkacKere++;\n\n\t\t\t\tif( küçükDizi.front > büyükDizi.front ) \n\t\t\t\t\tIsle(büyükDizi, küçükDizi, kacKere);\n\t\t\t\telse \n\t\t\t\t\tIsle(küçükDizi, büyükDizi, kacKere);\t\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t}\n} \n\n\nint main(string[] argv)\n{\n\tauto girişDizisi = stdin.readln.to!dstring.chomp.split.map!( a => to!int(a) );\n\tauto ilkDizi = stdin.readln.to!dstring.chomp.split.map!( a => to!int(a) ).array;\n\tauto ikinciDizi = stdin.readln.to!dstring.chomp.split.map!( a => to!int(a) ).array;\n\tint sonuç = 0;\n\tif( ilkDizi.front > ikinciDizi.front ) \n\t\tIsle(ikinciDizi, ilkDizi, sonuç);\n\telse \n\t\tIsle(ilkDizi, ikinciDizi, sonuç);\t\n\twriteln(sonuç);\n return 0;\n}\n"}, {"source_code": "import\n\t\tstd.conv,\n\t\tstd.file,\n\t\tstd.array,\n\t\tstd.stdio,\n\t\tstd.string,\n\t\tstd.algorithm;\n\n\nvoid main()\n{\n\treadln;\n\n\tauto a = readln.splitter.map!(to!uint).array;\n\tauto b = readln.splitter.map!(to!uint).array;\n\n\tuint cnt;\n\n\twhile(a.length)\n\t{\n\t\tuint u = a[0], v = b[0];\n\n\t\ta.popFront;\n\t\tb.popFront;\n\n\t\twhile(true)\n\t\t{\n\t\t\tif(u == v)\n\t\t\t{\n\t\t\t\tcnt++;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(u > v)\n\t\t\t{\n\t\t\t\tv += b[0];\n\t\t\t\tb.popFront;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tu += a[0];\n\t\t\t\ta.popFront;\n\t\t\t}\n\t\t}\n\t}\n\n\tcnt.writeln;\n}\n"}], "negative_code": [{"source_code": "import\n\t\tstd.conv,\n\t\tstd.file,\n\t\tstd.array,\n\t\tstd.stdio,\n\t\tstd.string,\n\t\tstd.algorithm;\n\n\nvoid main()\n{\n\treadln;\n\n\tauto a = readln.splitter.map!(to!uint).array;\n\tauto b = readln.splitter.map!(to!uint).array;\n\n\tuint cnt;\n\n\twhile(a.length)\n\t{\n\t\tuint u = a[0], v = b[0];\n\n\t\ta.popFront;\n\t\tb.popFront;\n\n\t\twhile(true)\n\t\t{\n\t\t\ta.writeln;\n\t\t\tb.writeln;\n\n\t\t\tif(u == v)\n\t\t\t{\n\t\t\t\tcnt++;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif(u > v)\n\t\t\t{\n\t\t\t\tv += b[0];\n\t\t\t\tb.popFront;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tu += a[0];\n\t\t\t\ta.popFront;\n\t\t\t}\n\t\t}\n\t}\n\n\tcnt.writeln;\n}\n"}], "src_uid": "cb5cbfb4d184cda21ebfbcf47bb970dc"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto arr = iota(1L, n+1L).array;\n long a = scan;\n long b = scan;\n if(abs(a - b) > 1 || a + b > n - 2){\n writeln(-1);\n return;\n }\n long swp = max(a, b);\n if(a > b){\n arr.reverse;\n }\n for(int i = 0; i+1 < n; i += 2){\n if(!swp){\n break;\n }\n swap(arr[i], arr[i+1]);\n --swp;\n }\n long ac = 0, bc = 0;\n for(int i = 1; i < n-1; ++i){\n if(arr[i] > arr[i-1] && arr[i] > arr[i+1]){\n ++ac;\n }else if( arr[i] < arr[i-1] && arr[i] < arr[i+1]){\n ++bc;\n }\n }\n if(ac == a && bc == b){\n for(int i = 0; i < n; ++i){\n write(arr[i], \" \");\n }\n writeln;\n return;\n }else if (ac == a || bc == b){\n swap(arr[n-1], arr[n-2]);\n ac = 0; bc = 0;\n for(int i = 1; i < n-1; ++i){\n if(arr[i] > arr[i-1] && arr[i] > arr[i+1]){\n ++ac;\n }else if( arr[i] < arr[i-1] && arr[i] < arr[i+1]){\n ++bc;\n }\n }\n }\n if(ac == a && bc == b){\n for(int i = 0; i < n; ++i){\n write(arr[i], \" \");\n }\n writeln;\n }else{\n show(arr);\n writeln(-1);\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.algorithm;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint [] solve (int n, int a, int b)\r\n{\r\n\tif (abs (a - b) > 1)\r\n\t{\r\n\t\treturn [-1];\r\n\t}\r\n\tif (a + b > n - 2)\r\n\t{\r\n\t\treturn [-1];\r\n\t}\r\n\tif (a > b)\r\n\t{\r\n\t\treturn solve (n, b, a).map !(x => n + 1 - x).array;\r\n\t}\r\n\tauto res = new int [n];\r\n\tint lo = 1;\r\n\tint hi = n;\r\n\tint pos = 0;\r\n\tif (b > a)\r\n\t{\r\n\t\tres[pos++] = hi--;\r\n\t\tres[pos++] = lo++;\r\n\t\tb -= 1;\r\n\t}\r\n\telse\r\n\t{\r\n\t\tres[pos++] = lo++;\r\n\t}\r\n\twhile (a > 0 && b > 0)\r\n\t{\r\n\t\tres[pos++] = hi--;\r\n\t\ta -= 1;\r\n\t\tres[pos++] = lo++;\r\n\t\tb -= 1;\r\n\t}\r\n\twhile (pos < n)\r\n\t{\r\n\t\tres[pos++] = lo++;\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, a, b;\r\n\t\treadf !(\" %s %s %s\") (n, a, b);\r\n\t\twritefln !(\"%(%s %)\") (solve (n, a, b));\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto arr = iota(1L, n+1L).array;\n long a = scan;\n long b = scan;\n if(abs(a - b) > 1){\n writeln(-1);\n return;\n }\n int st = (a > b);\n long swp = max(a, b);\n for(int i = st; i+1 < n; i += 2){\n if(!swp){\n break;\n }\n swap(arr[i], arr[i+1]);\n --swp;\n }\n if(swp > 0){\n writeln(-1);\n return;\n }\n long ac = 0, bc = 0;\n for(int i = 1; i < n-1; ++i){\n if(arr[i] > arr[i-1] && arr[i] > arr[i+1]){\n ++ac;\n }else if( arr[i] < arr[i-1] && arr[i] < arr[i+1]){\n ++bc;\n }\n }\n if(ac == a && bc == b){\n for(int i = 0; i < n; ++i){\n write(arr[i], \" \");\n }\n writeln;\n return;\n }else if (ac == a || bc == b){\n swap(arr[n-1], arr[n-2]);\n ac = 0; bc = 0;\n for(int i = 1; i < n-1; ++i){\n if(arr[i] > arr[i-1] && arr[i] > arr[i+1]){\n ++ac;\n }else if( arr[i] < arr[i-1] && arr[i] < arr[i+1]){\n ++bc;\n }\n }\n }\n if(ac == a && bc == b){\n for(int i = 0; i < n; ++i){\n write(arr[i], \" \");\n }\n writeln;\n }else{\n writeln(-1);\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"}], "src_uid": "2fdbf033e83d7c17841f640fe1fc0e55"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nint[][] divs;\nconst int sz = 200002;\nvoid preprocess(){\n divs = new int[][sz];\n for(int k = 1; k < sz; ++k){\n for(int m = 2*k; m < sz; m += k){\n divs[m] ~= k;\n }\n }\n}\n\nvoid solve(){\n auto n = scan!int;\n auto arr = scanArray!int;\n\n auto cnt = new long[](sz);\n auto push = new long[](sz);\n long maxcnt = 0;\n\n foreach(el; arr){\n ++cnt[el];\n }\n auto rbt = redBlackTree!int(arr);\n\n auto uniqs = rbt.array.sort.reverse;\n foreach(el; uniqs){\n foreach(divi; divs[el]){\n push[divi] = max(push[el] + cnt[el], push[divi]);\n }\n maxcnt = max(push[el] + cnt[el], maxcnt);\n }\n writeln(n - maxcnt);\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n preprocess;\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.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 auto memo = new int[](10^^5 * 2 + 1);\r\n foreach (a; readln.split) memo[a.to!int] += 1;\r\n\r\n auto DP = new int[](10^^5 * 2 + 1);\r\n foreach (i; 1..10^^5 * 2 + 1) {\r\n DP[i] += memo[i];\r\n auto j = i * 2;\r\n while (j <= 10^^5 * 2) {\r\n DP[j] = max(DP[i], DP[j]);\r\n j += i;\r\n }\r\n }\r\n\r\n writeln(N - DP.maxElement());\r\n }\r\n}"}], "negative_code": [], "src_uid": "5984e49e7e03c16d7b20ad85288b62b8"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nclass SegmentTree(T)\n{\n class Node\n {\n int leftIndex;\n int rightIndex;\n T[] maximum;\n T[] minimum;\n Node left;\n Node right;\n\n this(int leftIndex, int rightIndex, int m)\n {\n this.maximum = new T[m];\n this.minimum = new T[m];\n this.leftIndex = leftIndex;\n this.rightIndex = rightIndex;\n this.left = this.right = null;\n }\n }\n\n protected Node root;\n immutable static T bound = T.max;\n\n this(T[][] arr)\n {\n this.initializeTree(this.root, arr, 0, cast(int)arr.length - 1);\n }\n\n protected void initializeTree(ref Node node, T[][] arr, int leftIndex, int rightIndex)\n {\n auto m = cast(int)arr[0].length;\n node = new Node(leftIndex, rightIndex, m);\n if (leftIndex == rightIndex)\n {\n foreach (i; 0 .. m)\n {\n node.maximum[i] = node.minimum[i] = arr[leftIndex][i];\n }\n return;\n }\n auto mid = (leftIndex + rightIndex) >> 1;\n initializeTree(node.left, arr, leftIndex, mid);\n initializeTree(node.right, arr, mid + 1, rightIndex);\n foreach (i; 0 .. m)\n {\n node.maximum[i] = max(node.left.maximum[i], node.right.maximum[i]);\n node.minimum[i] = min(node.left.minimum[i], node.right.minimum[i]);\n }\n }\n\n T[5] queryMax(int left, int right)\n {\n return _queryMax(root, left, right);\n }\n\n protected T[5] _queryMax(Node node, int left, int right)\n {\n auto m = cast(int)node.maximum.length;\n T[5] res;\n if (left <= node.leftIndex && right >= node.rightIndex)\n {\n foreach (i; 0 .. m)\n {\n res[i] = node.maximum[i];\n }\n return res;\n }\n if (left > node.rightIndex || right < node.leftIndex)\n {\n foreach (i; 0 .. m)\n {\n res[i] = -T.max;\n }\n return res;\n }\n auto leftMax = _queryMax(node.left, left, right);\n auto rightMax = _queryMax(node.right, left, right);\n foreach (i; 0 .. m)\n {\n res[i] = max(leftMax[i], rightMax[i]);\n }\n return res;\n }\n}\n\nvoid solve(int n, int m, int k, int[][] a)\n{\n auto st = new SegmentTree!int(a);\n auto sl = -1, sr = -1;\n auto longest = 0;\n auto prev = new int[m];\n foreach (i; 0 .. n)\n {\n auto left = i + longest, right = n - 1;\n if (left >= n)\n {\n break;\n }\n fill(prev, 0);\n if (left > i)\n {\n auto ret = st.queryMax(i, left - 1);\n foreach (j; 0 .. m)\n {\n prev[j] = ret[j];\n }\n }\n while (left <= right)\n {\n auto mid = (left + right) >> 1;\n auto ret = st.queryMax(left, mid);\n auto need = 0;\n foreach (j; 0 .. m)\n {\n need += max(prev[j], ret[j]);\n if (need > k)\n {\n break;\n }\n }\n if (need > k)\n {\n right = mid - 1;\n }\n else\n {\n left = mid + 1;\n foreach (j; 0 .. m)\n {\n prev[j] = max(prev[j], ret[j]);\n }\n if (mid - i + 1 > longest)\n {\n longest = mid - i + 1;\n sl = i;\n sr = mid;\n }\n }\n }\n }\n auto s = new int[m];\n fill(s, 0);\n if (longest > 0)\n {\n foreach (i; sl .. sr + 1)\n {\n foreach (j; 0 .. m)\n {\n s[j] = max(s[j], a[i][j]);\n }\n }\n }\n foreach (i; 0 .. m)\n {\n write(s[i]);\n if (i < m)\n {\n write(\" \");\n }\n }\n writeln();\n}\n\nint main(string[] args)\n{\n int n, m, k;\n while (readf(\"%d %d %d\\n\", &n, &m, &k) == 3)\n {\n auto a = new int[][](n, m);\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. m)\n {\n readf(\" %d\", &a[i][j]);\n }\n readln;\n }\n solve(n, m, k, a);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nclass SegmentTree(T)\n{\n class Node\n {\n int leftIndex;\n int rightIndex;\n T[5] maximum;\n T[5] minimum;\n Node left;\n Node right;\n\n this(int leftIndex, int rightIndex, int m)\n {\n this.leftIndex = leftIndex;\n this.rightIndex = rightIndex;\n this.left = this.right = null;\n }\n }\n\n protected Node root;\n immutable static T bound = T.max;\n\n this(T[][] arr)\n {\n this.initializeTree(this.root, arr, 0, cast(int)arr.length - 1);\n }\n\n protected void initializeTree(ref Node node, T[][] arr, int leftIndex, int rightIndex)\n {\n auto m = cast(int)arr[0].length;\n node = new Node(leftIndex, rightIndex, m);\n if (leftIndex == rightIndex)\n {\n foreach (i; 0 .. m)\n {\n node.maximum[i] = node.minimum[i] = arr[leftIndex][i];\n }\n return;\n }\n auto mid = (leftIndex + rightIndex) >> 1;\n initializeTree(node.left, arr, leftIndex, mid);\n initializeTree(node.right, arr, mid + 1, rightIndex);\n foreach (i; 0 .. m)\n {\n node.maximum[i] = max(node.left.maximum[i], node.right.maximum[i]);\n node.minimum[i] = min(node.left.minimum[i], node.right.minimum[i]);\n }\n }\n\n T[5] queryMax(int left, int right)\n {\n return _queryMax(root, left, right);\n }\n\n protected T[5] _queryMax(Node node, int left, int right)\n {\n auto m = cast(int)node.maximum.length;\n T[5] res;\n if (left <= node.leftIndex && right >= node.rightIndex)\n {\n foreach (i; 0 .. m)\n {\n res[i] = node.maximum[i];\n }\n return res;\n }\n if (left > node.rightIndex || right < node.leftIndex)\n {\n foreach (i; 0 .. m)\n {\n res[i] = -T.max;\n }\n return res;\n }\n auto leftMax = _queryMax(node.left, left, right);\n auto rightMax = _queryMax(node.right, left, right);\n foreach (i; 0 .. m)\n {\n res[i] = max(leftMax[i], rightMax[i]);\n }\n return res;\n }\n}\n\nvoid solve(int n, int m, int k, int[][] a)\n{\n auto st = new SegmentTree!int(a);\n auto sl = -1, sr = -1;\n auto longest = 0;\n auto prev = new int[m];\n foreach (i; 0 .. n)\n {\n auto left = i + longest, right = n - 1;\n if (left >= n)\n {\n break;\n }\n fill(prev, 0);\n if (left > i)\n {\n auto ret = st.queryMax(i, left - 1);\n foreach (j; 0 .. m)\n {\n prev[j] = ret[j];\n }\n }\n while (left <= right)\n {\n auto mid = (left + right) >> 1;\n auto ret = st.queryMax(left, mid);\n auto need = 0;\n foreach (j; 0 .. m)\n {\n need += max(prev[j], ret[j]);\n if (need > k)\n {\n break;\n }\n }\n if (need > k)\n {\n right = mid - 1;\n }\n else\n {\n left = mid + 1;\n foreach (j; 0 .. m)\n {\n prev[j] = max(prev[j], ret[j]);\n }\n if (mid - i + 1 > longest)\n {\n longest = mid - i + 1;\n sl = i;\n sr = mid;\n }\n }\n }\n }\n auto s = new int[m];\n fill(s, 0);\n if (longest > 0)\n {\n foreach (i; sl .. sr + 1)\n {\n foreach (j; 0 .. m)\n {\n s[j] = max(s[j], a[i][j]);\n }\n }\n }\n foreach (i; 0 .. m)\n {\n write(s[i]);\n if (i < m)\n {\n write(\" \");\n }\n }\n writeln();\n}\n\nint main(string[] args)\n{\n int n, m, k;\n while (readf(\"%d %d %d\\n\", &n, &m, &k) == 3)\n {\n auto a = new int[][](n, m);\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. m)\n {\n readf(\" %d\", &a[i][j]);\n }\n readln;\n }\n solve(n, m, k, a);\n }\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nclass SegmentTree(T)\n{\n class Node\n {\n int leftIndex;\n int rightIndex;\n T[] maximum;\n T[] minimum;\n Node left;\n Node right;\n\n this(int leftIndex, int rightIndex, int m)\n {\n this.maximum = new T[m];\n this.minimum = new T[m];\n this.leftIndex = leftIndex;\n this.rightIndex = rightIndex;\n this.left = this.right = null;\n }\n }\n\n protected Node root;\n immutable static T bound = T.max;\n\n this(T[][] arr)\n {\n this.initializeTree(this.root, arr, 0, cast(int)arr.length - 1);\n }\n\n protected void initializeTree(ref Node node, T[][] arr, int leftIndex, int rightIndex)\n {\n auto m = cast(int)arr[0].length;\n node = new Node(leftIndex, rightIndex, m);\n if (leftIndex == rightIndex)\n {\n foreach (i; 0 .. m)\n {\n node.maximum[i] = node.minimum[i] = arr[leftIndex][i];\n }\n return;\n }\n auto mid = (leftIndex + rightIndex) >> 1;\n initializeTree(node.left, arr, leftIndex, mid);\n initializeTree(node.right, arr, mid + 1, rightIndex);\n foreach (i; 0 .. m)\n {\n node.maximum[i] = max(node.left.maximum[i], node.right.maximum[i]);\n node.minimum[i] = min(node.left.minimum[i], node.right.minimum[i]);\n }\n }\n\n T count(int left, int right)\n {\n auto m = cast(int)root.maximum.length;\n auto res = 0;\n foreach (i; 0 .. m)\n {\n auto ret = _queryMax(root, left, right, i);\n res += ret;\n }\n return res;\n }\n\n protected T _queryMax(Node node, int left, int right, int idx)\n {\n if (left <= node.leftIndex && right >= node.rightIndex)\n {\n return node.maximum[idx];\n }\n if (left > node.rightIndex || right < node.leftIndex)\n {\n return -T.max;\n }\n auto leftMax = _queryMax(node.left, left, right, idx);\n auto rightMax = _queryMax(node.right, left, right, idx);\n return max(leftMax, rightMax);\n }\n}\n\nvoid solve(int n, int m, int k, int[][] a)\n{\n auto st = new SegmentTree!int(a);\n auto sl = -1, sr = -1;\n auto longest = 0;\n foreach (i; 0 .. n)\n {\n auto left = i + longest, right = n - 1;\n if (left >= n)\n {\n break;\n }\n auto leftBound = i;\n auto need = 0;\n while (left <= right)\n {\n auto mid = (left + right) >> 1;\n auto inc = st.count(leftBound, mid);\n if (need + inc <= k)\n {\n left = mid + 1;\n need += inc;\n leftBound = left;\n if (mid - i + 1 > longest)\n {\n longest = mid - i + 1;\n sl = i;\n sr = mid;\n }\n }\n else\n {\n right = mid - 1;\n }\n }\n }\n auto s = new int[m];\n fill(s, 0);\n if (longest > 0)\n {\n foreach (i; sl .. sr + 1)\n {\n foreach (j; 0 .. m)\n {\n s[j] = max(s[j], a[i][j]);\n }\n }\n }\n foreach (i; 0 .. m)\n {\n write(s[i]);\n if (i < m)\n {\n write(\" \");\n }\n }\n writeln();\n}\n\nint main(string[] args)\n{\n int n, m, k;\n while (readf(\"%d %d %d\\n\", &n, &m, &k) == 3)\n {\n auto a = new int[][](n, m);\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. m)\n {\n readf(\" %d\", &a[i][j]);\n }\n readln;\n }\n solve(n, m, k, a);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nclass SegmentTree(T)\n{\n class Node\n {\n int leftIndex;\n int rightIndex;\n T[] maximum;\n T[] minimum;\n Node left;\n Node right;\n\n this(int leftIndex, int rightIndex, int m)\n {\n this.maximum = new T[m];\n this.minimum = new T[m];\n this.leftIndex = leftIndex;\n this.rightIndex = rightIndex;\n this.left = this.right = null;\n }\n }\n\n protected Node root;\n immutable static T bound = T.max;\n\n this(T[][] arr)\n {\n this.initializeTree(this.root, arr, 0, cast(int)arr.length - 1);\n }\n\n protected void initializeTree(ref Node node, T[][] arr, int leftIndex, int rightIndex)\n {\n auto m = cast(int)arr[0].length;\n node = new Node(leftIndex, rightIndex, m);\n if (leftIndex == rightIndex)\n {\n foreach (i; 0 .. m)\n {\n node.maximum[i] = node.minimum[i] = arr[leftIndex][i];\n }\n return;\n }\n auto mid = (leftIndex + rightIndex) >> 1;\n initializeTree(node.left, arr, leftIndex, mid);\n initializeTree(node.right, arr, mid + 1, rightIndex);\n foreach (i; 0 .. m)\n {\n node.maximum[i] = max(node.left.maximum[i], node.right.maximum[i]);\n node.minimum[i] = min(node.left.minimum[i], node.right.minimum[i]);\n }\n }\n\n T count(int left, int right)\n {\n auto m = cast(int)root.maximum.length;\n auto res = 0;\n foreach (i; 0 .. m)\n {\n auto ret = _queryMax(root, left, right, i);\n res += ret;\n }\n return res;\n }\n\n protected T _queryMax(Node node, int left, int right, int idx)\n {\n if (left <= node.leftIndex && right >= node.rightIndex)\n {\n return node.maximum[idx];\n }\n if (left > node.rightIndex || right < node.leftIndex)\n {\n return -T.max;\n }\n auto leftMax = _queryMax(node.left, left, right, idx);\n auto rightMax = _queryMax(node.right, left, right, idx);\n return max(leftMax, rightMax);\n }\n}\n\nvoid solve(int n, int m, int k, int[][] a)\n{\n auto st = new SegmentTree!int(a);\n auto sl = -1, sr = -1;\n auto longest = 0;\n foreach (i; 0 .. n)\n {\n auto left = i + longest, right = n - 1;\n if (left >= n)\n {\n break;\n }\n auto need = 0;\n while (left <= right)\n {\n auto mid = (left + right) >> 1;\n auto inc = st.count(left, mid);\n if (need + inc <= k)\n {\n left = mid + 1;\n need += inc;\n if (mid - i + 1 > longest)\n {\n longest = mid - i + 1;\n sl = i;\n sr = mid;\n }\n }\n else\n {\n right = mid - 1;\n }\n }\n }\n auto s = new int[m];\n fill(s, 0);\n if (longest > 0)\n {\n foreach (i; sl .. sr + 1)\n {\n foreach (j; 0 .. m)\n {\n s[j] = max(s[j], a[i][j]);\n }\n }\n }\n foreach (i; 0 .. m)\n {\n write(s[i]);\n if (i < m)\n {\n write(\" \");\n }\n }\n writeln();\n}\n\nint main(string[] args)\n{\n int n, m, k;\n while (readf(\"%d %d %d\\n\", &n, &m, &k) == 3)\n {\n auto a = new int[][](n, m);\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. m)\n {\n readf(\" %d\", &a[i][j]);\n }\n readln;\n }\n solve(n, m, k, a);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nclass SegmentTree(T)\n{\n class Node\n {\n int leftIndex;\n int rightIndex;\n T[] maximum;\n T[] minimum;\n Node left;\n Node right;\n\n this(int leftIndex, int rightIndex, int m)\n {\n this.maximum = new T[m];\n this.minimum = new T[m];\n this.leftIndex = leftIndex;\n this.rightIndex = rightIndex;\n this.left = this.right = null;\n }\n }\n\n protected Node root;\n immutable static T bound = T.max;\n\n this(T[][] arr)\n {\n this.initializeTree(this.root, arr, 0, cast(int)arr.length - 1);\n }\n\n protected void initializeTree(ref Node node, T[][] arr, int leftIndex, int rightIndex)\n {\n auto m = cast(int)arr[0].length;\n node = new Node(leftIndex, rightIndex, m);\n if (leftIndex == rightIndex)\n {\n foreach (i; 0 .. m)\n {\n node.maximum[i] = node.minimum[i] = arr[leftIndex][i];\n }\n return;\n }\n auto mid = (leftIndex + rightIndex) >> 1;\n initializeTree(node.left, arr, leftIndex, mid);\n initializeTree(node.right, arr, mid + 1, rightIndex);\n foreach (i; 0 .. m)\n {\n node.maximum[i] = max(node.left.maximum[i], node.right.maximum[i]);\n node.minimum[i] = min(node.left.minimum[i], node.right.minimum[i]);\n }\n }\n\n T[] queryMax(int left, int right)\n {\n auto m = cast(int)root.maximum.length;\n int[] res;\n foreach (i; 0 .. m)\n {\n auto ret = _queryMax(root, left, right, i);\n res ~= ret;\n }\n return res;\n }\n\n protected T _queryMax(Node node, int left, int right, int idx)\n {\n if (left <= node.leftIndex && right >= node.rightIndex)\n {\n return node.maximum[idx];\n }\n if (left > node.rightIndex || right < node.leftIndex)\n {\n return -T.max;\n }\n auto leftMax = _queryMax(node.left, left, right, idx);\n auto rightMax = _queryMax(node.right, left, right, idx);\n return max(leftMax, rightMax);\n }\n}\n\nvoid solve(int n, int m, int k, int[][] a)\n{\n auto st = new SegmentTree!int(a);\n auto sl = -1, sr = -1;\n auto longest = 0;\n foreach (i; 0 .. n)\n {\n auto left = i + longest, right = n - 1;\n if (left >= n)\n {\n break;\n }\n auto prev = new int[m];\n fill(prev, 0);\n while (left <= right)\n {\n auto mid = (left + right) >> 1;\n auto ret = st.queryMax(left, mid);\n auto need = 0;\n foreach (j; 0 .. m)\n {\n need += max(prev[j], ret[j]);\n if (need > k)\n {\n break;\n }\n }\n if (need <= k)\n {\n left = mid + 1;\n foreach (j; 0 .. m)\n {\n prev[j] = max(prev[j], ret[j]);\n }\n if (mid - i + 1 > longest)\n {\n longest = mid - i + 1;\n sl = i;\n sr = mid;\n }\n }\n else\n {\n right = mid - 1;\n }\n }\n }\n auto s = new int[m];\n fill(s, 0);\n if (longest > 0)\n {\n foreach (i; sl .. sr + 1)\n {\n foreach (j; 0 .. m)\n {\n s[j] = max(s[j], a[i][j]);\n }\n }\n }\n foreach (i; 0 .. m)\n {\n write(s[i]);\n if (i < m)\n {\n write(\" \");\n }\n }\n writeln();\n}\n\nint main(string[] args)\n{\n int n, m, k;\n while (readf(\"%d %d %d\\n\", &n, &m, &k) == 3)\n {\n auto a = new int[][](n, m);\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. m)\n {\n readf(\" %d\", &a[i][j]);\n }\n readln;\n }\n solve(n, m, k, a);\n }\n return 0;\n}"}], "src_uid": "15570b36212b2ce2272195d92def258d"} {"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 a = readln.chomp.split.map!(to!int).array;\n \n int q;\n readf(\"%s\", &q);\n readln;\n \n int[int] cnt;\n cnt[0] = 0;\n foreach (e; a) {\n int cursum = 0;\n foreach (i; 1 .. k+1) {\n cursum += e;\n cnt[cursum] = min(i, cnt.get(cursum, k));\n }\n }\n \n debug { cnt.writeln; }\n \n while (q--) {\n int x;\n readf(\"%s\", &x);\n readln;\n \n int ans = k+1;\n foreach (val; cnt.keys) {\n if (val > x) { continue; }\n \n int rst = x - val;\n int tot = cnt.get(val, k+1) + cnt.get(rst, k+1);\n \n ans = min(ans, tot);\n }\n \n if (ans == k+1) { ans = -1; }\n \n ans.writeln;\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, k;\n\twhile (readf (\" %s %s \", &n, &k) > 0)\n\t{\n\t\tauto a = readln.split.map !(to !(int)).array;\n\n\t\talias Pair = Tuple !(int, q{x}, int, q{y});\n\t\tPair [] v;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (u; 0..k + 1)\n\t\t\t{\n\t\t\t\tv ~= Pair (a[i] * u, u);\n\t\t\t}\n\t\t}\n\t\tsort (v);\n\n\t\tint q;\n\t\treadf (\" %s\", &q);\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tint s;\n\t\t\treadf (\" %s\", &s);\n\t\t\tauto u = v;\n\t\t\tint res = k + 1;\n\t\t\twhile (!u.empty)\n\t\t\t{\n\t\t\t\twhile (!u.empty && u.front.x + u.back.x > s)\n\t\t\t\t{\n\t\t\t\t\tu.popBack ();\n\t\t\t\t}\n\t\t\t\twhile (!u.empty && u.front.x + u.back.x == s)\n\t\t\t\t{\n\t\t\t\t\tres = min (res, u.front.y + u.back.y);\n\t\t\t\t\tu.popBack ();\n\t\t\t\t}\n\t\t\t\tif (!u.empty)\n\t\t\t\t{\n\t\t\t\t\tu.popFront ();\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (res > k)\n\t\t\t{\n\t\t\t\tres = -1;\n\t\t\t}\n\t\t\twriteln (res);\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\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n auto a = readln.chomp.split.map!(to!int).array;\n \n int q;\n readf(\"%s\", &q);\n readln;\n \n int[int] cnt;\n foreach (e; a) {\n int cursum = 0;\n foreach (i; 1 .. k+1) {\n cursum += e;\n cnt[cursum] = min(i, cnt.get(cursum, k));\n }\n }\n \n debug { cnt.writeln; }\n \n while (q--) {\n int x;\n readf(\"%s\", &x);\n readln;\n \n int ans = k+1;\n foreach (val; cnt.keys) {\n if (val > x) { continue; }\n \n int rst = x - val;\n int tot = cnt.get(val, k+1) + cnt.get(rst, k+1);\n \n ans = min(ans, tot);\n }\n \n if (ans == k+1) { ans = -1; }\n \n ans.writeln;\n }\n}"}], "src_uid": "5d8521e467cad53cf9403200e4c99b89"} {"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", "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, 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}"}, {"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"}], "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\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\t\tbool f(int x){ // \"can buy x or more goods\" (not necessarily can by exact x)\n\t\t\tint m = x / k, r = x % k;\n\t\t\tlong q;\n\t\t\tforeach(a; as[0 .. r]){\n\t\t\t\tif(q + a < as[k - 1]) q += a;\n\t\t\t\telse{\n\t\t\t\t\tq = 0;\n\t\t\t\t\tr = 0;\n\t\t\t\t\tm += 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach(i; 1 .. m + 1) q += as[r + k * i - 1];\n\t\t\tlog(\"x:\", x, \"m:\", m, \"r:\", r, \"q:\", q, \"f:\", q <= p);\n\t\t\treturn q <= p;\n\t\t}\n\n\t\tint ans = uplimit(0, n, &f);\n\t\tans.writeln;\n\n\t}\n}\n\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\tT downlimit(T)(T a, T c, bool delegate(T) f){\n\t\tif(f(a)) return a; if(! f(c)) return c + 1;\n\t\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) c = b; else a = b; }\n\t\treturn c;\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\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\n\t\tbool f(int x){\n\t\t\tint m = x / k, r = x % k;\n\t\t\tlong q;\n\t\t\tlog(\"x:\", x, \"m:\", m, \"r:\", r);\n\t\t\tforeach(a; as[0 .. r]) q += a;\n\t\t\tforeach(i; 1 .. m + 1) q += as[r + k * m - 1];\n\t\t\treturn q <= p;\n\t\t}\n\n\t\tint ans = uplimit(0, n, &f);\n\t\tans.writeln;\n\n\t}\n}\n\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\tT downlimit(T)(T a, T c, bool delegate(T) f){\n\t\tif(f(a)) return a; if(! f(c)) return c + 1;\n\t\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) c = b; else a = b; }\n\t\treturn c;\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\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\t\tbool f(int x){\n\t\t\tint m = x / k, r = x % k;\n\t\t\tlong q;\n\t\t\tforeach(a; as[0 .. r]) q += a;\n\t\t\tforeach(i; 1 .. m + 1) q += as[r + k * i - 1];\n\t\t\tlog(\"x:\", x, \"m:\", m, \"r:\", r, \"q:\", q, \"f:\", q <= p);\n\t\t\treturn q <= p;\n\t\t}\n\n\t\tint ans = uplimit(0, n, &f);\n\t\tans.writeln;\n\n\t}\n}\n\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\tT downlimit(T)(T a, T c, bool delegate(T) f){\n\t\tif(f(a)) return a; if(! f(c)) return c + 1;\n\t\twhile(a + 1 < c){ T b = (a + c) / 2; if(f(b)) c = b; else a = b; }\n\t\treturn c;\n\t}\n"}], "src_uid": "79d07b0f6ea14daf208aef1acd6466c1"} {"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 long[long] cubic;\n for (long i = 1; i * i * i <= 10L ^^ 18; ++i) cubic[i * i * i] = i;\n \n auto N = readln.chomp.to!int;\n while (N--) {\n auto s = readln.split.map!(to!long);\n auto a = s[0];\n auto b = s[1];\n if (a * b in cubic && a % cubic[a * b] == 0 && b % cubic[a * b] == 0) {\n writeln(\"Yes\");\n } else {\n writeln(\"No\");\n }\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, std.numeric;\n\nint n;\n\nvoid main() {\n scan(n);\n\n int a, b;\n\n while (n--) {\n scan(a, b);\n writeln(judge(a, b) ? \"Yes\" : \"No\");\n }\n}\n\nbool judge(int a, int b) {\n long btm = 0, top = 10^^6 + 1;\n long ab = 1L*a*b;\n\n while (top - btm > 1) {\n long mid = btm + (top - btm) / 2;\n\n if (mid*mid*mid <= ab) {\n btm = mid;\n }\n else {\n top = mid;\n }\n }\n\n if (btm*btm*btm != ab) {\n return false;\n }\n\n if (a % btm == 0 && b % btm == 0) {\n return true;\n }\n else {\n return false;\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": "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(a^(1/k))\nulong floorKthRoot(ulong a, ulong k) {\n import core.bitop : bsr;\n import std.algorithm : min;\n if (a == 0) {\n return 0;\n } else if (k <= 1) {\n return a;\n } else if (k == 2) {\n ulong 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 } else if (k <= 40) {\n // min x s.t. x^k >= 2^64\n enum ulong[] HIS =\n [0, 0, 4294967296UL, 2642246, 65536, 7132, 1626, 566, 256, 139, 85, 57,\n 41, 31, 24, 20, 16, 14, 12, 11, 10, 9, 8, 7, 7, 6, 6, 6, 5, 5, 5, 5,\n 4, 4, 4, 4, 4, 4, 4, 4, 4];\n ulong lo = 1UL << (bsr(a) / k);\n ulong hi = min(1UL << (bsr(a) / k + 1), HIS[cast(size_t)(k)]);\n for (; lo + 1 < hi; ) {\n const ulong mid = (lo + hi) / 2;\n ulong b = mid * mid;\n foreach (i; 2 .. k) b *= mid;\n ((b <= a) ? lo : hi) = mid;\n }\n return lo;\n } else if (k <= 63) {\n return ((1UL << k) <= a) ? 2 : 1;\n } else {\n return 1;\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 \n const long x = floorKthRoot(A * B, 3);\n const ans = (A * B == x^^3 && A % x == 0 && B % x == 0);\n writeln(ans ? \"Yes\" : \"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "933135ef124b35028c1f309d69515e44"} {"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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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\tstring t;\n\tloop:while((t=readln.strip)!=\"\")\n\t{\n\t\tint[char] q;\n\t\tforeach(i;\"Bulbasaur\")q[i]=0;\n\n\t\tforeach(i;t)q[i]++;\n\t\twriteln(min(q['B'],q['b'],q['a']/2,q['u']/2,q['l'],q['s'],q['r']));\n\t}\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable string str = \"Bulbasaur\";\nvoid main(string[] args) \n{\n string s;\n while((s = readln.strip) != \"\")\n {\n int [256] num;\n foreach(char c; s) \n {\n num[c]++;\n }\n int res = int.max;\n foreach(char c;str)\n {\n int d =cast(int)(str.count(c));\n res = min(res,num[c]/d);\n }\n writeln(res);\n }\n}"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable string str = \"Bulbasaur\";\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tint [256] num;\n\t\tforeach (char c; s)\n\t\t{\n\t\t\tnum[c] += 1;\n\t\t}\n\t\tint res = int.max;\n\t\tforeach (char c; str)\n\t\t{\n\t\t\tint d = cast (int) (str.count (c));\n\t\t\tres = min (res, num[c] / d);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "9c429fd7598ea75acce09805a15092d0"} {"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\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 (a);\r\n\t\tint l = NA, r = NA;\r\n\t\tint curL = NA;\r\n\t\tint prev = NA;\r\n\t\tforeach (ref c; a.group)\r\n\t\t{\r\n\t\t\tauto value = c[0];\r\n\t\t\tauto num = c[1];\r\n\t\t\tif (prev + 1 != value)\r\n\t\t\t{\r\n\t\t\t\tcurL = value;\r\n\t\t\t}\r\n\t\t\tif (num < k)\r\n\t\t\t{\r\n\t\t\t\tcurL = value + 1;\r\n\t\t\t}\r\n\t\t\telse if (r - l <= value - curL)\r\n\t\t\t{\r\n\t\t\t\tl = curL;\r\n\t\t\t\tr = value;\r\n\t\t\t}\r\n\t\t\tprev = value;\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (l == NA ? [NA] : [l, r]);\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 K = scan!int;\r\n auto A = scan!long(N);\r\n\r\n long[] nums = A.sort.group.filter!(g => g[1] >= K).map!\"a[0]\".array;\r\n\r\n if (nums.empty) return \"-1\"; \r\n\r\n nums.sort;\r\n long cur = nums[0];\r\n long con, maxCon;\r\n long l = cur, r = cur;\r\n foreach(n; nums[1..$]) {\r\n if (n == cur + 1) {\r\n con++;\r\n if (maxCon.chmax(con)) {\r\n r = n;\r\n l = n - con;\r\n }\r\n } else con = 0;\r\n\r\n cur = n;\r\n }\r\n\r\n return [l, r].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, 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>>\".writefln(benchmark!problem(1)); BORDER.writeln; } }\r\n else problem();\r\n}\r\nenum YESNO = [true: \"Yes\", false: \"No\"];\r\n\r\n// -----------------------------------------------"}], "negative_code": [], "src_uid": "13fd45f1892f96eab1d5ab966f465a05"} {"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 A, B, K; get(A, B, K);\r\n if (K == 0) {\r\n char[] res;\r\n foreach (_; 0..B) res ~= '1';\r\n foreach (_; 0..A) res ~= '0';\r\n writeln(\"Yes\");\r\n writeln(res);\r\n writeln(res);\r\n return;\r\n }\r\n\r\n if (A + B - 2 < K || A < 1 || B < 2) return writeln(\"No\");\r\n auto a = A - 1, b = B - 2;\r\n char[] x;\r\n x ~= '0';\r\n foreach (_; 1..K) {\r\n if (a) {\r\n x ~= '0';\r\n --a;\r\n } else {\r\n x ~= '1';\r\n --b;\r\n }\r\n }\r\n x ~= '1';\r\n while (a) {\r\n x ~= '0';\r\n --a;\r\n }\r\n while (b) {\r\n x ~= '1';\r\n --b;\r\n }\r\n x ~= '1';\r\n reverse(x);\r\n\r\n a = A - 1; b = B - 2;\r\n char[] y;\r\n y ~= '1';\r\n foreach (_; 1..K) {\r\n if (a) {\r\n y ~= '0';\r\n --a;\r\n } else {\r\n y ~= '1';\r\n --b;\r\n }\r\n }\r\n y ~= '0';\r\n while (a) {\r\n y ~= '0';\r\n --a;\r\n }\r\n while (b) {\r\n y ~= '1';\r\n --b;\r\n }\r\n y ~= '1';\r\n reverse(y);\r\n writeln(\"Yes\");\r\n writeln(x);\r\n writeln(y);\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 a = RD;\r\n\tauto b = RD;\r\n\tauto k = RD;\r\n\r\n\tstring ans1, ans2;\r\n\tif (a == 0)\r\n\t{\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tforeach (i; 0..b)\r\n\t\t\t{\r\n\t\t\t\tans1 ~= '1';\r\n\t\t\t\tans2 ~= '1';\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (b == 1)\r\n\t{\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tans1 ~= '1';\r\n\t\t\tans2 ~= '1';\r\n\t\t\tforeach (i; 0..a)\r\n\t\t\t{\r\n\t\t\t\tans1 ~= '0';\r\n\t\t\t\tans2 ~= '0';\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (k == 0)\r\n\t{\r\n\t\tforeach (i; 0..b)\r\n\t\t{\r\n\t\t\tans1 ~= '1';\r\n\t\t\tans2 ~= '1';\r\n\t\t}\r\n\t\tforeach (i; 0..a)\r\n\t\t{\r\n\t\t\tans1 ~= '0';\r\n\t\t\tans2 ~= '0';\r\n\t\t}\r\n\t}\r\n\telse if (k <= a + b - 2)\r\n\t{\r\n\t\tauto d = k-1;\r\n\t\tans1 ~= \"11\";\r\n\t\tans2 ~= \"10\";\r\n\t\tauto aa = min(a-1, d);\r\n\t\tforeach (i; 0..aa)\r\n\t\t{\r\n\t\t\tans1 ~= '0';\r\n\t\t\tans2 ~= '0';\r\n\t\t}\r\n\t\td -= aa;\r\n\t\tforeach (i; 0..d)\r\n\t\t{\r\n\t\t\tans1 ~= '1';\r\n\t\t\tans2 ~= '1';\r\n\t\t}\r\n\t\tans1 ~= '0';\r\n\t\tans2 ~= '1';\r\n\t\tauto rem_a = a - 1 - aa;\r\n\t\tauto rem_b = b - 2 - d;\r\n\t\tforeach (i; 0..rem_a)\r\n\t\t{\r\n\t\t\tans1 ~= '0';\r\n\t\t\tans2 ~= '0';\r\n\t\t}\r\n\t\tforeach (i; 0..rem_b)\r\n\t\t{\r\n\t\t\tans1 ~= '1';\r\n\t\t\tans2 ~= '1';\r\n\t\t}\r\n\t}\r\n\r\n\tif (ans1.empty)\r\n\t\twriteln(\"No\");\r\n\telse\r\n\t{\r\n\t\twriteln(\"Yes\");\r\n\t\twriteln(ans1);\r\n\t\twriteln(ans2);\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 A, B, K; get(A, B, K);\r\n if (K == 0) {\r\n char[] res;\r\n foreach (_; 0..B) res ~= '1';\r\n foreach (_; 0..A) res ~= '0';\r\n writeln(\"Yes\");\r\n writeln(res);\r\n writeln(res);\r\n return;\r\n }\r\n\r\n if (A < K) return writeln(\"No\");\r\n if (B < 2) return writeln(\"No\");\r\n char[] x;\r\n foreach (_; 0..K) x ~= '0';\r\n foreach (_; 0..B - 1) x ~= '1';\r\n foreach (_; 0..A - K) x ~= '0';\r\n x ~= '1';\r\n reverse(x);\r\n\r\n char[] y;\r\n y ~= '1';\r\n foreach (_; 0..K) y ~= '0';\r\n foreach (_; 0..B - 2) y ~= '1';\r\n foreach (_; 0..A - K) y ~= '0';\r\n y ~= '1';\r\n reverse(y);\r\n writeln(\"Yes\");\r\n writeln(x);\r\n writeln(y);\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 a = RD;\r\n\tauto b = RD;\r\n\tauto k = RD;\r\n\r\n\tstring ans1, ans2;\r\n\tif (a == 0)\r\n\t{\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tforeach (i; 0..b)\r\n\t\t\t{\r\n\t\t\t\tans1 ~= '1';\r\n\t\t\t\tans2 ~= '1';\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (b == 1)\r\n\t{\r\n\t\tif (k == 0)\r\n\t\t{\r\n\t\t\tans1 ~= '1';\r\n\t\t\tans2 ~= '1';\r\n\t\t\tforeach (i; 0..a)\r\n\t\t\t{\r\n\t\t\t\tans1 ~= '0';\r\n\t\t\t\tans2 ~= '0';\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\telse if (k <= a + b - 2)\r\n\t{\r\n\t\tauto d = a + b - 2 - k;\r\n\t\tans1 ~= '1';\r\n\t\tans2 ~= '1';\r\n\t\tauto aa = min(a-1, d);\r\n\t\tforeach (i; 0..aa)\r\n\t\t{\r\n\t\t\tans1 ~= '0';\r\n\t\t\tans2 ~= '0';\r\n\t\t}\r\n\t\td -= aa;\r\n\t\tforeach (i; 0..d)\r\n\t\t{\r\n\t\t\tans1 ~= '1';\r\n\t\t\tans2 ~= '1';\r\n\t\t}\r\n\t\tauto rem_a = a - 1 - aa;\r\n\t\tauto rem_b = b - 2 - d;\r\n\t\tans1 ~= '1';\r\n\t\tans2 ~= '0';\r\n\t\tforeach (i; 0..rem_a)\r\n\t\t{\r\n\t\t\tans1 ~= '0';\r\n\t\t\tans2 ~= '0';\r\n\t\t}\r\n\t\tforeach (i; 0..rem_b)\r\n\t\t{\r\n\t\t\tans1 ~= '1';\r\n\t\t\tans2 ~= '1';\r\n\t\t}\r\n\t\tans1 ~= '0';\r\n\t\tans2 ~= '1';\r\n\t}\r\n\r\n\tif (ans1.empty)\r\n\t\twriteln(\"No\");\r\n\telse\r\n\t{\r\n\t\twriteln(\"Yes\");\r\n\t\twriteln(ans1);\r\n\t\twriteln(ans2);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "ea620a8dbef506567464dcaddcc2b34f"} {"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.exception;\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[ ] allocArray(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, m, k;\nint[100] _colors;\nint[ ] colors;\nint[100][100] _p;\nint[100][ ] p;\nulong[101][101][100] dp;//[pos][groupsLeft][prevColor]\n\nenum IMPOSSIBLE = ulong.max >>> 2;\n\nulong dyn(int pos, int groupsLeft, int prevColor) {\n if (pos == n)\n return groupsLeft ? IMPOSSIBLE : 0;\n if (~dp[pos][groupsLeft][prevColor])\n return dp[pos][groupsLeft][prevColor];\n ulong result = IMPOSSIBLE;\n if (colors[pos]) {\n if (prevColor == colors[pos])\n result = dyn(pos + 1, groupsLeft, colors[pos]);\n else if (groupsLeft)\n result = dyn(pos + 1, groupsLeft - 1, colors[pos]);\n } else {\n if (prevColor)\n result = dyn(pos + 1, groupsLeft, prevColor) + p[pos][prevColor - 1];\n if (groupsLeft)\n foreach (i; 1 .. m + 1)\n if (i != prevColor)\n result = min(result, dyn(pos + 1, groupsLeft - 1, i) + p[pos][i - 1]);\n }\n return (dp[pos][groupsLeft][prevColor] = result);\n}\n\nvoid main() {\n while (read(&n, &m, &k)) {\n colors = _colors[0 .. n];\n p = _p[0 .. n];\n foreach (ref x; colors)\n read(&x);\n foreach (ref row; p)\n foreach (ref x; row[0 .. m])\n read(&x);\n memset(dp.ptr, 0xFF, dp.sizeof);\n const result = dyn(0, k, 0);\n if (result < IMPOSSIBLE)\n writeln(result);\n else\n write(\"-1\\n\");\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 long INF = 10L ^^ 18 + 23;\n\nvoid main()\n{ \n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto p = new int[][] (n+1);\n foreach (i; 1 .. n+1) p[i] = [0] ~ readln.chomp.split.map!(to!int).array;\n \n debug { c.writeln; p.writeln; }\n \n auto dp = new long[][][] (n+1, k+1, m+1);\n foreach (i; 0 .. n+1) {\n foreach (j; 0 .. k+1) {\n dp[i][j].fill(INF); \n }\n }\n \n dp[0][0].fill(0);\n if (c[1] != 0) dp[1][1][c[1]] = 0;\n else dp[1][1][] = p[1].map!(to!long).array;\n \n foreach (i; 2 .. n+1) {\n foreach (j; 1 .. k+1) {\n foreach (pc; 1 .. m+1) {\n if (c[i] != 0) {\n auto prevGroup = pc == c[i] ? j : j-1;\n dp[i][j][c[i]] = min(dp[i][j][c[i]], dp[i-1][prevGroup][pc]);\n \n continue;\n }\n \n foreach (cc; 1 .. m+1) {\n auto prevGroups = pc == cc ? j : j-1;\n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][prevGroups][pc] + p[i][cc]);\n }\n }\n }\n }\n \n debug { dp.each!(r => r.each!writeln); }\n \n auto ans = dp[n][k].dropOne.minElement;\n if (ans == INF) ans = -1;\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 int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto p = new int[][] (n+1);\n foreach (i; 1 .. n+1) p[i] = [int.max] ~ readln.chomp.split.map!(to!int).array;\n \n debug { c.writeln; p.writeln; }\n \n auto mn = new int[][][] (n+1, k+1, 2);\n foreach (i; 1 .. n+1) foreach (j; 1 .. k+1) mn[i][j].fill(0);\n \n auto dp = new long[][][] (n+1, k+1, m+1);\n foreach (i; 0 .. n+1) {\n foreach (j; 0 .. k+1) {\n dp[i][j].fill(INF); \n }\n }\n \n dp[0][0].fill(0);\n\n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. min(i+1, k+1)) {\n void calcMin(int cc, int cost) {\n if (i == 1 && j == 1) {\n dp[i][j][cc] = cost;\n return;\n }\n \n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][j][cc] + cost);\n \n auto mnOther = mn[i-1][j-1][0] != cc ? mn[i-1][j-1][0] : mn[i-1][j-1][1];\n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][j-1][mnOther] + cost);\n }\n \n if (c[i] != 0) {\n calcMin(c[i], 0);\n } else {\n foreach (cc; 1 .. m+1) {\n calcMin(cc, p[i][cc]);\n }\n }\n \n foreach (cc; 1 .. m+1) {\n if (dp[i][j][cc] < dp[i][j][mn[i][j][0]]) mn[i][j][1] = mn[i][j][0], mn[i][j][0] = cc;\n else if (dp[i][j][cc] < dp[i][j][mn[i][j][1]]) mn[i][j][1] = cc;\n }\n }\n }\n \n debug { \n mn.dropOne.each!writeln;\n \n foreach (i; 1 .. n+1) { \n foreach (j; 1 .. k+1) dp[i][j].writeln;\n writeln;\n }\n }\n \n auto ans = dp[n][k].dropOne.minElement;\n if (ans == INF) ans = -1;\n ans.writeln;\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.exception;\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[ ] allocArray(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, m, k;\nint[100] _colors;\nint[ ] colors;\nint[100][100] _p;\nint[100][ ] p;\nulong[101][101][100] dp;//[pos][groupsLeft][prevColor]\n\nenum IMPOSSIBLE = (ulong.max - 1) >>> 2;\n\nulong dyn(int pos, int groupsLeft, int prevColor) {\n if (pos == n)\n return groupsLeft ? IMPOSSIBLE : 0;\n if (~dp[pos][groupsLeft][prevColor])\n return dp[pos][groupsLeft][prevColor];\n ulong result = IMPOSSIBLE;\n if (colors[pos]) {\n if (prevColor == colors[pos])\n result = dyn(pos + 1, groupsLeft, colors[pos]);\n else if (groupsLeft)\n result = dyn(pos + 1, groupsLeft - 1, colors[pos]);\n } else {\n if (prevColor)\n result = dyn(pos + 1, groupsLeft, prevColor) + p[pos][prevColor - 1];\n if (groupsLeft)\n foreach (i; 1 .. m + 1)\n if (i != prevColor)\n result =\n min(result, dyn(pos + 1, groupsLeft - 1, i) + p[pos][i - 1]);\n }\n return (dp[pos][groupsLeft][prevColor] = result);\n}\n\nvoid main() {\n while (read(&n, &m, &k)) {\n colors = _colors[0 .. n];\n p = _p[0 .. n];\n foreach (ref x; colors)\n read(&x);\n foreach (ref row; p)\n foreach (ref x; row[0 .. m])\n read(&x);\n memset(dp.ptr, 0xFF, dp.sizeof);\n const result = dyn(0, k, 0);\n if (result != IMPOSSIBLE)\n writeln(result);\n else\n write(\"-1\\n\");\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 long INF = 10L ^^ 18 + 23;\n\nvoid main()\n{ \n int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto p = new int[][] (n+1);\n foreach (i; 1 .. n+1) p[i] = [int.max] ~ readln.chomp.split.map!(to!int).array;\n \n debug { c.writeln; p.writeln; }\n \n auto mn = new int[][][] (n+1, k+1, 2);\n foreach (i; 1 .. n+1) foreach (j; 1 .. k+1) mn[i][j].fill(0);\n \n auto dp = new long[][][] (n+1, k+1, m+1);\n foreach (i; 0 .. n+1) {\n foreach (j; 0 .. k+1) {\n dp[i][j].fill(INF); \n }\n }\n \n dp[0][0].fill(0);\n\n foreach (i; 2 .. n+1) {\n foreach (j; 1 .. min(i+1, k+1)) {\n void calcMin(int cc, int cost) {\n if (i == 1 && j == 1) {\n dp[i][j][cc] = cost;\n return;\n }\n \n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][j][cc] + cost);\n \n auto mnOther = mn[i-1][j-1][0] != cc ? mn[i-1][j-1][0] : mn[i-1][j-1][1];\n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][j-1][mnOther] + cost);\n }\n \n if (c[i] != 0) {\n calcMin(c[i], 0);\n } else {\n foreach (cc; 1 .. m+1) {\n calcMin(cc, p[i][cc]);\n }\n }\n \n foreach (cc; 1 .. m+1) {\n if (dp[i][j][cc] < dp[i][j][mn[i][j][0]]) mn[i][j][1] = mn[i][j][0], mn[i][j][0] = cc;\n else if (dp[i][j][cc] < dp[i][j][mn[i][j][1]]) mn[i][j][1] = cc;\n }\n }\n }\n \n debug { \n mn.dropOne.each!writeln;\n \n foreach (i; 1 .. n+1) { \n foreach (j; 1 .. k+1) dp[i][j].writeln;\n writeln;\n }\n }\n \n auto ans = dp[n][k].dropOne.minElement;\n if (ans == INF) ans = -1;\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 int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto p = new int[][] (n+1);\n foreach (i; 1 .. n+1) p[i] = [int.max] ~ readln.chomp.split.map!(to!int).array;\n \n debug { c.writeln; p.writeln; }\n \n auto mn = new int[][][] (n+1, k+1, 2);\n foreach (i; 1 .. n+1) foreach (j; 1 .. k+1) mn[i][j].fill(0);\n \n auto dp = new long[][][] (n+1, k+1, m+1);\n foreach (i; 0 .. n+1) {\n foreach (j; 0 .. k+1) {\n dp[i][j].fill(INF); \n }\n }\n \n dp[0][0].fill(0);\n if (c[1] != 0) dp[1][1][c[1]] = 0;\n else dp[1][1][] = p[1].map!(to!long).array;\n \n foreach (i; 2 .. n+1) {\n foreach (j; 1 .. k+1) {\n void calcMin(int cc, int cost) {\n debug { if (i == 2 && j == 2) writeln(cost); }\n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][j][cc] + cost);\n \n auto mnOther = mn[i-1][j-1][0] != cc ? mn[i-1][j-1][0] : mn[i-1][j-1][1];\n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][j-1][mnOther] + cost);\n }\n \n if (c[i] != 0) {\n calcMin(c[i], 0);\n continue;\n }\n\n foreach (cc; 1 .. m+1) {\n calcMin(cc, p[i][cc]);\n }\n \n foreach (cc; 1 .. m+1) {\n if (dp[i][j][cc] < dp[i][j][mn[i][j][0]]) mn[i][j][1] = mn[i][j][0], mn[i][j][0] = cc;\n else if (dp[i][j][cc] < dp[i][j][mn[i][j][1]]) mn[i][j][1] = cc;\n }\n }\n }\n \n debug { mn.dropOne.each!writeln; }\n \n debug { foreach (i; 1 .. n+1) { dp[i].each!(r => r.dropOne.writeln); writeln; } }\n \n auto ans = dp[n][k].dropOne.minElement;\n if (ans == INF) ans = -1;\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 int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto p = new int[][] (n+1);\n foreach (i; 1 .. n+1) p[i] = [int.max] ~ readln.chomp.split.map!(to!int).array;\n \n debug { c.writeln; p.writeln; }\n \n auto mn = new int[][][] (n+1, k+1, 2);\n foreach (i; 1 .. n+1) foreach (j; 1 .. k+1) mn[i][j].fill(0);\n \n auto dp = new long[][][] (n+1, k+1, m+1);\n foreach (i; 0 .. n+1) {\n foreach (j; 0 .. k+1) {\n dp[i][j].fill(INF); \n }\n }\n \n dp[0][0].fill(0);\n if (c[1] != 0) dp[1][1][c[1]] = 0;\n else dp[1][1][] = p[1].map!(to!long).array;\n \n mn[1][1] = p[1].enumerate.array.sort!((t1, t2) => t1[1] < t2[1])\n .map!(t => t[0].to!int).array.take(2).array;\n \n foreach (i; 2 .. n+1) {\n foreach (j; 1 .. k+1) {\n void calcMin(int cc, int cost) {\n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][j][cc] + cost);\n \n auto mnOther = mn[i-1][j-1][0] != cc ? mn[i-1][j-1][0] : mn[i-1][j-1][1];\n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][j-1][mnOther] + cost);\n debug { if (i == 1 && j == 1) writeln(cost, ' ', dp[i][j][cc]); }\n }\n \n if (c[i] != 0) {\n calcMin(c[i], 0);\n } else {\n foreach (cc; 1 .. m+1) {\n calcMin(cc, p[i][cc]);\n }\n }\n \n foreach (cc; 1 .. m+1) {\n if (dp[i][j][cc] < dp[i][j][mn[i][j][0]]) mn[i][j][1] = mn[i][j][0], mn[i][j][0] = cc;\n else if (dp[i][j][cc] < dp[i][j][mn[i][j][1]]) mn[i][j][1] = cc;\n }\n }\n }\n \n debug { \n mn.dropOne.each!writeln;\n \n foreach (i; 1 .. n+1) { \n foreach (j; 1 .. k+1) dp[i][j].writeln;\n writeln;\n }\n }\n \n auto ans = dp[n][k].dropOne.minElement;\n if (ans == INF) ans = -1;\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 int n, m, k;\n readf(\"%s %s %s\", &n, &m, &k);\n readln;\n\n auto c = [0] ~ readln.chomp.split.map!(to!int).array;\n \n auto p = new int[][] (n+1);\n foreach (i; 1 .. n+1) p[i] = [0] ~ readln.chomp.split.map!(to!int).array;\n \n debug { c.writeln; p.writeln; }\n \n auto dp = new long[][][] (n+1, k+1, m+1);\n foreach (i; 0 .. n+1) {\n foreach (j; 0 .. k+1) {\n dp[i][j].fill(INF); \n }\n }\n \n foreach (j; 0 .. k+1) dp[0][j].fill(0);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. k+1) {\n foreach (pc; 1 .. m+1) {\n if (c[i] != 0) {\n auto prevGroup = pc == c[i] ? j : j-1;\n dp[i][j][c[i]] = min(dp[i][j][c[i]], dp[i-1][prevGroup][pc]);\n \n continue;\n }\n \n foreach (cc; 1 .. m+1) {\n auto prevGroups = pc == cc ? j : j-1;\n dp[i][j][cc] = min(dp[i][j][cc], dp[i-1][prevGroups][pc] + p[i][cc]);\n }\n }\n }\n }\n \n auto ans = dp[n][k].minElement;\n if (ans == INF) ans = -1;\n ans.writeln;\n}"}], "src_uid": "f8fa6afc8946289c484503b0bf9d5551"} {"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\timmutable int n = 9;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto s = readln.strip.dup;\n\t\t\ts.find ('9')[0] = '1';\n\t\t\twriteln (s);\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 t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n auto arr = new dchar[][] (9);\n foreach (r; 0 .. 9) {\n arr[r] = readln.chomp.map!(to!dchar).array;\n }\n \n int c = 0;\n foreach (r; 0 .. 9) {\n arr[r][c] = arr[r][(c+1)%9];\n c += 3;\n if (c >= 9) {\n c %= 9;\n c += 1;\n }\n }\n \n foreach (r; 0 .. 9) {\n writeln(arr[r]);\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nchar change(char c) {\n c += 1;\n if (c > '9') c = '1';\n return c;\n}\n\nvoid main()\n{\n auto T = readln.chomp.to!int;\n foreach (_; 0..T) {\n char[9][9] S;\n foreach (i; 0..9) foreach (j, c; readln.chomp) S[i][j] = c;\n S[0][0] = change(S[0][0]);\n S[1][3] = change(S[1][3]);\n S[2][6] = change(S[2][6]);\n S[3][1] = change(S[3][1]);\n S[4][4] = change(S[4][4]);\n S[5][7] = change(S[5][7]);\n S[6][2] = change(S[6][2]);\n S[7][5] = change(S[7][5]);\n S[8][8] = change(S[8][8]);\n foreach (s; S) writeln(s);\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 char[][][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = new char[][](9);\n\t\tforeach (i; 0..9)\n\t\t{\n\t\t\ts[i] = RD!(char[]);\n\t\t}\n\t\t\n\t\tforeach (i; 0..3)\n\t\t{\n\t\t\tforeach (j; 0..3)\n\t\t\t{\n\t\t\t\tif (i % 3 == 2)\n\t\t\t\t\ts[i+j*3][i*3+j] = s[i+j*3-1][i*3+j];\n\t\t\t\telse\n\t\t\t\t\ts[i+j*3][i*3+j] = s[i+j*3+1][i*3+j];\n\t\t\t}\n\t\t}\n\t\tans[ti] = s;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (ee; e)\n\t\t\twriteln(ee);\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\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 char[][][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto s = new char[][](9);\n\t\tforeach (i; 0..9)\n\t\t{\n\t\t\ts[i] = RD!(char[]);\n\t\t}\n\t\t\n\t\tforeach (i; 0..9)\n\t\t{\n\t\t\tif (i % 3 == 2)\n\t\t\t\ts[i][i] = s[i-1][i];\n\t\t\telse\n\t\t\t\ts[i][i] = s[i+1][i];\n\t\t}\n\t\tans[ti] = s;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (ee; e)\n\t\t\twriteln(ee);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "0e21f1c48c8c0463b2ffa7275eddc633"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\nimport std.conv;\n\nvoid main()\n{\n readln;\n \n auto items = readln\n .split\n .map!(a => to!uint(a))\n .array\n .sort!\"a > b\";\n \n uint summ = items\n .save\n .reduce!((a,b) => a+b);\n\n uint money;\n uint halfMoney = summ / 2;\n uint counter;\n \n foreach(item; items)\n {\n money += item;\n ++counter;\n if (money > halfMoney) break;\n }\n \n counter.writeln;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.sorting;\n\n/* Condizioni:\n - valore maggiore del restante;\n - minor numero possibile di monete;\n*/\nulong sum(uint[] coins) {\n ulong sum = 0;\n foreach(coin; coins) {\n sum += coin;\n }\n return sum;\n}\n\nuint minimum_coins(uint[] coins) {\n auto sortedCoins = sort!(\"a > b\")(coins);\n auto sum = sum(coins);\n uint mine = 0, n_coins=0;\n foreach(coin; sortedCoins) {\n mine += coin;\n n_coins++;\n if (mine > sum / 2) {\n break;\n }\n }\n return n_coins;\n}\n\nint main() {\n uint n, coin;\n uint[] coins;\n readf(\"%s\", &n);\n for(int i = 0; i < n; i++) {\n readf(\" %s\", &coin);\n coins ~= coin;\n }\n auto n_coins = minimum_coins(coins);\n write(n_coins);\n return 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;\n\tscanf(\"%d\", &n);\n\tint[] coins = new int[n];\n\tforeach (int i; 0..n)\n\t{\n\t\tint a;\n\t\tscanf(\"%d\", &a);\n\t\tcoins[i] = a;\n\t}\n\n\tsort!((a, b) => a > b)(coins);\n\tint sum = 0;\n\tforeach (int i; coins)\n\t{\n\t\tsum += i;\n\t}\n\tint ms = 0;\n\tint noc = 0;\n\tforeach (int i; coins)\n\t{\n\t\tms += i;\n\t\tnoc++;\n\t\tsum -= i;\n\t\tif (ms > sum)\n\t\t\tbreak;\n\t}\n\tprintf(\"%d\", noc);\n\treturn 0;\n}\n"}], "negative_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 readln;\n auto items = readln\n .split\n .map!(a => to!uint(a))\n .array\n .sort!\"a > b\";\n uint summ = items\n .save\n .reduce!((a,b) => a+b);\n\n uint money;\n uint halfMoney = cast(uint)ceil(cast(double)summ/2);\n uint counter;\n \n foreach(item; items)\n {\n money += item;\n ++counter;\n if (money > halfMoney) break;\n }\n \n counter.writeln;\n}"}], "src_uid": "ee535e202b7662dbaa91e869c8c6cee1"} {"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 s = readln.strip;\r\n\r\n\t\tint balance = 0;\r\n\t\tint res = 0;\r\n\t\tauto num = new int [n + 1];\r\n\t\tforeach (ref c; s)\r\n\t\t{\r\n\t\t\tif (c == '(')\r\n\t\t\t{\r\n\t\t\t\tres += (num[balance] == 0);\r\n\t\t\t\tnum[balance] += 1;\r\n\t\t\t\tbalance += 1;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tnum[balance] = 0;\r\n\t\t\t\tbalance -= 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;\r\nvoid main () {\r\n\tforeach (r; 0..readln.strip.to !(int)) {\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\twriteln (n - readln.strip.count (\")(\"));\r\n\t}\r\n}\r\n"}, {"source_code": "import std;\r\nvoid main () {\r\n\tforeach (r; 0..readln.strip.to !(int)) {\r\n\t\tauto n = readln.strip.to !(int);\r\n\t\twriteln (n - readln.strip.count (\")(\"));\r\n\t}\r\n}"}], "negative_code": [], "src_uid": "6280a3373ab8fc34bb41fd98648019a6"} {"source_code": "import std.stdio;\nimport std.math;\n\nunittest{\n assert(solve([0,0,1,1]) == [1,0,0,1],\"A\");\n\n assert(solve([0,0,0,1]) == [1,0,1,1],\"B\");\n\n assert(solve([0,0,1,2]) == [],\"C\");\n\n assert(solve([-1,1,1,-1]) == [1, 1,-1,-1 ],\"D1\");\n\n assert(solve([-100,100,100,-100]) == [100,100,-100,-100],\"D2\");\n\n}\n\n\nint[] solve(int[] p){\n int d,d2;\n int[] p0 = p[0..2];\n int[] p1 = p[2..$];\n d = abs(p0[0] - p1[0]);\n d2 = abs(p0[1] - p1[1]);\n debug(1) writeln(\">\",d);\n debug(1) writeln(\"!\",d2);\n\n\n if(d > 0 && d2 >0){\n if(d != d2){\n return [];\n }\n }\n\n if(d == 0){\n d = d2;\n }\n\n int[] r;\n if(p0[0] == p1[0]){\n auto f = p0[0];\n r = [f+d,p0[1],f+d,p1[1]];\n debug(1) writeln(\"A\");\n } else if(p0[1] == p1[1]){\n auto f = p0[1];\n r = [p0[0],f+d,p1[0],f+d];\n debug(1) writeln(\"B\");\n } else {\n auto t = p0;\n if(p0[0] < p1[0]){\n r = [p0[0]+d,p0[1],p1[0]-d,p1[1]];\n } else {\n r = [p0[0]-d,p0[1],p1[0]+d,p1[1]];\n }\n debug(1) writeln(\"C\");\n }\n debug(1) writeln(r);\n return r;\n}\n\nvoid main(){\n int[] x = new int[4];\n for(int i = 0; i< x.length; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n if (s.length == 0){\n writeln(-1);\n return;\n }\n writefln(\"%s %s %s %s\",s[0],s[1],s[2],s[3]);\n}\n", "positive_code": [{"source_code": "import std.math;\nimport std.typecons;\nimport std.algorithm;\n\nalias Tuple!(int, \"x\", int, \"y\") Point;\n\nbool solve(const Point a, const Point b, out Point c, out Point d) {\n\tauto dx = abs(a.x - b.x);\n\tauto dy = abs(a.y - b.y);\n\tif (0 != dx && 0 != dy && dx != dy) {\n\t\treturn false;\n\t}\n\n\tauto dd = max(dx, dy);\n\tauto addX = (0 == dx) ? dd : 0;\n\tauto addY = (0 == dy) ? dd : 0;\n\tc.x = a.x + addX;\n\tc.y = b.y + addY;\n\td.x = b.x + addX;\n\td.y = a.y + addY;\n\n\treturn true;\n}\n\nunittest {\n\t{\n\t\tPoint c, d;\n\t\tassert(solve(Point(0, 0), Point(0, 1), c, d));\n\t}\n}\n\nint main(string[] argv) {\n\timport std.stdio;\n\tPoint a, b, c, d;\n\twhile (readf(\" %s %s %s %s\", &(a.x), &(a.y), &(b.x), &(b.y))) {\n\t\tif (solve(a, b, c, d)) {\n\t\t\twriteln(c.x, ' ', c.y, ' ', d.x, ' ', d.y);\n\t\t} else {\n\t\t\twriteln(-1);\n\t\t}\n\t}\n return 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.math;\n\nunittest{\n assert(solve([0,0,1,1]) == [1,0,0,1],\"A\");\n // assert(solve([0,0,1,0]) == [0,1,1,1],\"A1\");\n // assert(solve([0,0,-1,0]) == [0,1,1,0],\"A2\");\n // assert(solve([0,0,1,1]) == [0,1,-1,1],\"A3\");\n // assert(solve([0,0,0,1]) == [1,0,1,1],\"A4\");\n // assert(solve([0,0,-1,1]) == [0,-1,-1,0],\"A5\");\n // assert(solve([0,0,1,-1]) == [1,0,0,-1],\"A6\");\n // assert(solve([0,0,0,-1]) == [1,-1,1,0],\"A7\");\n // assert(solve([0,0,-1,-1]) == [-1,0,0,-1],\"A8\");\n\n assert(solve([0,0,0,1]) == [1,0,1,1],\"B\");\n}\n\nint[] solve(int[] p){\n int d,h;\n int[] p0 = p[0..2];\n int[] p1 = p[2..$];\n if (p0[0] - p1[0] != 0){\n d = abs(p0[0] - p1[0]);\n } else {\n d = abs(p0[1] - p1[1]);\n }\n\n int[] r;\n if(p0[0] == p1[0]){\n auto f = p0[0];\n r = [f+d,p0[1],f+d,p1[1]];\n } else if(p0[1] == p1[1]){\n auto f = p0[1];\n r = [p0[0],f+d,p1[0],f+d];\n } else {\n auto t = p0;\n if(p0[0] > p1[0]){\n t = p1;\n }\n r = [t[0]+d,t[1],t[0],t[1]+d];\n }\n debug(1) writeln(r);\n return r;\n}\n\nvoid main(){\n int[] x = new int[4];\n for(int i = 0; i< x.length; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n if (s.length == 0){\n writeln(-1);\n return;\n }\n writefln(\"%s %s %s %s\",s[0],s[1],s[2],s[3]);\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\n\nunittest{\n assert(solve([0,0,1,1]) == [1,0,0,1],\"A\");\n // assert(solve([0,0,1,0]) == [0,1,1,1],\"A1\");\n // assert(solve([0,0,-1,0]) == [0,1,1,0],\"A2\");\n // assert(solve([0,0,1,1]) == [0,1,-1,1],\"A3\");\n // assert(solve([0,0,0,1]) == [1,0,1,1],\"A4\");\n // assert(solve([0,0,-1,1]) == [0,-1,-1,0],\"A5\");\n // assert(solve([0,0,1,-1]) == [1,0,0,-1],\"A6\");\n // assert(solve([0,0,0,-1]) == [1,-1,1,0],\"A7\");\n // assert(solve([0,0,-1,-1]) == [-1,0,0,-1],\"A8\");\n\n assert(solve([0,0,0,1]) == [1,0,1,1],\"B\");\n\n assert(solve([0,0,1,2]) == [],\"C\");\n}\n\nint[] solve(int[] p){\n int d,d2;\n int[] p0 = p[0..2];\n int[] p1 = p[2..$];\n d = abs(p0[0] - p1[0]);\n d2 = abs(p0[1] - p1[1]);\n debug(1) writeln(\">\",d);\n debug(1) writeln(\"!\",d2);\n\n\n if(d > 0 && d2 >0){\n if(d != d2){\n return [];\n }\n }\n\n if(d == 0){\n d = d2;\n }\n\n int[] r;\n if(p0[0] == p1[0]){\n auto f = p0[0];\n r = [f+d,p0[1],f+d,p1[1]];\n } else if(p0[1] == p1[1]){\n auto f = p0[1];\n r = [p0[0],f+d,p1[0],f+d];\n } else {\n auto t = p0;\n if(p0[0] > p1[0]){\n t = p1;\n }\n r = [t[0]+d,t[1],t[0],t[1]+d];\n }\n debug(1) writeln(r);\n return r;\n}\n\nvoid main(){\n int[] x = new int[4];\n for(int i = 0; i< x.length; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n if (s.length == 0){\n writeln(-1);\n return;\n }\n writefln(\"%s %s %s %s\",s[0],s[1],s[2],s[3]);\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\n\nunittest{\n assert(solve([0,0,1,1]) == [0,1,1,0],\"A\");\n assert(solve([0,0,0,1]) == [1,0,1,1],\"A\");\n}\n\nint[] solve(int[] p){\n int d,h;\n int[] p0 = p[0..2];\n int[] p1 = p[2..$];\n if (p0[0] - p1[0] != 0){\n d = abs(p0[0] - p1[0]);\n } else {\n d = abs(p0[1] - p1[1]);\n }\n auto pts =\n[\n [p0[0] ,p0[1]+d,3,4],\n [p0[0] ,p0[1]-d,3,5],\n [p0[0]+d,0 ,1,4],\n [p0[0]+d,p0[1]+d,1,3],\n [p0[0]+d,p0[1]-d,2,3],\n [p0[0]-d,0 ,2,8],\n [p0[0]-d,p0[1]+d,1,6],\n [p0[0]-d,p0[1]-d,2,6]\n];\n\n for(int i = 0; i < pts.length; i++){\n if(p1[0] == pts[i][0] && p1[1] == pts[i][1]){\n debug(1) writefln(\">%s\",i);\n auto s0 = pts[i][2]-1;\n auto s1 = pts[i][3]-1;\n debug(1) writeln([pts[s0][0],pts[s0][1],pts[s1][0],pts[s1][1]]);\n return [pts[s0][0],pts[s0][1],pts[s1][0],pts[s1][1]];\n }\n //debug(1) writefln(pts);\n }\n return [];\n}\n\nvoid main(){\n\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\n\nunittest{\n assert(solve([0,0,1,1]) == [0,1,1,0],\"A\");\n assert(solve([0,0,0,1]) == [1,0,1,1],\"A\");\n}\n\nint[] solve(int[] p){\n int d,h;\n int[] p0 = p[0..2];\n int[] p1 = p[2..$];\n if (p0[0] - p1[0] != 0){\n d = abs(p0[0] - p1[0]);\n } else {\n d = abs(p0[1] - p1[1]);\n }\n auto pts =\n[\n [p0[0] ,p0[1]+d,3,4],\n [p0[0] ,p0[1]-d,3,5],\n [p0[0]+d,0 ,1,4],\n [p0[0]+d,p0[1]+d,1,3],\n [p0[0]+d,p0[1]-d,2,3],\n [p0[0]-d,0 ,2,8],\n [p0[0]-d,p0[1]+d,1,6],\n [p0[0]-d,p0[1]-d,2,6]\n];\n\n for(int i = 0; i < pts.length; i++){\n if(p1[0] == pts[i][0] && p1[1] == pts[i][1]){\n debug(1) writefln(\">%s\",i);\n auto s0 = pts[i][2]-1;\n auto s1 = pts[i][3]-1;\n debug(1) writeln([pts[s0][0],pts[s0][1],pts[s1][0],pts[s1][1]]);\n return [pts[s0][0],pts[s0][1],pts[s1][0],pts[s1][1]];\n }\n //debug(1) writefln(pts);\n }\n return [];\n}\n\nvoid main(){\n int[] x = new int[4];\n for(int i = 0; i< x.length; i++){\n readf(\"%s \",x.ptr+i);\n }\n auto s = solve(x);\n if (s.length == 0){\n writeln(-1);\n return;\n }\n writefln(\"%s %s %s %s\",s[0],s[1],s[2],s[3]);\n}\n"}], "src_uid": "71dea31e1244797f916adf5f526f776e"} {"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\nbool check(int ban) {\r\n int[] as;\r\n foreach (a; A) {\r\n if (a != ban) {\r\n as ~= a;\r\n }\r\n }\r\n const asLen = cast(int)(as.length);\r\n for (int l = 0, r = asLen - 1; l < r; ++l, --r) {\r\n if (as[l] != as[r]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n\r\nbool solve() {\r\n for (int l = 0, r = N - 1; l < r; ++l, --r) {\r\n if (A[l] != A[r]) {\r\n if (check(A[l])) return true;\r\n if (check(A[r])) return true;\r\n return false;\r\n }\r\n }\r\n return true;\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 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 }\r\n } catch (EOFException e) {\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\twhile (n >= 2 && a.front == a.back)\r\n\t\t{\r\n\t\t\tn -= 2;\r\n\t\t\ta = a[1..$ - 1];\r\n\t\t}\r\n\t\tbool ok = false;\r\n\t\tok |= a.equal (a.retro);\r\n\t\tif (!a.empty)\r\n\t\t{\r\n\t\t\tauto u = a.filter !(c => c != a.front).array;\r\n\t\t\tok |= u.equal (u.retro);\r\n\t\t\tauto v = a.filter !(c => c != a.back).array;\r\n\t\t\tok |= v.equal (v.retro);\r\n\t }\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\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 = ma(n, readInt!int);\n\tint[2] nonGood = [-1, -1];\n\tint lo = 0;\n\tint hi = n - 1;\n\twhile (lo < hi)\n\t{\n\t\tif (a[lo] != a[hi]) { nonGood = [a[lo], a[hi]]; break; }\n\t\tlo++, hi--;\n\t}\n\tbool isGood(int v)\n\t{\n\t\tdebug writeln(\"trying \", v);\n\t\tint lo = 0;\n\t\tint hi = n - 1;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\twhile (a[lo] == v) lo++;\n\t\t\twhile (a[hi] == v) hi--;\n\t\t\tif (lo >= hi) break;\n\t\t\tif (a[lo] != a[hi]) return false;\n\t\t\tlo++, hi--;\n\t\t}\n\t\tdebug writeln(\"which is good\");\n\t\treturn true;\n\t}\n\tif (nonGood == [-1, -1] || isGood(nonGood[0]) || isGood(nonGood[1]))\n\t\treturn writeln(\"YES\");\n\treturn writeln(\"NO\");\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.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool is_palindrome(int[] a)\n{\n foreach (i ; 0 .. a.length)\n if (a[i] != a[$ - 1 - i])\n return false;\n return true;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n foreach (casenum ; 1 .. t + 1) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.splitter.map!(to!int).array;\n int i = 0;\n int j = n - 1;\n int bad1 = -1;\n int bad2 = -1;\n while (i < n && j >= 0) {\n if (a[i] != a[j]) {\n bad1 = a[i];\n bad2 = a[j];\n break;\n }\n i++;\n j--;\n }\n if (bad1 == -1 || bad2 == -1) {\n writeln(\"YES\");\n } else {\n auto a1 = a.filter!(x => x != bad1).array;\n auto a2 = a.filter!(x => x != bad2).array;\n if (is_palindrome(a1) || is_palindrome(a2))\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\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!int;\r\n\r\n\t\tbool dfs(int l, int r, int x)\r\n\t\t{\r\n\t\t\tif (l >= r) return true;\r\n\t\t\tif (a[l] == a[r]) return dfs(l+1, r-1, x);\r\n\r\n\t\t\tbool res;\r\n\t\t\tif (a[l] == x || x == 0)\r\n\t\t\t\tres |= dfs(l+1, r, a[l]);\r\n\t\t\tif (a[r] == x || x == 0)\r\n\t\t\t\tres |= dfs(l, r-1, a[r]);\r\n\t\t\treturn res;\r\n\t\t}\r\n\t\tans[ti] = dfs(0, n-1, 0);\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": "// 提出解\r\nvoid solve(){\r\n\tA: foreach(_; 0 .. scan!int){\r\n\t\tint n = scan!int;\r\n\t\tint[] as = scan!int(n);\r\n\r\n\t\tint[] xs;\r\n\t\tfor(int i = 0, j = n - 1; i < j; i ++, j --){\r\n\t\t\tif(as[i] != as[j]){\r\n\t\t\t\txs = [as[i], as[j]];\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(xs.length == 0){\r\n\t\t\t\"YES\".print;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tforeach(x; xs){\r\n\t\t\tbool isOK = 1;\r\n\t\t\tfor(int i = 0, j = n - 1; i < j; ){\r\n\t\t\t\tif(as[i] == x){\r\n\t\t\t\t\ti ++;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\telse if(as[j] == x){\r\n\t\t\t\t\tj --;\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\t\t\t\tif(as[i] != as[j]){\r\n\t\t\t\t\tisOK = 0;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\ti ++, j --;\r\n\t\t\t}\r\n\t\t\tif(isOK){\r\n\t\t\t\t\"YES\".print;\r\n\t\t\t\tcontinue A;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\"NO\".print;\r\n\t}\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// 愚直解\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テストケース\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テンプレ\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// ライブラリ(基本)\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// ライブラリ(追加)\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 m, n;\r\n\t\treadf !(\" %s %s\") (m, n);\r\n\t\twriteln ((m > 1) + (n > 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 a = readln.splitter.map !(to !(int)).array;\r\n\t\twhile (n >= 2 && a.front == a.back)\r\n\t\t{\r\n\t\t\tn -= 2;\r\n\t\t\ta = a[1..$];\r\n\t\t}\r\n\t\tbool ok = false;\r\n\t\tok |= a.equal (a.retro);\r\n\t\tif (!a.empty)\r\n\t\t{\r\n\t\t\tauto u = a.filter !(c => c != a.front).array;\r\n\t\t\tok |= u.equal (u.retro);\r\n\t\t\tauto v = a.filter !(c => c != a.back).array;\r\n\t\t\tok |= v.equal (v.retro);\r\n\t }\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\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\twhile (n >= 2 && a.front == a.back)\r\n\t\t{\r\n\t\t\tn -= 2;\r\n\t\t\ta = a[1..$];\r\n\t\t}\r\n\t\tbool ok = false;\r\n\t\tok |= a.equal (a.retro);\r\n\t\tauto u = a.filter !(c => c != a.front).array;\r\n\t\tok |= u.equal (u.retro);\r\n\t\tauto v = a.filter !(c => c != a.back).array;\r\n\t\tok |= v.equal (v.retro);\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\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 = ma(n, readInt!int);\n\tauto dv = redBlackTree!int();\n\tforeach(ai; a) dv.insert(ai);\n\tauto a0 = dv.front;\n\tint[2] nonGood = [-1, -1];\n\tint lo = 0;\n\tint hi = n - 1;\n\twhile (lo < hi)\n\t{\n\t\twhile (a[lo] == a0) lo++;\n\t\twhile (a[hi] == a0) hi--;\n\t\tif (lo >= hi) break;\n\t\tif (a[lo] != a[hi]) nonGood = [a[lo], a[hi]];\n\t\tlo++, hi--;\n\t}\n\tbool isGood(int v)\n\t{\n\t\tdebug writeln(\"trying \", v);\n\t\tint lo = 0;\n\t\tint hi = n - 1;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\twhile (a[lo] == v) lo++;\n\t\t\twhile (a[hi] == v) hi--;\n\t\t\tif (lo >= hi) break;\n\t\t\tif (a[lo] != a[hi]) return false;\n\t\t\tlo++, hi--;\n\t\t}\n\t\tdebug writeln(\"which is good\");\n\t\treturn true;\n\t}\n\tif (nonGood == [-1, -1] || isGood(nonGood[0]) || isGood(nonGood[1]))\n\t\treturn writeln(\"YES\");\n\treturn writeln(\"NO\");\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": "712e6e228e8b7cedd9bf6b85cd35c0b7"} {"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 long ct, cw;\n readf(\"%s %s\", &ct, &cw);\n readln;\n \n Tuple!(long, long)[] arr;\n foreach (_; 0 .. n-1) {\n long t, w;\n readf(\"%s %s\", &t, &w);\n readln;\n \n arr ~= tuple(t, w);\n }\n \n arr.schwartzSort!(x => x[0]);\n \n debug { arr.writeln; }\n \n auto rbt = make!(RedBlackTree!(long, \"a < b\", true));\n \n while (arr.back[0] > ct) {\n rbt.insert(arr.back[1] - arr.back[0] + 1);\n arr.popBack();\n }\n\n int ans = rbt.length.to!int + 1;\n while (!rbt.empty && rbt.front <= ct) {\n if (!rbt.empty && rbt.front <= ct) {\n ct -= rbt.front;\n rbt.removeFront();\n }\n \n while (!arr.empty && arr.back[0] > ct) {\n rbt.insert(arr.back[1] - arr.back[0] + 1);\n arr.popBack();\n }\n \n ans = min(ans, rbt.length + 1);\n }\n \n ans = min(ans, rbt.length + 1);\n \n ans.writeln;\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\", 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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\tlong t,w;\n\t\tinput(&t,&w);\n\t\tauto a=new pll[n-1];\n\t\tforeach(i;0..n-1) input(&a[i].fi,&a[i].se);\n\t\tsort(a);\n\t\tauto r=new long[n-1];\n\t\tforeach(i;0..n-1)r[i]=a[i].se-a[i].fi+1;\n\t\tint pos=upb(a,mp(t,long.max));\n\t\tauto q=rbt!(true,long)(r[pos..$]);\n\t\tint ans=q.length;\n\t\twhile(!q.empty && t>=q.front)\n\t\t{\n\t\t\tt-=q.front;\n\t\t\tq.removeFront;\n\t\t\tint p=upb(a,mp(t,long.max));\n\t\t\tif(p0)\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\", 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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\tlong t,w;\n\t\tinput(&t,&w);\n\t\tauto a=new pll[n-1];\n\t\tforeach(i;0..n-1) input(&a[i].fi,&a[i].se);\n\t\tsort(a);\n\t\tauto r=new long[n-1];\n\t\tforeach(i;0..n-1)r[i]=a[i].se-a[i].fi+1;\n\t\tint pos=upb(a,mp(t,long.max));\n\t\tauto q=heapify(r[pos..$]);\n\t\tint ans=q.length;\n\t\twhile(!q.empty && t>=q.front)\n\t\t{\n\t\t\tt-=q.front;\n\t\t\tq.removeFront;\n\t\t\tint p=upb(a,mp(t,long.max));\n\t\t\tforeach(i;r[p..pos])q.insert(i);\n\t\t\tpos=p;\n\t\t\tans=min(ans,q.length);\n\t\t}\n\t\twriteln(ans+1);\n\t}\n\tdebug system(\"pause\");\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;\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\", 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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\tlong t,w;\n\t\tinput(&t,&w);\n\t\tauto a=new pll[n-1];\n\t\tforeach(i;0..n-1) input(&a[i].fi,&a[i].se);\n\t\tsort(a);\n\t\tauto r=new long[n-1];\n\t\tforeach(i;0..n-1)r[i]=a[i].se-a[i].fi+1;\n\t\tint pos=upb(a,mp(t,long.max));\n\t\tauto q=rbt!(true,long)(r[pos..$]);\n\t\tint ans=q.length;\n\t\twhile(pos>0 && !q.empty && t>=q.front)\n\t\t{\n\t\t\tt-=q.front;\n\t\t\tq.removeFront;\n\t\t\tint p=upb(a,mp(t,long.max));\n\t\t\tif(p0)\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\", 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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\tlong t,w;\n\t\tinput(&t,&w);\n\t\tauto a=new pll[n-1];\n\t\tforeach(i;0..n-1) input(&a[i].fi,&a[i].se);\n\t\tsort(a);\n\t\tauto r=new long[n-1];\n\t\tforeach(i;0..n-1)r[i]=a[i].se-a[i].fi+1;\n\t\tint pos=upb(a,mp(t,long.max));\n\t\tauto q=rbt!(true)(r[pos..$]);\n\t\tint ans=q.length;\n\t\twhile(pos>0 && !q.empty && t>=q.front)\n\t\t{\n\t\t\tt-=q.front;\n\t\t\tq.removeFront;\n\t\t\tint p=upb(a,mp(t,long.max));\n\t\t\tq.insert(r[p..pos]);\n\t\t\tpos=p;\n\t\t\tans=min(ans,q.length);\n\t\t}\n\t\twriteln(ans+1);\n\t}\n\tdebug system(\"pause\");\n}"}], "src_uid": "3fb43df3a6f763f196aa514f305473e2"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 b = RDA;\n\n\t\tbool[long] set;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (set.get(b[i], false))\n\t\t\t{\n\t\t\t\tans[ti] = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tset[b[i]] = true;\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\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\tsort (a);\n\t\twriteln (a.isStrictlyMonotonic ? \"NO\" : \"YES\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "3674a98de27b9bd2c8eb951da72996f5"} {"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 long[int] freq;\n auto y=new int[](n);\n auto ng=new bool[](n);\n foreach(i; 0..n){\n auto s=readln.chomp.to!(char[]);\n char[] st;\n foreach(c; s){\n if(c=='('){\n st~='(';\n }else{\n if(st.length>0){\n if(st.back=='(') st=st[0..($-1)];\n else st~=')';\n }else{\n st~=')';\n }\n }\n }\n int x=0;\n foreach(c; st){\n if(c=='(') x++;\n else x--;\n }\n if(st.length>=2 && (st[0]==')' && st[$-1]=='(')){ng[i]=true; continue;}\n y[i]=x;\n if(x in freq) freq[x]++;\n else freq[x]=1;\n hell:;\n }\n \n long tot=0;\n foreach(i; 0..n)if(ng[i]==false){\n if(y[i]>=0 && (-y[i] in freq)){\n tot+=freq[-y[i]];\n }\n // writeln(tot);\n }\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) e=l[i].to!(typeof(e));\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\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n string[] strs;\n foreach (_; 0..n) strs ~= readln.chomp;\n \n long ans = 0;\n int [int] v;\n foreach (s; strs) {\n int sc = 0, lo = 0;\n foreach (c; s) {\n if (c == '(') ++sc;\n else {\n --sc;\n lo = min(lo, sc);\n }\n }\n \n debug { writeln(s, ' ', sc, ' ', lo); }\n \n if (lo < 0 && lo < sc) continue;\n \n ans += sc == 0 ? v.get(0, 0) * 2 + 1 : v.get(-sc, 0);\n v[sc] += 1;\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 N = readln.chomp.to!int;\n auto S = N.iota.map!(_ => readln.chomp).array;\n auto cnts = new int[](N);\n auto mns = new int[](N);\n int[int] mn;\n\n\n foreach (i, s; S.enumerate) {\n int cnt = 0;\n int minv = 0;\n foreach (c; s) {\n cnt += c == '(' ? 1 : -1;\n minv = min(minv, cnt);\n }\n cnts[i] = cnt;\n mns[i] = minv;\n if (minv == cnts[i]) mn[minv] += 1;\n }\n\n long ans = 0;\n foreach (i; 0..N) {\n if (mns[i] < 0) continue;\n if (-cnts[i] !in mn) continue;\n ans += mn[-cnts[i]];\n }\n\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 n; rd(n);\n long[int] freq;\n auto y=new int[](n);\n auto ng=new bool[](n);\n foreach(i; 0..n){\n auto s=readln.chomp.to!(char[]);\n char[] st;\n foreach(c; s){\n if(c=='('){\n st~='(';\n }else{\n if(st.length>0){\n if(st.back=='(') st=st[0..($-1)];\n else st~=')';\n }else{\n st~=')';\n }\n }\n }\n int x=0;\n foreach(c; st){\n if(c=='(') x++;\n else x--;\n }\n if(st.length>=2 && (st[0]==')' && st[$-1]=='(')) continue;\n y[i]=x;\n if(x in freq) freq[x]++;\n else freq[x]=1;\n hell:;\n }\n \n long tot=0;\n foreach(i; 0..n)if(ng[i]==false){\n if(y[i]>=0 && (-y[i] in freq)){\n tot+=freq[-y[i]];\n }\n // writeln(tot);\n }\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) 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; rd(n);\n long[int] freq;\n auto y=new int[](n);\n auto ng=new bool[](n);\n foreach(i; 0..n){\n auto s=readln.chomp.to!(char[]);\n int x=0;\n foreach(c; s){\n if(c=='('){\n if(x<0){ng[i]=true; goto hell;}\n else x++;\n }else{\n x--;\n }\n }\n y[i]=x;\n if(x in freq) freq[x]++;\n else freq[x]=1;\n hell:;\n }\n \n long tot=0;\n foreach(i; 0..n)if(ng[i]==false){\n if(y[i]>=0 && (-y[i] in freq)){\n tot+=freq[-y[i]];\n if(freq[y[i]]==0) tot--;\n }\n // writeln(tot);\n }\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) e=l[i].to!(typeof(e));\n}"}], "src_uid": "f5f163198fbde6a5c15c50733cfd9176"} {"source_code": "import std.stdio;\nimport std.container;\nint sz(t)(ref t x){return cast(int)x.length;}\n\nstruct trie{\n int[][] tr;\n int[] c;\n int root=1,cur=1;\n this(int n){\n tr=new int[][](n,2);\n c=new int[n];\n update(0,1);\n }\n void update(int x,int v){\n int n=root;\n c[n]+=v;\n for(int i=29;i>=0;i--){\n int k=(x>>i)&1;\n if(tr[n][k]==0){\n ++cur;\n tr[n][k]=cur;\n }\n n=tr[n][k];\n c[n]+=v;\n }\n }\n int query(int x){\n int n=root,r=0;\n for(int i=29;i>=0;i--){\n int k=(x>>i)&1;\n if(tr[n][k^1]==0 || c[tr[n][k^1]]==0) r=r;\n else{\n r^=(1<=0;i--){\n int k=(x>>i)&1;\n if(tr[n][k]==0){\n ++cur;\n tr[n][k]=cur;\n }\n n=tr[n][k];\n c[n]+=v;\n }\n }\n int query(int x){\n int n=root,r=0;\n for(int i=29;i>=0;i--){\n int k=(x>>i)&1;\n if(tr[n][k^1]==0 || c[tr[n][k^1]]==0) r=r;\n else{\n r^=(1< 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 long n, k;\n read(n, k);\n auto a = makeArray!long(n, next!long);\n auto w = makeArray!long(k, next!long);\n auto sa = sort(a[]);\n auto sw = sort(w[]);\n size_t i = 0;\n size_t pi = -1;\n long res = 0;\n long[] nw = null;\n foreach(ref wi; sw)\n {\n if (wi == 1)\n {\n res += 2 * sa.back;\n sa.popBack;\n }\n else\n {\n res += sa.back;\n sa.popBack;\n nw ~= wi - 1;\n }\n }\n foreach_reverse(wi; nw)\n {\n res += sa.at(i);\n i += wi;\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) { 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!int;\n\t\tauto a = RDA;\n\t\tauto w = RDA;\n\t\t\n\t\tdebug writeln(a);\n\t\ta.sort!\"a > b\";\n\t\tw.sort;\n\t\tdebug writeln(a);\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tdebug writeln(\"w[i]:\", w[i], \" \", a);\n\t\t\tif (w[i] == 1)\n\t\t\t{\n\t\t\t\tans[ti] += a.front * 2; a.popFront;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans[ti] += a.front; a.popFront;\n\t\t\t}\n\t\t\tif (w[i] == 2)\n\t\t\t{\n\t\t\t\tans[ti] += a.front; a.popFront;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tdebug writeln(\"w[i]:\", w[i], \" \", a);\n\t\t\tif (w[i] <= 2) continue;\n\t\t\tforeach (j; 0..w[i]-2)\n\t\t\t{\n\t\t\t\ta.popFront;\n\t\t\t}\n\t\t\tans[ti] += a.front; a.popFront;\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;\nimport std.range;\nimport std.algorithm;\n\nvoid main() {\n\tint t;\n\tscanf(\"%d\", &t);\n\t\n\twhile (t--) {\n\t\tint n, k; \n\t\tscanf(\"%d%d\", &n, &k);\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\tint[] cnt = new int[k];\n\t\tforeach (i; iota(k)) scanf(\"%d\", &cnt[i]);\n\t\t\n\t\tsort(arr);\n\t\tsort(cnt);\n\t\t\n\t\tint largest_index = n - 1;\n\t\tint smallest_index = 0;\n\t\t\n\t\tlong res = 0;\n\t\t\n\t\tfor (int i = 0; i < n && cnt[i] == 1; i++) {\n\t\t\tres += 2 * arr[largest_index--];\n\t\t}\n\t\t\n\t\tfor (int i = cnt.length - 1; i >= 0 && cnt[i] > 1; i--) {\n\t\t\tres += arr[largest_index--];\n\t\t\tres += arr[smallest_index];\n\t\t\tsmallest_index += cnt[i] - 1;\n\t\t}\n\t\t\n\t\tres.writeln;\n\t}\n}\n"}], "negative_code": [], "src_uid": "9802646ecc8890bb046d5ec1a4262d70"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1398/problem/C\n//\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long t = readln.chomp.to!long;\n while(t--) {\n long n = readln.chomp.to!long;\n string s = readln.strip;\n\n long[] a;\n\n foreach(ch; s)\n a ~= ch - '0';\n\n long[long] counter;\n counter[0] = 1;\n\n long cumulative = 0;\n long ans = 0;\n\n for(int i = 0; i < n; ++i) {\n cumulative += a[i];\n //writefln(\"cumulative: %s\", cumulative);\n\n long x = cumulative - i - 1;\n\n //writefln(\"buscando %s\", x);\n\n if(counter.get(x, -1) == -1)\n counter[x] = 0;\n counter[x] += 1;\n\n //writefln(\"counter de %s: %s\", x, counter[x]);\n\n ans += counter[x] - 1;\n }\n\n ans.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\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\t\tint[int] cnt;\n\t\tcnt[0] = 1;\n\t\tint x;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tx += s[i] - '0';\n\t\t\tauto y = x-i-1;\n\t\t\tans[ti] += cnt.get(y, 0);\n\t\t\tcnt[y] += 1;\n\t\t\tdebug writeln(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}"}, {"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.strip.map !(q{a - '0'}).array;\n\t\ta[] -= 1;\n\t\tint [int] f;\n\t\tf[0] = 1;\n\t\tint cur = 0;\n\t\tlong res = 0;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tcur += c;\n\t\t\tf[cur] += 1;\n\t\t\tres += f[cur] - 1;\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 s = RD!string;\n\t\tint[int] cnt;\n\t\tcnt[0] = 1;\n\t\tint x;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tx += s[i] - '0';\n\t\t\tauto y = x-i-1;\n\t\t\tans[ti] += cnt.get(y, 0);\n\t\t\tcnt[y] += 1;\n\t\t\tdebug writeln(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}"}], "src_uid": "e5244179b8ef807b1c6abfe113bd4f3b"} {"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[][] v = new char[][n];\n bool seat_found = false;\n for (int i = 0; i < n; i++) {\n v[i] = new char[5];\n v[i] = cin.read_string.dup;\n }\n\n for (int i = 0; i < n; i++) {\n bool flag1 = (v[i][0] == 'O' && v[i][1] == 'O');\n bool flag2 = (v[i][3] == 'O' && v[i][4] == 'O'); \n if (!seat_found && flag1) {\n seat_found = true;\n v[i][0] = '+';\n v[i][1] = '+';\n } else if (!seat_found && flag2) {\n seat_found = true;\n v[i][3] = '+';\n v[i][4] = '+';\n }\n }\n\n if (!seat_found) writeln(\"NO\");\n else {\n writeln(\"YES\");\n foreach (i; v) {\n foreach(j; i) \n write(j);\n writeln();\n }\n }\n } \n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid position(int n, int row, int col, char[6][1000] rows)\n{\n\trows[row][col] = rows[row][col + 1] = '+';\n\n\tprintf(\"YES\\n\");\n\tfor (int i = 0; i < n; i++) {\n\t\tprintf(\"%s\\n\", rows[i].ptr);\n\t}\n}\n\nvoid main()\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\n\tchar[6][1000] rows;\n\tfor (int i = 0; i < n; i++) {\n\t\tscanf(\"%s\", rows[i].ptr);\n\t}\n\n\tfor (int i = 0; i < n; i++) {\n\t\tif (rows[i][0] == 'O' && rows[i][1] == 'O') {\n\t\t\tposition(n, i, 0, rows);\n\t\t\treturn;\n\t\t}\n\t\tif (rows[i][3] == 'O' && rows[i][4] == 'O') {\n\t\t\tposition(n, i, 3, rows);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprintf(\"NO\\n\");\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;\n\tscanf(\"%d\\n\", &n);\n\tstring[] seats; seats.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tseats[i] = readln();\n\t}\n\tbool there_is_seat = false;\n\tforeach (int i; 0..n)\n\t{\n\t\tif (canFind(seats[i], \"OO\") == true)\n\t\t{\n\t\t\tthere_is_seat = true;\n\t\t\tseats[i] = replaceFirst(seats[i], \"OO\", \"++\");\n\t\t\tbreak;\n\t\t}\n\t}\n\tprintf(there_is_seat ? \"YES\\n\" : \"NO\");\n\tif (there_is_seat)\n\t{\n\t\tforeach (int i; 0..n)\n\t\t{\n\t\t\twrite(seats[i]);\n\t\t}\n\t}\n\treturn 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 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[][] v = new char[][n];\n bool seat_found = false;\n for (int i = 0; i < n; i++) {\n v[i] = new char[5];\n v[i] = cin.read_string.dup;\n }\n\n for (int i = 0; i < n; i++) {\n bool flag1 = (v[i][0] == 'O' && v[i][1] == 'O');\n bool flag2 = (v[i][3] == 'O' && v[i][4] == 'O'); \n if (!seat_found && flag1) {\n seat_found = true;\n v[i][0] = '+';\n v[i][1] = '+';\n } else if (!seat_found && flag2) {\n seat_found = true;\n v[i][3] = '+';\n v[i][4] = '+';\n }\n }\n\n if (!seat_found) writeln(\"NO\");\n else {\n foreach (i; v) {\n foreach(j; i) \n write(j);\n writeln();\n }\n }\n } \n}"}, {"source_code": "import std.stdio;\n\nvoid position(int n, int row, int col, char[1000][6] rows)\n{\n\trows[row][col] = rows[row][col + 1] = '+';\n\n\tfor (int i = 0; i < n; i++) {\n\t\tprintf(\"%s\\n\", rows[i].ptr);\n\t}\n}\n\nvoid main()\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\n\tchar[1000][6] rows;\n\tfor (int i = 0; i < n; i++) {\n\t\tscanf(\"%s\", rows[i].ptr);\n\t}\n\n\tfor (int i = 0; i < n; i++) {\n\t\tif (rows[i][0] == 'O' && rows[i][1] == 'O') {\n\t\t\tposition(n, i, 0, rows);\n\t\t\treturn;\n\t\t}\n\t\tif (rows[i][3] == 'O' && rows[i][4] == 'O') {\n\t\t\tposition(n, i, 3, rows);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tprintf(\"NO\\n\");\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;\n\tscanf(\"%d\\n\", &n);\n\tstring[] seats; seats.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tseats[i] = readln();\n\t}\n\tbool there_is_seat = false;\n\tforeach (int i; 0..n)\n\t{\n\t\tif (canFind(seats[i], \"OO\") == true)\n\t\t{\n\t\t\tthere_is_seat = true;\n\t\t\tseats[i] = replace(seats[i], \"OO\", \"++\");\n\t\t\tbreak;\n\t\t}\n\t}\n\tprintf(there_is_seat ? \"YES\\n\" : \"NO\");\n\tif (there_is_seat)\n\t{\n\t\tforeach (int i; 0..n)\n\t\t{\n\t\t\twrite(seats[i]);\n\t\t}\n\t}\n\treturn 0;\n}"}], "src_uid": "e77787168e1c87b653ce1f762888ac57"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 long[](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 cnt;\n\t\tforeach (i; 0..n*2)\n\t\t\tcnt += (a[i] == 0 ? -1 : 1);\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[n-i-1] == 0 ? -1 : 1);\n\t\t}\n\t\tauto c = new int[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tc[i+1] = c[i] + (a[n+i] == 0 ? -1 : 1);\n\t\t}\n\t\tint[int] set;\n\t\tforeach (i; 0..n+1)\n\t\t{\n\t\t\tauto v = set.get(b[i], int.max);\n\t\t\tset[b[i]] = min(v, i);\n\t\t}\n\t\tint tmp = int.max;\n\t\tforeach (i; 0..n+1)\n\t\t{\n\t\t\tauto remain = cnt - c[i];\n\t\t\tauto v = set.get(remain, -1);\n\t\t\tif (v != -1)\n\t\t\t\ttmp.chmin(i + v);\n\t\t\tdebug writeln(\"cnt:\", cnt, \" c[i]:\", c[i]);\n\t\t\tdebug writeln(i, \":\", tmp);\n\t\t}\n\t\tans[ti] = tmp;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\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 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.split.map!(to!int).array;\n \n auto le = a[0 .. n];\n auto r = a[n .. $];\n \n debug { writeln(le); writeln(r); }\n \n int go(int[] a, int[] b) {\n int[int] sc;\n sc[0] = n;\n int cur = 0;\n foreach (i, e; a.enumerate(1)) {\n if (e == 1) { cur += 1; }\n else { cur -= 1; }\n \n sc[cur] = n - i;\n }\n \n debug { sc.writeln; }\n \n int eat = sc[0] + n;\n int now = 0;\n foreach_reverse (i, e; b) {\n if (e == 1) { now -= 1; }\n else { now += 1; }\n \n if (now !in sc) { continue; }\n \n eat = min(eat, i + sc[now]);\n }\n \n return eat;\n }\n \n go(le, r).writeln();\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\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(-1);\n\n\t\tint[int[]] memo;\n\t\tint dfs(int l, int r, int[] cnt)\n\t\t{\n\t\t\tauto diff = cnt[0] - cnt[1];\n\t\t\tif (diff == 0) return r-l;\n\t\t\tauto m = memo.get([l, r], -1);\n\t\t\tif (m != -1) return m;\n\n\t\t\tauto high = diff > 0 ? 0 : 1;\n\t\t\tint r1 = int.max, r2 = int.max;\n\t\t\tif (l != 0)\n\t\t\t{\n\t\t\t\tif (a[l-1] == high || abs(diff)+1 < l-1)\n\t\t\t\t{\n\t\t\t\t\tauto tmp = cnt.dup;\n\t\t\t\t\t--tmp[a[l-1]];\n\t\t\t\t\tr1 = dfs(l-1, r, tmp);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (r != n*2)\n\t\t\t{\n\t\t\t\tif (a[r] == high || abs(diff)+1 < n*2 - r - 1)\n\t\t\t\t{\n\t\t\t\t\tauto tmp = cnt.dup;\n\t\t\t\t\t--tmp[a[r]];\n\t\t\t\t\tr2 = dfs(l, r+1, tmp);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmemo[[l, r].idup] = min(r1, r2);\n\t\t\treturn min(r1, r2);\n\t\t}\n\n\t\tint[] cnt = [0, 0];\n\t\tforeach (e; a)\n\t\t\t++cnt[e];\n\t\tans[ti] = dfs(n, n, cnt);\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; }\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 (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int(-1);\n\n\t\tint[int[]] memo;\n\t\tint dfs(int l, int r, int[] cnt)\n\t\t{\n\t\t\tauto diff = cnt[0] - cnt[1];\n\t\t\tif (diff == 0) return r-l;\n\t\t\tauto m = memo.get([l, r], -1);\n\t\t\tif (m != -1) return m;\n\n\t\t\tauto high = diff > 0 ? 0 : 1;\n\t\t\tint r1 = int.max, r2 = int.max;\n\t\t\tif (l != 0)\n\t\t\t{\n\t\t\t\tif (a[l-1] == high || diff+1 < l-1)\n\t\t\t\t{\n\t\t\t\t\tauto tmp = cnt.dup;\n\t\t\t\t\t--tmp[a[l-1]];\n\t\t\t\t\tr1 = dfs(l-1, r, tmp);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (r != n*2)\n\t\t\t{\n\t\t\t\tif (a[r] == high || diff+1 < n*2 - r - 1)\n\t\t\t\t{\n\t\t\t\t\tauto tmp = cnt.dup;\n\t\t\t\t\t--tmp[a[r]];\n\t\t\t\t\tr2 = dfs(l, r+1, tmp);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmemo[[l, r].idup] = min(r1, r2);\n\t\t\treturn min(r1, r2);\n\t\t}\n\n\t\tint[] cnt = [0, 0];\n\t\tforeach (e; a)\n\t\t\t++cnt[e];\n\t\tans[ti] = dfs(n, n, cnt);\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; }\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 (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA!int(-1);\n\n\t\tint[int[]] memo;\n\t\tint dfs(int l, int r, int[] cnt)\n\t\t{\n\t\t\tauto diff = cnt[0] - cnt[1];\n\t\t\tif (diff == 0) return r-l;\n\t\t\tauto m = memo.get([l, r], -1);\n\t\t\tif (m != -1) return m;\n\n\t\t\tauto high = diff > 0 ? 0 : 1;\n\t\t\tint r1 = int.max, r2 = int.max;\n\t\t\tif (l != 0)\n\t\t\t{\n\t\t\t\tif (a[l-1] == high || abs(diff)+1 <= l-1)\n\t\t\t\t{\n\t\t\t\t\tauto tmp = cnt.dup;\n\t\t\t\t\t--tmp[a[l-1]];\n\t\t\t\t\tr1 = dfs(l-1, r, tmp);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (r != n*2)\n\t\t\t{\n\t\t\t\tif (a[r] == high || abs(diff)+1 <= n*2 - r - 1)\n\t\t\t\t{\n\t\t\t\t\tauto tmp = cnt.dup;\n\t\t\t\t\t--tmp[a[r]];\n\t\t\t\t\tr2 = dfs(l, r+1, tmp);\n\t\t\t\t}\n\t\t\t}\n\t\t\tmemo[[l, r].idup] = min(r1, r2);\n\t\t\treturn min(r1, r2);\n\t\t}\n\n\t\tint[] cnt = [0, 0];\n\t\tforeach (e; a)\n\t\t\t++cnt[e];\n\t\tans[ti] = dfs(n, n, cnt);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "b010397b6aeab4ad3f0c9f8e45b34691"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main()\n{\n int n;\n\tscanf(\"%d\", &n);\n\n\tint[] p = new int[n];\n\tfor (int i = 0; i < n; i++) {\n\t\tscanf(\"%d\", &p[i]);\n\t}\n\n\tp.sort();\n\n\tprintf(\"%d\\n\", p[(n - 1) / 2]);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto n = readln.strip.to !(int);\n\tauto a = readln.split.map !(to !(int)).array;\n\tsort (a);\n\twriteln (a[(n - 1) / 2]);\n}\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\tauto n = readln.strip.to !(int);\n\tauto a = readln.split.map !(to !(int)).array;\n\twriteln (a[(n - 1) / 2]);\n}\n"}], "src_uid": "fa9cc3ba103ed1f940c9e80a7ea75f72"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nlong lcm(long a, long b)\n{\n return a * b / gcd(a, b);\n}\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(long[]);\n auto ls = new long[](N);\n ls[0] = as[0];\n foreach (i; 1..N) ls[i] = gcd(as[i], ls[i-1]);\n auto rs = new long[](N);\n rs[$-1] = as[$-1];\n foreach_reverse (i; 0..N-1) rs[i] = gcd(as[i], rs[i+1]);\n\n auto x = rs[1];\n foreach (i; 1..N-1) x = lcm(x, gcd(ls[i-1], rs[i+1]));\n writeln(lcm(x, ls[$-2]));\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\timmutable int limit = 200_001;\n\n\tauto s = new int [limit];\n\tfor (int d = 2; d < limit; d++)\n\t{\n\t\tif (s[d] == 0)\n\t\t{\n\t\t\ts[d] = d;\n\t\t\tfor (int e = d; e * 1L * d < limit; e++)\n\t\t\t{\n\t\t\t\tif (s[e * d] == 0)\n\t\t\t\t{\n\t\t\t\t\ts[e * d] = d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto num = new int [] [limit];\n\t\tforeach (c; readln.splitter.map !(to !(int)))\n\t\t{\n\t\t\tint [int] fact;\n\t\t\twhile (s[c] > 0)\n\t\t\t{\n\t\t\t\tfact[s[c]] += 1;\n\t\t\t\tc /= s[c];\n\t\t\t}\n\t\t\tforeach (prime, power; fact)\n\t\t\t{\n\t\t\t\tnum[prime] ~= power;\n\t\t\t}\n\t\t}\n\t\tlong res = 1;\n\t\tforeach (prime, ref list; num)\n\t\t{\n\t\t\tif (list.length >= n - 1)\n\t\t\t{\n\t\t\t\tsort !(q{a > b}) (list);\n\t\t\t\tres *= prime ^^ list[n - 2];\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\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 ess = new int[][lim];\n \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 ess[p] ~= e;\n }\n }\n if (a > 1) {\n ess[a] ~= 1;\n }\n }\n \n long ans = 1;\n foreach (p; 2 .. lim) {\n if (ess[p].length >= N - 1) {\n ess[p].sort;\n ess[p].reverse;\n ans *= p^^ess[p][N - 2];\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\timmutable int limit = 200_001;\n\n\tauto s = new int [limit];\n\tfor (int d = 2; d * d < limit; d++)\n\t{\n\t\tif (s[d] == 0)\n\t\t{\n\t\t\ts[d] = d;\n\t\t\tfor (int e = d * d; e < limit; e += d)\n\t\t\t{\n\t\t\t\tif (s[e] == 0)\n\t\t\t\t{\n\t\t\t\t\ts[e] = d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto num = new int [] [limit];\n\t\tforeach (c; readln.splitter.map !(to !(int)))\n\t\t{\n\t\t\tint [int] fact;\n\t\t\twhile (s[c] > 0)\n\t\t\t{\n\t\t\t\tfact[s[c]] += 1;\n\t\t\t\tc /= s[c];\n\t\t\t}\n\t\t\tforeach (prime, power; fact)\n\t\t\t{\n\t\t\t\tnum[prime] ~= power;\n\t\t\t}\n\t\t}\n\t\tlong res = 1;\n\t\tforeach (prime, ref list; num)\n\t\t{\n\t\t\tif (list.length >= n - 1)\n\t\t\t{\n\t\t\t\tsort !(q{a > b}) (list);\n\t\t\t\tres *= prime ^^ list[n - 2];\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "3634a3367a1f05d1b3e8e4369e8427fb"} {"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 = 15;\n\nstruct LongString\n{\n\tstring s;\n\tbool [] [limit] mark;\n\n\tthis (string r)\n\t{\n\t\ts = r;\n\t\tforeach (len; 1..limit)\n\t\t{\n\t\t\tmark[len] = new bool [1 << len];\n\t\t}\n\t\tforeach (pos; 0..s.length)\n\t\t{\n\t\t\tforeach (len; 1..limit)\n\t\t\t{\n\t\t\t\tif (pos + len <= s.length)\n\t\t\t\t{\n\t\t\t\t\tauto t = s[pos..pos + len]\n\t\t\t\t\t .to !(int) (2);\n\t\t\t\t\tmark[len][t] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (s.length > 2 * limit)\n\t\t{\n\t\t\ts = s[0..limit] ~ \"*\" ~ s[$ - limit..$];\n\t\t}\n\t\tdebug {writeln (s, \": \", mark[].map !(sum));}\n\t}\n\n\tthis (LongString a, LongString b)\n\t{\n\t\ts = a.s ~ b.s;\n\t\tforeach (len; 1..limit)\n\t\t{\n\t\t\tmark[len] = new bool [1 << len];\n\t\t\tmark[len][] |= a.mark[len][];\n\t\t\tmark[len][] |= b.mark[len][];\n\t\t}\n\t\tforeach (x; 1..a.s.length + 1)\n\t\t{\n\t\t\tforeach (y; 1..b.s.length + 1)\n\t\t\t{\n\t\t\t\tif (x + y < limit)\n\t\t\t\t{\n\t\t\t\t\tauto t = (a.s[$ - x..$] ~ b.s[0..y])\n\t\t\t\t\t .to !(int) (2);\n\t\t\t\t\tmark[x + y][t] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (s.length > 2 * limit)\n\t\t{\n\t\t\ts = s[0..limit] ~ \"*\" ~ s[$ - limit..$];\n\t\t}\n\t\tdebug {writeln (s, \": \", mark[].map !(sum));}\n\t}\n\n\tint fullness ()\n\t{\n\t\tforeach (len; 1..limit)\n\t\t{\n\t\t\tif (!all (mark[len]))\n\t\t\t{\n\t\t\t\treturn len - 1;\n\t\t\t}\n\t\t}\n\t\treturn limit - 1;\n\t}\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tLongString [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto t = readln.strip;\n\t\t\ts ~= LongString (t);\n\t\t}\n\n\t\tint m;\n\t\treadf (\" %s\", &m);\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\ts ~= LongString (s[u], s[v]);\n\t\t\twriteln (s.back.fullness);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.stdio, std.string;\nstruct S {\n\tstring s;\n\tbool [] [9] m;\n\n\tthis (string r) {\n\t\ts = r;\n\t\tforeach (w; 1..9)\n\t\t\tm[w] = new bool [1 << w];\n\t\tforeach (w; 1..9)\n\t\t\tforeach (p; w..s.length + 1)\n\t\t\t\tm[w][s[p - w..p].to !(int) (2)] = 1;\n\t}\n\n\tthis (S a, S b) {\n\t\ts = a.s ~ b.s;\n\t\tif (s.length > 2 * 9)\n\t\t\ts = s[0..9] ~ \"*\" ~ s[$ - 9..$];\n\t\tforeach (w; 1..9)\n\t\t\tm[w] = a.m[w].dup,\n\t\t\tm[w][] |= b.m[w][];\n\t\tforeach (x; 1..a.s.length + 1)\n\t\t\tforeach (y; 1..b.s.length + 1)\n\t\t\t\tif (x + y < 9)\n\t\t\t\t\tm[x + y][(a.s[$ - x..$] ~ b.s[0..y]).to !(int) (2)] = 1;\n\t}\n}\n\nvoid main () {\n\tS [] s;\n\tforeach (i; 0..readln.strip.to!int)\n\t\ts ~= S (readln.strip);\n\tforeach (j; 0..readln.strip.to!int) {\n\t\tint u, v;\n\t\treadf (\" %s %s\", &u, &v);\n\t\ts ~= S (s[u - 1], s[v - 1]);\n\t\ts[$ - 1].m[1..$].countUntil !(x => !x.all).writeln;\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 K = 10;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto S = new string[N];\n foreach (i; 0 .. N) {\n S[i] = readToken();\n }\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 heads = new string[N + M];\n auto tails = new string[N + M];\n auto has = new bool[][][](N + M, K);\n foreach (i; 0 .. N + M) {\n foreach (k; 0 .. K) {\n has[i][k] = new bool[1 << k];\n }\n }\n foreach (i; 0 .. N) {\n const len = cast(int)(S[i].length);\n if (len > K) {\n heads[i] = S[i][0 .. K];\n tails[i] = S[i][$ - K .. $];\n } else {\n heads[i] = tails[i] = S[i];\n }\n foreach (k; 1 .. K) {\n foreach (x; 0 .. len - k + 1) {\n int p;\n foreach (l; 0 .. k) {\n p |= (S[i][x + l] - '0') << l;\n }\n has[i][k][p] = true;\n }\n }\n }\n \n foreach (j; 0 .. M) {\n const i = N + j;\n heads[i] = heads[A[j]] ~ heads[B[j]];\n if (heads[i].length > K) {\n heads[i] = heads[i][0 .. K];\n }\n tails[i] = tails[A[j]] ~ tails[B[j]];\n if (tails[i].length > K) {\n tails[i] = tails[i][$ - K .. $];\n }\n foreach (k; 1 .. K) {\n foreach (p; 0 .. 1 << k) {\n has[i][k][p] = has[A[j]][k][p] || has[B[j]][k][p];\n }\n }\n const lenA = cast(int)(tails[A[j]].length);\n const lenB = cast(int)(heads[B[j]].length);\n foreach (kA; 1 .. lenA + 1) foreach (kB; 1 .. lenB + 1) {\n if (kA + kB < K) {\n int p;\n foreach (l; 0 .. kA) {\n p |= (tails[A[j]][lenA - kA + l] - '0') << l;\n }\n foreach (l; 0 .. kB) {\n p |= (heads[B[j]][l] - '0') << (kA + l);\n }\n has[i][kA + kB][p] = true;\n }\n }\n int ans;\n foreach (k; 1 .. K) {\n if (has[i][k].all) {\n ans = k;\n }\n }\n writeln(ans);\n }\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\nenum K = 10;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto S = new string[N];\n foreach (i; 0 .. N) {\n S[i] = readToken();\n }\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 heads = new string[N + M];\n auto tails = new string[N + M];\n auto has = new bool[][][](N + M, K);\n foreach (i; 0 .. N + M) {\n foreach (k; 0 .. K) {\n has[i][k] = new bool[1 << k];\n }\n }\n foreach (i; 0 .. N) {\n const len = cast(int)(S[i].length);\n heads[i] = S[i][0 .. min(K - 1, len)];\n tails[i] = S[i][len - min(K - 1, len) .. len];\n foreach (k; 1 .. K) {\n foreach (x; 0 .. len - k + 1) {\n int p;\n foreach (l; 0 .. k) {\n p |= (S[i][x + l] - '0') << l;\n }\n debug {\n writeln(i, \" \", k, \" \", p);\n }\n has[i][k][p] = true;\n }\n }\n }\n \n foreach (j; 0 .. M) {\n const i = N + j;\n heads[i] = heads[A[j]] ~ heads[B[j]];\n if (heads[i].length > K - 1) {\n heads[i] = heads[i][0 .. K - 1];\n }\n tails[i] = tails[A[j]] ~ tails[B[j]];\n if (tails[i].length > K - 1) {\n tails[j] = tails[i][$ - (K - 1) .. $];\n }\n foreach (k; 1 .. K) {\n foreach (p; 0 .. 1 << k) {\n has[i][k][p] = has[A[j]][k][p] || has[B[j]][k][p];\n }\n }\n debug {\n writeln(tails[A[j]], \" \", heads[B[j]]);\n }\n const lenA = cast(int)(tails[A[j]].length);\n const lenB = cast(int)(heads[B[j]].length);\n foreach (kA; 1 .. lenA + 1) foreach (kB; 1 .. lenB + 1) {\n if (kA + kB < K) {\n int p;\n foreach (l; 0 .. kA) {\n p |= (tails[A[j]][$ - 1 - l] - '0') << l;\n }\n foreach (l; 0 .. kB) {\n p |= (heads[B[j]][l] - '0') << (kA + l);\n }\n debug {\n writeln(i, \" \", kA, \" \", kB, \" \", p);\n }\n has[i][kA + kB][p] = true;\n }\n }\n int ans;\n foreach (k; 1 .. K) {\n if (has[i][k].all) {\n ans = k;\n }\n }\n writeln(ans);\n }\n \n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "0d8b5bd6c118f98d579da8c79482cfa7"} {"source_code": "import std.stdio;\n\nvoid main() {\n\tint n;\n\treadf(\" %s\", &n);\n\n\tint max, min;\n\treadf(\" %s\", &min);\n\tmax = min;\n\tint counter, temp;\n\tfor (int i = 1; i < n; i++) {\n\t\treadf(\" %s\", &temp);\n\t\tif (temp > max) {\n\t\t\tcounter++;\n\t\t\tmax = temp;\n\t\t} \n\n\t\tif (temp < min) {\n\t\t\tcounter++;\n\t\t\tmin = temp;\n\t\t} \n\t}\n\n\twriteln(counter);\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.math;\n\nvoid main() {\n int n = readln.chomp.to!int;\n auto p = readln.chomp.split.map!(to!int);\n\n int max = p[0];\n int min = p[0];\n int cnt = 0;\n for (int i = 1; i < n; i++) {\n if (max < p[i]) {\n cnt++;\n max = p[i];\n } else if (min > p[i]) {\n cnt++;\n min = p[i];\n }\n }\n\n cnt.writeln;\n}"}, {"source_code": "import std.stdio,\n\tstd.array,\n\tstd.conv;\n\nvoid main() {\n\treadln;\n\tauto nums = to!(int[])(readln.split);\n\tint max_point = nums[0], min_point = nums[0];\n\tint count_amazing;\n\tforeach(m; nums[1..$]){\n\t\tif(m > max_point){\n\t\t\tmax_point = m;\n\t\t\tcount_amazing++;\n\t\t}\n\t\telse if (m < min_point){\n\t\t\tmin_point = m;\n\t\t\tcount_amazing++;\n\t\t}\n\t}\n\twriteln(count_amazing);\n}\n"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm\n , std.range\n , std.container;\n\n\n\nvoid main() {\n alias insertion_sort = bad_insertion_sort;\n int n;\n int[] data;\n readf(\"%s\\n\", &n);\n \n {\n int t; readf(\"%s \", &t);\n data ~= t;\n }\n \n insertion_sort(data);\n \n uint much_wow;\n \n for(int i; i < n - 1; ++i) {\n int t;\n readf(\"%s \", &t);\n if(t > data[$ - 1] || t < data[0]) {\n ++much_wow;\n }\n data ~= t;\n insertion_sort(data);\n \n //data.writeln();\n }\n \n much_wow.writeln();\n}\n\n\nvoid bad_insertion_sort(T, alias pred = (c, d) => c < d)(T[] data) @nogc {\n foreach (i, immutable value; data[1 .. $]) {\n auto j = i + 1;\n for ( ; j > 0 && pred(value, data[j - 1]); --j) {\n data[j] = data[j - 1];\n }\n data[j] = value;\n }\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n, e;\n\tscanf(\"%d %d\", &n, &e);\n\tint max = e;\n\tint min = e;\n\tint count = 0;\n\tforeach (int i; 1..n)\n\t{\n\t\tscanf(\"%d\", &e);\n\t\tif (e > max) \n\t\t{\n\t\t\tcount++;\n\t\t\tmax = e;\n\t\t}\n\t\telse if (e < min)\n\t\t{\n\t\t\tcount++;\n\t\t\tmin = e;\n\t\t}\n\t}\n\twrite(count);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "a61b96d4913b419f5715a53916c1ae93"} {"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\tstring s = read;\n\tX[] xs;\n\tforeach(i; 0 .. n) xs ~= X(s[i] == '1', rint, rint);\n\t\n\tint ans = 0;\n\tforeach(t; 0 .. 200){\n\t\tint tmp = 0;\n\t\tforeach(i, x; xs){\n\t\t\tbool isNot;\n\t\t\tif(t < x.b) isNot = 0;\n\t\t\telse if((t - x.b) / x.a % 2 == 0) isNot = 1;\n\t\t\telse isNot = 0;\n\t\t\t\n\t\t\tif(isNot ^x.isOn) tmp += 1;\n\t\t\tif(t < 20) log(\"t:\", t, \"i:\", i, \"x:\", x, \"isNot:\" , isNot, \"tmp:\", tmp);\n\t\t}\n\t\tans = max(ans, tmp);\n\t}\n\t\n\tans.writeln;\n}\nstruct X{\n\tbool isOn;\n\tint a, b;\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 s = RD!string;\n\tauto a = new long[](n);\n\tauto b = new long[](n);\n\tforeach (i; 0..n)\n\t{\n\t\ta[i] = RD;\n\t\tb[i] = RD;\n\t}\n\n\tauto c = new int[](n);\n\tforeach (i; 0..n)\n\t\tc[i] = s[i] == '1' ? 1 : 0;\n\n\tlong ans = c.sum;\n\tforeach (_; 0..10^^4)\n\t{\n\t\tb[] -= 1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] == 0)\n\t\t\t{\n\t\t\t\tc[i] ^= 1;\n\t\t\t\tb[i] = a[i];\n\t\t\t}\n\t\t}\n\t\tans = max(ans, c.sum);\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "2ff789ae0095bb7ff0e747b0d4df59bc"} {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint divs = 0;\n\tforeach (p; 2..51)\n\t{\n\t\tbool ok = true;\n\t\tfor (int d = 2; d * d <= p; d++)\n\t\t{\n\t\t\tif (p % d == 0)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t}\n\t\tif (!ok)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\twriteln (p);\n\t\tstdout.flush ();\n\t\tbool cur = (readln.strip == \"yes\");\n\t\tdivs += cur;\n\t\tif (cur && p * p <= 100)\n\t\t{\n\t\t\twriteln (p * p);\n\t\t\tstdout.flush ();\n\t\t\tbool next = (readln.strip == \"yes\");\n\t\t\tdivs += next;\n\t\t}\n\t}\n\twriteln (divs > 1 ? \"composite\" : \"prime\");\n}\n", "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\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 ask(int x) {\n writeln(x);\n stdout.flush();\n static char[4] storage;\n auto s = storage[ ];\n readln(s);\n return s[0] == 'y';\n}\n\nvoid main() {\n bool found;\n foreach (x; [2, 3, 5, 7])\n if (ask(x)) {\n if (found) {\n write(\"composite\\n\");\n return;\n }\n found = true;\n foreach (y; [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) {\n if (x * y > 100)\n break;\n if (ask(x * y)) {\n write(\"composite\\n\");\n return;\n }\n }\n }\n write(\"prime\\n\");\n}\n"}], "negative_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\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\nenum primes = [2, 3, 5, 7];\n\nvoid main() {\n char[3] storage;\n foreach (x; primes) {\n writeln(x);\n stdout.flush();\n auto s = storage[ ];\n readln(s);\n if (s[0] == 'y') {\n write(\"composite\\n\");\n return;\n }\n }\n write(\"prime\\n\");\n}\n"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\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\nenum primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71];\n\nvoid main() {\n char[4] storage;\n foreach (x; primes) {\n writeln(x);\n stdout.flush();\n auto s = storage[ ];\n readln(s);\n if (s[0] == 'y') {\n write(\"composite\\n\");\n return;\n }\n }\n write(\"prime\\n\");\n}\n"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\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\nchar[4] storage;\n\nbool ask(int x) {\n writeln(x);\n stdout.flush();\n auto s = storage[ ];\n readln(s);\n return s[0] == 'y';\n}\n\nvoid main() {\n bool found;\n foreach (x; [2, 3, 5, 7])\n if (ask(x)) {\n if (found) {\n write(\"composite\\n\");\n return;\n }\n found = true;\n foreach (y; [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47])\n if (ask(x * y)) {\n write(\"composite\\n\");\n return;\n }\n }\n write(\"prime\\n\");\n}\n"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\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\nchar[4] storage;\n\nbool ask(int x) {\n writeln(x);\n stdout.flush();\n auto s = storage[ ];\n readln(s);\n return s[0] == 'y';\n}\n\nvoid main() {\n bool found;\n foreach (x; [2, 3, 5, 7])\n if (ask(x)) {\n if (found) {\n write(\"composite\\n\");\n return;\n }\n found = true;\n foreach (y; [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) {\n if (x * y > 100)\n break;\n if (ask(x * y)) {\n write(\"composite\\n\");\n return;\n }\n }\n }\n write(\"prime\\n\");\n}\n"}, {"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\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\nenum primes = [2, 3, 5, 7];\n\nvoid main() {\n char[4] storage;\n foreach (x; primes) {\n writeln(x);\n stdout.flush();\n auto s = storage[ ];\n readln(s);\n if (s[0] == 'y') {\n write(\"composite\\n\");\n return;\n }\n }\n write(\"prime\\n\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tbool ok = false;\n\tforeach (p; [2, 3, 5, 7])\n\t{\n\t\twriteln (p);\n\t\tstdout.flush ();\n\t\tok |= readln.strip == \"yes\";\n\t}\n\twriteln (ok ? \"composite\" : \"prime\");\n}\n"}], "src_uid": "8cf479fd47050ba96d21f3d8eb43c8f0"} {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\nbool solve(char[][] c){\n size_t n = c.length;\n for(int i = 0; i < n; i++){\n for(int j = 0; j < n; j++){\n int imp = 0;\n int cnt = 0;\n for(int a = i-1; a <= i+1; a++){\n for(int b = j-1;b <= j+1; b++){\n imp++;\n if(a >= 0 && a < n){\n if(b >= 0 && b < n){\n // write(c[a][b]);\n if(c[a][b] == 'o' && imp % 2 == 0){\n cnt++;\n }\n }\n }\n }\n }\n // writeln();\n // writeln(cnt);\n if(cnt % 2 == 1){\n return false;\n }\n }\n }\n return true;\n}\n\nvoid main(){\n int n;\n char c;\n\n readf(\"%s\\n\",&n);\n\n char[][] l = new char[][](n,n);\n for(int i = 0; i < n; i++){\n for(int j = 0; j < n; j++){\n char t = '\\n';\n while(t == '\\n'){\n readf(\"%c\",&t);\n }\n l[i][j] = t;\n }\n }\n if(solve(l)){\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\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\nimmutable DX = [ +1, 0, -1, 0, ];\nimmutable DY = [ 0, +1, 0, -1, ];\n\nint N;\nstring[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new string[N];\n\t\tforeach (x; 0 .. N) {\n\t\t\tA[x] = readToken;\n\t\t}\n\t\t\n\t\tbool ans = true;\n\t\tforeach (x; 0 .. N) foreach (y; 0 .. N) {\n\t\t\tint cnt;\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 < N && 0 <= yy && yy < N) {\n\t\t\t\t\tif (A[xx][yy] == 'o') {\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tans = ans && (cnt % 2 == 0);\n\t\t}\n\t\twriteln(ans ? \"YES\" : \"NO\");\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "03fcf7402397b94edd1d1837e429185d"} {"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!long;\r\n long twos;\r\n foreach(el; a)\r\n if (!(el & 1)) {\r\n while(el % 2 == 0) {\r\n el >>= 1;\r\n twos++;\r\n }\r\n }\r\n if (twos >= n)\r\n writeln(0);\r\n else {\r\n long[] oper;\r\n foreach(el;iota(n,0,-1).array) {\r\n if (!(el & 1)) {\r\n long tmp;\r\n while(el % 2 == 0) {\r\n el >>= 1;\r\n tmp++;\r\n }\r\n oper ~= tmp;\r\n }\r\n }\r\n sort!\"a > b\"(oper);\r\n n -= twos;\r\n foreach(i, el; oper)\r\n if (el >= n) {\r\n writeln(i+1);\r\n return;\r\n }\r\n else\r\n n -= el;\r\n\r\n writeln(-1);\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.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 auto am = a.length.iota.map!(i => a[i] * (i + 1)).array;\n long lowzeroes = a.map!(x => cast(long)bsf(x)).sum;\n auto clzamd = a.length.iota.map!(i => bsf(am[i]) - bsf(a[i])).array.sort.reverse.array;\n long ans = 0;\n foreach (x ; clzamd) {\n if (lowzeroes >= n)\n break;\n if (x <= 0)\n break;\n lowzeroes += x;\n ans++;\n }\n writeln(lowzeroes >= n ? ans : -1);\n }\n}\n"}], "negative_code": [], "src_uid": "96f0df1c8e014229e5ef773789aa2205"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nlong sum(int left, int right, long[] s)\n{\n long res = 0;\n if (right > 0) res += s[right - 1];\n if (left > 0) res -= s[left - 1];\n return res;\n}\n\nvoid solve(int[] a, int n)\n{\n auto fdp = new long[n + 1];\n auto bdp = new long[n + 1];\n auto fs = new long[n + 1];\n auto fidx = new int[n + 1];\n auto bidx = new int[n + 1];\n foreach (i; 0 .. n + 1)\n {\n fs[i] = 0;\n if (i < n) fs[i] = a[i];\n if (i > 0) fs[i] += fs[i - 1];\n fdp[i] = sum(0, i, fs) - sum(i, i, fs);\n fidx[i] = i;\n if (i > 0)\n {\n auto val = fdp[i - 1] - a[i - 1];\n if (val > fdp[i])\n {\n fdp[i] = val;\n fidx[i] = fidx[i - 1];\n }\n }\n }\n for (int i = n; i >= 0; -- i)\n {\n bdp[i] = sum(i, i, fs) - sum(i, n, fs);\n bidx[i] = i;\n if (i < n)\n {\n auto val = bdp[i + 1] + a[i];\n if (val > bdp[i])\n {\n bdp[i] = val;\n bidx[i] = bidx[i + 1];\n }\n }\n }\n long ans = long.min;\n int li = -1, mi = -1, ri = -1;\n foreach (i; 0 .. n + 1)\n {\n if (fdp[i] + bdp[i] > ans)\n {\n ans = fdp[i] + bdp[i];\n li = fidx[i];\n ri = bidx[i];\n mi = i;\n }\n }\n writeln(li, \" \", mi, \" \", ri);\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;\nimport std.algorithm;\n\nlong sum(int left, int right, long[] s)\n{\n long res = 0;\n if (right > 0) res += s[right - 1];\n if (left > 0) res -= s[left - 1];\n return res;\n}\n\nvoid solve(int[] a, int n)\n{\n auto fdp = new long[n + 1];\n auto bdp = new long[n + 1];\n auto fs = new long[n + 1];\n auto fidx = new int[n + 1];\n auto bidx = new int[n + 1];\n foreach (i; 0 .. n + 1)\n {\n fs[i] = 0;\n if (i < n) fs[i] = a[i];\n if (i > 0) fs[i] += fs[i - 1];\n fdp[i] = long.min;\n foreach (j; 0 .. i + 1)\n {\n auto val = sum(0, j, fs) - sum(j, i, fs);\n if (val > fdp[i])\n {\n fdp[i] = val;\n fidx[i] = j;\n }\n }\n }\n for (int i = n; i >= 0; -- i)\n {\n bdp[i] = long.min;\n foreach (j; i .. n + 1)\n {\n auto val = sum(i, j, fs) - sum(j, n, fs);\n if (val > bdp[i])\n {\n bdp[i] = val;\n bidx[i] = j;\n }\n }\n }\n long ans = long.min;\n int li = -1, mi = -1, ri = -1;\n foreach (i; 0 .. n + 1)\n {\n if (fdp[i] + bdp[i] > ans)\n {\n ans = fdp[i] + bdp[i];\n li = fidx[i];\n ri = bidx[i];\n mi = i;\n }\n }\n writeln(li, \" \", mi, \" \", ri);\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}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nlong sum(int left, int right, long[] s)\n{\n long res = 0;\n if (right > 0) res += s[right - 1];\n if (left > 0) res -= s[left - 1];\n return res;\n}\n\nvoid solve(int[] a, int n)\n{\n auto fdp = new long[n + 1];\n auto bdp = new long[n + 1];\n auto fs = new long[n + 1];\n auto fidx = new int[n + 1];\n auto bidx = new int[n + 1];\n foreach (i; 0 .. n + 1)\n {\n fs[i] = 0;\n if (i < n) fs[i] = a[i];\n if (i > 0) fs[i] += fs[i - 1];\n fdp[i] = sum(0, i, fs) - sum(i, i, fs);\n fidx[i] = i;\n if (i > 0)\n {\n auto val = fdp[i - 1];\n if (i < n) val -= a[i];\n if (val > fdp[i])\n {\n fdp[i] = val;\n fidx[i] = fidx[i - 1];\n }\n }\n }\n for (int i = n; i >= 0; -- i)\n {\n bdp[i] = sum(i, i, fs) - sum(i, n, fs);\n bidx[i] = i;\n if (i < n)\n {\n auto val = bdp[i + 1] + a[i];\n if (val > bdp[i])\n {\n bdp[i] = val;\n bidx[i] = bidx[i + 1];\n }\n }\n }\n long ans = long.min;\n int li = -1, mi = -1, ri = -1;\n foreach (i; 0 .. n + 1)\n {\n if (fdp[i] + bdp[i] > ans)\n {\n ans = fdp[i] + bdp[i];\n li = fidx[i];\n ri = bidx[i];\n mi = i;\n }\n }\n writeln(li, \" \", mi, \" \", ri);\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.string;\nimport std.algorithm;\n\nlong sum(int left, int right, long[] s)\n{\n long res = 0;\n if (right > 0) res += s[right - 1];\n if (left > 0) res -= s[left - 1];\n return res;\n}\n\nvoid solve(int[] a, int n)\n{\n auto fdp = new long[n + 1];\n auto bdp = new long[n + 1];\n auto fs = new long[n + 1];\n auto fidx = new int[n + 1];\n auto bidx = new int[n + 1];\n foreach (i; 0 .. n + 1)\n {\n fs[i] = 0;\n if (i < n) fs[i] = a[i];\n if (i > 0) fs[i] += fs[i - 1];\n fdp[i] = sum(0, i, fs) - sum(i, i, fs);\n fidx[i] = i;\n if (i > 0 && i < n)\n {\n auto val = fdp[i - 1] - a[i];\n if (val > fdp[i])\n {\n fdp[i] = val;\n fidx[i] = fidx[i - 1];\n }\n }\n }\n for (int i = n; i >= 0; -- i)\n {\n bdp[i] = sum(i, i, fs) - sum(i, n, fs);\n bidx[i] = i;\n if (i < n)\n {\n auto val = bdp[i + 1] + a[i];\n if (val > bdp[i])\n {\n bdp[i] = val;\n bidx[i] = bidx[i + 1];\n }\n }\n }\n long ans = long.min;\n int li = -1, mi = -1, ri = -1;\n foreach (i; 0 .. n + 1)\n {\n if (fdp[i] + bdp[i] > ans)\n {\n ans = fdp[i] + bdp[i];\n li = fidx[i];\n ri = bidx[i];\n mi = i;\n }\n }\n writeln(li, \" \", mi, \" \", ri);\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}"}], "src_uid": "34fb8f05351998266403dbecd15d7191"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 W = RD;\n\t\tauto w = RDA;\n\n\t\tauto index = w.MAKE_IDX!\"a > b\";\n\t\tlong tot;\n\t\tforeach (i; index)\n\t\t{\n\t\t\tif (w[i] > W) continue;\n\t\t\tif (w[i] >= (W+1) / 2)\n\t\t\t{\n\t\t\t\ttot += w[i];\n\t\t\t\tans[ti] ~= i+1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ttot += w[i];\n\t\t\tans[ti] ~= i+1;\n\t\t\tif (tot >= (W+1) / 2) break;\n\t\t}\n\t\tif (tot < (W+1) / 2)\n\t\t\tans[ti].length = 0;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e.length == 0)\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}\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 w;\n\t\treadf !(\" %s %s\") (n, w);\n\t\treadln;\n\t\tauto s = readln.splitter.map !(to !(long)).array;\n\t\tauto p = n.iota.array;\n\t\tp.sort !((i, j) => s[i] > s[j]);\n\t\tint [] answer;\n\t\tlong total = 0;\n\t\tforeach (ref i; p)\n\t\t{\n\t\t\tif (total + s[i] <= w)\n\t\t\t{\n\t\t\t\tanswer ~= i + 1;\n\t\t\t\ttotal += s[i];\n\t\t\t}\n\t\t}\n\t\tif (total * 2 < w)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (answer.length);\n\t\t\twritefln !(\"%(%s %)\") (answer);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "afe8710473db82f8d53d28dd32646774"} {"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 k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto a = new int [2000 + 1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\ta[x]++;\n\t\t}\n\t\tlong res = 0;\n\t\tint v = k;\n\t\tforeach_reverse (i, c; a)\n\t\t{\n\t\t\tforeach (j; 0..c)\n\t\t\t{\n\t\t\t\tif (v == k)\n\t\t\t\t{\n\t\t\t\t\tres += (i - 1) * 2;\n\t\t\t\t}\n\t\t\t\tv--;\n\t\t\t\tif (v == 0)\n\t\t\t\t{\n\t\t\t\t\tv = 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 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;\nint[] F;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = readInt;\n\t\tF = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tF[i] = readInt;\n\t\t}\n\t\t\n\t\tF.sort();\n\t\tint ans;\n\t\tfor (int i = N - 1; i >= 0; i -= K) {\n\t\t\tans += (F[i] - 1) * 2;\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "b8d8f0e86ecb600f7559a6aec629946e"} {"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!long);\n auto l = s[0];\n auto r = s[1];\n\n long sm(long a, long n) {\n a %= MOD;\n n %= MOD;\n return n * (a + (n - 1)) % MOD;\n }\n\n long calc(long x, long n, long a, long cnt) {\n long res = 0;\n while (cnt + n + 2 * n <= x) {\n (res += sm(a, n)) %= MOD;\n (a += 2 * n % MOD) %= MOD;\n cnt += n + 2 * n;\n n = n * 4;\n }\n (res += sm(a, min(x - cnt, n))) %= MOD;\n return res;\n }\n\n long ansl = calc(l-1, 1, 1, 0) + calc(l-1, 2, 2, 1);\n long ansr = calc(r, 1, 1, 0) + calc(r, 2, 2, 1);\n writeln(((ansr - ansl) % MOD + MOD) % MOD);\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\nlong MOD = 1_000_000_007;\n\nlong find(long idx) {\n\n long eve = 1;\n long[] nn = [0, 0]; // 0 even, 1 odd\n uint turn = 1;\n long mul = 1;\n long tt = 0;\n if (idx <= 0)\n return 0;\n while (true) {\n if (tt + mul > idx) {\n nn[turn] += (idx - tt);\n tt += (idx - tt);\n break;\n }\n\n nn[turn] += mul;\n tt += mul;\n\n turn = 1 - turn;\n mul = 2 * mul;\n }\n long nod = nn[1];\n long nev = nn[0];\n\n long tt1 = ((nod % MOD) * (nod % MOD)) % MOD;\n long tt2 = 0;\n if (nev > 0)\n tt2 = (((nev + 1) % MOD) * (nev % MOD) % MOD);\n\n return (tt1 + tt2) % MOD;\n}\n\nvoid main() {\n GC.disable();\n\n long l, r;\n readf(\" %s %s\", l, r);\n\n writeln((find(r) - find(l - 1) + MOD) % MOD);\n\n}\n"}, {"source_code": "module c;import std.algorithm.comparison;\nimport std.algorithm.iteration;\nimport std.algorithm.searching;\nimport std.range;\nimport std.stdio;\n\nconst MOD = 1000000007;\n\nprivate long sum(long n) {\n long[] count = [0, 0];\n long n1 = 0, d = 1, s = 0;\n int odd = 1;\n while (n1 < n) {\n if (n1 + d >= n) {\n count[odd] += n - n1;\n break;\n } else {\n n1 += d;\n count[odd] += d;\n d *= 2;\n odd = 1 - odd;\n }\n }\n count[0] %= MOD;\n count[1] %= MOD;\n return (count[0]*(count[0]+1) + count[1]*count[1]) % MOD;\n}\n\nvoid main() {\n long l, r;\n readf(\"%s %s\", l, r);\n writeln((MOD + sum(r) - sum(l-1)) % MOD);\n}\n"}], "negative_code": [], "src_uid": "40a5e4b4193901cb3004dac24dba1d62"} {"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 isz(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, m, k;\n n = rd!int;\n m = rd!int;\n k = rd!int;\n int win = min(m, n/k);\n int leftj = (m - win);\n int max2 = leftj/(k-1) + (leftj % (k - 1) != 0);\n writeln(win - max2);\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", "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, k;\n\t\treadf !(\" %s %s %s\") (n, m, k);\n\t\tauto win = min (m, n / k);\n\t\tauto left = m - win;\n\t\tauto others = k - 1;\n\t\tauto lose = (left + others - 1) / others;\n\t\twriteln (win - lose);\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 long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto k = RD!int;\n\t\t\n\t\tauto cnt = n / k;\n\t\tauto x = min(cnt, m);\n\t\tm -= x;\n\t\tans[ti] = x - (m+k-2) / (k-1);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_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 isz(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, m, k;\n n = rd!int;\n m = rd!int;\n k = rd!int;\n int win = min(m, n/k);\n int leftj = (m - win);\n int max2 = leftj/(k-1) + (leftj % (k - 1));\n writeln(win - max2);\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": "6324ca46b6f072f8952d2619cb4f73e6"} {"source_code": "import std.stdio;\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 T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) {\r\n int N, K; scanf(\"%d %d\\n\", &N, &K);\r\n int[] xs, ys;\r\n if (K == 0) {\r\n for (int i = 0; i < N/2; i++) {\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n } else if (K <= N - 2) {\r\n for (int i = 1; i < N/2; i++) {\r\n if (i == K || i == N-1-K) continue;\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n xs ~= N - 1;\r\n ys ~= K;\r\n xs ~= 0;\r\n ys ~= N - 1 - K;\r\n } else {\r\n // K == N - 1\r\n if (N >= 8) {\r\n xs ~= N-1; ys ~= N-2;\r\n xs ~= 1; ys ~= 3;\r\n xs ~= 0; ys ~= N-4;\r\n xs ~= N-3; ys ~= 2;\r\n for (int i = 4; i < N/2; i++) {\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n } else {\r\n writeln(-1);\r\n continue;\r\n }\r\n }\r\n DBG!N;\r\n DBG!K;\r\n long s = 0;\r\n for (int i = 0; i < N/2; i++) {\r\n s += xs[i] & ys[i];\r\n }\r\n DBG!s;\r\n assert(xs.length == N/2 && ys.length == N/2);\r\n assert(s == K);\r\n for (int i = 0; i < N/2; i++) {\r\n writefln(\"%d %d\", xs[i], ys[i]);\r\n }\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\tint n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\tint [2] [] a;\r\n\t\tforeach (i; 0..n / 2)\r\n\t\t{\r\n\t\t\ta ~= [i, n - 1 - i];\r\n\t\t}\r\n\t\tif (n == 4 && k == 3)\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tint t = min (k, n - 2);\r\n\t\tint pos = (t >= n / 2) ? (n - 1 - t) : (t);\r\n\t\tint qos = (t >= n / 2);\r\n\t\tswap (a[0][0], a[pos][qos]);\r\n\t\tif (k > t)\r\n\t\t{\r\n\t\t\tswap (a[pos][qos], a[$ - 1][0]);\r\n\t\t}\r\n\t\twritefln !(\"%(%(%s %)\\n%)\") (a);\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 k = RD!int;\r\n\r\n\t\tif (n == 4 && k == 3) continue;\r\n\r\n\t\tforeach (i; 0..n/2)\r\n\t\t{\r\n\t\t\tans[ti] ~= [i, n-i-1];\r\n\t\t}\r\n\r\n\t\tauto x = k & (n/2-1);\r\n\t\tswap(ans[ti][x][1], ans[ti][0][1]);\r\n\t\tif (k & (n/2))\r\n\t\t{\r\n\t\t\tif (x != n/2-1)\r\n\t\t\t\tswap(ans[ti][n/2-1][1], ans[ti][0][0]);\r\n\t\t\telse\r\n\t\t\t\tswap(ans[ti][n/2-2][1], ans[ti][0][0]);\r\n\t\t}\r\n\t\tdebug \r\n\t\t{\r\n\t\t\tlong tot;\r\n\t\t\tforeach (ee; ans[ti])\r\n\t\t\t\ttot += ee[0] & ee[1];\r\n\t\t\tif (tot != k)\r\n\t\t\t\twriteln(\"wa:n=\", n, \" k=\", k);\r\n\t\t}\r\n\t}\r\n\tdebug writeln(\"done\");\r\n\tdebug readln;\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\tforeach (ee; e)\r\n\t\t\twriteln(ee[0], \" \", ee[1]);\r\n\t}\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 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\r\n\t\tif (n == 4 && k == 3) break;\r\n\r\n\t\tforeach (i; 0..n/2)\r\n\t\t{\r\n\t\t\tans[ti] ~= [i, n-i-1];\r\n\t\t}\r\n\r\n\t\tauto x = k & (n/2-1);\r\n\t\tswap(ans[ti][x][1], ans[ti][0][1]);\r\n\t\tif (k & (n/2))\r\n\t\t{\r\n\t\t\tif (x != n/2-1)\r\n\t\t\t\tswap(ans[ti][n/2-1][1], ans[ti][0][0]);\r\n\t\t\telse\r\n\t\t\t\tswap(ans[ti][n/2-2][1], ans[ti][0][0]);\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\tforeach (ee; e)\r\n\t\t\twriteln(ee[0], \" \", ee[1]);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio;\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 T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) {\r\n int N, K; scanf(\"%d %d\\n\", &N, &K);\r\n int[] xs, ys;\r\n if (K == 0) {\r\n for (int i = 0; i < N/2; i++) {\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n } else if (K <= N - 2) {\r\n for (int i = 1; i < N/2; i++) {\r\n if (i == K || i == N-1-K) continue;\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n xs ~= N - 1;\r\n ys ~= K;\r\n xs ~= 0;\r\n ys ~= N - 1 - K;\r\n } else {\r\n // K == N - 1\r\n if (N >= 8) {\r\n xs ~= N-1; ys ~= N-2;\r\n xs ~= 1; ys ~= 3;\r\n xs ~= 0; ys ~= N-4;\r\n xs ~= N-3; ys ~= 2;\r\n for (int i = 4; i < N/2; i++) {\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n } else {\r\n writeln(-1);\r\n return;\r\n }\r\n }\r\n DBG!N;\r\n DBG!K;\r\n long s = 0;\r\n for (int i = 0; i < N/2; i++) {\r\n s += xs[i] & ys[i];\r\n }\r\n DBG!s;\r\n assert(xs.length == N/2 && ys.length == N/2);\r\n assert(s == K);\r\n for (int i = 0; i < N/2; i++) {\r\n writefln(\"%d %d\", xs[i], ys[i]);\r\n }\r\n\r\n }\r\n}\r\n"}, {"source_code": "import std.stdio;\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 T = readln.chomp.to!int;\r\n foreach (t; 0 .. T) {\r\n int N, K; scanf(\"%d %d\\n\", &N, &K);\r\n int[] xs, ys;\r\n if (K == 0) {\r\n for (int i = 0; i < N/2; i++) {\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n } else if (K <= N - 2) {\r\n for (int i = 1; i < N/2; i++) {\r\n if (i == K || i == N-1-K) continue;\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n xs ~= N - 1;\r\n ys ~= K;\r\n xs ~= 0;\r\n ys ~= N - 1 - K;\r\n } else {\r\n // K == N - 1\r\n if (N >= 8) {\r\n xs ~= N-1;\r\n ys ~= N-2;\r\n xs ~= 1;\r\n ys ~= 3;\r\n xs ~= 0;\r\n ys ~= N-4;\r\n xs ~= N - 3;\r\n ys ~= 2;\r\n for (int i = 5; i < N/2; i++) {\r\n xs ~= i;\r\n ys ~= (N - 1) - i;\r\n }\r\n } else {\r\n writeln(-1);\r\n return;\r\n }\r\n }\r\n assert(xs.length == N/2 && ys.length == N/2);\r\n long s = 0;\r\n for (int i = 0; i < N/2; i++) {\r\n s += xs[i] & ys[i];\r\n }\r\n assert(s == K);\r\n for (int i = 0; i < N/2; i++) {\r\n writefln(\"%d %d\", xs[i], ys[i]);\r\n }\r\n\r\n }\r\n}\r\n"}], "src_uid": "28d1c6a6effb1aea722164d5735377fc"} {"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 \n bool ans = true;\n int now;\n foreach (s; S) {\n (s == 'A') ? ++now : --now;\n ans = ans && (now >= 0);\n }\n ans = ans && (S[$ - 1] == 'B');\n writeln(ans ? \"YES\" : \"NO\");\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\nbool solve (string s)\r\n{\r\n\tif (s.back != 'B')\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tint b = 0;\r\n\tforeach (ref c; s)\r\n\t{\r\n\t\tb += (c == 'A') ? +1 : -1;\r\n\t\tif (b < 0)\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 s = readln.strip;\r\n\t\twriteln (solve (s) ? \"YES\" : \"NO\");\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\nbool solve (string s)\r\n{\r\n\tif (!s.canFind ('B'))\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tint b = 0;\r\n\tforeach (ref c; s)\r\n\t{\r\n\t\tb += (c == 'A') ? +1 : -1;\r\n\t\tif (b < 0)\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 s = readln.strip;\r\n\t\twriteln (solve (s) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "src_uid": "0b9be2f076cfa13cdc76c489bf1ea416"} {"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\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 int X, Y; readf(\"%d %d\\n\", &X, &Y); X--; Y--;\r\n auto _A = readln.chomp.split(\" \").map!(to!int).array;\r\n auto A = new bool[N];\r\n foreach (a; _A) {\r\n a--;\r\n A[a] = true;\r\n }\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 alias P = Tuple!(bool,\"g\", int,\"v\", int,\"p\");\r\n alias S = Tuple!(int,bool);\r\n S[P] cache;\r\n S f(bool g, int v, int p) {\r\n auto key = P(g, v, p);\r\n if (key in cache) return cache[key];\r\n int ans = 0;\r\n bool a_exist = A[v];\r\n foreach (nv; G[v]) {\r\n if (nv == p) continue;\r\n auto c = f(g, nv, v);\r\n if (c[1]) {\r\n ans += c[0] + (g ? 1 : 2);\r\n a_exist = true;\r\n }\r\n }\r\n return cache[key] = S(ans, a_exist);\r\n }\r\n\r\n auto dx = new int[N]; dx[] = INF;\r\n auto dy = new int[N]; dy[] = INF;\r\n void filld(int v, int p, int d, int[] ds) {\r\n ds[v] = d;\r\n foreach (nv; G[v]) {\r\n if (nv == p) continue;\r\n filld(nv, v, d+1, ds);\r\n }\r\n }\r\n filld(X, -1, 0, dx);\r\n filld(Y, -1, 0, dy);\r\n\r\n int total = f(false, X, -1)[0];\r\n int ans = INF;\r\n for (int z = 0; z < N; z++) {\r\n if (A[z]) {\r\n ans = min(ans, total - dx[z] + dy[z]);\r\n }\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 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 n, k;\r\n\t\treadf !(\" %s %s\") (n, k);\r\n\t\tint x, y;\r\n\t\treadf !(\" %s %s\") (x, y);\r\n\t\tx -= 1;\r\n\t\ty -= 1;\r\n\t\treadln;\r\n\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta[] -= 1;\r\n\t\tauto imp = new bool [n];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\timp[c] = true;\r\n\t\t}\r\n\t\timp[y] = true;\r\n\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 d = new int [n];\r\n\r\n\t\tvoid recur (int v, int p, int depth)\r\n\t\t{\r\n\t\t\td[v] = depth;\r\n\t\t\tforeach (ref 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, depth + 1);\r\n\t\t\t\t\timp[v] |= imp[u];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\trecur (x, NA, 0);\r\n\r\n\t\twriteln ((imp.sum - 1) * 2 - d[y]);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "a688369a2b95a8e32d00541d54f3bec6"} {"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;\nlong[][] M;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n M = new long[][](N, N);\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n M[x][y] = readLong();\n }\n \n auto ans = new long[N];\n foreach (i; 0 .. N) {\n const j = (i + 1) % N;\n const k = (i + 2) % N;\n const b = M[i][j] * M[i][k] / M[j][k];\n long lo = 0, hi = 2 * cast(long)(sqrt(cast(real)(b))) + 10;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n (mid * mid >= b) ? (hi = mid) : (lo = mid);\n }\n ans[i] = hi;\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.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint gcd(int a, int b) {\n if (b == 0) return a;\n else return gcd(b,a%b);\n}\n\nvoid main() {\n int n;\n readf!\" %s\"(n);\n\n int[][] a = new int[][](n,n);\n\n foreach (i; 0 .. n) {\n foreach (j; 0 .. n) {\n readf!\" %s\"(a[i][j]);\n }\n }\n\n int g = 0;\n foreach(j; 0 .. n) {\n g = gcd(g,a[0][j]);\n }\n\n int ans;\n for (long i = 1; i*i <= g; i++) {\n if (g % i == 0) {\n if ((a[0][1]/i) * (a[0][2]/i) == a[1][2]){\n ans = to!int(i);\n break;\n }\n if ((a[0][1]/(g/i)) * (a[0][2]/(g/i)) == a[1][2]) {\n ans = g/i;\n break;\n }\n }\n }\n\n writef!\"%d \"(ans);\n foreach (i; 1 .. n) {\n writef!\"%d \"(a[0][i]/ans);\n }\n writeln();\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\nint N;\nlong[][] M;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n M = new long[][](N, N);\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n M[x][y] = readLong();\n }\n \n auto ans = new long[N];\n foreach (i; 0 .. N) {\n const j = (i + 1) % N;\n const k = (i + 2) % N;\n const b = M[i][j] * M[i][k] / M[j][k];\n long lo = 0, hi = b;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n (mid * mid >= b) ? (hi = mid) : (lo = mid);\n }\n ans[i] = hi;\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"}], "src_uid": "ced70b400694fa16929d4b0bce3da294"} {"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\nint M, K;\nstring S;\nint[] C;\nint[][] X;\n\nint[][] uss;\nint[][] graph;\nint[] colors;\n\nvoid dfs(int u) {\n foreach (i; graph[u]) {\n const v = uss[i][0] ^ uss[i][1] ^ u;\n if (colors[v] == -1) {\n colors[v] = (colors[u] ^ ('1' - S[i]));\n dfs(v);\n }\n assert(colors[v] == (colors[u] ^ ('1' - S[i])));\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n M = readInt();\n K = readInt();\n S = readToken();\n C = new int[K];\n X = new int[][K];\n foreach (u; 0 .. K) {\n C[u] = readInt();\n X[u] = new int[C[u]];\n foreach (j; 0 .. C[u]) {\n X[u][j] = readInt() - 1;\n }\n }\n \n uss = new int[][M];\n foreach (u; 0 .. K) {\n foreach (j; 0 .. C[u]) {\n uss[X[u][j]] ~= u;\n }\n }\n graph = new int[][K + 1];\n foreach (i; 0 .. M) {\n switch (uss[i].length) {\n case 0: {\n // no edge\n } break;\n case 1: {\n uss[i] ~= K;\n graph[uss[i][0]] ~= i;\n graph[uss[i][1]] ~= i;\n } break;\n case 2: {\n graph[uss[i][0]] ~= i;\n graph[uss[i][1]] ~= i;\n } break;\n default: assert(false);\n }\n }\n debug {\n writeln(\"uss = \", uss);\n }\n colors = new int[K + 1];\n colors[] = -1;\n foreach_reverse (u; 0 .. K + 1) {\n if (colors[u] == -1) {\n colors[u] = 0;\n dfs(u);\n }\n }\n debug {\n writeln(\"colors = \", colors);\n }\n \n int ans;\n auto nums = new int[][](K + 1, 2);\n foreach (u; 0 .. K + 1) {\n ++nums[u][colors[u]];\n }\n auto uf = new int[K + 1];\n uf[] = -1;\n int get(int r) {\n if (uf.root(K) == r) {\n return nums[r][1];\n } else {\n return min(nums[r][0], nums[r][1]);\n }\n }\n \n foreach (i; 0 .. M) {\n if (uss[i]) {\n int ru = uf.root(uss[i][0]);\n int rv = uf.root(uss[i][1]);\n if (ru != rv) {\n ans -= get(ru);\n ans -= get(rv);\n uf.connect(ru, rv);\n if (ru != uf.root(ru)) {\n swap(ru, rv);\n }\n nums[ru][] += nums[rv][];\n ans += get(ru);\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\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, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto toDo = readln.strip.map !(x => x == '0').array;\n\t\tauto a = new int [] [n];\n\t\tauto s = new int [] [k];\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tint len;\n\t\t\treadf !(\" %s\") (len);\n\t\t\tforeach (i; 0..len)\n\t\t\t{\n\t\t\t\tint elem;\n\t\t\t\treadf !(\" %s\") (elem);\n\t\t\t\telem -= 1;\n\t\t\t\ta[elem] ~= j;\n\t\t\t\ts[j] ~= elem;\n\t\t\t}\n\t\t}\n\n\t\tauto p = k.iota.array;\n\t\tauto comp = new int [] [k];\n\t\tauto cost = new int [k];\n\t\tauto state = new int [k];\n\t\tauto stateRoot = new int [k];\n\t\tauto isFixed = new bool [k];\n\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tcomp[j] ~= j;\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\tp[v] = root (p[v]);\n\t\t\t}\n\t\t\treturn p[v];\n\t\t}\n\n\t\tint getState (int u)\n\t\t{\n\t\t\treturn state[u] ^ stateRoot[root (u)];\n\t\t}\n\n\t\tint totalCost = 0;\n\n\t\tvoid switchComp (int u)\n\t\t{\n\t\t\tauto x = root (u);\n\t\t\tdebug {writeln (\"switchComp \", u, \" \", x);}\n\t\t\tstateRoot[x] ^= 1;\n\t\t\tauto newCostX = comp[x].length.to !(int) - cost[x];\n\t\t\tdebug {writeln (cost[x], \" -> \", newCostX);}\n\t\t\ttotalCost -= cost[x];\n\t\t\tcost[x] = newCostX;\n\t\t\ttotalCost += cost[x];\n\t\t}\n\n\t\tbool unite (int u, int v, bool toDoHere)\n\t\t{\n\t\t\tauto x = root (u);\n\t\t\tauto y = root (v);\n\t\t\tdebug {writeln (\"unite \", u, \" \", v, \" \",\n\t\t\t toDoHere, \" \", x, \" \", y);}\n\t\t\tauto hasWork = toDoHere ^ getState (u) ^ getState (v);\n\t\t\tdebug {writeln (toDoHere, \" \", getState (u), \" \",\n\t\t\t getState (v));}\n\t\t\tif (hasWork)\n\t\t\t{\n\t\t\t\tdebug {writeln (\"hasWork \", x, \" \", y);}\n\t\t\t\tif (x == y)\n\t\t\t\t{\n\t\t\t\t\tassert (false);\n\t\t\t\t}\n\t\t\t\tauto newCostX =\n\t\t\t\t comp[x].length.to !(int) - cost[x];\n\t\t\t\tauto newCostY =\n\t\t\t\t comp[y].length.to !(int) - cost[y];\n\t\t\t\tif (!isFixed[x] && (isFixed[y] ||\n\t\t\t\t cost[x] + newCostY > newCostX + cost[y]))\n\t\t\t\t{\n\t\t\t\t\tswap (u, v);\n\t\t\t\t\tswap (x, y);\n\t\t\t\t}\n\t\t\t\tif (isFixed[y])\n\t\t\t\t{\n\t\t\t\t\tassert (false);\n\t\t\t\t}\n\t\t\t\tswitchComp (y);\n\t\t\t}\n\n\t\t\tif (x == y)\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (comp[y].length < comp[x].length)\n\t\t\t{\n\t\t\t\tswap (x, y);\n\t\t\t}\n\t\t\tif (stateRoot[x] != stateRoot[y])\n\t\t\t{\n\t\t\t\tforeach (w; comp[x])\n\t\t\t\t{\n\t\t\t\t\tstate[w] ^= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tp[x] = y;\n\t\t\tcomp[y] ~= comp[x];\n\t\t\tcost[y] += cost[x];\n\t\t\tisFixed[y] |= isFixed[x];\n\t\t\treturn true;\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tdebug {writeln (i + 1, \": type \", a[i].length);}\n\t\t\tdebug {writeln (\"state: \", state);}\n\t\t\tdebug {writeln (\"stateRoot: \", stateRoot);}\n\t\t\tdebug {writeln (\"getState: \", k.iota.map !(getState));}\n\t\t\tdebug {writeln (\"isFixed: \", isFixed);}\n\t\t\tif (a[i].length == 0)\n\t\t\t{\n\t\t\t}\n\t\t\telse if (a[i].length == 1)\n\t\t\t{\n\t\t\t\tauto u = a[i][0];\n\t\t\t\tauto x = root (u);\n\t\t\t\tauto hasWork = toDo[i] ^ getState (u);\n\t\t\t\tif (hasWork)\n\t\t\t\t{\n\t\t\t\t\tif (isFixed[x])\n\t\t\t\t\t{\n\t\t\t\t\t\tassert (false);\n\t\t\t\t\t}\n\t\t\t\t\tswitchComp (x);\n\t\t\t\t}\n\t\t\t\tisFixed[x] = true;\n\t\t\t}\n\t\t\telse if (a[i].length == 2)\n\t\t\t{\n\t\t\t\tunite (a[i][0], a[i][1], toDo[i]);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\n\t\t\twriteln (totalCost);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "10e6b62d5b1abf8e1ba964a38dc6a9e8"} {"source_code": "import std.stdio;\n\nint len, p1, p2;\nint[] ans;\nchar[] s;\n\nint main() {\n readln(s);\n ans.length = s.length;\n len = s.length - 1;\n p1 = 0, p2 = len - 1;\n for (int i = 0; i < len; ++ i) {\n if (s[i] == 'l') ans[p2 --] = i + 1;\n else ans[p1 ++] = i + 1;\n }\n for (int i = 0; i < len; ++ i) writeln(ans[i]);\n return 0;\n}\n", "positive_code": [{"source_code": "import std.array;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n\tstring commands = strip(stdin.readln());\n\n\tauto array = appender!(int[])();\n\n\tforeach (i, c; commands) {\n\t\tif (c == 'r') {\n\t\t\tstdout.writeln(i + 1);\n\t\t} else {\n\t\t\tarray.put(i + 1);\n\t\t}\n\t}\n\n\tauto end = array.data;\n\n\tfor (int i = end.length - 1; i >= 0; --i) {\n\t\tstdout.writeln(end[i]);\n\t}\n}"}, {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.typecons;\n\nvoid output (Tuple !(int, int, int) v [], int i)\n{\n\tif (i == -1)\n\t{\n\t\treturn;\n\t}\t\n\toutput (v, v[i][0]);\n\tprintf (\"%d\\n\", v[i][2]);\n\toutput (v, v[i][1]);\n}\n\nint main ()\n{\n\tstring s;\n\twhile ((s = readln ()) != null)\n\t{\n\t\tauto n = s.length - 1;\n\t\tTuple !(int, int, int) v [];\n\t\tv ~= tuple (-1, -1, 1);\n\t\tforeach (int i; 0..n - 1)\n\t\t{\n\t\t\tif (s[i] == 'l')\n\t\t\t{\n\t\t\t\tv[$ - 1][0] = i + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[$ - 1][1] = i + 1;\n\t\t\t}\n\t\t\tv ~= tuple (-1, -1, i + 2);\n\t\t}\n\n\t\toutput (v, 0);\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.typecons;\n\nint main ()\n{\n\tstring s;\n\twhile ((s = readln ()) != null)\n\t{\n\t\tauto n = s.length - 1;\n\t\tTuple !(int, int, int) v [];\n\t\tv ~= tuple (-1, -1, 1);\n\t\tforeach (int i; 0..n - 1)\n\t\t{\n\t\t\tif (s[i] == 'l')\n\t\t\t{\n\t\t\t\tv[$ - 1][0] = i + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tv[$ - 1][1] = i + 1;\n\t\t\t}\n\t\t\tv ~= tuple (-1, -1, i + 2);\n\t\t}\n\n\t\tvoid output (int i)\n\t\t{\n\t\t\tif (i == -1)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\t\n\t\t\toutput (v[i][0]);\n\t\t\tprintf (\"%d\\n\", v[i][2]);\n\t\t\toutput (v[i][1]);\n\t\t}\n\n\t\toutput (0);\n\t}\n\treturn 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 auto S = readln.chomp;\n auto N = S.length.to!int;\n auto A = new int[](N);\n int l = 0, r = N - 1;\n\n foreach (i; 0..N) {\n if (S[i] == 'l') {\n A[i] = r;\n r--;\n } else {\n A[i] = l;\n l++;\n }\n }\n\n auto B = new int[](N);\n foreach (i; 0..N) B[A[i]] = i;\n B.each!(b => (b + 1).writeln);\n}\n"}], "negative_code": [], "src_uid": "9d3c0f689ae1e6215448463def55df32"} {"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 c00, int c01, int c10, int c11, int depth, bool flag)\n{\n if (depth > 1000001)\n return int.max;\n\n if (c01 + c10 == 0)\n return 0;\n\n int ans1 = int.max, ans2 = int.max;\n\n if (flag) {\n if (c11 > 0) {\n int x = solve(c10, c11 - 1, c00, c01 + 1, depth + 1, !flag);\n if (x != int.max)\n ans1 = 1 + x;\n }\n }\n\n if (!flag) {\n if (c10 > 0) {\n int x = solve(c10 - 1, c11, c00 + 1, c01, depth + 1, !flag);\n if (x != int.max)\n ans2 = 1 + x;\n }\n }\n\n return min(ans1, ans2);\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.strip;\n auto b = readln.strip;\n int c00, c01, c10, c11;\n foreach (i ; 0 .. n) {\n if (a[i] == '0' && b[i] == '0')\n c00++;\n if (a[i] == '0' && b[i] == '1')\n c01++;\n if (a[i] == '1' && b[i] == '0')\n c10++;\n if (a[i] == '1' && b[i] == '1')\n c11++;\n }\n int ans1 = solve(c00, c01, c10, c11, 0, true);\n int ans2 = solve(c00, c01, c10, c11, 0, false);\n int ans = min(ans1, ans2);\n writeln(ans == int.max ? -1 : ans);\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 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 = RD!string;\r\n\t\tauto b = RD!string;\r\n\r\n\t\tlong x0, x1, y0, y1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] == b[i])\r\n\t\t\t{\r\n\t\t\t\tif (a[i] == '0')\r\n\t\t\t\t\t++x0;\r\n\t\t\t\telse\r\n\t\t\t\t\t++x1;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (a[i] == '0')\r\n\t\t\t\t\t++y0;\r\n\t\t\t\telse\r\n\t\t\t\t\t++y1;\r\n\t\t\t}\r\n\t\t}\r\n\t\tans[ti] = long.max;\r\n\t\tif ((x0+x1) % 2 == 1 && (x0+x1+1)/2 == x1)\r\n\t\t\tans[ti].chmin(x0+x1);\r\n\t\tif ((y0+y1) % 2 == 0 && (y0+y1+1)/2 == y1)\r\n\t\t\tans[ti].chmin(y0+y1);\r\n\t\tif (ans[ti] == long.max)\r\n\t\t\tans[ti] = -1;\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;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint solve (int n, bool [] a, bool [] b)\r\n{\r\n\tauto aOnes = a.sum.to !(int);\r\n\tauto bOnes = b.sum.to !(int);\r\n\tauto same = n.iota.count !(i => a[i] == b[i]).to !(int);\r\n\tauto diff = n - same;\r\n\tint res = int.max;\r\n\tif (aOnes == bOnes)\r\n\t{\r\n\t\tres = min (res, diff);\r\n\t}\r\n\tif (aOnes + bOnes == n + 1)\r\n\t{\r\n\t\tres = min (res, same);\r\n\t}\r\n\tif (res == int.max)\r\n\t{\r\n\t\tres = -1;\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\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.strip.map !(q{a == '1'}).array;\r\n\t\tauto b = readln.strip.map !(q{a == '1'}).array;\r\n\t\twriteln (solve (n, a, b));\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 INF = 10^^9;\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 ans = INF;\n if (A == B) {\n ans = 0;\n } else {\n const a = cast(int)(A.count('1'));\n const b = cast(int)(B.count('1'));\n if (a >= 1 && b >= 1 && a == b) {\n int d;\n foreach (i; 0 .. N) {\n if (A[i] != B[i]) {\n ++d;\n }\n }\n chmin(ans, d);\n }\n if (a >= 1 && b >= 1 && (a - 1) + (b - 1) == N - 1) {\n int d;\n foreach (i; 0 .. N) {\n if (A[i] == B[i]) {\n ++d;\n }\n }\n chmin(ans, d);\n }\n }\n \n writeln((ans >= INF) ? -1 : ans);\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 s1 = cast(byte[]) readString;\n auto s2 = cast(byte[]) readString;\n int[2][2] cnt;\n foreach(i; 0 .. n)\n {\n cnt[s1[i]-'0'][s2[i]-'0']++;\n }\n debug {\n foreach(r; cnt) writeln(r);\n }\n int minops = int.max;\n int k = cnt[1][0];\n if (cnt[0][1] == k) minops = min(minops, 2 * k);\n k = cnt[0][0];\n if (cnt[1][1] - k - 1 == 0) minops = min(minops, 2 * k + 1);\n if (minops != int.max) return writeln(minops);\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"}], "negative_code": [], "src_uid": "84c0f17a45826a6e43d1f4717e62c194"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 m = RD!int;\n\t\tauto a = RDA;\n\t\tans[ti] = a.sum == m;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\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 int summ = 0, el;\n foreach(i; 0..n){\n el = rd!int;\n summ += el;\n }\n if(summ == m){\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/**********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": [], "src_uid": "941adee47c2a28588ebe7dfe16e0c91a"} {"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 while (T--) {\n auto s = readln.split.map!(to!long);\n auto A = s[0];\n auto B = s[1];\n auto D = abs(A - B);\n long tmp = 0;\n for (long i = 0; ; ++i) {\n tmp += i;\n if (tmp >= D && tmp % 2 == D % 2) {\n i.writeln;\n break;\n }\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; }\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 (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto d = max(a, b) - min(a, b);\n\t\tlong x, j;\n\t\tforeach (i; 1..10^^5)\n\t\t{\n\t\t\tif (x >= d && (x - d) % 2 == 0) break;\n\t\t\tx = cast(long)i * (i+1) / 2;\n\t\t\tj = i;\n\t\t}\n\t\tans[ti] = j;\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; }\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 (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto d = max(a, b) - min(a, b);\n\t\tlong x, j;\n\t\tforeach (i; 1..10^^5)\n\t\t{\n\t\t\tif (x >= d) break;\n\t\t\tx = i * (i+1) / 2;\n\t\t\tj = i;\n\t\t}\n\t\tif (x == d)\n\t\t\tans[ti] = j;\n\t\telse\n\t\t\tans[ti] = j+1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "29e84addbc88186bce40d68cf124f5da"} {"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 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 a = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n a[x][y] = A[x][y] - '0';\n }\n \n int[][] ans;\n void oper(int x0, int y0, int x1, int y1, int x2, int y2) {\n ans ~= [x0, y0, x1, y1, x2, y2];\n a[x0][y0] ^= 1;\n a[x1][y1] ^= 1;\n a[x2][y2] ^= 1;\n }\n \n foreach (x; 0 .. M - 2) foreach (y; 0 .. N - 2) {\n if (a[x][y]) {\n oper(x, y, x, y + 1, x + 1, y);\n }\n }\n foreach (x; 0 .. M - 2) {\n const y = N - 2;\n if (a[x][y]) {\n if (a[x][y + 1]) {\n oper(x, y, x, y + 1, x + 1, y);\n } else {\n oper(x, y, x + 1, y, x + 1, y + 1);\n }\n } else {\n if (a[x][y + 1]) {\n oper(x, y + 1, x + 1, y, x + 1, y + 1);\n } else {\n oper(x, y, x, y + 1, x + 1, y);\n oper(x, y, x, y + 1, x + 1, y);\n }\n }\n }\n foreach (y; 0 .. N - 2) {\n const x = M - 2;\n if (a[x][y]) {\n if (a[x + 1][y]) {\n oper(x, y, x + 1, y, x, y + 1);\n } else {\n oper(x, y, x, y + 1, x + 1, y + 1);\n }\n } else {\n if (a[x + 1][y]) {\n oper(x + 1, y, x, y + 1, x + 1, y + 1);\n } else {\n oper(x, y, x + 1, y, x, y + 1);\n oper(x, y, x + 1, y, x, y + 1);\n }\n }\n }\n {\n const x = M - 2, y = N - 2;\n foreach (p; 0 .. 1 << 4) {\n auto bs = new int[4];\n foreach (i; 0 .. 4) {\n if (p & 1 << i) {\n foreach (j; 0 .. 4) {\n if (i != j) {\n bs[j] ^= 1;\n }\n }\n }\n }\n debug {\n writeln(p, \": \", bs);\n }\n bool ok = true;\n foreach (j; 0 .. 4) {\n ok = ok && (a[x + j / 2][y + j % 2] == bs[j]);\n }\n if (ok) {\n if (p & 1 << 0) oper(x, y + 1, x + 1, y, x + 1, y + 1);\n if (p & 1 << 1) oper(x, y, x + 1, y, x + 1, y + 1);\n if (p & 1 << 2) oper(x, y, x, y + 1, x + 1, y + 1);\n if (p & 1 << 3) oper(x, y, x, y + 1, x + 1, y);\n }\n }\n }\n \n writeln(ans.length);\n foreach (row; ans) {\n foreach (i; 0 .. 6) {\n if (i > 0) write(\" \");\n write(row[i] + 1);\n }\n writeln;\n }\n debug {\n writeln(\"a = \", a);\n }\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\tint rows, cols;\n\t\treadf !(\" %s %s\") (rows, cols);\n\t\treadln;\n\t\tuint [] [] board;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tboard ~= readln.strip.map !(q{a - '0'}).array;\n\t\t}\n\n\t\tint [] [] answer;\n\n\t\tvoid go (int row, int col,\n\t\t int row1, int col1, int row2, int col2)\n\t\t{\n\t\t\tanswer ~= [row, col, row1, col1, row2, col2];\n\t\t\tboard[row][col] ^= 1;\n\t\t\tboard[row1][col1] ^= 1;\n\t\t\tboard[row2][col2] ^= 1;\n\t\t}\n\n\t\tforeach_reverse (row; 0..rows)\n\t\t{\n\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t{\n\t\t\t\tif ((row == rows - 1 && rows % 2 == 1) ||\n\t\t\t\t (col == cols - 1 && cols % 2 == 1))\n\t\t\t\t{\n\t\t\t\t\tif (board[row][col])\n\t\t\t\t\t{\n\t\t\t\t\t\tauto row1 = max (row - 1, 0);\n\t\t\t\t\t\tauto col1 = max (col - 1, 0);\n\t\t\t\t\t\tauto row2 = row1 + 1;\n\t\t\t\t\t\tauto col2 = col1;\n\t\t\t\t\t\tif (row2 == row &&\n\t\t\t\t\t\t col2 == col)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trow2 = row1;\n\t\t\t\t\t\t\tcol2 = col1 + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tgo (row, col,\n\t\t\t\t\t\t row1, col1, row2, col2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid doSquare (int row, int col)\n\t\t{\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\tauto total = board[row + 0][col + 0] +\n\t\t\t\t board[row + 1][col + 0] +\n\t\t\t\t board[row + 0][col + 1] +\n\t\t\t\t board[row + 1][col + 1];\n\t\t\t\tif (total == 0)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tint [] seqRow;\n\t\t\t\tint [] seqCol;\n\t\t\t\tforeach_reverse (value; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (rowT; row..row + 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (colT; col..col + 2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (board[rowT][colT]\n\t\t\t\t\t\t\t == value)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tseqRow ~= rowT;\n\t\t\t\t\t\t\t\tseqCol ~= colT;\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 (total == 2)\n\t\t\t\t{\n\t\t\t\t\tseqRow.popFront ();\n\t\t\t\t\tseqCol.popFront ();\n\t\t\t\t}\n\t\t\t\tgo (seqRow[0], seqCol[0],\n\t\t\t\t seqRow[1], seqCol[1],\n\t\t\t\t seqRow[2], seqCol[2]);\n\t\t\t}\n\t\t}\n\n\t\tfor (int row = 0; row + 1 < rows; row += 2)\n\t\t{\n\t\t\tfor (int col = 0; col + 1 < cols; col += 2)\n\t\t\t{\n\t\t\t\tdoSquare (row, col);\n\t\t\t}\n\t\t}\n\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 (board[row][col])\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\twriteln (answer.length);\n\t\tforeach (ref line; answer)\n\t\t{\n\t\t\twritefln !(\"%(%s %)\") (line.map !(q{a + 1}));\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(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 m = RD!int;\n\t\tauto s = new char[][](n);\n\t\tforeach (i; 0..n)\n\t\t\ts[i] = RD!(char[]);\n\n\t\tforeach (y; 0..n-1)\n\t\t{\n\t\t\tforeach (x; 0..m-1)\n\t\t\t{\n\t\t\t\tdebug writeln(\"y:\", y, \" x:\", x);\n\t\t\t\tvoid draw(long[] pos)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= [pos[0]+1, pos[1]+1, pos[2]+1, pos[3]+1, pos[4]+1, pos[5]+1];\n\t\t\t\t\tforeach (i; 0..3)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto yy = cast(int)pos[i*2];\n\t\t\t\t\t\tauto xx = cast(int)pos[i*2+1];\n\t\t\t\t\t\ts[yy][xx] = s[yy][xx] == '0' ? '1' : '0';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvoid fin()\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdraw(tmp);\n\t\t\t\t}\n\t\t\t\tvoid fin2()\n\t\t\t\t{\n\t\t\t\t\tlong[] tmp;\n\t\t\t\t\tbool mode;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (mode) continue;\n\t\t\t\t\t\t\t\tmode = true;\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdraw(tmp);\n\t\t\t\t\tfin();\n\t\t\t\t}\n\t\t\t\tif (y == n-2 && x == m-2)\n\t\t\t\t{\n\t\t\t\t\tlong cnt;\n\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (s[y+i][x+j] == '1')\n\t\t\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (cnt == 4)\n\t\t\t\t\t{\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\t\tdraw([y, x, y+1, x, y+1, x+1]);\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t\t\tfin();\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 3)\n\t\t\t\t\t{\n\t\t\t\t\t\tfin();\t\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tfin2();\n\t\t\t\t\t}\n\t\t\t\t\telse if (cnt == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tlong[] tmp;\n\t\t\t\t\t\tint mode;\n\t\t\t\t\t\tforeach (i; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (s[y+i][x+j] == '0')\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif (mode == 2) continue;\n\t\t\t\t\t\t\t\t\t++mode;\n\t\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\ttmp ~= [y+i, x+j];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdraw(tmp);\n\t\t\t\t\t\tfin2();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (y == n-2)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '1' && s[y+1][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y+1, x, y, x+1]);\n\t\t\t\t\telse if (s[y][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y+1][x] == '1')\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t\telse if (x == m-2)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '1' && s[y][x+1] == '1')\n\t\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t\telse if (s[y][x] == '1')\n\t\t\t\t\t\tdraw([y, x, y+1, x, y+1, x+1]);\n\t\t\t\t\telse if (s[y][x+1] == '1')\n\t\t\t\t\t\tdraw([y+1, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == '0') continue;\n\t\t\t\t\tdraw([y, x, y, x+1, y+1, x+1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t\twriteln(s[i]);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\tforeach (ee; e)\n\t\t{\n\t\t\tee.map!(to!string).join(\" \").writeln;\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main () {\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests) {\n\t\tint rows, cols;\n\t\treadf !(\" %s %s \") (rows, cols);\n\t\tuint [] [] board;\n\t\tforeach (row; 0..rows)\n\t\t\tboard ~= readln.strip.map !(q{a - '0'}).array;\n\n\t\tint [] [] answer;\n\n\t\tvoid go (int row, int col, int row1, int col1, int row2, int col2) {\n\t\t\tanswer ~= [row, col, row1, col1, row2, col2];\n\t\t\tboard[row][col] ^= 1;\n\t\t\tboard[row1][col1] ^= 1;\n\t\t\tboard[row2][col2] ^= 1;\n\t\t}\n\n\t\tforeach_reverse (row; 0..rows)\n\t\t\tforeach_reverse (col; 0..cols)\n\t\t\t\tif ((row == rows - 1 && rows % 2 == 1) || (col == cols - 1 && cols % 2 == 1))\n\t\t\t\t\tif (board[row][col]) {\n\t\t\t\t\t\tauto row1 = max (row - 1, 0);\n\t\t\t\t\t\tauto col1 = max (col - 1, 0);\n\t\t\t\t\t\tauto row2 = row1 + 1;\n\t\t\t\t\t\tauto col2 = col1;\n\t\t\t\t\t\tif (row2 == row && col2 == col) {\n\t\t\t\t\t\t\trow2 = row1;\n\t\t\t\t\t\t\tcol2 = col1 + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tgo (row, col, row1, col1, row2, col2);\n\t\t\t\t\t}\n\n\t\tvoid doSquare (int row, int col) {\n\t\t\twhile (true) {\n\t\t\t\tauto total = board[row + 0][col + 0] +\n\t\t\t\t board[row + 1][col + 0] +\n\t\t\t\t board[row + 0][col + 1] +\n\t\t\t\t board[row + 1][col + 1];\n\t\t\t\tif (total == 0)\n\t\t\t\t\tbreak;\n\t\t\t\tint [] seqRow, seqCol;\n\t\t\t\tforeach_reverse (value; 0..2)\n\t\t\t\t\tforeach (rowT; row..row + 2)\n\t\t\t\t\t\tforeach (colT; col..col + 2)\n\t\t\t\t\t\t\tif (board[rowT][colT] == value) {\n\t\t\t\t\t\t\t\tseqRow ~= rowT;\n\t\t\t\t\t\t\t\tseqCol ~= colT;\n\t\t\t\t\t\t\t}\n\t\t\t\tif (total == 2) {\n\t\t\t\t\tseqRow.popFront ();\n\t\t\t\t\tseqCol.popFront ();\n\t\t\t\t}\n\t\t\t\tgo (seqRow[0], seqCol[0],\n\t\t\t\t seqRow[1], seqCol[1],\n\t\t\t\t seqRow[2], seqCol[2]);\n\t\t\t}\n\t\t}\n\n\t\tfor (int row = 0; row + 1 < rows; row += 2)\n\t\t\tfor (int col = 0; col + 1 < cols; col += 2)\n\t\t\t\tdoSquare (row, col);\n\n\t\twriteln (answer.length);\n\t\tforeach (ref line; answer)\n\t\t\twritefln !(\"%(%s %)\") (line.map !(q{a + 1}));\n\t}\n}\n"}], "negative_code": [], "src_uid": "7dd42c258865a14ad6c3184e631d8555"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tbool have0 = false;\n\t\tbool have1 = false;\n\t\tforeach (ref c; s)\n\t\t{\n\t\t\tif (c == '0')\n\t\t\t{\n\t\t\t\twriteln (have0 ? 1 : 3, \" \", 1);\n\t\t\t\thave0 ^= true;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twriteln (1, \" \", have1 ? 1 : 3);\n\t\t\t\thave1 ^= true;\n\t\t\t}\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;\n\nvoid main() {\n auto S = readln.chomp;\n auto N = S.length.to!int;\n\n int v_count = 0;\n int h_count = 0;\n\n foreach (s; S) {\n if (s == '1') {\n writeln(1, \" \", h_count + 1);\n h_count += 2;\n if (h_count == 4) h_count = 0;\n } else {\n writeln(3, \" \", v_count + 1);\n v_count += 1;\n if (v_count == 4) v_count = 0;\n }\n }\n}\n"}], "negative_code": [], "src_uid": "a63cdbd1009a60c0f9b52e4ffbba252e"} {"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\tlong tt = readln().chomp.to!long;\n\tforeach (t; 0 .. tt) {\n\t\treadln();\n\t\tlong[] piles = readln().chomp.split(\" \").map!(to!long).array;\n\t\tbool winner = true;\n\t\tbool didBreak = false;\n\t\tforeach (i; piles) {\n\t\t\tif (i == 1) {\n\t\t\t\twinner = !winner;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdidBreak = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!didBreak) {\n\t\t\twinner = !winner;\n\t\t}\n\t\twriteln(winner ? \"First\" : \"Second\");\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);\n\tforeach (test; 0..tests)\n\t{\n\t\tauto n = readln.strip.to !(int);\n\t\tauto p = readln.splitter.countUntil !(q{a != \"1\"});\n\t\twriteln (((p < 0 ? ~n : p) & 1) ? \"Second\" : \"First\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "0c9030689394ad4e126e5b8681f1535c"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.numeric;\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\tauto a = readln.split.map !(to !(int)).array;\n\t\tforeach (k; 2..4)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\twhile (a[i] % k == 0)\n\t\t\t\t{\n\t\t\t\t\ta[i] /= k;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (a.all !(x => x == a[0]) ? \"Yes\" : \"No\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\n\nvoid solve(int[] a)\n{\n auto n = cast(int)a.length;\n foreach (i; 0 .. n)\n {\n while (a[i] % 2 == 0)\n {\n a[i] >>= 1;\n }\n while (a[i] % 3 == 0)\n {\n a[i] /= 3;\n }\n if (i > 0 && a[i] != a[i - 1])\n {\n writeln(\"No\");\n return;\n }\n }\n writeln(\"Yes\");\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": "2bb893703cbffe9aeaa0bed02f42a05c"} {"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 A = s[0];\n auto B = s[1];\n auto C = s[2];\n auto D = s[3];\n --A, --B, --C, --D;\n\n const int H = 50;\n const int W = 50;\n auto ans = new int[][](H, W);\n\n foreach (i; 0..H)\n foreach (j; 0..W) {\n if (i < H/2 && j < W/2)\n ans[i][j] = 1;\n else if (i < H/2 && j >= W/2)\n ans[i][j] = 2;\n else if (i >= H/2 && j < W/2)\n ans[i][j] = 3;\n else\n ans[i][j] = 4;\n }\n\n for (int i = 0; i < H/2-1; i += 2) {\n for (int j = 0; j < W/2-1; ++j) {\n if (j % 3 == 0 && B > 0)\n ans[i][j] = 2, --B;\n else if (j % 3 == 1 && C > 0)\n ans[i][j] = 3, --C;\n else if (j % 3 == 2 && D > 0)\n ans[i][j] = 4, --D;\n }\n }\n\n for (int i = 0; i < H/2-1; i += 2) {\n for (int j = W/2+1; j < W; ++j) {\n if (j % 3 == 0 && A > 0)\n ans[i][j] = 1, --A;\n else if (j % 3 == 1 && C > 0)\n ans[i][j] = 3, --C;\n else if (j % 3 == 2 && D > 0)\n ans[i][j] = 4, --D;\n }\n }\n\n for (int i = H/2+1; i < H; i += 2) {\n for (int j = 0; j < W/2-1; ++j) {\n if (j % 3 == 0 && A > 0)\n ans[i][j] = 1, --A;\n else if (j % 3 == 1 && B > 0)\n ans[i][j] = 2, --B;\n else if (j % 3 == 2 && D > 0)\n ans[i][j] = 4, --D;\n }\n }\n\n for (int i = H/2+1; i < H; i += 2) {\n for (int j = W/2+1; j < W; ++j) {\n if (j % 3 == 0 && A > 0)\n ans[i][j] = 1, --A;\n else if (j % 3 == 1 && B > 0)\n ans[i][j] = 2, --B;\n else if (j % 3 == 2 && C > 0)\n ans[i][j] = 3, --C;\n }\n }\n\n writeln(H, \" \", W);\n ans.map!(a => a.map!(b => ('A' + b - 1).to!char)).each!writeln;\n}\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\nvoid main()\n{\n auto v = readln.chomp.split.map!(to!int).array;\n \n char[50][44] ans;\n debug { ans.length.writeln; }\n \n foreach (ref e; v) e -= 1;\n debug { v.writeln; }\n \n auto clrs = ['a', 'b', 'c', 'd'];\n \n foreach (i; 0..44) ans[i].fill(clrs[i / 11]);\n \n void go(char c, int x, int st) {\n if (x == 0) return;\n \n outer: foreach (ref r; ans[st..st+11].dropOne.dropBackOne.stride(2)) {\n foreach (ref p; r.length.iota.dropOne.dropBackOne.stride(2)) {\n r[p] = c;\n --x;\n if (x == 0) {\n debug { r.writeln; }\n break outer;\n }\n }\n }\n }\n \n foreach (i; (44).iota.stride(11)) {\n auto nxt = ((i/11) + 1) % 4;\n debug { i.writeln; nxt.writeln; clrs[nxt].writeln; }\n go(clrs[nxt], v[nxt], i); \n }\n \n writeln(ans.length, ' ', ans[0].length);\n ans.each!writeln;\n}"}], "negative_code": [], "src_uid": "637b0a757223521c44674bf1663a1114"} {"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[100_000] arr, ht;\n int n;\n int curht = 0, maxht = 0;\n readf(\" %s\\n\", &n);\n foreach ( i ; 0 .. n ) {\n readf(\" %s\", &arr[i]);\n if (arr[i] > curht) ++curht;\n else curht = arr[i];\n ht[i] = curht;\n }\n curht = 0;\n foreach_reverse ( i ; 0 .. n ) {\n if (arr[i] > curht) ++curht;\n else curht = arr[i];\n int joinht = min(curht, ht[i]);\n if (joinht > maxht) maxht = joinht; \n }\n writeln(maxht);\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\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int[100_000] arr, ht;\n int n;\n int curht = 0, maxht = 0;\n readf(\" %s\\n\", &n);\n foreach ( i ; 0 .. n ) {\n readf(\" %s\", &arr[i]);\n if (arr[i] > curht) {\n ++curht;\n if (curht > maxht) maxht = curht;\n }\n else curht = arr[i];\n ht[i] = curht;\n }\n curht = 0;\n foreach_reverse ( i ; 0 .. n ) {\n if (arr[i] > curht) {\n ++curht;\n if (curht > maxht) maxht = curht;\n }\n else curht = arr[i];\n int joinht = min(curht, ht[i]) * 2;\n if (joinht > maxht) maxht = joinht; \n }\n ++maxht;\n maxht /= 2;\n writeln(maxht);\n \n return 0;\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 h = readln.chomp.split.map!(to!int).array;\n \n auto d = new int[](n);\n d.fill(INF);\n \n void go(int[] h, int[] d) {\n int cur = 1;\n foreach (i, e; h) {\n cur = min(cur, e);\n d[i] = min(cur, d[i]);\n cur += 1;\n }\n }\n \n go(h, d);\n \n h.reverse();\n d.reverse();\n go(h, d);\n \n int ans = d.maxElement;\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 int n;\n readf(\"%s\", &n);\n readln;\n \n auto h = readln.chomp.split.map!(to!int).array;\n \n auto d = new int[](n);\n int cur = 1;\n foreach (i, e; h) {\n cur = min(cur, e);\n d[i] = cur;\n cur += 1;\n }\n \n cur = 1;\n foreach_reverse (i, e; h) {\n cur = min(cur, e);\n d[i] = min(d[i], cur);\n cur += 1;\n }\n \n int ans = d.maxElement;\n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.math;\nimport std.numeric;\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\tauto a = readln.split.map !(to !(int)).array;\n\t\tauto lo = new int [n];\n\t\tlo.front = 1;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tlo[i] = min (lo[i - 1] + 1, a[i]);\n\t\t}\n\n\t\tauto hi = new int [n];\n\t\thi.back = 1;\n\t\tforeach_reverse (i; 0..n - 1)\n\t\t{\n\t\t\thi[i] = min (hi[i + 1] + 1, a[i]);\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tres = max (res, min (lo[i], hi[i]));\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "a548737890b4bf322d0f8989e5cd25ac"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n struct P {\n int y, x;\n }\n\n auto xs = new int[](n), ys = new int[](n);\n bool[P] seen;\n foreach (i; 0 .. n) {\n rd(xs[i], ys[i]);\n if (i > 0) {\n seen[P(xs[i], ys[i])] = true;\n }\n }\n auto vy = new int[](n), vx = new int[](n);\n foreach (i; 0 .. n) {\n rd(vx[i], vy[i]);\n }\n foreach (i; 0 .. n) {\n auto tx = xs[0] + vx[i], ty = ys[0] + vy[i];\n foreach (j; 0 .. n) {\n if (i != j) {\n auto p = P(tx - vx[j], ty - vy[j]);\n if ((p in seen) == null || !seen[p]) {\n goto hell;\n }\n seen[p] = false;\n }\n }\n writeln(tx, \" \", ty);\n return;\n hell:\n // revert\n foreach (j; 1 .. n) {\n seen[P(xs[j], ys[j])] = true;\n }\n }\n import std.exception : enforce;\n\n enforce(false);\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\nalias Point = Tuple!(int, \"x\", int, \"y\");\n\nvoid main() {\n int n;\n scan(n);\n\n auto xys = new Point[](n);\n auto abs = new Point[](n);\n\n foreach (i ; 0 .. n) {\n int x, y;\n scan(x, y);\n xys[i] = Point(x, y);\n }\n\n foreach (i ; 0 .. n) {\n int a, b;\n scan(a, b);\n abs[i] = Point(a, b);\n }\n\n int[Point] cnt;\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. n) {\n int xx = xys[i].x + abs[j].x;\n int yy = xys[i].y + abs[j].y;\n\n cnt[Point(xx, yy)]++;\n\n if (cnt[Point(xx, yy)] == n) {\n writefln(\"%d %d\", xx, yy);\n return;\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}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto X = new long[](N);\n auto Y = new long[](N);\n auto A = new long[](N);\n auto B = new long[](N);\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!long);\n X[i] = s[0];\n Y[i] = s[1];\n }\n foreach (i; 0..N) {\n auto s = readln.split.map!(to!long);\n A[i] = s[0];\n B[i] = s[1];\n }\n\n long[long][long] mp;\n foreach (i; 0..N) {\n foreach (j; 0..N) {\n long x = X[i] + A[j];\n long y = Y[i] + B[j];\n mp[x][y] += 1;\n }\n }\n\n foreach (x; mp.keys) {\n foreach (y; mp[x].keys) {\n if (mp[x][y] == N) {\n writeln(x, \" \", y);\n return;\n }\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\tlong x = 0;\n\t\tlong y = 0;\n\t\tforeach (i; 0..n * 2)\n\t\t{\n\t\t\tint u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\tx += u;\n\t\t\ty += v;\n\t\t}\n\t\twriteln (x / n, \" \", y / n);\n\t}\n}\n"}], "negative_code": [], "src_uid": "ba526a7f29cf7f83afa0b71bcd06e86b"} {"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 k = next!long;\n auto d = next!int;\n // k ^ d >= n\n long pot = 1;\n bool possible = false;\n foreach(p; 0 .. d + 1)\n {\n if (pot >= n) {possible = true; break;}\n pot *= k;\n }\n if (!possible) return writeln(-1);\n auto res = new long[][](d, n);\n foreach(i; 0 .. d) res[i][0] = 0;\n foreach(j; 1 .. n)\n {\n long carry = 1;\n foreach(i; 0 .. d)\n\t{\n\t if (carry)\n\t {\n\t res[i][j] = res[i][j - 1] + carry;\n\t if (res[i][j] == k)\n\t\t{\n\t\t res[i][j] = 0;\n\t\t carry = 1;\n\t\t}\n\t else\n\t\t{\n\t\t carry = 0;\n\t\t}\n\t }\n\t else\n\t {\n\t res[i][j] = res[i][j - 1];\n\t }\n\t}\n assert(carry == 0);\n }\n foreach(row; res)\n {\n foreach(elem; row)\n\t{\n\t write(elem + 1, \" \");\n\t}\n 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", "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 std.conv;\nimport core.bitop;\n\nalias Int = int;\nimmutable Int N_MAX = pow(10, 3) + 11;\nimmutable Int D_MAX = pow(10, 3) + 11;\nimmutable Int K_MAX = pow(10, 9) + 11;\n\nInt T[D_MAX][N_MAX];\n\nmixin template Inputter() {\n Int N;\n Int K;\n Int D;\n\n bool input(T)(T s) {\n if ( readf(\" %s %s %s\", &N, &K, &D) ) {\n debug writefln(\"N = %s, K = %s, D = %s\", N, K, D);\n return true;\n }\n return false;\n }\n}\n\nmixin template Outputter() {\n bool ok;\n\n void output() {\n if ( ok ) {\n foreach ( i; 0 .. D ) {\n foreach ( j; 0 .. N ) {\n writef(\"%s \", T[i][j]);\n }\n writeln(\"\");\n }\n } else {\n writefln(\"-1\");\n }\n }\n}\n\nmixin template Solver() {\n void init() {\n }\n \n void solve() {\n foreach ( i; 0 .. D ) {\n T[i][0] = 1;\n }\n ok = find(1);\n }\n\n bool find( int c ) {\n debug writefln(\"@find: c = %s\", c);\n if ( c >= N ) return true;\n foreach ( i; 0 .. D ) {\n T[i][c] = T[i][c - 1];\n }\n if ( ! add(c, 0) ) return false;\n return find(c + 1);\n }\n\n bool add( int c, int r ) {\n if ( r >= D ) return false;\n debug writefln(\"@add: c = %s, r = %s\", c, r);\n if ( T[r][c] + 1 > K ) {\n T[r][c] = 1;\n return add(c, r + 1);\n }\n T[r][c] ++;\n return true;\n }\n}\n\n// Runner {{{\nmixin template Runner() {\n void run() {\n while ( input(stdin) ) {\n init();\n solve();\n output();\n }\n }\n}\n// }}}\n\n// Solution {{{\nstruct Solution {\n mixin Solver;\n mixin Inputter;\n mixin Outputter;\n mixin Runner;\n}\n// }}}\n\n// main() {{{\nSolution s;\nvoid main() {\n s.run();\n}\n// }}}\n"}], "negative_code": [], "src_uid": "4dddcf0ded11672a4958fb0d391dbaf5"} {"source_code": "import std.algorithm, std.range, std.stdio, std.string;\nvoid main () {\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0) {\n\t\twriteln (!!(k % n) * 2);\n\t\twritefln !(\"%(%(%d%)\\n%)\") (n.iota.map !(r =>\n\t\t n.iota.map !(c => ((r + c) % n * n + r < k))));\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, k;\n read(n), read(k);\n auto qperrow = new int[cast(size_t)n];\n foreach(i; 0 .. k % n)\n qperrow[i] = k / n + 1;\n foreach(i; k % n .. n)\n qperrow[i] = k / n;\n auto res = new int[][cast(size_t)n];\n foreach(ref row; res)\n {\n row = new int[cast(size_t)n];\n row[] = 0;\n }\n int cnt = 0;\n int rcnt = 0;\n int i = 0;\n int j = 0;\n while(cnt < k)\n {\n if (rcnt == qperrow[i])\n {\n i++;\n rcnt = 0;\n }\n res[cast(size_t)i][cast(size_t)j] = 1;\n j++; j %= n;\n rcnt++;\n cnt++;\n }\n if (k % n == 0)\n {\n writeln(0);\n }\n else\n {\n writeln(2);\n }\n foreach(row; res)\n {\n foreach(cell; row)\n write(cell);\n 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\tauto a = new char[][][](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\t\n\t\ta[ti] = new char[][](n, n);\n\t\tans[ti] = k % n == 0 ? 0 : 2;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t\ta[ti][i][j] = '0';\n\t\t}\n\n\t\t(){\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 (k == 0) return;\n\t\t\t\ta[ti][j][(i+j)%n] = '1';\n\t\t\t\t--k;\n\t\t\t}\n\t\t}}();\n\t}\n\n\tforeach (ti, e; ans)\n\t{\n\t\twriteln(e);\n\t\tforeach (ee; a[ti])\n\t\t\twriteln(ee);\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.algorithm, std.range, std.stdio;\nvoid main() {\n\treadln;\n\tint n, k;\n\twhile (readf!\" %s %s\"(n, k) > 0)\n\t\twritefln!\"%s\\n%(%(%d%)\\n%)\"(!!(k % n) * 2,\n\t\t\tn.iota.map!(r => n.iota.map!(c => ((r + c) % n * n + r < k))));\n}\n"}, {"source_code": "import std.algorithm, std.range, std.stdio;\nvoid main () {\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t\twritefln !(\"%s\\n%(%(%d%)\\n%)\") (!!(k % n) * 2,\n\t\t\tn.iota.map !(r => n.iota.map !(c => ((r + c) % n * n + r < k))));\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.range, std.stdio, std.string;\nvoid main () {\n\treadln;\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0) {\n\t\twritefln !(\"%(%(%d%)\\n%)\") (n.iota.map !(r =>\n\t\t n.iota.map !(c => ((r + c) % n * n + r < k))));\n\t}\n}\n"}], "src_uid": "0f18382d450be90edf1fd1a3770b232b"} {"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 S = readln.chomp.to!(char[]);\n int r, s;\n foreach (c; S) {\n if (c == '<') r = 0;\n else ++r;\n }\n foreach_reverse (c; S) {\n if (c == '>') s = 0;\n else ++s;\n }\n writeln(min(r, s));\n}\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n foreach (_; 0..N) solve();\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 solve() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n int ans = 1 << 29;\n foreach (i; 0..N) {\n if (S[i] == '>' || S[N - i - 1] == '<') {\n ans = i;\n break;\n }\n }\n ans.writeln;\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) solve;\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 solve()\n{\n auto n = readln.chomp.to!int;\n auto S = readln.chomp.to!(char[]);\n foreach (i, c; S) {\n if (c == '>') {\n writeln(min(i, n-i));\n return;\n }\n }\n writeln(\"0\");\n return;\n}\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n foreach (_; 0..N) solve();\n}"}], "src_uid": "0ba97bcfb5f539c848f2cd097b34ff33"} {"source_code": "import std.stdio;\nimport std.math;\n\n/// Template for power function. Returns a^n.\npure T pow(T)(const T a, uint n) {\n\tT res = 1;\n\tT x = a;\n\twhile (0 != n) {\n\t\tif (1 == n % 2) {\n\t\t\tres *= x;\n\t\t}\n\t\tx *= x;\n\t\tn /= 2;\n\t}\n\treturn res;\n}\n\nbool eq(const double a, const double b, const double EPS = 1E-7) {\n\treturn abs(a - b) <= EPS;\n}\n\nunittest {\n\tassert(243 == pow!int(3, 5));\n\tassert(1 == pow!uint(234, 0));\n\tassert(4 == pow!ulong(2, 2));\n\tassert(256 == pow!long(2, 8));\n\tassert(161051 == pow!ulong(11, 5));\n}\n\npure double solve(const uint m, const uint n) {\n\tdouble res = 0.0;\n\tforeach(i; 0 .. m) {\n\t\tres += (i + 1) * (pow!double(cast(double)(i + 1) / m, n) - pow!double(cast(double)i / m, n));\n\t}\n\treturn res;\n}\n\nunittest {\n\tassert(eq(3.5, solve(6, 1)));\n\tassert(eq(4.958333333333, solve(6, 3)));\n\tassert(eq(1.75, solve(2, 2)));\n}\n\nint main(string[] argv) {\n\tuint m = 0;\n\tuint n = 0;\n\treadf(\" %s %s\", &m, &n);\n\twritefln(\"%.7f\", solve(m, 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\tint m;\n\tint n;\n\twhile (readf (\" %s %s\", &m, &n) > 0)\n\t{\n\t\treal res = 0.0;\n\t\treal p = 1.0;\n\t\tfor (int i = m; i >= 1; i--)\n\t\t{\n\t\t\treal temp = (i - 1.0L) / i;\n\t\t\ttemp = 1.0L - pow (temp, n);\n\t\t\tres += temp * p * i;\n\t\t\tp *= 1.0L - temp;\n\t\t}\n\t\twritefln (\"%.20f\", res);\n\t}\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 M, N;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\treal ans = 0.0;\n\t\tforeach (x; 0 .. M) {\n\t\t\tans += 1.0 - (x / cast(real)(M)) ^^ N;\n\t\t}\n\t\twritefln(\"%.10f\", ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "f70ac2c4e0f62f9d6ad1e003aedd86b2"} {"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\nint[][] G;\nint[] sz;\n\nvoid 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\nvoid main() {\n try {\n for (; ; ) {\n N = 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 sz = new int[N];\n dfsSz(0, -1);\n \n int[] rs;\n for (int u = 0; ; ) {\n int vm = -1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (vm == -1 || sz[vm] < sz[v]) {\n vm = v;\n }\n }\n if (vm == -1 || sz[u] >= 2 * sz[vm]) {\n rs ~= u;\n if (sz[u] == 2 * sz[vm]) {\n rs ~= vm;\n }\n break;\n } else {\n sz[u] -= sz[vm];\n sz[vm] += sz[u];\n u = vm;\n }\n }\n debug {\n writeln(\"rs = \", rs);\n }\n \n int[][] ans;\n auto par = new int[N];\n foreach (r; rs) {\n foreach (j; G[r]) {\n const s = A[j] ^ B[j] ^ r;\n if (rs.count(s) == 0) {\n int[] us;\n void dfs(int u, int p) {\n us ~= u;\n par[u] = p;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n dfs(v, u);\n }\n }\n }\n dfs(s, r);\n debug {\n writeln(r, \" \", s, \" \", us);\n }\n int now = s;\n foreach (u; us) {\n if (par[u] != r) {\n ans ~= [r, now, u];\n now = u;\n ans ~= [u, par[u], s];\n }\n }\n ans ~= [r, now, s];\n }\n }\n }\n \n ans = ans.filter!(row => (row[1] != row[2])).array;\n \n writeln(ans.length);\n foreach (row; ans) {\n writeln(row[0] + 1, \" \", row[1] + 1, \" \", row[2] + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"C\"\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\nint main() {\n auto 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;\n g[b] ~= a;\n }\n bool[] isCent = new bool[n];\n int[] sz = new int[n];\n void dfs(int p, int b) {\n sz[p] = 1; isCent[p] = true;\n foreach (d; g[p]) {\n if (d == b) continue;\n dfs(d, p);\n sz[p] += sz[d];\n if (sz[d] > n/2) isCent[p] = false;\n }\n if (n - sz[p] > n/2) isCent[p] = false;\n }\n dfs(0, -1);\n\n// writeln(isCent);\n\n Appender!(int[]) ap;\n int[] par = new int[n];\n void sea(int p, int b) {\n par[p] = b;\n ap ~= p;\n foreach (d; g[p]) {\n if (d == b) continue;\n sea(d, p);\n }\n }\n int[3][] res;\n foreach (i; 0..n) {\n if (!isCent[i]) continue;\n foreach (j; g[i]) {\n if (isCent[j]) continue;\n// writeln(i, \" -> \", j);\n ap.clear();\n sea(j, i);\n int p = j;\n foreach (d; ap.data) {\n if (d == j) continue;\n res ~= [i, p, d]; p = d;\n res ~= [d, par[d], j];\n }\n res ~= [i, p, j];\n }\n }\n\n writeln(res.length);\n foreach (v; res) {\n writeln(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"}], "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[] A, B;\n\nint[][] G;\nint[][] 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 void dfs(int u, int p, int d) {\n //\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n dfs(v, u, d + 1);\n }\n }\n }\n foreach (i; G[r]) {\n const v = A[i] ^ B[i] ^ r;\n if (!del[v]) {\n dfs(v, r, 1);\n //\n }\n }\n //\n }\n\n long calc(int u) {\n long ret;\n void dfs(int u, int p, long d) {\n ret += d;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n dfs(v, u, d + 1);\n }\n }\n }\n dfs(u, -1, 0);\n debug {\n writeln(\"calc \", u, \" = \", ret);\n }\n return ret;\n }\n\n // void solveRec(int u) {\n int 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 /*\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 */\n ////\n int same = -1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (sz[u] - sz[v] == sz[v]) {\n same = v;\n }\n }\n }\n debug {\n writefln(\"u = %s, same = %s\", u, same);\n }\n del[u] = true;\n int ret = u;\n if (same != -1) {\n del[same] = true;\n const resU = calc(u);\n const resSame = calc(same);\n if (resU < resSame) {\n ret = same;\n }\n }\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (v != same) {\n const res = solveRec(v);\n if (v != res) {\n ans ~= [u, v, res];\n }\n }\n }\n }\n if (same != -1) {\n foreach (i; G[same]) {\n const v = A[i] ^ B[i] ^ same;\n if (!del[v]) {\n const res = solveRec(v);\n if (v != res) {\n ans ~= [same, v, res];\n }\n }\n }\n }\n return ret;\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 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 ans = [];\n solveCentroidDecomp;\n writeln(ans.length);\n foreach_reverse (op; ans) {\n writeln(op[0] + 1, \" \", op[1] + 1, \" \", op[2] + 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\nint N;\nint[] A, B;\n\nint[][] G;\nint[][] 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 void dfs(int u, int p, int d) {\n //\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n dfs(v, u, d + 1);\n }\n }\n }\n foreach (i; G[r]) {\n const v = A[i] ^ B[i] ^ r;\n if (!del[v]) {\n dfs(v, r, 1);\n //\n }\n }\n //\n }\n\n long calc(int u) {\n long ret;\n void dfs(int u, int p, long d) {\n ret += d;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n dfs(v, u, d + 1);\n }\n }\n }\n dfs(u, -1, 0);\n debug {\n writeln(\"calc \", u, \" = \", ret);\n }\n return ret;\n }\n\n // void solveRec(int u) {\n int 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 /*\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 */\n ////\n int same = -1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (sz[u] - sz[v] == sz[v]) {\n same = v;\n }\n }\n }\n debug {\n writefln(\"u = %s, same = %s\", u, same);\n }\n del[u] = true;\n int ret = u;\n if (same != -1) {\n del[same] = true;\n const resU = calc(u);\n const resSame = calc(same);\n if (resU < resSame) {\n ret = same;\n }\n }\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (v != same) {\n const res = solveRec(v);\n if (v != res) {\n ans ~= [u, v, res];\n }\n }\n }\n }\n if (same != -1) {\n foreach (i; G[same]) {\n const v = A[i] ^ B[i] ^ same;\n if (!del[v]) {\n const res = solveRec(v);\n if (v != res) {\n ans ~= [same, v, res];\n }\n }\n }\n }\n return ret;\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 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 ans = [];\n solveCentroidDecomp;\n writeln(ans.length);\n foreach (op; ans) {\n writeln(op[0] + 1, \" \", op[1] + 1, \" \", op[2] + 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\nint N;\nint[] A, B;\n\nint[][] G;\nint[][] 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 void dfs(int u, int p, int d) {\n //\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n dfs(v, u, d + 1);\n }\n }\n }\n foreach (i; G[r]) {\n const v = A[i] ^ B[i] ^ r;\n if (!del[v]) {\n dfs(v, r, 1);\n //\n }\n }\n //\n }\n\n // void solveRec(int u) {\n int 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 /*\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n solveRec(v);\n }\n }\n */\n ////\n int same = -1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (sz[u] - sz[v] == sz[v]) {\n same = v;\n }\n }\n }\n debug {\n writefln(\"u = %s, same = %s\", u, same);\n }\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (v != same) {\n const res = solveRec(v);\n if (v != res) {\n ans ~= [u, v, res];\n }\n }\n }\n }\n if (same != -1) {\n del[same] = true;\n foreach (i; G[same]) {\n const v = A[i] ^ B[i] ^ same;\n if (!del[v]) {\n const res = solveRec(v);\n if (v != res) {\n ans ~= [same, v, res];\n }\n }\n }\n }\n return u;\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 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 ans = [];\n solveCentroidDecomp;\n writeln(ans.length);\n foreach (op; ans) {\n writeln(op[0] + 1, \" \", op[1] + 1, \" \", op[2] + 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\nint N;\nint[] A, B;\n\nint[][] G;\nint[][] 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 void dfs(int u, int p, int d) {\n //\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n dfs(v, u, d + 1);\n }\n }\n }\n foreach (i; G[r]) {\n const v = A[i] ^ B[i] ^ r;\n if (!del[v]) {\n dfs(v, r, 1);\n //\n }\n }\n //\n }\n\n // void solveRec(int u) {\n int 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 const res = solveRec(v);\n if (sz[u] - sz[v] > sz[v] && v != res) {\n ans ~= [u, v, res];\n }\n }\n }\n // break;\n return u;\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 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 ans = [];\n solveCentroidDecomp;\n writeln(ans.length);\n foreach (op; ans) {\n writeln(op[0] + 1, \" \", op[1] + 1, \" \", op[2] + 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\nint N;\nint[] A, B;\n\nint[][] G;\nint[][] 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 void dfs(int u, int p, int d) {\n //\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v] && v != p) {\n dfs(v, u, d + 1);\n }\n }\n }\n foreach (i; G[r]) {\n const v = A[i] ^ B[i] ^ r;\n if (!del[v]) {\n dfs(v, r, 1);\n //\n }\n }\n //\n }\n\n // void solveRec(int u) {\n int 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 /*\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n solveRec(v);\n }\n }\n */\n ////\n int same = -1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (sz[u] - sz[v] == sz[v]) {\n same = v;\n }\n }\n }\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!del[v]) {\n if (v != same) {\n const res = solveRec(v);\n if (v != res) {\n ans ~= [u, v, res];\n }\n }\n }\n }\n if (same != -1) {\n foreach (i; G[same]) {\n const v = A[i] ^ B[i] ^ same;\n if (!del[v]) {\n const res = solveRec(v);\n if (v != res) {\n ans ~= [same, v, res];\n }\n }\n }\n }\n return u;\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 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 ans = [];\n solveCentroidDecomp;\n writeln(ans.length);\n foreach (op; ans) {\n writeln(op[0] + 1, \" \", op[1] + 1, \" \", op[2] + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "32fdea91454384b103f52743c1128cfc"} {"source_code": "module cf_43A;\n\nimport std.stdio;\n\nvoid main() {\n int n, maxGoals = 0;\n int[string] teamGoals;\n string teamName, winTeam;\n\n readf(\"%d\", &n);\n for (int i = 0; i < n; ++i) {\n readf(\" %s\\n\", &teamName);\n\n if (++teamGoals[teamName] > maxGoals) {\n winTeam = teamName;\n maxGoals = teamGoals[teamName];\n }\n }\n\n writeln(winTeam);\n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n int i;\n readf(\"%d\\n\", &i);\n string winner = \"\";\n int most = 0;\n int[string] m;\n // writeln(\"Entering loop\");\n for (int j = 0; j < i; ++j) {\n //writeln(\"Reading\");\n string t = readln();\n m[t] = m.get(t, 0) + 1;\n //writef(\"%s has %d\\n\", t, m[t]);\n if (m[t] > most) {\n most = m[t];\n winner = t;\n }\n }\n write(winner);\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.strip.to!int;\n string s,w;\n int[string] aa;\n int ans=0;\n while(n--){\n s=readln.strip;\n aa[s]++;\n if(aa[s]>ans){\n w=s;\n ans=aa[s];\n }\n }\n writeln(w);\n}\n\n"}], "negative_code": [], "src_uid": "e3dcb1cf2186bf7e67fd8da20c1242a9"} {"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 res = s.length.to !(int);\n\t\tint a = 0, b = 0;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == 'A')\n\t\t\t{\n\t\t\t\ta += 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tb += 1;\n\t\t\t\tif (a > 0 && b > 0)\n\t\t\t\t{\n\t\t\t\t\ta -= 1;\n\t\t\t\t\tb -= 1;\n\t\t\t\t\tres -= 2;\n\t\t\t\t}\n\t\t\t\telse if (b >= 2)\n\t\t\t\t{\n\t\t\t\t\tb -= 2;\n\t\t\t\t\tres -= 2;\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;\nimport std.string;\nimport std.array;\n\nvoid main() {\n\tint t;\n\treadf(\"%d\\n\", &t);\n\twhile(t--) {\n\t\tauto str = readln.strip;\n\t\tchar[] stack;\n\t\tstack.reserve(str.length);\n\t\tforeach(c; str) {\n\t\t\tstack ~= c;\n\t\t\tif(stack.length >= 2) {\n\t\t\t\tif((stack[$-2] == 'A' || stack[$-2] == 'B') && stack[$-1] == 'B') {\n\t\t\t\t\tstack.popBack();\n\t\t\t\t\tstack.popBack();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln(stack.length);\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 = 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\tint cnt, cnt_b;\n\t\tforeach_reverse (i; 0..s.length)\n\t\t{\n\t\t\tif (s[i] == 'B')\n\t\t\t\t++cnt_b;\n\t\t\telse if (cnt_b >= 1)\n\t\t\t{\n\t\t\t\t--cnt_b;\n\t\t\t\tcnt += 2;\n\t\t\t}\n\t\t}\n\t\tcnt += cnt_b - (cnt_b % 2);\n\t\tans[ti] = cast(int)s.length - cnt;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\t\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "ee295fd90ee9283709447481f172c73c"} {"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\tauto x = readln.split.map!(to!int);\n\tauto t = x[1] - 1;\n\tauto tp = readln.split.map!(to!int);\n\tint i;\n\twhile (i < tp.length) {\n\t\tif (i == t) break;\n\t\ti += tp[i];\n\t}\n\n\tif (i == t) writeln(\"YES\");\n\telse writeln(\"NO\");\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, T; scanf(\"%d %d\\n\", &N, &T);\n auto as = readln.chomp.split(\" \").map!(to!int).array;\n\n auto bs = new int[N];\n foreach (int i, a; as) {\n bs[i] = i + a;\n }\n\n bool dfs(int index) {\n if (index == T - 1) return true;\n if (bs[index] == 0) return false;\n return dfs(bs[index]);\n }\n\n writeln(dfs(0) ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string;\n\nvoid main(string[] args){\n\tint n, t;\n\treadf(\" %s %s\\n\", &n, &t);\n\t--t;\n\tint[] line = to!(int[])(readln.strip.split) ~ 0;\n\tint point = 0;\n\twhile(point < t)\n\t\tpoint += line[point];\n\n\twriteln(point == t ? \"YES\" : \"NO\");\n}"}, {"source_code": "import std.stdio;\n\nint[] a;\n\nvoid main() {\n\n\tint n, t;\n\n\tscanf(\"%d%d\", &n, &t);\n\t--t;\n\n\tint c;\n\tforeach (i; 0 .. n - 1) {\n\t\tscanf(\"%d\", &c);\n\t\ta ~= c;\n\t}\n\n\tint x = 0;\n\twhile (x < t)\n\t\tx += a[x];\n\n\tputs((x == t) ? \"YES\" : \"NO\");\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 nt = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto as = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n auto n = nt[0], t = nt[1]-1;\n int i=0;\n while(i=0.7.3\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n// import dcomp.twosat;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n int n, m;\n sc.read(n, m);\n auto sat = TwoSat(m);\n int[][] g = new int[][n];\n foreach (i; 0..n) {\n int k;\n sc.read(k);\n g[i] = new int[k];\n foreach (j; 0..k) {\n sc.read(g[i][j]);\n }\n g[i][] -= 1;\n }\n\n foreach (i; 0..n-1) {\n //g[i], g[i+1]\n int mi = min(g[i].length, g[i+1].length).to!int;\n bool dif = false;\n foreach (j; 0..mi) {\n int x = g[i][j];\n int y = g[i+1][j];\n if (x != y) {\n dif = true;\n if (x > y) {\n //only true, false\n sat.addCond(x, true, y, false);\n sat.addCond(x, false, y, false);\n sat.addCond(x, true, y, true);\n } else {\n //only ~(false, true)\n sat.addCond(x, true, y, false);\n }\n break;\n }\n }\n if (!dif) {\n if (g[i].length > g[i+1].length) {\n writeln(\"No\");\n return 0;\n }\n }\n }\n if (!sat.exec()) {\n writeln(\"No\");\n return 0;\n }\n auto res = sat.res.enumerate.filter!\"a[1]==true\".array;\n writeln(\"Yes\");\n writeln(res.length);\n writeln(res.map!\"a[0]+1\".map!(to!string).join(\" \"));\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/twosat.d */\n \n// module dcomp.twosat;\n\n// import dcomp.graph.scc;\n// import dcomp.array;\n\n \nstruct TwoSat {\n \n bool[] res;\n\n struct Edge {int to;}\n FastAppender!(Edge[])[] g;\n\n \n void addCond(int a, bool aExp, int b, bool bExp) {\n g[2*a+(aExp?0:1)] ~= Edge(2*b+(bExp?1:0));\n g[2*b+(bExp?0:1)] ~= Edge(2*a+(aExp?1:0));\n }\n\n \n bool exec() {\n import std.array : array;\n import std.algorithm : map;\n import std.conv : to;\n int n = res.length.to!int;\n auto sccInfo = scc(g.map!(v => v.data).array);\n for (int i = 0; i < n; i++) {\n if (sccInfo.id[2*i] == sccInfo.id[2*i+1]) return false;\n res[i] = sccInfo.id[2*i] < sccInfo.id[2*i+1];\n }\n return true;\n }\n \n this(int n) {\n res = new bool[n];\n g = new FastAppender!(Edge[])[](2*n);\n }\n}\n\n \n \n\n \n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/scc.d */\n// module dcomp.graph.scc;\n\n// import dcomp.array;\n// import dcomp.graph.primitive;\n// import dcomp.container.deque;\n\n \nstruct SCCInfo {\n int[] id; \n int[][] groups; \n \n int[] group(int i) {\n return groups[id[i]];\n } \n this(int n) {\n id = new int[n];\n }\n}\n\n \nSCCInfo scc(T)(T g) {\n import std.range;\n import std.algorithm : each, map, min, reverse;\n import std.conv : to;\n int n = g.length.to!int;\n auto sccInfo = SCCInfo(n);\n with (sccInfo) {\n bool[] inS = new bool[n];\n int[] low = new int[n], ord = new int[n]; ord[] = -1;\n int time = 0;\n Deque!int st;\n int bufC = 0;\n FastAppender!(int[]) buf; buf.reserve(n);\n FastAppender!(int[][]) gBuf;\n void dfs(int v) {\n low[v] = ord[v] = time++;\n st.insertBack(v);\n inS[v] = true;\n foreach (e; g[v]) {\n if (ord[e.to] == -1) {\n dfs(e.to);\n low[v] = min(low[v], low[e.to]);\n } else if (inS[e.to]) {\n low[v] = min(low[v], ord[e.to]);\n }\n }\n if (low[v] == ord[v]) {\n while (true) {\n int u = st.back; st.removeBack;\n buf ~= u;\n if (u == v) break;\n }\n auto gr = buf.data[bufC..$];\n bufC = buf.length.to!int;\n gr.each!(x => inS[x] = false);\n gBuf ~= gr;\n }\n }\n foreach (i; 0..n) {\n if (ord[i] == -1) dfs(i);\n }\n groups = gBuf.data;\n reverse(groups);\n groups.each!((i, v) => v.each!(x => id[x] = i.to!int));\n }\n return sccInfo;\n}\n\n \n \n\n \n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/deque.d */\n// module dcomp.container.deque;\n\nstruct DequePayload(T) {\n import core.exception : RangeError;\n import core.memory : GC;\n import std.range : ElementType, isInputRange;\n import std.traits : isImplicitlyConvertible;\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 ref inout(T) front() inout { return this[0]; }\n ref inout(T) back() inout { return this[$-1]; }\n Range opSlice() {return Range(&this, 0, length); }\n \n alias Range = RangeT!(DequePayload!T);\n alias ConstRange = RangeT!(const DequePayload!T);\n alias ImmutableRange = RangeT!(immutable DequePayload!T);\n\n static struct RangeT(A) {\n import std.traits : CopyTypeQualifiers;\n alias E = CopyTypeQualifiers!(A, T);\n A *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\n\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 alias Payload = DequePayload!T;\n alias Range = Payload.Range;\n alias ConstRange = Payload.ConstRange;\n alias ImmutableRange = Payload.ImmutableRange;\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 \n @property bool empty() const { return (!havePayload || p.empty); }\n \n @property size_t length() const { return (havePayload ? p.length : 0); }\n \n alias opDollar = length;\n ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }\n \n ref inout(T) front() inout {C; return (*p)[0]; }\n \n ref inout(T) back() inout {C; return (*p)[$-1]; }\n void clear() { if (p) p.clear(); }\n \n void insertFront(T v) {I; p.insertFront(v); }\n \n void insertBack(T v) {I; p.insertBack(v); }\n \n alias stableInsertBack = insertBack;\n \n void removeFront() {C; p.removeFront(); }\n \n void removeBack() {C; p.removeBack(); }\n \n Range opSlice() {I; return Range(p, 0, length); }\n}\n\n \n \n\n \n\n \n\n \n\n \n\n \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/graph/primitive.d */\n// module dcomp.graph.primitive;\n\n \n\nimport std.range : ElementType;\nalias EdgeType(R) = ElementType!(ElementType!R);\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/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", "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\nTuple!(int, int[]) scc(in int[][][] graph) {\n const n = cast(int)(graph[0].length);\n int compN;\n auto compIds = new int[n];\n int[] us;\n void dfs(int s, int u, int a, int b) {\n if (compIds[u] == a) {\n compIds[u] = b;\n foreach (v; graph[s][u]) {\n dfs(s, v, a, b);\n }\n if (s == 0) {\n us ~= u;\n }\n }\n }\n foreach (u; 0 .. n) {\n dfs(0, u, 0, -1);\n }\n foreach_reverse (u; us) {\n if (compIds[u] == -1) {\n dfs(1, u, -1, compN);\n ++compN;\n }\n }\n return tuple(compN, compIds);\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const M = 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 (j; 0 .. L[i]) {\n S[i][j] = readInt() - 1;\n }\n }\n \n bool ans = true;\n auto graph = new int[][][](2, M << 1);\n void addEdge(int x, int y) {\n graph[0][x] ~= y;\n graph[1][y] ~= x;\n }\n \n foreach (i; 0 .. N - 1) {\n for (int j = 0; ; ++j) {\n if (j == L[i]) {\n break;\n } else if (j == L[i + 1]) {\n ans = false;\n break;\n } else {\n const u = S[i][j], v = S[i + 1][j];\n if (u < v) {\n // CAP(u) || NOCAP(v)\n addEdge(u << 1 | 0, v << 1 | 0);\n addEdge(v << 1 | 1, u << 1 | 1);\n break;\n } else if (u > v) {\n // CAP(u) && NOCAP(v)\n addEdge(u << 1 | 0, u << 1 | 1);\n addEdge(v << 1 | 1, v << 1 | 0);\n break;\n }\n }\n }\n }\n auto res = scc(graph);\n foreach (u; 0 .. M) {\n ans = ans && (res[1][u << 1 | 0] != res[1][u << 1 | 1]);\n }\n if (ans) {\n int[] us;\n foreach (u; 0 .. M) {\n if (res[1][u << 1 | 0] < res[1][u << 1 | 1]) {\n us ~= u;\n }\n }\n writeln(\"Yes\");\n writeln(us.length);\n foreach (index, u; us) {\n if (index > 0) write(\" \");\n write(u + 1);\n }\n writeln;\n } else {\n writeln(\"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "c3fe773066f6c2d5eba74b6b2b8751ef"} {"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 X = new int[][](10, 2);\n foreach (i; 0..10) X[i][0] = 0;\n foreach (i; 0..10) X[i][1] = 1;\n\n foreach (i; 0..N) {\n auto s = readln.split;\n auto op = s[0];\n auto n = s[1].to!int;\n foreach (j; 0..10) {\n bool b = (n & (1 << j)) != 0;\n if (op[0] == '|') {\n X[j][0] |= b;\n X[j][1] |= b;\n } else if (op[0] == '&') {\n X[j][0] &= b;\n X[j][1] &= b;\n } else {\n X[j][0] ^= b;\n X[j][1] ^= b;\n }\n }\n }\n\n\n int opor = 0;\n int opand = 0;\n int opxor = 0;\n\n foreach (i; 0..10) {\n if (X[i][0] == 0 && X[i][1] == 0) {\n\n } else if (X[i][0] == 0 && X[i][1] == 1) {\n opand |= (1 << i);\n } else if (X[i][0] == 1 && X[i][1] == 0) {\n opand |= (1 << i);\n opxor |= (1 << i);\n } else {\n opor |= (1 << i);\n opand |= (1 << i);\n }\n }\n\n writeln(3);\n writeln(\"| \", opor);\n writeln(\"& \", opand);\n writeln(\"^ \", opxor);\n}\n", "positive_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 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\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 Action { none, flip, set, unset }\n\nvoid main() {\n int n;\n while (read(n)) {\n Action[10] bits;\n while (n--) {\n char c;\n int x;\n read(c, x);\n final switch (c) {\n case '&': {\n foreach (i; 0 .. 10) {\n if (!(x & 0x1))\n bits[i] = Action.unset;\n x >>= 1;\n }\n break;\n }\n case '|': {\n foreach (i; 0 .. 10) {\n if (x & 0x1)\n bits[i] = Action.set;\n x >>= 1;\n }\n break;\n }\n case '^': {\n foreach (i; 0 .. 10) {\n if (x & 0x1)\n bits[i] ^= 0x1;\n x >>= 1;\n }\n break;\n }\n }\n }\n\n auto accumulate(Action action)() {\n return iota(10).filter!(i => bits[i] == action).fold!`a | 1 << b`(0x0);\n }\n\n write(\"3\\n& \", accumulate!(Action.unset) ^ 0x3FF);\n write(\"\\n| \", accumulate!(Action.set));\n writeln(\"\\n^ \", accumulate!(Action.flip));\n debug writeln();\n }\n\n stdout.flush();\n _Exit(0);\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 = 10;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto A = new string[N];\n auto X = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readToken();\n X[i] = readInt();\n }\n \n int[] ans = [(1 << E) - 1, 0, 0];\n foreach (e; 0 .. E) {\n auto ts = new int[2];\n foreach (s; 0 .. 2) {\n int z = s << e;\n foreach (i; 0 .. N) {\n switch (A[i]) {\n case \"&\": z &= X[i]; break;\n case \"|\": z |= X[i]; break;\n case \"^\": z ^= X[i]; break;\n default: assert(false);\n }\n }\n ts[s] = (z >> e) & 1;\n }\n debug {\n writeln(e, \": \", ts);\n }\n switch (ts[0] << 0 | ts[1] << 1) {\n case 0: ans[0] ^= 1 << e; break;\n case 1: ans[2] ^= 1 << e; break;\n case 2: break;\n case 3: ans[1] ^= 1 << e; break;\n default: assert(false);\n }\n }\n writeln(3);\n writefln(\"& %s\", ans[0]);\n writefln(\"| %s\", ans[1]);\n writefln(\"^ %s\", ans[2]);\n \n debug {\n foreach (z; 0 .. 1 << E) {\n int expected = z;\n foreach (i; 0 .. N) {\n switch (A[i]) {\n case \"&\": expected &= X[i]; break;\n case \"|\": expected |= X[i]; break;\n case \"^\": expected ^= X[i]; break;\n default: assert(false);\n }\n }\n int actual = z;\n actual &= ans[0];\n actual |= ans[1];\n actual ^= ans[2];\n assert(expected == actual);\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "19c32b8c1d3db5ab10aca271135aa9b8"} {"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\tauto q = RD!int;\r\n\tauto a = RDA;\r\n\r\n\tlong cnt = a.sum;\r\n\tlong[] ans;\r\n\tforeach (i; 0..q)\r\n\t{\r\n\t\tauto t = RD!int;\r\n\t\tif (t == 1)\r\n\t\t{\r\n\t\t\tauto x = RD!int-1;\r\n\t\t\tif(a[x] == 1)\r\n\t\t\t{\r\n\t\t\t\t--cnt;\r\n\t\t\t\ta[x] = 0;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t++cnt;\r\n\t\t\t\ta[x] = 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tauto k = RD!int;\r\n\t\t\tif (k <= cnt)\r\n\t\t\t\tans ~= 1;\r\n\t\t\telse\r\n\t\t\t\tans ~= 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.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 a = readln.splitter.map !(to !(int)).array;\r\n\t\tauto s = sum (a);\r\n\t\tforeach (r; 0..q)\r\n\t\t{\r\n\t\t\tint t, z;\r\n\t\t\treadf !(\" %s %s\") (t, z);\r\n\t\t\tif (t == 1)\r\n\t\t\t{\r\n\t\t\t\tauto x = z - 1;\r\n\t\t\t\ts -= (a[x] == 1);\r\n\t\t\t\ta[x] ^= 1;\r\n\t\t\t\ts += (a[x] == 1);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tauto k = z;\r\n\t\t\t\twriteln (to !(int) (k <= s));\r\n\t\t\t}\r\n\t\t}\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 N = readInt();\r\n const Q = 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 as = A.dup;\r\n int now = cast(int)(as.count(1));\r\n \r\n foreach (q; 0 .. Q) {\r\n const typ = readInt();\r\n if (typ == 1) {\r\n const x = readInt() - 1;\r\n if (as[x] == 1) --now;\r\n as[x] = 1 - as[x];\r\n if (as[x] == 1) ++now;\r\n } else {\r\n const k = readInt();\r\n writeln((now >= k) ? 1 : 0);\r\n }\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "ccf7aba6ca9bbf39a5ec8a20ec018825"} {"source_code": "import std.stdio;\nint or(int a, int b)\n{\n\tif (a==1 || b==1)\n\t{\n\t\treturn 1;\n\t}\n\telse\n\t{\n\t\treturn 0;\n\t}\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\tint[] n = new int[2*b];\n\tint[] m = new int[b];\n\tfor (int i=0; i= l; i--) {\r\n if (abs(A[i]) == 2) rrt++;\r\n if (A[i] < 0) {\r\n ri = i;\r\n break;\r\n }\r\n }\r\n if (lrt > rrt) {\r\n // remove right\r\n int tnt = nt - rrt;\r\n if (max_nt < tnt) {\r\n max_nt = tnt;\r\n ans = [l, ri];\r\n }\r\n } else {\r\n // remove left\r\n int tnt = nt - lrt;\r\n if (max_nt < tnt) {\r\n max_nt = tnt;\r\n ans = [li, r];\r\n }\r\n }\r\n }\r\n }\r\n auto removed = [ ans[0], N - ans[1] ];\r\n writefln(\"%(%s %)\", removed);\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": "7f71bea1c62b0a027c8d55431fbc7db7"} {"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 long ans = 0L;\n while (n--) {\n int t, T, x, cost;\n readf(\"%s %s %s %s\", &t, &T, &x, &cost);\n readln;\n \n int capacity = T - t;\n \n if (m <= capacity) {\n ans += cost;\n continue;\n }\n \n if (capacity <= 0) {\n ans += cost + m.to!long * x;\n continue;\n }\n \n auto cur1 = (m + capacity - 1).to!long / capacity * cost;\n auto cur2 = m % capacity == 0 ? 10L ^^ 18 :\n m.to!long / capacity * cost + (capacity + m % capacity).to!long * x;\n auto cur3 = cost + m.to!long * x;\n \n auto cur = min(cur1, min(cur2, cur3));\n \n debug { cur.writeln; }\n \n ans += cur;\n }\n \n ans.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.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 long ans = 0L;\n while (n--) {\n int t, T, x, cost;\n readf(\"%s %s %s %s\", &t, &T, &x, &cost);\n readln;\n \n int capacity = T - t;\n \n if (m <= capacity) {\n ans += cost;\n continue;\n }\n \n if (capacity <= 0) {\n ans += cost + m.to!long * x;\n continue;\n }\n \n auto cur1 = (m + capacity - 1).to!long / capacity * cost;\n auto cur2 = cost + m.to!long * x;\n \n auto cur = min(cur1, cur2);\n \n debug { cur.writeln; }\n \n ans += cur;\n }\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.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 long ans = 0L;\n while (n--) {\n int t, T, x, cost;\n readf(\"%s %s %s %s\", &t, &T, &x, &cost);\n readln;\n \n int capacity = T - t;\n \n if (capacity >= m) {\n ans += cost;\n continue;\n }\n \n if (capacity <= 0) {\n ans += cost + m.to!long * x;\n continue;\n }\n \n auto cur1 = (m + capacity - 1).to!long / capacity * cost;\n auto cur2 = m % capacity == 0 ? 10 ^^ 9 :\n max(m.to!long / capacity, 1L) * cost + (capacity + m % capacity).to!long * x;\n auto cur3 = cost + m.to!long * x;\n \n auto cur = min(cur1, min(cur2, cur3));\n \n debug { cur.writeln; }\n \n ans += cur;\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\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto ans = 0L;\n while (n--) {\n int t, T, x, cost;\n readf(\"%s %s %s %s\", &t, &T, &x, &cost);\n readln;\n \n int capacity = T - t;\n \n if (capacity >= m) {\n ans += cost;\n continue;\n }\n \n if (capacity <= 0) {\n ans += cost + m.to!long * x;\n continue;\n }\n \n auto cur1 = (m + capacity - 1).to!long / capacity * cost;\n auto cur2 = m % capacity == 0 ? 10 ^^ 9 :\n m.to!long / capacity * cost + (capacity + m % capacity).to!long * x;\n auto cur3 = cost + m.to!long * x;\n \n auto cur = min(cur1, min(cur2, cur3));\n \n debug { cur.writeln; }\n \n ans += cur;\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\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto ans = 0L;\n while (n--) {\n int t, T, x, cost;\n readf(\"%s %s %s %s\", &t, &T, &x, &cost);\n readln;\n \n int capacity = T - t;\n \n if (capacity >= m) {\n ans += cost;\n continue;\n }\n \n if (capacity <= 0) {\n ans += cost + m.to!long * x;\n continue;\n }\n \n auto cur1 = (m + capacity - 1).to!long / capacity * cost;\n auto cur2 = m % capacity == 0 ? 10 ^^ 9 :\n max(m.to!long / capacity, 1) * cost + (capacity + m % capacity).to!long * x;\n auto cur3 = cost + m.to!long * x;\n \n auto cur = min(cur1, min(cur2, cur3));\n \n debug { cur.writeln; }\n \n ans += cur;\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\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto ans = 0L;\n while (n--) {\n int t, T, x, cost;\n readf(\"%s %s %s %s\", &t, &T, &x, &cost);\n readln;\n \n int capacity = T - t;\n \n if (capacity >= m) {\n ans += cost;\n continue;\n }\n \n if (capacity <= 0) {\n ans += cost + m.to!long * x;\n continue;\n }\n \n auto cur1 = (m + capacity - 1).to!long / capacity * cost;\n auto cur2 = m % capacity == 0 ? 10 ^^ 9 :\n m.to!long / capacity * cost + (capacity + m % capacity) * x;\n auto cur3 = cost + m.to!long * x;\n \n auto cur = min(cur1, min(cur2, cur3));\n \n debug { cur.writeln; }\n \n ans += cur;\n }\n \n ans.writeln;\n}"}], "src_uid": "96a3f9d559a40050095de2f5f70b147f"} {"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 == 'L'}).array;\r\n\t\tauto fwd = new int [] [] (2, n);\r\n\r\n\t\tauto go ()\r\n\t\t{\r\n\t\t\tauto res = new int [] [] (2, n + 1);\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tforeach (d; 0..2)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (d ^ s[i])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tres[d][i + 1] = res[!d][i] + 1;\r\n\t\t\t\t\t}\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 lo = go ();\r\n\t\treverse (s);\r\n\t\ts[] ^= 1;\r\n\t\tauto hi = go ();\r\n\t\tforeach (ref line; hi)\r\n\t\t{\r\n\t\t\treverse (line);\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\")\r\n\t\t (iota (n + 1).map !(i => lo[0][i] + hi[0][i] + 1));\r\n\t}\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 n = readln.chomp.to!int;\r\n auto v = readln.chomp.array;\r\n \r\n void go(dchar[] v, int[dchar][] arr) {\r\n arr[0]['L'] = 0;\r\n arr[0]['R'] = 0;\r\n foreach (i, e; v.enumerate(1)) {\r\n auto calc = (dchar now, dchar other) =>\r\n e == now ? 1 + arr[i-1][other] : 0;\r\n \r\n arr[i]['L'] = calc('L', 'R');\r\n arr[i]['R'] = calc('R', 'L');\r\n }\r\n }\r\n \r\n auto pref = new int[dchar][] (n+1);\r\n go(v, pref);\r\n \r\n auto suf = new int[dchar][] (n+1);\r\n go(v.retro().array, suf);\r\n suf.reverse();\r\n \r\n debug { pref.writeln; suf.writeln; }\r\n \r\n auto ans = (n+1).iota.map!(x => 1 + pref[x]['L'] + suf[x]['R']);\r\n \r\n ans.map!(to!string).join(\" \").writeln();\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 char[] ds; get(ds);\r\n auto ls = new int[][](N + 1, 2);\r\n auto rs = new int[][](N + 1, 2);\r\n foreach (i; 0..N) {\r\n if (ds[i] == 'L') ls[i+1][0] = ls[i][1] + 1;\r\n if (ds[i] == 'R') ls[i+1][1] = ls[i][0] + 1;\r\n }\r\n foreach_reverse (i; 0..N) {\r\n if (ds[i] == 'R') rs[i][0] = rs[i+1][1] + 1;\r\n if (ds[i] == 'L') rs[i][1] = rs[i+1][0] + 1;\r\n }\r\n writefln!\"%(%d %)\"(0.iota(N + 1).map!(i => ls[i][0] + rs[i][0] + 1));\r\n }\r\n}"}], "negative_code": [], "src_uid": "f51a46e87b8871c3f581786f84e5e6d1"} {"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 int[] a; readA(n, a);\n\n auto mp = 1_500_000;\n auto p = primes(mp);\n\n auto f = new int[][](mp);\n foreach (i; 2..mp) {\n auto m = i;\n while (m > 1) {\n auto fi = factor(m, p);\n if (f[i].empty || f[i][$-1] != fi) f[i] ~= fi;\n m /= fi;\n }\n }\n\n auto b = new int[](n), v = new bool[](mp), mi = -1;\n foreach (i; 0..n) {\n for (auto c = mi == -1 ? a[i] : mi;; ++c) {\n if (f[c].any!(fi => v[fi])) continue;\n b[i] = c;\n foreach (fi; f[c]) v[fi] = true;\n if (mi == -1 && c > a[i])\n mi = 2;\n else if (mi > 1)\n mi = c;\n break;\n }\n }\n\n foreach (i; 0..n) {\n write(b[i]);\n if (i < n-1) write(\" \");\n }\n writeln;\n}\n\npure T[] primes(T)(T n)\n{\n import std.algorithm, std.bitmanip, std.conv, std.range;\n\n auto sieve = BitArray();\n sieve.length((n+1)/2);\n sieve = ~sieve;\n\n foreach (p; 1..((nsqrt(n)-1)/2+1))\n if (sieve[p])\n for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)\n sieve[q] = false;\n\n auto r = sieve.bitsSet.map!(to!T).map!(\"a*2+1\").array;\n r[0] = 2;\n\n return r;\n}\n\npure T factor(T)(T n, const T[] p)\n{\n auto ma = nsqrt(n)+1;\n foreach (pi; p)\n if (pi > ma) return n;\n else if (n%pi == 0) return pi;\n return n;\n}\n\npure T nsqrt(T)(T n)\n{\n import std.algorithm, std.conv, std.range, core.bitop;\n if (n <= 1) return n;\n T m = 1 << (n.bsr/2+1);\n return iota(1, m).map!\"a*a\".assumeSorted!\"a <= b\".lowerBound(n).length.to!T;\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\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 2000000; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tif (v * v > i) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!yes) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tbool[int] done;\n\t\n\tint m = 0;\n\tforeach (i, v; a) {\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tint w = v;\n\t\tfor (;;) {\n\t\t\tbool dame = false;\n\t\t\tint z = w;\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p > z) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdame |= z % p == 0 && p in done;\n\t\t\t\tif (z % p == 0) {\n\t\t\t\t\tz /= p;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!dame) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++w;\n\t\t}\n\t\tint z = w;\n\t\tforeach (p; primes) {\n\t\t\tif (p > z) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (z % p == 0) {\n\t\t\t\tz /= p;\n\t\t\t\tdone[p] = true;\n\t\t\t}\n\t\t}\n\t\tdone[w] = true;\n\t\tw.write;\n\t\tif (w > v)\n\t\t\tbreak;\n\t}\n\tforeach (p; primes) {\n\t\tif (m >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tp.write;\n\t}\n\twriteln;\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{\n\tint n = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 1000000; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tif (v * v > i) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!yes) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tbool[int] done;\n\t\n\tint m = 0;\n\tforeach (i, v; a) {\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tint w = v;\n\t\tfor (;;) {\n\t\t\tbool dame = false;\n\t\t\tint z = w;\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p > z) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdame |= z % p == 0 && p in done;\n\t\t\t\tif (z % p == 0) {\n\t\t\t\t\tz /= p;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!dame) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++w;\n\t\t}\n\t\tint z = w;\n\t\tforeach (p; primes) {\n\t\t\tif (p > z) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (z % p == 0) {\n\t\t\t\tz /= p;\n\t\t\t\tdone[p] = true;\n\t\t\t}\n\t\t}\n\t\tdone[w] = true;\n\t\tw.write;\n\t\tif (w > v)\n\t\t\tbreak;\n\t}\n\tforeach (p; primes) {\n\t\tif (m >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tp.write;\n\t}\n\twriteln;\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 = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 200000; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tbool[int] done;\n\t\n\tint m = 0;\n\tforeach (i, v; a) {\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tint w = v;\n\t\tfor (;;) {\n\t\t\tbool dame = false;\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p > w) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdame |= w % p == 0 && p in done;\n\t\t\t}\n\t\t\tif (!dame) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++w;\n\t\t}\n\t\tforeach (p; primes) {\n\t\t\tif (p > w) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (w % p == 0) {\n\t\t\t\tdone[p] = true;\n\t\t\t}\n\t\t}\n\t\tdone[w] = true;\n\t\tw.write;\n\t\tif (w > v)\n\t\t\tbreak;\n\t}\n\tforeach (p; primes) {\n\t\tif (m >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tp.write;\n\t}\n\twriteln;\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\tint n = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 100100; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tint[] ans;\n\tbool[int] done;\n\t\n\tforeach (i, v; a) {\n\t\tif (pr.contains(v)) {\n\t\t\tans ~= v;\n\t\t\tdone[v] = true;\n\t\t} else {\n\t\t\tint w = v;\n\t\t\tfor (;;) {\n\t\t\t\tbool dame = false;\n\t\t\t\tforeach (p; primes) {\n\t\t\t\t\tif (p > w) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdame |= w % p == 0 && p in done;\n\t\t\t\t}\n\t\t\t\tif (!dame) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t++w;\n\t\t\t}\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p * p > w) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (w % p == 0) {\n\t\t\t\t\tdone[p] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans ~= w;\n\t\t\tif (w > v)\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tforeach (p; primes) {\n\t\tif (ans.length >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tans ~= p;\n\t}\n\twritefln(\"%(%d %)\", ans);\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 = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 300000; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tif (!yes) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tbool[int] done;\n\t\n\tint m = 0;\n\tforeach (i, v; a) {\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tint w = v;\n\t\tfor (;;) {\n\t\t\tbool dame = false;\n\t\t\tint z = w;\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p > z) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdame |= z % p == 0 && p in done;\n\t\t\t\tif (z % p == 0) {\n\t\t\t\t\tz /= p;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!dame) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++w;\n\t\t}\n\t\tint z = w;\n\t\tforeach (p; primes) {\n\t\t\tif (p > z) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (z % p == 0) {\n\t\t\t\tz /= p;\n\t\t\t\tdone[p] = true;\n\t\t\t}\n\t\t}\n\t\tdone[w] = true;\n\t\tw.write;\n\t\tif (w > v)\n\t\t\tbreak;\n\t}\n\tforeach (p; primes) {\n\t\tif (m >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tp.write;\n\t}\n\twriteln;\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\tint n = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 200000; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tint[] ans;\n\tbool[int] done;\n\t\n\tforeach (i, v; a) {\n\t\tint w = v;\n\t\tfor (;;) {\n\t\t\tbool dame = false;\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p > w) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdame |= w % p == 0 && p in done;\n\t\t\t}\n\t\t\tif (!dame) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++w;\n\t\t}\n\t\tforeach (p; primes) {\n\t\t\tif (p > w) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (w % p == 0) {\n\t\t\t\tdone[p] = true;\n\t\t\t}\n\t\t}\n\t\tans ~= w;\n\t\tdone[w] = true;\n\t\tif (w > v)\n\t\t\tbreak;\n\t}\n\tforeach (p; primes) {\n\t\tif (ans.length >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tans ~= p;\n\t}\n\twritefln(\"%(%d %)\", ans);\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 = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 200000; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tif (!yes) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tbool[int] done;\n\t\n\tint m = 0;\n\tforeach (i, v; a) {\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tint w = v;\n\t\tfor (;;) {\n\t\t\tbool dame = false;\n\t\t\tint z = w;\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p > w) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdame |= z % p == 0 && p in done;\n\t\t\t\tif (z % p == 0) {\n\t\t\t\t\tz /= p;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!dame) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++w;\n\t\t}\n\t\tint z = w;\n\t\tforeach (p; primes) {\n\t\t\tif (p > z) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (z % p == 0) {\n\t\t\t\tz /= p;\n\t\t\t\tdone[p] = true;\n\t\t\t}\n\t\t}\n\t\tdone[w] = true;\n\t\tw.write;\n\t\tif (w > v)\n\t\t\tbreak;\n\t}\n\tforeach (p; primes) {\n\t\tif (m >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (m) write = \" \";\n\t\t++m;\n\t\tp.write;\n\t}\n\twriteln;\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\tint n = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 100100; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tint[] ans;\n\tbool[int] done;\n\t\n\tforeach (i, v; a) {\n\t\tif (pr.contains(v)) {\n\t\t\tans ~= v;\n\t\t\tdone[v] = true;\n\t\t} else {\n\t\t\tint w = v;\n\t\t\tfor (;;) {\n\t\t\t\tbool dame = false;\n\t\t\t\tforeach (p; primes) {\n\t\t\t\t\tif (p > w) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tdame |= w % p == 0 && p in done;\n\t\t\t\t}\n\t\t\t\tif (!dame) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t++w;\n\t\t\t}\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p * p > w) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (w % p == 0) {\n\t\t\t\t\tdone[p] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans ~= w;\n\t\t\tdone[w] = true;\n\t\t\tif (w > v)\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tforeach (p; primes) {\n\t\tif (ans.length >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tans ~= p;\n\t}\n\twritefln(\"%(%d %)\", ans);\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\tint n = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 100100; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tint[] ans;\n\tbool[int] done;\n\t\n\tforeach (i, v; a) {\n\t\tint w = v;\n\t\tfor (;;) {\n\t\t\tbool dame = false;\n\t\t\tforeach (p; primes) {\n\t\t\t\tif (p > w) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdame |= w % p == 0 && p in done;\n\t\t\t}\n\t\t\tif (!dame) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++w;\n\t\t}\n\t\tforeach (p; primes) {\n\t\t\tif (p > w) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (w % p == 0) {\n\t\t\t\tdone[p] = true;\n\t\t\t}\n\t\t}\n\t\tans ~= w;\n\t\tdone[w] = true;\n\t\tif (w > v)\n\t\t\tbreak;\n\t}\n\tforeach (p; primes) {\n\t\tif (ans.length >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tans ~= p;\n\t}\n\twritefln(\"%(%d %)\", ans);\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\tint n = readln.chomp.to!int;\n\tint[] a = readln.chomp.split.map!(to!int).array;\n\tint[] primes = [2];\n\tfor (int i = 3; i <= 100100; i += 2) {\n\t\tbool yes = true;\n\t\tforeach (v; primes) {\n\t\t\tyes &= i % v != 0;\n\t\t}\n\t\tif (yes) {\n\t\t\tprimes ~= i;\n\t\t}\n\t}\n\tauto pr = assumeSorted(primes);\n\tint m = 0;\n\tint index = 0;\n\tint[] ans;\n\tbool[int] done;\n\tforeach (i, v; a) {\n\t\tif (pr.contains(v)) {\n\t\t\tans ~= v;\n\t\t\tdone[v] = true;\n\t\t} else {\n\t\t\tint ite = v;\n\t\t\tfor (;;) {\n\t\t\t\tauto ret = pr.upperBound(ite);\n\t\t\t\tite = ret.front;\n\t\t\t\tif (ite !in done) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans ~= ite;\n\t\t\tdone[ite] = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tforeach (p; primes) {\n\t\tif (ans.length >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tif (p in done) {\n\t\t\tcontinue;\n\t\t}\n\t\tans ~= p;\n\t}\n\twritefln(\"%(%d %)\", ans);\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; readV(n);\n int[] a; readA(n, a);\n\n auto mp = 1_500_000;\n auto p = primes(mp);\n\n auto f = new int[][](mp);\n foreach (i; 2..mp) {\n auto m = i;\n while (m > 1) {\n auto fi = factor(m, p);\n if (f[i].empty || f[i][$-1] != fi) f[i] ~= fi;\n m /= fi;\n }\n }\n\n auto b = new int[](n), v = new bool[](mp), mi = -1;\n foreach (i; 0..n) {\n for (auto c = mi == -1 ? a[i] : b[i-1];; ++c) {\n if (f[c].any!(fi => v[fi])) continue;\n b[i] = c;\n foreach (fi; f[c]) v[fi] = true;\n if (mi == -1 && c > a[i])\n mi = 2;\n else if (mi > 1)\n mi = c;\n break;\n }\n }\n\n foreach (i; 0..n) {\n write(b[i]);\n if (i < n-1) write(\" \");\n }\n writeln;\n}\n\npure T[] primes(T)(T n)\n{\n import std.algorithm, std.bitmanip, std.conv, std.range;\n\n auto sieve = BitArray();\n sieve.length((n+1)/2);\n sieve = ~sieve;\n\n foreach (p; 1..((nsqrt(n)-1)/2+1))\n if (sieve[p])\n for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)\n sieve[q] = false;\n\n auto r = sieve.bitsSet.map!(to!T).map!(\"a*2+1\").array;\n r[0] = 2;\n\n return r;\n}\n\npure T factor(T)(T n, const T[] p)\n{\n auto ma = nsqrt(n)+1;\n foreach (pi; p)\n if (pi > ma) return n;\n else if (n%pi == 0) return pi;\n return n;\n}\n\npure T nsqrt(T)(T n)\n{\n import std.algorithm, std.conv, std.range, core.bitop;\n if (n <= 1) return n;\n T m = 1 << (n.bsr/2+1);\n return iota(1, m).map!\"a*a\".assumeSorted!\"a <= b\".lowerBound(n).length.to!T;\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; readV(n);\n int[] a; readA(n, a);\n\n auto mp = 200_000;\n auto p = primes(mp);\n\n auto f = new int[][](mp);\n foreach (i; 2..mp) {\n auto m = i;\n while (m > 1) {\n auto fi = factor(m, p);\n if (f[i].empty || f[i][$-1] != fi) f[i] ~= fi;\n m /= fi;\n }\n }\n\n auto b = new int[](n), v = new bool[](mp), mi = -1;\n foreach (i; 0..n) {\n for (auto c = mi == -1 ? a[i] : mi;; ++c) {\n if (f[c].any!(fi => v[fi])) continue;\n b[i] = c;\n foreach (fi; f[c]) v[fi] = true;\n if (mi == -1 && c > a[i])\n mi = 2;\n else if (mi > 1)\n mi = c;\n break;\n }\n }\n\n foreach (i; 0..n) {\n write(b[i]);\n if (i < n-1) write(\" \");\n }\n writeln;\n}\n\npure T[] primes(T)(T n)\n{\n import std.algorithm, std.bitmanip, std.conv, std.range;\n\n auto sieve = BitArray();\n sieve.length((n+1)/2);\n sieve = ~sieve;\n\n foreach (p; 1..((nsqrt(n)-1)/2+1))\n if (sieve[p])\n for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)\n sieve[q] = false;\n\n auto r = sieve.bitsSet.map!(to!T).map!(\"a*2+1\").array;\n r[0] = 2;\n\n return r;\n}\n\npure T factor(T)(T n, const T[] p)\n{\n auto ma = nsqrt(n)+1;\n foreach (pi; p)\n if (pi > ma) return n;\n else if (n%pi == 0) return pi;\n return n;\n}\n\npure T nsqrt(T)(T n)\n{\n import std.algorithm, std.conv, std.range, core.bitop;\n if (n <= 1) return n;\n T m = 1 << (n.bsr/2+1);\n return iota(1, m).map!\"a*a\".assumeSorted!\"a <= b\".lowerBound(n).length.to!T;\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; readV(n);\n int[] a; readA(n, a);\n\n auto mp = 1_000_000;\n auto p = primes(mp);\n\n auto f = new int[][](mp);\n foreach (i; 2..mp) {\n auto m = i;\n while (m > 1) {\n auto fi = factor(m, p);\n if (f[i].empty || f[i][$-1] != fi) f[i] ~= fi;\n m /= fi;\n }\n }\n\n auto b = new int[](n), v = new bool[](mp), mi = -1;\n foreach (i; 0..n) {\n for (auto c = mi == -1 ? a[i] : mi;; ++c) {\n if (f[c].any!(fi => v[fi])) continue;\n b[i] = c;\n foreach (fi; f[c]) v[fi] = true;\n if (mi == -1 && c > a[i])\n mi = 2;\n else if (mi > 1)\n mi = c;\n break;\n }\n }\n\n foreach (i; 0..n) {\n write(b[i]);\n if (i < n-1) write(\" \");\n }\n writeln;\n}\n\npure T[] primes(T)(T n)\n{\n import std.algorithm, std.bitmanip, std.conv, std.range;\n\n auto sieve = BitArray();\n sieve.length((n+1)/2);\n sieve = ~sieve;\n\n foreach (p; 1..((nsqrt(n)-1)/2+1))\n if (sieve[p])\n for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)\n sieve[q] = false;\n\n auto r = sieve.bitsSet.map!(to!T).map!(\"a*2+1\").array;\n r[0] = 2;\n\n return r;\n}\n\npure T factor(T)(T n, const T[] p)\n{\n auto ma = nsqrt(n)+1;\n foreach (pi; p)\n if (pi > ma) return n;\n else if (n%pi == 0) return pi;\n return n;\n}\n\npure T nsqrt(T)(T n)\n{\n import std.algorithm, std.conv, std.range, core.bitop;\n if (n <= 1) return n;\n T m = 1 << (n.bsr/2+1);\n return iota(1, m).map!\"a*a\".assumeSorted!\"a <= b\".lowerBound(n).length.to!T;\n}\n"}], "src_uid": "bf8bbbb225813cdf42e7a2e454f0b787"} {"source_code": "module _template;\nimport std.stdio;\nimport std.algorithm;\nimport std.container;\nimport std.range;\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 string[] arr = new string[n];\n\n for (int i = 0; i < n; i++) {\n arr[i] = cin.read_string;\n }\n int count = 0;\n bool flag = true;\n for (int i = 0; i < arr[0].length; i++) {\n for (int j = 0; j < n - 1; j++) {\n if (arr[j][i] != arr[j + 1][i]) {\n flag = false;\n break;\n }\n }\n if (flag) count++;\n } \n writeln(count);\n } \n}", "positive_code": [{"source_code": "module cf_172A;\n\nimport std.stdio;\n\nvoid main() {\n int n;\n string phoneNumber;\n string prevPhoneNumber;\n int[] count;\n\n readf(\"%d \", &n);\n for (int i = 0; i < n; ++i) {\n readf(\"%s\\n\", &phoneNumber);\n\n if (i > 0) {\n for (int j = 0; j < phoneNumber.length; ++j) {\n if (prevPhoneNumber[j] != phoneNumber[j]) {\n ++count[j];\n }\n }\n } else {\n count = new int[phoneNumber.length];\n }\n prevPhoneNumber = phoneNumber.idup;\n }\n\n int pref = 0;\n while (pref < count.length && count[pref] == 0) {\n ++pref;\n }\n\n writeln(pref);\n}"}], "negative_code": [], "src_uid": "081b35620952bd32ce6d8ddc756e5c9d"} {"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 iteration(int i, int n, int[] a)\n{\n if (i % 2 == 0) {\n for (int j = 0; j <= n - 2 - 1; j += 2) {\n if (a[j] > a[j + 1])\n swap(a[j], a[j + 1]);\n }\n } else {\n for (int j = 1; j <= n - 1 - 1; j += 2) {\n if (a[j] > a[j + 1])\n swap(a[j], a[j + 1]);\n }\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 ans = 0;\n for (int i = 0; i < n; i++) {\n if (a.isSorted!\"a= 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\twhile (true)\r\n\t\t{\r\n\t\t\tbool ok = true;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (a[i] != i+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) break;\r\n\r\n\t\t\tforeach (i; 0..n-1)\r\n\t\t\t{\r\n\t\t\t\tif (i % 2 != ans[ti] % 2) continue;\r\n\t\t\t\tif (a[i] > a[i+1])\r\n\t\t\t\t\tswap(a[i], a[i+1]);\r\n\t\t\t}\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.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 iteration(int i, int n, int[] a)\n{\n if (i % 2 == 0) {\n for (int j = 0; j <= n - 2 - 1; j += 2) {\n if (a[j] > a[j + 1])\n swap(a[j], a[j + 1]);\n }\n } else {\n for (int j = 1; j <= n - 1 - 1; j += 2) {\n if (a[j] > a[j + 1])\n swap(a[j], a[j + 1]);\n }\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 writeln(a);\n int ans = 0;\n for (int i = 0; i < n; i++) {\n if (a.isSorted!\"a 0)\n\t{\n\t\tauto a = new point [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &a[i].x, &a[i].y);\n\t\t}\n\t\tsort !(\"a.x - a.y < b.x - b.y\") (a);\n\n\t\tlong [] z;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tz ~= c.x - c.y;\n\t\t}\n\n\t\tlong [] b;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tb ~= c.x + c.y;\n\t\t}\n\n\t\tlong [] pmin;\n\t\tlong [] pmax;\n\t\tfill_extrema (b, pmin, pmax);\n\n\t\tlong [] smin;\n\t\tlong [] smax;\n\t\treverse (b);\n\t\tfill_extrema (b, smin, smax);\n\t\treverse (b);\n\t\treverse (smin);\n\t\treverse (smax);\n\n\t\tbool check (long lim)\n\t\t{\n\t\t\tint j = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\twhile ((j < n) && (z[j] - z[i] <= lim))\n\t\t\t\t{\n\t\t\t\t\tj++;\n\t\t\t\t}\n\n\t\t\t\tlong lo = min (pmin[i], smin[j]);\n\t\t\t\tlong hi = max (pmax[i], smax[j]);\n\t\t\t\tif (hi - lo <= lim)\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tlong lo = 0;\n\t\tlong hi = 1L << 32;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tlong me = lo + ((hi - lo) >> 1);\n\t\t\tif (check (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\twritefln (\"%.20f\", lo * 0.5);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.typecons;\n\nalias Tuple !(long, \"x\", long, \"y\") point;\n\nvoid fill_extrema (long [] b, ref long [] tmin, ref long [] tmax)\n{\n\ttmin ~= +(1L << 36);\n\ttmax ~= -(1L << 36);\n\tforeach (d; b)\n\t{\n\t\ttmin ~= min (tmin[$ - 1], d);\n\t\ttmax ~= max (tmax[$ - 1], d);\n\t}\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new point [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &a[i].x, &a[i].y);\n\t\t}\n\t\tsort !(\"a.x - a.y < b.x - b.y\") (a);\n\n\t\tlong [] z;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tz ~= c.x - c.y;\n\t\t}\n\n\t\tlong [] b;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tb ~= c.x + c.y;\n\t\t}\n\n\t\tlong [] pmin;\n\t\tlong [] pmax;\n\t\tfill_extrema (b, pmin, pmax);\n\n\t\tlong [] smin;\n\t\tlong [] smax;\n\t\treverse (b);\n\t\tfill_extrema (b, smin, smax);\n\t\treverse (b);\n\t\treverse (smin);\n\t\treverse (smax);\n\n\t\tbool check (long lim)\n\t\t{\n\t\t\tint i = 0;\n\t\t\tint j = 0;\n\t\t\twhile (i < n)\n\t\t\t{\n\t\t\t\twhile ((j < n) && (z[j] - z[i] <= lim))\n\t\t\t\t{\n\t\t\t\t\tj++;\n\t\t\t\t}\n\n\t\t\t\tlong lo = min (pmin[i], smin[j]);\n\t\t\t\tlong hi = max (pmax[i], smax[j]);\n\t\t\t\tif (hi - lo <= lim)\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\twhile ((i < n) && (z[i] == z[i - 1]));\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tlong lo = 0;\n\t\tlong hi = 1L << 32;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tlong me = lo + ((hi - lo) >> 1);\n\t\t\tif (check (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\twritefln (\"%.20f\", lo * 0.5);\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.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nalias Tuple !(long, \"x\", long, \"y\") point;\n\nbool less_plus (T) (auto ref T a, auto ref T b)\n{\n\treturn a.x + a.y < b.x + b.y;\n}\n\nbool less_minus (T) (auto ref T a, auto ref T b)\n{\n\treturn a.x - a.y < b.x - b.y;\n}\n\nvoid fill_extrema (long [] b, ref long [] tmin, ref long [] tmax)\n{\n\ttmin ~= +(1L << 36);\n\ttmax ~= -(1L << 36);\n\tforeach (d; b)\n\t{\n\t\ttmin ~= min (tmin[$ - 1], d);\n\t\ttmax ~= max (tmax[$ - 1], d);\n\t}\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new point [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &a[i].x, &a[i].y);\n\t\t}\n\t\tsort !(less_minus, SwapStrategy.stable) (a);\n\n\t\tlong [] z;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tz ~= c.x - c.y;\n\t\t}\n\n\t\tlong [] b;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tb ~= c.x + c.y;\n\t\t}\n\n\t\tlong [] pmin;\n\t\tlong [] pmax;\n\t\tfill_extrema (b, pmin, pmax);\n\n\t\tlong [] smin;\n\t\tlong [] smax;\n\t\treverse (b);\n\t\tfill_extrema (b, smin, smax);\n\t\treverse (b);\n\t\treverse (smin);\n\t\treverse (smax);\n\n\t\tdebug {writeln (a);}\n\t\tdebug {writeln (b);}\n\t\tdebug {writeln (z);}\n\t\tdebug {writeln (pmin);}\n\t\tdebug {writeln (pmax);}\n\t\tdebug {writeln (smin);}\n\t\tdebug {writeln (smax);}\n\n\t\tbool check (long lim)\n\t\t{\n\t\t\tint i = 0;\n\t\t\tint j = 0;\n\t\t\twhile (i < n)\n\t\t\t{\n\t\t\t\twhile ((j < n) && (z[j] - z[i] <= lim))\n\t\t\t\t{\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t\tdebug {writefln (\"i = %s, j = %s\", i, j);}\n\n\t\t\t\tlong lo = min (pmin[i], smin[j]);\n\t\t\t\tlong hi = max (pmax[i], smax[j]);\n\t\t\t\tdebug {writefln (\"%s %s\", lo, hi);}\n\t\t\t\tif (hi - lo <= lim)\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\twhile ((i < n) && (z[i] == z[i - 1]));\n\t\t\t}\n\t\t\tdebug {writefln (\"check (%s)\", lim);}\n\t\t\treturn false;\n\t\t}\n\n\t\tlong lo = 0;\n\t\tlong hi = 1L << 32;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tlong me = lo + ((hi - lo) >> 1);\n\t\t\tdebug {writefln (\"%10s %10s %10s\", lo, me, hi);}\n\t\t\tif (check (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\tdebug {writefln (\"%10s %10s %10s\", lo, me, hi);}\n\t\t}\n\n\t\twritefln (\"%.20f\", lo * 0.5);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.typecons;\n\nalias Tuple !(int, \"x\", int, \"y\") point;\n\nvoid fill_extrema (long [] b, ref long [] tmin, ref long [] tmax)\n{\n\ttmin ~= +(1L << 36);\n\ttmax ~= -(1L << 36);\n\tforeach (d; b)\n\t{\n\t\ttmin ~= min (tmin[$ - 1], d);\n\t\ttmax ~= max (tmax[$ - 1], d);\n\t}\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new point [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &a[i].x, &a[i].y);\n\t\t}\n\t\tsort !(\"a.x - a.y < b.x - b.y\") (a);\n\n\t\tlong [] z;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tz ~= c.x - c.y;\n\t\t}\n\n\t\tlong [] b;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tb ~= c.x + c.y;\n\t\t}\n\n\t\tlong [] pmin;\n\t\tlong [] pmax;\n\t\tfill_extrema (b, pmin, pmax);\n\n\t\tlong [] smin;\n\t\tlong [] smax;\n\t\treverse (b);\n\t\tfill_extrema (b, smin, smax);\n\t\treverse (b);\n\t\treverse (smin);\n\t\treverse (smax);\n\n\t\tbool check (long lim)\n\t\t{\n\t\t\tint i = 0;\n\t\t\tint j = 0;\n\t\t\twhile (i < n)\n\t\t\t{\n\t\t\t\twhile ((j < n) && (z[j] - z[i] <= lim))\n\t\t\t\t{\n\t\t\t\t\tj++;\n\t\t\t\t}\n\n\t\t\t\tlong lo = min (pmin[i], smin[j]);\n\t\t\t\tlong hi = max (pmax[i], smax[j]);\n\t\t\t\tif (hi - lo <= lim)\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\ti++;\n\t\t\t\t}\n\t\t\t\twhile ((i < n) && (z[i] == z[i - 1]));\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tlong lo = 0;\n\t\tlong hi = 1L << 32;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tlong me = lo + ((hi - lo) >> 1);\n\t\t\tif (check (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\twritefln (\"%.20f\", lo * 0.5);\n\t}\n}\n"}], "negative_code": [], "src_uid": "f9a902e97b3a7c6ce0708c11be1fa631"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid solve()\n{\n int n, k;\n readf!(\" %s %s\")(n, k);\n readln;\n int[] arr = readln.splitter.map!(to!int).array;\n assert(arr.length == n);\n if (k == 1)\n {\n iota(1, arr.length-1, 2).count().writeln();\n return;\n }\n iota(1, arr.length-1).filter!(i => arr[i] > arr[i - 1] + arr[i + 1]).count()\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", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid solve()\n{\n int n, k;\n readf!(\" %s %s\")(n, k);\n readln;\n int[] arr = readln.splitter.map!(to!int).array;\n assert(arr.length == n);\n if (k == 1)\n {\n writeln((n - 1) / 2);\n return;\n }\n iota(1, arr.length - 1).count!(i=>arr[i] > arr[i - 1] + arr[i + 1]).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;\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 ((k == 1) ? (n - 1) / 2 :\r\n\t\t iota (1, n - 1).count !(i => a[i] > a[i - 1] + a[i + 1]));\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;\n\nvoid solve()\n{\n int n, k;\n readf!(\" %s %s\")(n, k);\n readln;\n int[] arr = readln.splitter.map!(to!int).array;\n assert(arr.length == n);\n if (k == 1)\n {\n iota(1, arr.length-1, 2).count().writeln();\n return;\n }\n iota(1, arr.length-1, 2).filter!(i => arr[i] > arr[i - 1] + arr[i + 1]).count()\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 int n, k;\n readf!(\" %s %s\")(n, k);\n readln;\n int[] arr = readln.splitter.map!(to!int).array;\n assert(arr.length == n);\n if (k == 1)\n {\n iota(1, arr.length, 2).count().writeln();\n return;\n }\n iota(1, arr.length-1, 2).filter!(i => arr[i] > arr[i - 1] + arr[i + 1]).count()\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"}], "src_uid": "4d5d20fd586ddbea2adeab104a6c2aec"} {"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 mx = new bool[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 0 .. n/4) {\n char c;\n readf(\"%s\", &c);\n \n int v = c >= 'A' ? c - 'A' + 10 : c - '0';\n foreach (k; 0 .. 4) {\n mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;\n }\n }\n \n readln;\n }\n \n debug { mx.each!writeln; }\n \n auto val = new int[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];\n }\n }\n \n debug { val.each!writeln; }\n \n bool isOk(int x) {\n int sz = x*x;\n foreach (i; 1 .. n/x + 1) {\n foreach (j; 1 .. n/x + 1) {\n int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];\n if (cval != 0 && cval != sz) { return false; }\n }\n }\n \n return true;\n }\n \n int ans = 1;\n foreach (m; 2 .. n+1) {\n if (n % m != 0) { continue; }\n if (isOk(m)) { ans = m; }\n }\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;\n readf(\"%s\", &n);\n readln;\n\n auto mx = new bool[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 0 .. n/4) {\n char c;\n readf(\"%s\", &c);\n \n int v = c >= 'A' ? c - 'A' + 10 : c - '0';\n foreach (k; 0 .. 4) {\n mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;\n }\n }\n \n readln;\n }\n \n debug { mx.each!writeln; }\n \n auto val = new int[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];\n }\n }\n \n debug { val.each!writeln; }\n \n bool isOk(int x) {\n int sz = x*x;\n foreach (i; 1 .. n/x + 1) {\n foreach (j; 1 .. n/x + 1) {\n int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];\n if (cval != 0 && cval != sz) { return false; }\n }\n }\n \n return true;\n }\n \n int ans = (n+1).iota[1 .. $].filter!(x => n % x == 0 && isOk(x)).array.back;\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 int n;\n readf(\"%s\", &n);\n readln;\n\n auto mx = new bool[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 0 .. n/4) {\n char c;\n readf(\"%s\", &c);\n \n int v = c >= 'A' ? c - 'A' + 10 : c - '0';\n foreach (k; 0 .. 4) {\n mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;\n }\n }\n \n readln;\n }\n \n debug { mx.each!writeln; }\n \n auto val = new int[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];\n }\n }\n \n debug { val.each!writeln; }\n \n bool isOk(int x) {\n x = ((x+3) / 4) * 4;\n int sz = x*x;\n foreach (i; 1 .. n/x + 1) {\n foreach (j; 1 .. n/x + 1) {\n int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];\n if (cval != 0 && cval != sz) { return false; }\n }\n }\n \n return true;\n }\n \n int le = 1, r = n;\n while (le < r) {\n int m = (le + r) / 2 + 1;\n if (isOk(m)) { le = m; }\n else { r = m-1; }\n }\n \n le.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 mx = new bool[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 0 .. n/4) {\n char c;\n readf(\"%s\", &c);\n \n int v = c >= 'A' ? c - 'A' + 10 : c - '0';\n foreach (k; 0 .. 4) {\n mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;\n }\n }\n \n readln;\n }\n \n debug { mx.each!writeln; }\n \n auto val = new int[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];\n }\n }\n \n debug { val.each!writeln; }\n \n bool isOk(int x) {\n int sz = x*x;\n foreach (i; 1 .. n/x + 1) {\n foreach (j; 1 .. n/x + 1) {\n int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];\n if (cval != 0 && cval != sz) { return false; }\n }\n }\n \n return true;\n }\n \n int ans = 1;\n foreach (m; 2 .. n+1) {\n if (isOk(m)) { ans = m; }\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;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n auto mx = new bool[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 0 .. n/4) {\n char c;\n readf(\"%s\", &c);\n \n int v = c >= 'A' ? c - 'A' + 10 : c - '0';\n foreach (k; 0 .. 4) {\n mx[i][1 + j*4 + k] = (v & (1 << (3 - k))) > 0;\n }\n }\n \n readln;\n }\n \n debug { mx.each!writeln; }\n \n auto val = new int[][] (n+1, n+1);\n \n foreach (i; 1 .. n+1) {\n foreach (j; 1 .. n+1) {\n val[i][j] = mx[i][j] + val[i-1][j] + val[i][j-1] - val[i-1][j-1];\n }\n }\n \n debug { val.each!writeln; }\n \n bool isOk(int x) {\n int sz = x*x;\n foreach (i; 1 .. n/x + 1) {\n foreach (j; 1 .. n/x + 1) {\n int cval = val[i*x][j*x] - val[(i-1)*x][j*x] - val[i*x][(j-1)*x] + val[(i-1)*x][(j-1)*x];\n if (cval != 0 && cval != sz) { return false; }\n }\n }\n \n return true;\n }\n \n int le = 1, r = n;\n while (le < r) {\n int m = (le + r) / 2 + 1;\n if (isOk(m)) { le = m; }\n else { r = m-1; }\n }\n \n le.writeln;\n}"}], "src_uid": "31d95251cd79d889ff9f0a624ef31394"} {"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\nlong n, h, m, k;\n\nint opCmp(long[2] a, long[2] b)\n{\n if (a[0] < b[0])\n return -1;\n if (a[0] > b[0])\n return +1;\n if (a[1] < b[1])\n return -1;\n if (a[1] > b[1])\n return +1;\n return 0;\n}\n\nlong pmod(long a, long m)\n{\n return (a%m + m)%m;\n}\n\nvoid main()\n{\n read(n), read(h), read(m), read(k);\n import std.container: redBlackTree, RedBlackTree;\n auto positions = redBlackTree!long();\n auto freights = new long[cast(size_t)n];\n foreach(i; 0 .. n)\n {\n long hi, mi;\n read(hi), read(mi); // realmente no importa hi??\n positions.insert(mi % (m / 2));\n freights[cast(size_t)i] = mi % (m / 2);\n }\n auto originalFreights = freights.dup;\n auto sortedFreights = sort(freights);\n import std.algorithm: min;\n long minRemoved = long.max;\n long bestPosition = -1;\n foreach(position; positions)\n {\n long r = position;\n long l = r - k;\n l = pmod(l, m / 2);\n long removed;\n if (l <= r)\n removed = sortedFreights.upperBound(l).lowerBound(r).length;\n else\n removed = sortedFreights.upperBound(l).length + sortedFreights.lowerBound(r).length;\n\n if (removed < minRemoved)\n {\n bestPosition = position;\n minRemoved = removed;\n }\n }\n writeln(minRemoved, \" \", bestPosition);\n long written = 0;\n foreach(i, freight; originalFreights)\n {\n long r = bestPosition;\n long l = r - k;\n l = pmod(l, m / 2);\n if (l <= r)\n {\n if (freight > l && freight < r)\n {\n written++;\n write(i + 1, \" \");\n continue;\n }\n }\n else\n {\n if (freight > l || freight < r)\n {\n written++;\n write(i + 1, \" \");\n continue;\n }\n }\n }\n writeln;\n assert(written == minRemoved);\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, h, m, k;\n\twhile (readf !(\" %s %s %s %s\") (n, h, m, k) > 0)\n\t{\n\t\tauto m2 = m / 2;\n\t\tauto r = new int [n];\n\t\tauto t = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf !(\" %s %s\") (r[i], t[i]);\n\t\t\tt[i] %= m2;\n\t\t}\n\t\tauto p = n.iota.array;\n\t\tp.schwartzSort !(i => t[i]);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tp ~= p[i];\n\t\t}\n\t\tint best = n + 1;\n\t\tint pos = -1;\n\t\tint j = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto cur = t[p[i]];\n\t\t\twhile (j < n * 2)\n\t\t\t{\n\t\t\t\tauto next = t[p[j]] + m2 * (j >= n);\n\t\t\t\tif (next >= cur + k)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tif (best > j - i - 1)\n\t\t\t{\n\t\t\t\tbest = j - i - 1;\n\t\t\t\tpos = t[p[j]];\n\t\t\t}\n\t\t}\n\n\t\twriteln (best, \" \", pos);\n\t\tint [] answer;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif ((0 < pos - t[i] && pos - t[i] < k) ||\n\t\t\t (0 < pos - t[i] + m2 && pos - t[i] + m2 < k))\n\t\t\t{\n\t\t\t\tanswer ~= i + 1;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%s %)\") (answer);\n\t}\n}\n"}], "negative_code": [], "src_uid": "19ff0b59e314cef6d7d4657f4c17d140"} {"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 = 998244353;\nalias Mint = ModInt!MO;\n\n\nvoid main() {\n try {\n for (; ; ) {\n const S = readToken();\n const T = readToken();\n const L = cast(int)(S.length);\n const M = cast(int)(T.length);\n \n auto dp = new Mint[][](L + 1, L + 1);\n foreach (j; M .. L + 1) {\n dp[0][j] += 1;\n }\n foreach_reverse (w; 1 .. L + 1) {\n foreach (i; 0 .. L - w + 1) {\n const j = i + w;\n // front\n if (i >= M || S[w - 1] == T[i]) {\n dp[i + 1][j] += dp[i][j];\n }\n // back\n if (j - 1 >= M || S[w - 1] == T[j - 1]) {\n dp[i][j - 1] += dp[i][j];\n }\n }\n }\n Mint ans;\n foreach (i; 0 .. L + 1) {\n ans += dp[i][i];\n }\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;\nimport std.typecons;\n\nimmutable int mod = 998_244_353;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip ()) != \"\")\n\t{\n\t\tauto t = readln.strip;\n\t\tauto n = s.length.to !(int);\n\t\tauto m = t.length.to !(int);\n\t\tauto f = new int [] [] (n + 1, n + 1);\n\t\tforeach (i; 0..n + 1)\n\t\t{\n\t\t\tf[i][i] = 1;\n\t\t}\n\t\tforeach (len; 0..n)\n\t\t{\n\t\t\tauto letter = s[len];\n\t\t\tforeach (start; 0..n + 1 - len)\n\t\t\t{\n\t\t\t\tauto finish = start + len;\n\t\t\t\tauto cur = f[start][finish];\n\t\t\t\tif (start > 0 &&\n\t\t\t\t (start - 1 >= m || letter == t[start - 1]))\n\t\t\t\t{\n\t\t\t\t\tf[start - 1][finish] += cur;\n\t\t\t\t\tif (f[start - 1][finish] >= mod)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[start - 1][finish] -= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (finish < n &&\n\t\t\t\t (finish >= m || letter == t[finish]))\n\t\t\t\t{\n\t\t\t\t\tf[start][finish + 1] += cur;\n\t\t\t\t\tif (f[start][finish + 1] >= mod)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[start][finish + 1] -= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (sum (f[0][m..$], 0L) % mod);\n\t}\n}\n"}], "negative_code": [], "src_uid": "077e0e207d3c530fbf1ba1ac6d3fba6e"} {"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(int[] a, int sum, ref Tuple!(int, int)[] ans)\n{\n if (a.length == 0)\n return sum == 0;\n\n if (sum == 0) {\n ans ~= tuple(cast(int)a.length, cast(int)a.length);\n return solve(a[0 .. $ - 1], sum, ans);\n return true;\n }\n\n if (sum < 0) {\n if (a.length >= 2 && a[$ - 1] < 0) {\n ans ~= tuple(cast(int)a.length - 1, cast(int)a.length);\n return solve(a[0 .. $ - 2], sum - 2 * a[$ - 1], ans);\n } else {\n ans ~= tuple(cast(int)a.length, cast(int)a.length);\n return solve(a[0 .. $ - 1], sum, ans);\n }\n } else {\n if (a.length >= 2 && a[$ - 1] > 0) {\n ans ~= tuple(cast(int)a.length - 1, cast(int)a.length);\n return solve(a[0 .. $ - 2], sum - 2 * a[$ - 1], ans);\n } else {\n ans ~= tuple(cast(int)a.length, cast(int)a.length);\n return solve(a[0 .. $ - 1], sum, ans);\n }\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!int).array;\n Tuple!(int, int)[] ans;\n if (solve(a, a.sum, ans)) {\n ans.reverse;\n writeln(ans.length);\n foreach (x; ans) {\n writefln(\"%d %d\", x[0], x[1]);\n }\n } else {\n writeln(-1);\n }\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\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\tif (sum (a) % 2 != 0)\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tauto b = a.enumerate.filter !(x => x.value != 0).array;\r\n\t\tb ~= typeof (b.front) (n, 0);\r\n\t\tint [] [] answer;\r\n\t\tif (b[0].index > 0)\r\n\t\t{\r\n\t\t\tanswer ~= [0, b[0].index];\r\n\t\t}\r\n\t\tfor (int i = 0; i + 2 < b.length; i += 2)\r\n\t\t{\r\n\t\t\tif (b[i].value == b[i + 1].value)\r\n\t\t\t{\r\n\t\t\t\tif ((b[i].index & 1) != (b[i + 1].index & 1))\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer ~= [b[i].index, b[i + 2].index];\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer ~= [b[i].index, b[i + 1].index - 1];\r\n\t\t\t\t\tanswer ~= [b[i + 1].index - 1, b[i + 2].index];\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\tanswer ~= [b[i].index, b[i + 1].index];\r\n\t\t\t\tanswer ~= [b[i + 1].index, b[i + 2].index];\r\n\t\t\t}\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\twriteln (line[0] + 1, \" \", line[1]);\r\n\t\t}\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[] solve() {\r\n const sumA = A.sum;\r\n if (sumA % 2 != 0) {\r\n return null;\r\n }\r\n \r\n auto fs = new bool[N];\r\n bool greedy(int a, int k) {\r\n foreach (i; 0 .. N) {\r\n if (i == 0 || fs[i - 1]) {\r\n continue;\r\n }\r\n if (A[i] == a && k > 0) {\r\n fs[i] = true;\r\n --k;\r\n }\r\n }\r\n return (k == 0);\r\n }\r\n if (sumA >= 0) {\r\n if (!greedy(+1, sumA / 2)) return null;\r\n } else {\r\n if (!greedy(-1, -sumA / 2)) return null;\r\n }\r\n debug {\r\n writeln(\"fs = \", fs);\r\n }\r\n \r\n int[] cuts;\r\n cuts ~= 0;\r\n foreach (i; 1 .. N) {\r\n if (fs[i - 1] == fs[i]) {\r\n assert(!fs[i]);\r\n cuts ~= i;\r\n }\r\n }\r\n cuts ~= N;\r\n return cuts;\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 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 debug {\r\n writeln(A, \": \", ans);\r\n }\r\n const len = cast(int)(ans.length) - 1;\r\n if (len >= 0) {\r\n writeln(len);\r\n foreach (i; 0 .. len) {\r\n writeln(ans[i] + 1, \" \", ans[i + 1]);\r\n }\r\n } else {\r\n writeln(-1);\r\n }\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\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\tif (sum (a) % 2 != 0)\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (!any (a))\r\n\t\t{\r\n\t\t\twriteln (1);\r\n\t\t\twriteln (1, \" \", n);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tauto b = a.enumerate.filter !(x => x.value != 0).array;\r\n\t\tb ~= typeof (b.front) (n, 0);\r\n\t\tint [] [] answer;\r\n\t\tfor (int i = 0; i + 2 < b.length; i += 2)\r\n\t\t{\r\n\t\t\tif (b[i].value == b[i + 1].value)\r\n\t\t\t{\r\n\t\t\t\tif ((b[i].index & 1) != (b[i + 1].index & 1))\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer ~= [b[i].index, b[i + 2].index];\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer ~= [b[i].index, b[i + 1].index - 1];\r\n\t\t\t\t\tanswer ~= [b[i + 1].index - 1, b[i + 2].index];\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\tanswer ~= [b[i].index, b[i + 1].index];\r\n\t\t\t\tanswer ~= [b[i + 1].index, b[i + 2].index];\r\n\t\t\t}\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\twriteln (line[0] + 1, \" \", line[1]);\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\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\tif (sum (a) % 2 != 0)\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tif (!any (a))\r\n\t\t{\r\n\t\t\twriteln (1);\r\n\t\t\twriteln (1, \" \", n);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tauto b = a.enumerate.filter !(x => x.value != 0).array;\r\n\t\tb ~= typeof (b.front) (n, 0);\r\n\t\tint [] [] answer;\r\n\t\tfor (int i = 0; i + 2 < b.length; i += 2)\r\n\t\t{\r\n\t\t\tif (b[i].value == b[i + 1].value)\r\n\t\t\t{\r\n\t\t\t\tanswer ~= [b[i].index, b[i + 2].index];\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tanswer ~= [b[i].index, b[i + 1].index];\r\n\t\t\t\tanswer ~= [b[i + 1].index, b[i + 2].index];\r\n\t\t\t}\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\twriteln (line[0] + 1, \" \", line[1]);\r\n\t\t}\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[] solve() {\r\n const sumA = A.sum;\r\n if (sumA % 2 != 0) {\r\n return null;\r\n }\r\n \r\n auto fs = new bool[N];\r\n bool greedy(int a, int k) {\r\n foreach (i; 0 .. N) {\r\n if (i > 0 && fs[i - 1]) {\r\n continue;\r\n }\r\n if (A[i] == a && k > 0) {\r\n fs[i] = true;\r\n --k;\r\n }\r\n }\r\n return (k == 0);\r\n }\r\n if (sumA >= 0) {\r\n if (!greedy(+1, sumA / 2)) return null;\r\n } else {\r\n if (!greedy(-1, -sumA / 2)) return null;\r\n }\r\n \r\n int[] cuts;\r\n cuts ~= 0;\r\n foreach (i; 1 .. N) {\r\n if (fs[i - 1] == fs[i]) {\r\n assert(!fs[i]);\r\n cuts ~= i;\r\n }\r\n }\r\n cuts ~= N;\r\n return cuts;\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 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 debug {\r\n writeln(A, \": \", ans);\r\n }\r\n const len = cast(int)(ans.length) - 1;\r\n if (len >= 0) {\r\n writeln(len);\r\n foreach (i; 0 .. len) {\r\n writeln(ans[i] + 1, \" \", ans[i + 1]);\r\n }\r\n } else {\r\n writeln(-1);\r\n }\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "src_uid": "54a3b38631ddc033597797263fd7fb22"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto a = RDA;\n\t\ta.sort!\"a > b\"();\n\n\t\tforeach (i; 1..min(k+1, n))\n\t\t{\n\t\t\ta[0] += a[i];\n\t\t}\n\t\tans[ti] = a[0];\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": "// Vicfred\n// https://codeforces.com/contest/1430/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, k;\n readf(\"%s %s\\n\", &n, &k);\n\n long[] a = readln.split.map!(to!long).array;\n\n a.sort;\n a.reverse;\n\n long ans = 0L;\n for(int i = 0; i <= k; ++i)\n ans += a[i];\n\n ans.writeln;\n }\n}\n"}], "negative_code": [], "src_uid": "08c797a7972fae99f8b64b47c53d8aeb"} {"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 auto s = readln.strip;\r\n dchar[int] dict;\r\n foreach (tup; zip(a, s))\r\n {\r\n if (tup[0] in dict)\r\n if (dict[tup[0]] != tup[1]) {\r\n writeln(\"NO\");\r\n return;\r\n }\r\n dict[tup[0]] = tup[1];\r\n }\r\n writeln(\"YES\");\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 auto s = readln.strip;\n char[int] m;\n bool good = true;\n foreach (i ; 0 .. a.length) {\n if (a[i] in m) {\n if (m[a[i]] != s[i]) {\n good = false;\n break;\n }\n } else {\n m[a[i]] = s[i];\n }\n }\n writeln(good ? \"YES\" : \"NO\");\n }\n}\n"}], "negative_code": [], "src_uid": "485d5984e34a479f2c074a305ae999ae"} {"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\tsort (a);\n\t\ta ~= int.max;\n\t\tauto b = group (a);\n\t\tdebug {writeln (b);}\n\n\t\tint [] res;\n\t\tint [] cur;\n\t\tint prev = int.min;\n\t\tint total = 0;\n\t\tforeach (ref g; b)\n\t\t{\n\t\t\tauto value = g[0];\n\t\t\tauto amount = g[1].to !(int);\n\n\t\t\tif (prev + 1 < value)\n\t\t\t{\n\t\t\t\tif (res.length < cur.length)\n\t\t\t\t{\n\t\t\t\t\tres = cur;\n\t\t\t\t}\n\t\t\t\tcur = null;\n\t\t\t}\n\n\t\t\tif (amount == 1)\n\t\t\t{\n\t\t\t\tcur ~= value;\n\t\t\t\tif (res.length < cur.length)\n\t\t\t\t{\n\t\t\t\t\tres = cur;\n\t\t\t\t}\n\t\t\t\tcur = [value];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcur ~= value.repeat (amount).array;\n\t\t\t}\n\n\t\t\tprev = value;\n\t\t}\n\n\t\tint [] temp;\n\t\tint [] add;\n\t\tint last = res.front;\n\t\tforeach (ref x; res)\n\t\t{\n\t\t\tif (last < x)\n\t\t\t{\n\t\t\t\tadd ~= x;\n\t\t\t\tlast = x;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttemp ~= x;\n\t\t\t}\n\t\t}\n\t\treverse (add);\n\t\tres = temp ~ add;\n\n\t\twriteln (res.length);\n\t\twritefln (\"%(%s %)\", res);\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\t\n\tint[] as;\n\tforeach(i; 0 .. n) as ~= read.to!int;\n\tlog(\"as:\", as);\n\tint amax = -1;\n\tforeach(a; as) amax = max(amax, a);\n\t\n\tint[] acount = new int[](amax + 1);\n\tforeach(a; as) acount[a] += 1;\n\tlog(\"acount:\", acount);\n\t\n\tint l, r, sum;\n\tint bestl = 0, bestr = -1, bestsum = 0;\n\tint s = 0; // 0=not selecting, 1=selecting\n\tforeach(i; 0 .. amax + 1){\n\t\tif(s == 0){\n\t\t\tif(acount[i] == 0) continue;\n\t\t\tif(acount[i] >= 1){\n\t\t\t\tsum = acount[i];\n\t\t\t\ts = 1;\n\t\t\t\tl = r = i;\n\t\t\t\tif(sum > bestsum) bestl = l, bestr = r, bestsum = sum;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tsum += acount[i];\n\t\t\tr = i;\n\t\t\tif(sum > bestsum) bestl = l, bestr = r, bestsum = sum;\n\t\t\tif(acount[i] == 0) s = 0;\n\t\t\tif(acount[i] == 1){\n\t\t\t\tsum = acount[i];\n\t\t\t\ts = 1;\n\t\t\t\tl = r = i;\n\t\t\t}\n\t\t}\n\t\tlog(\"i:\", i, \"l:\", l, \"r:\", r, \"sum:\", sum, \"bestl:\", bestl, \"bestr:\", bestr, \"bestsum:\", bestsum);\n\t}\n\t\n\tint[] ans;\n\tforeach(i; bestl .. bestr + 1) ans ~= i, acount[i] -= 1;\n\t\n\tforeach_reverse(i; bestl .. bestr + 1) while(acount[i] > 0) ans ~= i, acount[i] -= 1;\n\t\n\tans.length.writeln;\n\tans.map!(to!string).array.join(\" \").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 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\t\n\tint[] as;\n\tforeach(i; 0 .. n) as ~= read.to!int;\n\tlog(\"as:\", as);\n\tint amax = -1;\n\tforeach(a; as) amax = max(amax, a);\n\t\n\tint[] acount = new int[](amax + 1);\n\tforeach(a; as) acount[a] += 1;\n\tlog(\"acount:\", acount);\n\t\n\tint l, r, sum;\n\tint bestl = 0, bestr = -1, bestsum = 0;\n\tint s = 0; // 0=not selecting, 1=selecting\n\tforeach(i; 0 .. amax + 1){\n\t\tif(acount[i] == 0){\n\t\t\ts = 0, sum = 0;\n\t\t\tl = i + 1;\n\t\t}\n\t\telse if(acount[i] == 1){\n\t\t\tif(s == 0){\n\t\t\t\tl = r = i, sum += acount[i];\n\t\t\t\tif(sum > bestsum) bestr = r, bestl = l, bestsum = sum;\n\t\t\t\ts = 1, sum = 1;\n\t\t\t\tl = r = i;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tr = i, sum += acount[i];\n\t\t\t\tif(sum > bestsum) bestr = r, bestl = l, bestsum = sum;\n\t\t\t\ts = 0, sum = 0;\n\t\t\t\tl = i + 1;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif(s == 0) s = 1;\n\t\t\tr = i, sum += acount[i];\n\t\t\tif(sum > bestsum) bestr = r, bestl = l, bestsum = sum;\n\t\t}\n\t\tlog(\"i:\", i, \"l:\", l, \"r:\", r, \"sum:\", sum, \"bestl:\", bestl, \"bestr:\", bestr, \"bestsum:\", bestsum);\n\t}\n\t\n\tint[] ans;\n\tforeach(i; bestl .. bestr + 1) ans ~= i, acount[i] -= 1;\n\t\n\tforeach_reverse(i; bestl .. bestr + 1) while(acount[i] > 0) ans ~= i, acount[i] -= 1;\n\t\n\tans.length.writeln;\n\tans.map!(to!string).array.join(\" \").writeln;\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 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\t\n\tint[] as;\n\tforeach(i; 0 .. n) as ~= read.to!int;\n\tlog(\"as:\", as);\n\tint amax = -1;\n\tforeach(a; as) amax = max(amax, a);\n\t\n\tint[] acount = new int[](amax + 1);\n\tforeach(a; as) acount[a] += 1;\n\tlog(\"acount:\", acount);\n\t\n\tint l, r, sum;\n\tint bestl = 0, bestr = -1, bestsum = 0;\n\tint s = 0; // 0=not selecting, 1=selecting\n\tforeach(i; 0 .. amax + 1){\n\t\tif(acount[i] == 0){\n\t\t\ts = 0, sum = 0;\n\t\t\tl = i + 1;\n\t\t}\n\t\telse if(acount[i] == 1){\n\t\t\tif(s == 0){\n\t\t\t\tl = r = i, sum += acount[i];\n\t\t\t\tif(sum > bestsum) bestr = r, bestl = l, bestsum = sum;\n\t\t\t\ts = 1, sum = 1;\n\t\t\t\tl = r = i;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tr = i, sum += acount[i];\n\t\t\t\tif(sum > bestsum) bestr = r, bestl = l, bestsum = sum;\n\t\t\t\ts = 0, sum = 0;\n\t\t\t\tl = i + 1;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif(s == 0) s = 1;\n\t\t\tr = i, sum += acount[i];\n\t\t\tif(sum > bestsum) bestr = r, bestl = l, bestsum = sum;\n\t\t}\n\t\tlog(\"i:\", i, \"l:\", l, \"r:\", r, \"sum:\", sum, \"bestl:\", bestl, \"bestr:\", bestr, \"bestsum:\", bestsum);\n\t}\n\t\n\tint[] ans;\n\tforeach(i; bestl .. bestr + 1) ans ~= i, acount[i] -= 1;\n\t\n\tforeach_reverse(i; bestl .. bestr + 1) while(acount[i] > 0) ans ~= i, acount[i] -= 1;\n\t\n\tans.map!(to!string).array.join(\" \").writeln;\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 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\t\n\tint[] as;\n\tforeach(i; 0 .. n) as ~= read.to!int;\n\tlog(\"as:\", as);\n\tint amax = -1;\n\tforeach(a; as) amax = max(amax, a);\n\t\n\tint[] acount = new int[](amax + 1);\n\tforeach(a; as) acount[a] += 1;\n\tlog(\"acount:\", acount);\n\t\n\tint l, r, sum;\n\tint bestl = 0, bestr = -1, bestsum = 0;\n\tint s = 0; // 0=not selecting, 1=selecting\n\tforeach(i; 0 .. amax + 1){\n\t\tif(s == 0){\n\t\t\tif(acount[i] == 0) continue;\n\t\t\tif(acount[i] >= 1){\n\t\t\t\tsum = acount[i];\n\t\t\t\ts = 1;\n\t\t\t\tl = r = i;\n\t\t\t\tif(sum > bestsum) bestl = l, bestr = r, bestsum = sum;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tsum += acount[i];\n\t\t\tr = i;\n\t\t\tif(sum > bestsum) bestl = l, bestr = r, bestsum = sum;\n\t\t\tif(acount[i] <= 1) s = 0;\n\t\t}\n\t\tlog(\"i:\", i, \"l:\", l, \"r:\", r, \"sum:\", sum, \"bestl:\", bestl, \"bestr:\", bestr, \"bestsum:\", bestsum);\n\t}\n\t\n\tint[] ans;\n\tforeach(i; bestl .. bestr + 1) ans ~= i, acount[i] -= 1;\n\t\n\tforeach_reverse(i; bestl .. bestr + 1) while(acount[i] > 0) ans ~= i, acount[i] -= 1;\n\t\n\tans.length.writeln;\n\tans.map!(to!string).array.join(\" \").writeln;\n\t\n}\n"}], "src_uid": "9b205e01937903236d1c0553dd480c2a"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, x; rd(n, x);\n auto a=readln.split.to!(int[]);\n\n int[int] bef, aft;\n foreach(e; a){\n if(e in bef) bef[e]++;\n else bef[e]=1;\n if ((e&x) in aft) aft[e&x]++;\n else aft[e&x]=1;\n }\n int mn=3;\n foreach(e; a){\n if(bef[e]>1) mn=0;\n else{\n bef[e]--;\n if(((e&x) in bef) && bef[e&x]>0) mn=min(mn, 1);\n if(aft[e&x]>1) mn=min(mn, 2);\n bef[e]++;\n }\n }\n if(mn>2) writeln(-1);\n else writeln(mn);\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 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, x;\n readf(\"%s %s\", &n, &x);\n readln;\n\n int[int] cnt;\n readln.chomp.split.map!(to!int).each!(v => ++cnt[v]);\n \n debug { cnt.writeln; }\n \n int ans = 3;\n bool [int] afterAnd;\n foreach (k, v; cnt) {\n if (v > 1) {\n ans = 0;\n break;\n }\n \n auto now = k & x;\n if (now != k && now in cnt) ans = min(ans, 1);\n else if (now in afterAnd) ans = min(ans, 2);\n \n afterAnd[now] = true;\n }\n \n if (ans == 3) ans = -1;\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "f4bb0b8f285b0c8cbaf469964505cc56"} {"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.strip;\n\t\tauto b = readln.strip;\n\t\tint res = 0;\n\t\tint pos = -1;\n\t\tchar last = '*';\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\tres += 1;\n\t\t\t\tif (pos + 1 == i && last == b[i])\n\t\t\t\t{\n\t\t\t\t\tres -= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpos = i;\n\t\t\t\t\tlast = a[i];\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 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 s = readln.chomp;\n auto t = readln.chomp;\n auto ans = 0;\n auto chg = false;\n foreach (i; 0 .. n) {\n if ((s[i] == t[i]) || (i > 0 && s[i-1] != s[i] && chg)) {\n chg = false;\n continue;\n }\n \n ++ans;\n chg = true;\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 N = readln.chomp.to!int;\n auto A = readln.chomp;\n auto B = readln.chomp;\n long ans = 0;\n\n for (int i = 0; i < N; ++i) {\n if (A[i] == B[i]) continue;\n if (i == N - 1) {\n ans += 1;\n } else if (A[i+1] != B[i+1] && A[i] != A[i+1]) {\n ans += 1;\n i += 1;\n } else {\n ans += 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, std.bitmanip;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.chomp;\n auto B = readln.chomp;\n long ans = 0;\n\n for (int i = 0; i < N; ++i) {\n if (A[i] != B[i]) {\n if (i == N - 1 || A[i+1] == B[i+1]) {\n ans += 1;\n } else {\n ans += 1;\n ++i;\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 auto s = readln.chomp;\n auto t = readln.chomp;\n auto ans = 0;\n foreach (i; 0 .. n) {\n if (s[i] == t[i]) continue;\n if (i > 0 && s[i-1] != s[i] && s[i-1] != t[i-1]) continue;\n \n ++ans;\n }\n \n ans.writeln;\n}"}], "src_uid": "a57555f50985c6c3634de1e7c60553bd"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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, 26);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto m = RD!int;\n\t\tauto s = RD!string;\n\t\tauto p = RDA!int;\n\t\tauto cnt = new long[][](n+1, 26);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto num = s[i]-'a';\n\t\t\tcnt[i+1] = cnt[i].dup;\n\t\t\t++cnt[i+1][num];\n\t\t}\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tans[ti][] += cnt[p[i]][];\n\t\t}\n\t\tans[ti][] += cnt[n][];\n\t}\n\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"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\nvoid main() {\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int m = io.readInt;\n string s = io.readToken;\n long[] sum = new long[n];\n sum[n - 1]++;\n for (int i = 0; i < m; ++i) {\n sum[io.readInt - 1]++;\n }\n for (int i = n - 1; i--;) {\n sum[i] += sum[i + 1];\n }\n long[] count = new long[26];\n for (int i = 0; i < n; ++i) {\n count[s[i] - 'a'] += sum[i];\n }\n for (int i = 0; i < 26; ++i) {\n write(count[i], \" \\n\"[i == 25]);\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; }\nconst string alphabets = \"abcdefghijklmnopqrstuvwxyz\"; int ctoi(dchar c){ foreach(int i, a; alphabets) if(c == a) return i; return -1; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n foreach(_; 0 .. rint){\n int n = rint, m = rint;\n int[] as = readln.chomp.map!ctoi.array;\n int[] ps = rint(m).map!(x => x - 1).array;\n\n int[] us = new int[](n); // mistake just after position p (; 0 .. n)\n foreach(p; ps) us[p] += 1;\n\n int[] ans = new int[](26);\n int[] cs = new int[](26);\n foreach(i; 0 .. n){\n cs[as[i]] += 1;\n foreach(k; 0 .. 26) ans[k] += cs[k] * us[i];\n }\n \n foreach(k; 0 .. 26) ans[k] += cs[k];\n\n ans.map!(to!string).join(\" \").writeln;\n }\n\n}"}], "negative_code": [], "src_uid": "51ea912b40b07c1ba097292ffd0cec18"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 a = RD!string;\n\t\tauto b = RD!string;\n\n\t\tauto cnt = new long[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tcnt[i+1] = cnt[i];\n\t\t\tif (a[i] == '1')\n\t\t\t\t++cnt[i+1];\n\t\t\telse\n\t\t\t\t--cnt[i+1];\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong inv;\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tauto x = a[i]-'0';\n\t\t\tauto y = b[i]-'0';\n\t\t\tif ((x^inv) == y) continue;\n\n\t\t\tif (cnt[i+1] != 0)\n\t\t\t{\n\t\t\t\tdebug writeln(\"i:\", i);\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tinv ^= 1;\n\t\t}\n\t\tans[ti] = ok;\n\t}\n\t\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": "// Vicfred\n// https://codeforces.com/contest/1504/problem/B\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 string a, b;\n readf(\"%s\\n\", &a);\n readf(\"%s\\n\", &b);\n \n a ~= '0';\n b ~= '0';\n\n int cumulative = 0;\n bool valid = true;\n for(uint i = 0; i < n; ++i) {\n if(a[i] == '0')\n cumulative += 1;\n else\n cumulative -= 1;\n if((a[i] == b[i]) != (a[i+1] == b[i+1]) && cumulative != 0) {\n valid = false;\n break;\n }\n }\n if(valid)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1504/problem/B\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 string a, b;\n readf(\"%s\\n\", &a);\n readf(\"%s\\n\", &b);\n\n int cumulative = 0;\n bool valid = true;\n for(uint i = 0; i < n - 1; ++i) {\n if(a[i] == '0')\n cumulative += 1;\n else\n cumulative -= 1;\n if((a[i] == b[i]) != (a[i+1] == b[i+1]) && cumulative != 0) {\n valid = false;\n break;\n }\n }\n if(valid)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1504/problem/B\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 string a, b;\n readf(\"%s\\n\", &a);\n readf(\"%s\\n\", &b);\n\n int cumulative = 0;\n bool valid = true;\n for(uint i = 0; i < n - 1; ++i) {\n if(a[i] == '0')\n cumulative += 1;\n else\n cumulative -= 1;\n if((a[i] == b[i]) && a[i+1] != b[i+1] && cumulative != 0) {\n valid = false;\n break;\n }\n }\n if(valid)\n \"YES\".writeln;\n else\n \"NO\".writeln;\n}\n}\n\n"}], "src_uid": "ff95cd4632b2ddf8bb54981634badcae"} {"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 s;\n readf!\"%s\\n\"(s);\n\n /*int best_left = 0;\n int best_right = 0;\n int best_value = int.max;\n int left = 0;\n int right = 0;\n for (int i = 0; i < n; i++) {\n if (s[i] == 'a') {\n left = right;\n right = i;\n\n int value = right - left - 1;\n if ((value < best_value && s[left] == 'a' && s[right] == 'a' && left != right) || (value == best_value && value == 2 && s[left+1] != s[left+2])) {\n best_left = left;\n best_right = right;\n best_value = value;\n }\n }\n }\n\n // output cases\n if (best_value > 2) {\n writeln(-1);\n }\n else if (best_value == 2) {\n if (s[best_left+1] != s[best_left+2]) {\n writeln(4);\n } else writeln(-1);\n }\n else if (best_value == 1 || best_value == 0) {\n writeln(best_value+2);\n }\n else {\n writeln(-1);\n }*/\n int best = -1;\n\n for (int i = 0; i < n-1; i++) {\n if (s[i] == 'a' && s[i+1] == 'a') {\n best = 2;\n }\n }\n\n if (best == 2) {\n writeln(best);\n continue;\n }\n\n for (int i = 0; i < n-2; i++) {\n if (s[i] == 'a' && s[i+1] != 'a' && s[i+2] == 'a') {\n best = 3;\n }\n }\n\n if (best == 3) {\n writeln(best);\n continue;\n }\n\n for (int i = 0; i < n-3; i++) {\n if (s[i] == 'a' && s[i+1] != s[i+2] && s[i+3] == 'a') {\n best = 4;\n }\n }\n\n if (best == 4) {\n writeln(best);\n continue;\n }\n\n for (int i = 0; i < n-6; i++) {\n if (s[i] == 'a' && s[i+1] == s[i+2] && s[i+3] == 'a' && s[i+4] == s[i+5] && s[i+6] == 'a' && s[i+1] != s[i+4]) {\n best = 7;\n }\n }\n\n writeln(best);\n }\n}\n\n/*\ncabbabbcbbcbcbababcbcbababbabcbcaaa\n\nabcbbcbcbababbcbcbcbbbabbcbcbbabbcbcbcbabaabcbcbababca\n\nabba 2\nabbcbbcbcba vs abba -> abba 2\naba vs abba -> aba 1\nabba vs aba -> aba 1\nabcbca vs aba -> aba 1\naa vs aba -> aa 0 -> return\n\n\n\n\"aa\" -> that\n\"aba\"/\"aca\" -> ye\n\"abca\"/\"acba\" -> ye*/\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto w = scan!(dchar[]);\n auto check = new long[n];\n int st = -1;\n for(int i = 0; i < n; ++i){\n if(w[i] == 'a'){\n st = i;\n break;\n }\n }\n if(st == -1){\n writeln(-1);\n return;\n }\n long cntb = 0, cntc = 0;\n ll res = 10;\n for(int i = st+1; i < n; ++i){\n if(w[i] == 'b'){\n ++cntb;\n }else if(w[i] == 'c'){\n ++cntc;\n }else{\n if(cntb <= 1 && cntc <= 1){\n res = min(2 + cntc + cntb, res);\n }\n if(cntb == 2 && !cntc){\n if(check[i-3] == 2){\n res = min(7, res);\n }\n check[i] = 1;\n }else if(cntc == 2 && !cntb){\n if(check[i-3] == 1){\n res = min(7, res);\n }\n check[i] = 2;\n }\n cntb = 0;\n cntc = 0;\n }\n }\n\n if(res > 9){\n writeln(-1);\n }else{\n writeln(res);\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": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto w = scan!(dchar[]);\n auto check = new long[n];\n int st = -1;\n for(int i = 0; i < n; ++i){\n if(w[i] == 'a'){\n st = i;\n break;\n }\n }\n if(st == -1){\n writeln(-1);\n return;\n }\n long cntb = 0, cntc = 0;\n ll res = 10;\n for(int i = st+1; i < n; ++i){\n if(w[i] == 'b'){\n ++cntb;\n }else if(w[i] == 'c'){\n ++cntc;\n }else{\n if(cntb <= 1 && cntc <= 1){\n res = min(2 + cntc + cntb, res);\n }\n if(cntb == 2){\n if(check[i-3] == 2){\n res = min(7, res);\n }\n check[i] = 1;\n }else if(cntc == 2){\n if(check[i-3] == 1){\n res = min(7, res);\n }\n check[i] = 2;\n }\n cntb = 0;\n cntc = 0;\n }\n }\n\n if(res > 9){\n writeln(-1);\n }else{\n writeln(res);\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": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto w = scan!(dchar[]);\n auto check = new long[n];\n int st = -1;\n for(int i = 0; i < n; ++i){\n if(w[i] == 'a'){\n st = i;\n break;\n }\n }\n if(st == -1){\n writeln(-1);\n return;\n }\n long cntb = 0, cntc = 0;\n ll res = 10;\n for(int i = st+1; i < n; ++i){\n if(w[i] == 'b'){\n ++cntb;\n }else if(w[i] == 'c'){\n ++cntc;\n }else{\n if(cntb <= 1 && cntc <= 1){\n res = min(2 + cntc + cntb, res);\n }\n if(cntb == 2){\n if(check[i-3] == 2){\n res = min(7, res);\n }\n check[i] = 1;\n }else if(cntc == 2){\n if(check[i-3] == 1){\n res = min(7, res);\n }\n check[i] = 2;\n }\n cntb = 0;\n cntc = 0;\n }\n }\n\n if(res > 4){\n writeln(-1);\n }else{\n writeln(res);\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": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto w = scan!(dchar[]);\n int st = -1;\n for(int i = 0; i < n; ++i){\n if(w[i] == 'a'){\n st = i;\n break;\n }\n }\n if(st == -1){\n writeln(-1);\n return;\n }\n long cntb = 0, cntc = 0;\n ll res = 10;\n for(int i = st+1; i < n; ++i){\n if(w[i] == 'b'){\n ++cntb;\n }else if(w[i] == 'c'){\n ++cntc;\n }else{\n if(cntb <= 1 && cntc <= 1){\n res = min(2 + cntc + cntb, res);\n }\n cntb = 0;\n cntc = 0;\n }\n }\n if(res > 4){\n writeln(-1);\n }else{\n writeln(res);\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.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 s;\n readf!\"%s\\n\"(s);\n\n /*int best_left = 0;\n int best_right = 0;\n int best_value = int.max;\n int left = 0;\n int right = 0;\n for (int i = 0; i < n; i++) {\n if (s[i] == 'a') {\n left = right;\n right = i;\n\n int value = right - left - 1;\n if ((value < best_value && s[left] == 'a' && s[right] == 'a' && left != right) || (value == best_value && value == 2 && s[left+1] != s[left+2])) {\n best_left = left;\n best_right = right;\n best_value = value;\n }\n }\n }\n\n // output cases\n if (best_value > 2) {\n writeln(-1);\n }\n else if (best_value == 2) {\n if (s[best_left+1] != s[best_left+2]) {\n writeln(4);\n } else writeln(-1);\n }\n else if (best_value == 1 || best_value == 0) {\n writeln(best_value+2);\n }\n else {\n writeln(-1);\n }*/\n int best = -1;\n\n for (int i = 0; i < n-1; i++) {\n if (s[i] == 'a' && s[i+1] == 'a') {\n best = 2;\n }\n }\n\n if (best == 2) {\n writeln(best);\n continue;\n }\n\n for (int i = 0; i < n-2; i++) {\n if (s[i] == 'a' && s[i+1] != 'a' && s[i+2] == 'a') {\n best = 3;\n }\n }\n\n if (best == 3) {\n writeln(best);\n continue;\n }\n\n for (int i = 0; i < n-3; i++) {\n if (s[i] == 'a' && s[i+1] != s[i+2] && s[i+3] == 'a') {\n best = 4;\n }\n }\n\n writeln(best);\n }\n}\n\n/*\ncabbabbcbbcbcbababcbcbababbabcbcaaa\n\nabcbbcbcbababbcbcbcbbbabbcbcbbabbcbcbcbabaabcbcbababca\n\nabba 2\nabbcbbcbcba vs abba -> abba 2\naba vs abba -> aba 1\nabba vs aba -> aba 1\nabcbca vs aba -> aba 1\naa vs aba -> aa 0 -> return\n\n\n\n\"aa\" -> that\n\"aba\"/\"aca\" -> ye\n\"abca\"/\"acba\" -> ye*/\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 s;\n readf!\"%s\\n\"(s);\n\n int best_left = 0;\n int best_right = 0;\n int best_value = int.max;\n int left = 0;\n int right = 0;\n for (int i = 0; i < n; i++) {\n if (s[i] == 'a') {\n left = right;\n right = i;\n\n int value = right - left - 1;\n if ((value < best_value && s[left] == 'a' && s[right] == 'a' && left != right) || (value == best_value && value == 2 && s[left+1] != s[left+2])) {\n best_left = left;\n best_right = right;\n best_value = value;\n }\n }\n }\n\n // output cases\n if (best_value > 2) {\n writeln(-1);\n }\n else if (best_value == 2) {\n if (s[best_left+1] != s[best_left+2]) {\n writeln(4);\n } else writeln(-1);\n }\n else if (best_value == 1 || best_value == 0) {\n writeln(best_value+2);\n }\n else {\n writeln(\"something went terribly wrong...\");\n }\n }\n}\n\n/*\ncabbabbcbbcbcbababcbcbababbabcbcaaa\n\nabba 2\nabbcbbcbcba vs abba -> abba 2\naba vs abba -> aba 1\nabba vs aba -> aba 1\nabcbca vs aba -> aba 1\naa vs aba -> aa 0 -> return\n\n\n\n\"aa\" -> that\n\"aba\"/\"aca\" -> ye\n\"abca\"/\"acba\" -> ye*/\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 s;\n readf!\"%s\\n\"(s);\n\n int best_left = 0;\n int best_right = 0;\n int best_value = int.max;\n int left = 0;\n int right = 0;\n for (int i = 0; i < n; i++) {\n if (s[i] == 'a') {\n left = right;\n right = i;\n\n int value = right - left - 1;\n if (value < best_value && s[left] == 'a' && s[right] == 'a' && left != right) {\n best_left = left;\n best_right = right;\n best_value = value;\n }\n }\n }\n\n // output cases\n if (best_value > 2) {\n writeln(-1);\n }\n else if (best_value == 2) {\n if (s[best_left+1] != s[best_left+2]) {\n writeln(4);\n } else writeln(-1);\n }\n else if (best_value == 1 || best_value == 0) {\n writeln(best_value+2);\n }\n else {\n writeln(\"something went terribly wrong...\");\n }\n }\n}\n\n/*\ncabbabbcbbcbcbababcbcbababbabcbcaaa\n\nabba 2\nabbcbbcbcba vs abba -> abba 2\naba vs abba -> aba 1\nabba vs aba -> aba 1\nabcbca vs aba -> aba 1\naa vs aba -> aa 0 -> return\n\n\n\n\"aa\" -> that\n\"aba\"/\"aca\" -> ye\n\"abca\"/\"acba\" -> ye*/\n"}], "src_uid": "c2f3d09674190f90c940f134c3e22afe"} {"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 << 10;\n\nvoid main ()\n{\n\tint n, k, x;\n\twhile (readf (\" %s %s %s\", &n, &k, &x) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tint [limit] [2] c;\n\t\tint b = 0;\n\t\tforeach (v; a)\n\t\t{\n\t\t\tc[b][v] += 1;\n\t\t}\n\n\t\tforeach (step; 0..k)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tc[b][] = 0;\n\t\t\tint p = 0;\n\t\t\tforeach (v; 0..limit)\n\t\t\t{\n\t\t\t\tint d = c[!b][v] >> 1;\n\t\t\t\tc[b][v] += d;\n\t\t\t\tc[b][v ^ x] += d;\n\t\t\t\tif (c[!b][v] & 1)\n\t\t\t\t{\n\t\t\t\t\tc[b][v ^ (p ? 0 : x)] += 1;\n\t\t\t\t\tp ^= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint lo = int.max;\n\t\tint hi = int.min;\n\t\tforeach (v; 0..limit)\n\t\t{\n\t\t\tif (c[b][v])\n\t\t\t{\n\t\t\t\tlo = min (lo, v);\n\t\t\t\thi = max (hi, v);\n\t\t\t}\n\t\t}\n\t\twriteln (hi, \" \", lo);\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, k, x;\n readf(\"%s %s %s\", &n, &k, &x);\n readln;\n \n int [1 << 11][2] vals;\n \n readln.chomp.split.map!(to!int).each!(v => vals[0][v] += 1);\n \n debug { vals[0][0 .. 20].writeln; }\n \n foreach (i; 0 .. k) {\n int step = i & 1;\n vals[step ^ 1][] = 0;\n bool oddstart = true;\n foreach (v; 0 .. 1 << 11) {\n int cnt = vals[step][v];\n int modif = 0;\n if (cnt % 2 == 0) { modif = cnt / 2; } \n else {\n modif = cnt / 2 + (oddstart ? 1 : 0);\n oddstart ^= 1;\n }\n \n vals[step ^ 1][v ^ x] += modif;\n vals[step ^ 1][v] += cnt - modif;\n }\n }\n \n debug { vals[k & 1][1 .. 20].writeln; }\n \n int a, b;\n foreach (v; 0 .. 1 << 11) {\n if (vals[k & 1][v] > 0) { a = v; }\n }\n \n foreach_reverse (v; 0 .. 1 << 11) {\n if (vals[k & 1][v] > 0) { b = v; }\n }\n \n writeln(a, ' ', b);\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, x;\n readf(\"%s %s %s\", &n, &k, &x);\n readln;\n \n int [1 << 11][2] vals;\n \n readln.chomp.split.map!(to!int).each!(v => vals[0][v] += 1);\n \n debug { vals[0][1 .. 20].writeln; }\n \n foreach (i; 0 .. k) {\n int step = i & 1;\n vals[step ^ 1][] = 0;\n bool oddstart = true;\n foreach (v; 1 .. 1 << 11) {\n int cnt = vals[step][v];\n int modif = 0;\n if (cnt % 2 == 0) { modif = cnt / 2; } \n else {\n modif = cnt / 2 + (oddstart ? 1 : 0);\n oddstart ^= 1;\n }\n \n vals[step ^ 1][v ^ x] += modif;\n vals[step ^ 1][v] += cnt - modif;\n }\n }\n \n debug { vals[k & 1][1 .. 20].writeln; }\n \n int a, b;\n foreach (v; 1 .. 1 << 11) {\n if (vals[k & 1][v] > 0) { a = v; }\n }\n \n foreach_reverse (v; 1 .. 1 << 11) {\n if (vals[k & 1][v] > 0) { b = v; }\n }\n \n writeln(a, ' ', b);\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 << 10;\n\nvoid main ()\n{\n\tint n, k, x;\n\twhile (readf (\" %s %s %s\", &n, &k, &x) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tint [limit] [2] c;\n\t\tint b = 0;\n\t\tforeach (v; a)\n\t\t{\n\t\t\tc[b][v] += 1;\n\t\t}\n\n\t\tforeach (step; 0..k)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tc[b][] = 0;\n\t\t\tint p = 0;\n\t\t\tforeach (v; 0..limit)\n\t\t\t{\n\t\t\t\tint d = c[!b][v] >> 1;\n\t\t\t\tc[b][v] += d;\n\t\t\t\tc[!b][v ^ x] += d;\n\t\t\t\tif (c[!b][v] & 1)\n\t\t\t\t{\n\t\t\t\t\tc[b][v ^ (p ? 0 : x)] += 1;\n\t\t\t\t\tp ^= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint lo = int.max;\n\t\tint hi = int.min;\n\t\tforeach (v; 0..limit)\n\t\t{\n\t\t\tif (c[b][v])\n\t\t\t{\n\t\t\t\tlo = min (lo, v);\n\t\t\t\thi = max (hi, v);\n\t\t\t}\n\t\t}\n\t\twriteln (hi, \" \", lo);\n\t}\n}\n"}], "src_uid": "0fdac23c851841735105f4b1f1788d43"} {"source_code": "import std.stdio, std.string;\n\nbool ok(bool[long] c, long s, long ps)\n{\n if (ps >= s - ps && ((ps - (s - ps)) & 1) == 0)\n {\n auto v = (ps - (s - ps)) >> 1;\n if (v in c)\n {\n return true;\n }\n }\n return false;\n}\n\nvoid solve(int[] a)\n{\n auto n = cast(int)a.length;\n long s = 0;\n foreach (i; 0 .. n)\n {\n s += a[i];\n }\n long ps = a[0];\n for (int i = 1; i < n; ++ i)\n {\n if (ps == s - ps)\n {\n writeln(\"YES\");\n return;\n }\n ps += a[i];\n }\n foreach (i; 0 .. n)\n {\n if (a[i] == s - a[i])\n {\n writeln(\"YES\");\n return;\n }\n }\n bool[long] c;\n c[a[0]] = true;\n ps = a[0];\n for (int i = 1; i < n - 1; ++ i)\n {\n c[a[i]] = true;\n ps += a[i];\n if (ok(c, s, ps))\n {\n writeln(\"YES\");\n return;\n }\n }\n c.clear();\n c[a[n - 1]] = true;\n ps = a[n - 1];\n for (int i = n - 2; i > 0; -- i)\n {\n c[a[i]] = true;\n ps += a[i];\n if (ok(c, s, ps))\n {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\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, 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; }\n\nvoid solve(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n ll summ = 0;\n foreach(el; arr){\n summ += el;\n }\n if(summ % 2){\n writeln(\"NO\"); \n return;\n }\n bool[long] seen;\n seen[0] = 1;\n long req = (summ/2);\n ll cursum = 0;\n foreach(el; arr){\n cursum += el;\n if(cursum >= req && seen.get(cursum - req, 0) == 1){\n writeln(\"YES\");\n return;\n }\n seen[el] = 1;\n }\n seen.clear;\n cursum = 0;\n foreach_reverse(el; arr){\n cursum += el;\n if(cursum >= req && seen.get(cursum - req, 0) == 1){\n writeln(\"YES\");\n return;\n }\n seen[el] = 1;\n }\n writeln(\"NO\");\n}\n\nint main(){\n long t = 1;\n while(t--) solve();\n stdout.flush;\n return 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;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto a = next!long(n);\n long rightSum = cast(long) a.sum;\n auto rightSet = redBlackTree!(true, long)(a);\n long leftSum = 0;\n auto leftSet = redBlackTree!(true, long)();\n foreach(i, ai; a)\n {\n rightSum -= ai;\n rightSet.removeKey(ai);\n leftSum += ai;\n leftSet.insert(ai);\n if (leftSum < rightSum)\n\t{\n\t if ((rightSum - leftSum) % 2 == 0 &&\n\t ((rightSum - leftSum) / 2) in rightSet)\n\t return writeln(\"YES\");\n\t}\n else if (leftSum > rightSum)\n\t{\n\t if ((leftSum - rightSum) % 2 == 0 &&\n\t ((leftSum - rightSum) / 2) in leftSet)\n\t return writeln(\"YES\");\n\t}\n else\n\t{\n\t return writeln(\"YES\");\n\t}\n }\n return writeln(\"NO\");\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": "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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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!lint;\n\t\tRedBlackTree!lint q=new RedBlackTree!lint;\n\t\tq.insert(a[0]);\n\t\tlong s=a[0];\n\t\tlong sm=a.sum;\n\t\tif(sm&1){writeln(\"NO\");continue loop;}\n\t\tsm/=2;\n\t\tforeach(i;1..n)\n\t\t{\n\t\t\tq.insert(a[i]);\n\t\t\ts+=a[i];\n\t\t\tif(!q.equalRange(s-sm).empty){writeln(\"YES\");continue loop;}\n\t\t}\n\t\ts=0;\n\t\tq.clear;\n\t\ta.reverse;\n\t\ts=a[0];\n\t\tq.insert(a[0]);\n\t\tforeach(i;1..n)\n\t\t{\n\t\t\tq.insert(a[i]);\n\t\t\ts+=a[i];\n\t\t\tif(!q.equalRange(s-sm).empty){writeln(\"YES\");continue loop;}\n\t\t}\n\t\twriteln(\"NO\");\n\n\t}\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\n\nbool ok(bool[long] c, long s, long ps)\n{\n if (ps >= s - ps && ((ps - (s - ps)) & 1) == 0)\n {\n auto v = (ps - (s - ps)) >> 1;\n if (v in c)\n {\n return true;\n }\n }\n return false;\n}\n\nvoid solve(int[] a)\n{\n auto n = cast(int)a.length;\n long s = 0;\n foreach (i; 0 .. n)\n {\n s += a[i];\n }\n long ps = a[0];\n for (int i = 1; i < n; ++ i)\n {\n if (ps == s - ps)\n {\n writeln(\"YES\");\n return;\n }\n ps += a[i];\n }\n bool[long] c;\n c[a[0]] = true;\n ps = a[0];\n for (int i = 1; i < n - 1; ++ i)\n {\n c[a[i]] = true;\n ps += a[i];\n if (ok(c, s, ps))\n {\n writeln(\"YES\");\n return;\n }\n }\n c.clear();\n c[a[n - 1]] = true;\n ps = a[n - 1];\n for (int i = n - 2; i > 0; -- i)\n {\n c[a[i]] = true;\n ps += a[i];\n if (ok(c, s, ps))\n {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\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}"}, {"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 int n;\n @Dim(\"n\") int[] a;\n\n void solve(long tc = -1)\n {\n auto prefix_set = redBlackTree!(true, int)();\n auto suffix_set = redBlackTree!(true, int)(a);\n int prefix_sum = 0;\n int suffix_sum = a.sum;\n foreach(i, ai; a)\n {\n prefix_set.insert(ai);\n suffix_set.removeKey(ai);\n prefix_sum += ai;\n suffix_sum -= ai;\n if (suffix_sum == prefix_sum)\n return writeln(\"YES\");\n if ((suffix_sum - prefix_sum) % 2 == 0 &&\n (suffix_sum - prefix_sum) / 2 in suffix_set)\n return writeln(\"YES\");\n if ((prefix_sum - suffix_sum) % 2 == 0 &&\n (prefix_sum - suffix_sum) / 2 in prefix_set)\n return writeln(\"YES\");\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.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 int n;\n @Dim(\"n\") int[] a;\n\n void solve(long tc = -1)\n {\n auto prefix_set = redBlackTree!(true, int)();\n auto suffix_set = redBlackTree!(true, int)(a);\n long prefix_sum = 0;\n long suffix_sum = a.sum;\n foreach(i, ai; a)\n {\n prefix_set.insert(ai);\n suffix_set.removeKey(ai);\n prefix_sum += ai;\n suffix_sum -= ai;\n if (suffix_sum == prefix_sum)\n return writeln(\"YES\");\n if ((suffix_sum - prefix_sum) % 2 == 0 &&\n cast(int)((suffix_sum - prefix_sum) / 2) in suffix_set)\n return writeln(\"YES\");\n if ((prefix_sum - suffix_sum) % 2 == 0 &&\n cast(int)((prefix_sum - suffix_sum) / 2) in prefix_set)\n return writeln(\"YES\");\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.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 int n;\n @Dim(\"n\") int[] a;\n\n void solve(long tc = -1)\n {\n auto prefix_set = redBlackTree!(true, int)();\n auto suffix_set = redBlackTree!(true, int)(a);\n long prefix_sum = 0;\n long suffix_sum = a.map!(ai => cast(long) ai).sum;\n foreach(i, ai; a)\n {\n prefix_set.insert(ai);\n suffix_set.removeKey(ai);\n prefix_sum += ai;\n suffix_sum -= ai;\n if (suffix_sum == prefix_sum)\n return writeln(\"YES\");\n if ((suffix_sum - prefix_sum) % 2 == 0 &&\n cast(int)((suffix_sum - prefix_sum) / 2) in suffix_set)\n return writeln(\"YES\");\n if ((prefix_sum - suffix_sum) % 2 == 0 &&\n cast(int)((prefix_sum - suffix_sum) / 2) in prefix_set)\n return writeln(\"YES\");\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"}], "src_uid": "27b93795ffc771b47b995e2b83f7b945"} {"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 bool[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RDA;\n\t\t//s.sort!\"a > b\"();\n\t\tauto heap = heapify!\"a > b\"(s);\n\t\tbool ok;\n\t\tlong[] stack;\n\t\twhile (!heap.empty)\n\t\t{\n\t\t\tauto x = heap.front; heap.removeFront;\n\t\t\tif (x == 2048)\n\t\t\t{\n\t\t\t\tok = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (stack.length != 2)\n\t\t\t{\n\t\t\t\tstack ~= x;\n\t\t\t}\n\t\t\tdebug writeln(stack);\n\t\t\tif (stack.length == 2)\n\t\t\t{\n\t\t\t\tif (stack[0] == stack[1])\n\t\t\t\t{\n\t\t\t\t\theap.insert(stack[0] * 2);\n\t\t\t\t\tstack = [];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tstack = stack[1..$];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans[i] = ok;\n\t}\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 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\tint n = rint;\n\t\tlong[] as = rlong(n);\n\t\tlong s;\n\t\tforeach(a; as) if(a <= 2048) s += a;\n\t\t\n\t\tif(s >= 2048) \"Yes\".writeln;\n\t\telse \"No\".writeln; \n\t}\n}\n"}], "negative_code": [], "src_uid": "b40059fe9cbdb0cc3b64c3e463900849"} {"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 auto B = readln.split.map!(to!int).array;\n auto C = new Tuple!(int, int)[](N);\n auto D = new int[](N);\n\n A.sort!\"a > b\"();\n foreach (i; 0..N) C[i] = tuple(B[i], i);\n C.sort!\"a[0] < b[0]\"();\n\n\n foreach (i; 0..N) {\n D[C[i][1]] = A[i];\n }\n\n D.map!(d => d.to!string).join(\" \").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 M = readInt();\n auto A = new long[M];\n foreach (i; 0 .. M) {\n A[i] = readLong();\n }\n auto B = new long[M];\n foreach (i; 0 .. M) {\n B[i] = readLong();\n }\n \n auto as = new Tuple!(long, int)[M];\n auto bs = new Tuple!(long, int)[M];\n foreach (i; 0 .. M) {\n as[i] = tuple(A[i], i);\n bs[i] = tuple(B[i], i);\n }\n as.sort;\n bs.sort;\n \n auto ans = new long[M];\n foreach (i; 0 .. M) {\n ans[bs[i][1]] = as[M - 1 - i][0];\n }\n \n foreach (i; 0 .. M) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln;\n }\n } catch (EOFException e) {\n }\n}\n"}, {"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 ys = getVals!int();\n auto ix = new int[n];\n auto iy = new int[n];\n makeIndex!(\"a > b\")(xs, ix);\n makeIndex!(\"a < b\")(ys, iy);\n // writeln(ix.map!(a => xs[a]));\n // writeln(iy.map!(a => ys[a]));\n auto zs = new int[n];\n for (int i = 0; i < n; i++) {\n zs[iy[i]] = xs[ix[i]];\n }\n writeln(to!(string[])(zs).join(\" \"));\n}\n\n"}], "negative_code": [], "src_uid": "c51e15aeb3f287608a26b85865546e85"} {"source_code": "import std.stdio, std.algorithm;\n\nimmutable MOD = 95542721, P = 48;\n\nint cb(int x) {\n return 1L * x * x % MOD * x % MOD;\n}\n\nclass T {\n int[P] d;\n int l, r, sh, lz;\n T lt, rt;\n\n this(int L, int R, int[] a) {\n l = L; r = R;\n if (l + 1 == r) {\n d[0] = a[l];\n foreach (i; 1..P) d[i] = cb(d[i - 1]);\n return;\n }\n int m = l + (r - l >> 1);\n lt = new T(l, m, a); rt = new T(m, r, a);\n pu;\n }\n\n void pd() {\n if (lz) {\n (sh += lz) %= P;\n if (lt !is null) {\n (lt.lz += lz) %= P;\n (rt.lz += lz) %= P;\n }\n lz = 0;\n }\n }\n\n void pu() {\n sh = 0;\n foreach (i; 0..P)\n d[i] = (lt.d[(i + lt.sh) % P] + rt.d[(i + rt.sh) % P]) % MOD;\n }\n\n int q(int L, int R) {\n if (R <= l || r <= L) return 0;\n pd;\n if (L <= l && r <= R) return d[sh];\n return (lt.q(L, R) + rt.q(L, R)) % MOD;\n }\n\n void u(int L, int R) {\n if (L <= l && r <= R) {\n (lz += 1) %= P;\n pd;\n return;\n }\n pd;\n if (R <= l || r <= L) return;\n lt.u(L, R); rt.u(L, R);\n pu;\n }\n}\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n\n auto a = new int[n];\n foreach (i; 0..n) scanf(\" %d\", &a[i]);\n\n T tr = new T(0, n, a);\n\n int q;\n readf(\" %d\", &q);\n foreach (i; 0..q) {\n int t, l, r;\n scanf(\" %d %d %d\", &t, &l, &r);\n --l;\n if (t == 1) printf(\"%d\\n\", tr.q(l, r));\n else tr.u(l, r);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm;\n\nimmutable M = 95542721, P = 48;\n\nint cb(int x) {\n return 1L * x * x % M * x % M;\n}\n\nclass T {\n int[P] d;\n int l, r, sh, lz;\n T lt, rt;\n\n this(int L, int R, int[] a) {\n l = L; r = R;\n if (l + 1 == r) {\n d[0] = a[l];\n foreach (i; 1..P) d[i] = cb(d[i - 1]);\n return;\n }\n int m = l + (r - l >> 1);\n lt = new T(l, m, a); rt = new T(m, r, a);\n pu;\n }\n\n void pu() {\n foreach (i; 0..P)\n d[i] = (lt.d[(i + lt.lz) % P] + rt.d[(i + rt.lz) % P]) % M;\n }\n\n int q(int L, int R, int LZ = 0) {\n if (R <= l || r <= L) return 0;\n if (L <= l && r <= R) return d[(LZ + lz) % P];\n return (lt.q(L, R, LZ + lz) + rt.q(L, R, LZ + lz)) % M;\n }\n\n void u(int L, int R) {\n if (L <= l && r <= R) {\n (lz += 1) %= P;\n return;\n }\n if (R <= l || r <= L) return;\n lt.u(L, R); rt.u(L, R);\n pu;\n }\n}\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n\n auto a = new int[n];\n foreach (i; 0..n) scanf(\" %d\", &a[i]);\n\n T tr = new T(0, n, a);\n\n int q;\n readf(\" %d\", &q);\n foreach (i; 0..q) {\n int t, l, r;\n scanf(\" %d %d %d\", &t, &l, &r);\n --l;\n if (t == 1) printf(\"%d\\n\", tr.q(l, r));\n else tr.u(l, r);\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm;\n\nimmutable M = 95542721, P = 48;\n\nint cb(int x) {\n return 1L * x * x % M * x % M;\n}\n\nclass T {\n int[P] d;\n int l, r, lz;\n T lt, rt;\n\n this(int L, int R, int[] a) {\n l = L; r = R;\n if (l + 1 == r) {\n d[0] = a[l];\n foreach (i; 1..P) d[i] = cb(d[i - 1]);\n return;\n }\n int m = l + (r - l >> 1);\n lt = new T(l, m, a); rt = new T(m, r, a);\n pu;\n }\n\n void pu() {\n foreach (i; 0..P)\n d[i] = (lt.d[(i + lt.lz) % P] + rt.d[(i + rt.lz) % P]) % M;\n }\n\n int q(int L, int R, int LZ = 0) {\n if (R <= l || r <= L) return 0;\n if (L <= l && r <= R) return d[(LZ + lz) % P];\n return (lt.q(L, R, LZ + lz) + rt.q(L, R, LZ + lz)) % M;\n }\n\n void u(int L, int R) {\n if (L <= l && r <= R) {\n (lz += 1) %= P;\n return;\n }\n if (R <= l || r <= L) return;\n lt.u(L, R); rt.u(L, R);\n pu;\n }\n}\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n\n auto a = new int[n];\n foreach (i; 0..n) scanf(\" %d\", &a[i]);\n\n T tr = new T(0, n, a);\n\n int q;\n readf(\" %d\", &q);\n foreach (i; 0..q) {\n int t, l, r;\n scanf(\" %d %d %d\", &t, &l, &r);\n --l;\n if (t == 1) printf(\"%d\\n\", tr.q(l, r));\n else tr.u(l, r);\n }\n}\n"}, {"source_code": "import std.stdio;\n\nimmutable M = 95542721, P = 48;\n\nint cb(int x) {\n return 1L * x * x % M * x % M;\n}\n\nclass T {\n int[P] d;\n int l, r, lz;\n T lt, rt;\n\n this(int L, int R, int[] a) {\n l = L; r = R;\n if (l + 1 == r) {\n d[0] = a[l];\n foreach (i; 1..P) d[i] = cb(d[i - 1]);\n return;\n }\n int m = l + (r - l >> 1);\n lt = new T(l, m, a); rt = new T(m, r, a);\n pu;\n }\n\n void pu() {\n foreach (i; 0..P)\n d[i] = (lt.d[(i + lt.lz) % P] + rt.d[(i + rt.lz) % P]) % M;\n }\n\n int q(int L, int R, int LZ = 0) {\n if (R <= l || r <= L) return 0;\n if (L <= l && r <= R) return d[(LZ + lz) % P];\n return (lt.q(L, R, LZ + lz) + rt.q(L, R, LZ + lz)) % M;\n }\n\n void u(int L, int R) {\n if (R <= l || r <= L) return;\n if (L <= l && r <= R) { (lz += 1) %= P; return; }\n lt.u(L, R); rt.u(L, R);\n pu;\n }\n}\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n\n auto a = new int[n];\n foreach (i; 0..n) scanf(\" %d\", &a[i]);\n\n T tr = new T(0, n, a);\n\n int q;\n readf(\" %d\", &q);\n foreach (i; 0..q) {\n int t, l, r;\n scanf(\" %d %d %d\", &t, &l, &r);\n --l;\n if (t == 1) printf(\"%d\\n\", tr.q(l, r));\n else tr.u(l, r);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm;\n\nimmutable MOD = 95542721, P = 48;\n\nint cb(int x) {\n return 1L * x * x % MOD * x % MOD;\n}\n\nclass T {\n int[P] d;\n int l, r, lz;\n T lt, rt;\n\n this(int L, int R, int[] a) {\n l = L; r = R;\n if (l + 1 == r) {\n d[0] = a[l];\n foreach (i; 1..P) d[i] = cb(d[i - 1]);\n return;\n }\n int m = l + (r - l >> 1);\n lt = new T(l, m, a); rt = new T(m, r, a);\n pu;\n }\n\n void pu() {\n lz = 0;\n foreach (i; 0..P) d[i] = (lt.d[(i + lt.lz) % P] + rt.d[(i + rt.lz) % P]) % MOD;\n }\n\n int q(int L, int R, int LZ = 0) {\n if (R <= l || r <= L) return 0;\n if (L <= l && r <= R) return d[(LZ + lz) % P];\n return (lt.q(L, R, LZ + lz) + rt.q(L, R, LZ + lz)) % MOD;\n }\n\n void u(int L, int R, int LZ = 1) {\n if (L <= l && r <= R) {\n (lz += LZ) %= P;\n return;\n }\n if (R <= l || r <= L) return;\n lt.u(L, R, LZ + lz); rt.u(L, R, LZ + lz);\n pu;\n }\n}\n\nvoid main() {\n int n;\n readf(\" %d\", &n);\n\n auto a = new int[n];\n foreach (i; 0..n) scanf(\" %d\", &a[i]);\n\n T tr = new T(0, n, a);\n\n int q;\n readf(\" %d\", &q);\n foreach (i; 0..q) {\n int t, l, r;\n scanf(\" %d %d %d\", &t, &l, &r);\n --l;\n if (t == 1) printf(\"%d\\n\", tr.q(l, r));\n else tr.u(l, r);\n }\n}\n"}], "src_uid": "00c895db2071f787a336d13f3cdda65b"} {"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\nuint xrand() {\n static uint x = 314159265, y = 358979323, z = 846264338, w = 327950288;\n uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;\n}\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\nint N, S, X;\ndebug {\n int[] V, E;\n}\n\nalias List = Tuple!(int, \"value\", int, \"next\");\nList Ask(int i) {\n List ret;\n debug {\n ret.value = V[i];\n ret.next = E[i];\n } else {\n writeln(\"? \", i + 1);\n stdout.flush;\n ret.value = readInt();\n ret.next = readInt() - 1;\n }\n debug {\n writeln(\"Ask \", i, \" = \", ret);\n }\n return ret;\n}\n\nvoid Answer(int v) {\n writeln(\"! \", v);\n stdout.flush;\n import core.stdc.stdlib;\n exit(0);\n}\n\nvoid main() {\n N = readInt();\n S = readInt() - 1;\n X = readInt();\n debug {\n V = new int[N];\n E = new int[N];\n foreach (i; 0 .. N) {\n V[i] = readInt();\n E[i] = readInt() - 1;\n }\n }\n \n auto list = new List[N];\n list[] = List(-58, -58);\n \n list[S] = Ask(S);\n if (list[S].value >= X) {\n Answer(list[S].value);\n }\n \n int[] perm = iota(N).array;\n foreach (j; 0 .. N) {\n swap(perm[xrand() % (j + 1)], perm[j]);\n }\n \n int im = S;\n const m = cast(int)(floorSqrt(N));\n foreach (j; 0 .. m) {\n const i = perm[j];\n list[i] = Ask(i);\n if (list[i].value < X) {\n if (list[im].value < list[i].value) {\n im = i;\n }\n }\n }\n \n for (int i = im; ; ) {\n i = list[i].next;\n if (i < 0) {\n Answer(-1);\n }\n list[i] = Ask(i);\n if (list[i].value >= X) {\n Answer(list[i].value);\n }\n }\n}\n", "positive_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;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, s, x;\n sc.read(n, s, x); s--;\n int[] v = new int[n];\n int[] nx = new int[n];\n void query(int p) {\n writeln(\"? \", p+1);\n stdout.flush;\n sc.read(v[p], nx[p]);\n if (nx[p] != -1) nx[p]--;\n }\n void ans(int x) {\n writeln(\"! \", x);\n stdout.flush;\n }\n import std.random;\n auto gen = Random(unpredictableSeed);\n query(s);\n if (x <= v[s]) {\n ans(v[s]);\n return 0;\n }\n int ma = v[s], mp = s;\n foreach (ph; 0..999) {\n int p = uniform(0, n);\n query(p);\n if (ma < v[p] && v[p] < x) {\n ma = v[p];\n mp = p;\n }\n }\n while (mp != -1) {\n query(mp);\n if (x <= v[mp]) {\n ans(v[mp]);\n return 0;\n }\n mp = nx[mp];\n }\n ans(-1);\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"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\tif (val == -1)\n\t\t\tassert(0);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tauto f = sort(d);\n\tauto pos = cast(int)(f.lowerBound(tuple(x, 0, 0)).length) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! \", d[0][0]);\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\twhile (h[0] < x)\n\t{\n\t\tif (h[2] == -1)\n\t\t{\n\t\t\twriteln(\"! \", -1);\n\t\t\tstdout.flush;\n\t\t\treturn;\n\t\t}\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t\tif (h[0] == -1)\n\t\t\tassert(0);\n\t}\n\twriteln(\"! \", h[0]);\n\tstdout.flush;\n}\n"}, {"source_code": "module solution;\nimport std.algorithm;\nimport std.array;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int half = 999;\nimmutable int NA = -1;\n\nvoid main ()\n{\n//\trndGen.seed (12526362);\n\tint n, start, x;\n\treadf (\" %s %s %s\", &n, &start, &x);\n\talias Node = Tuple !(int, q{value}, int, q{next});\n\tauto a = new Node [n + 1];\n\ta[] = Node (NA, NA);\n\tauto p = n.iota.array;\n\trandomShuffle (p);\n\tp[] += 1;\n\tp = p.take (min (half, n)).array;\n\n\tvoid ask (int c)\n\t{\n\t\tif (a[c].value != NA)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\twriteln (\"? \", c);\n\t\tstdout.flush ();\n\t\treadf (\" %s %s\", &a[c].value, &a[c].next);\n\t}\n\n\tvoid answer (int v)\n\t{\n\t\twriteln (\"! \", v);\n\t\tstdout.flush ();\n\t}\n\n\task (start);\n\tint closest = start;\n\tforeach (c; p)\n\t{\n\t\task (c);\n\t\tif (a[c].value < x)\n\t\t{\n\t\t\tif (a[closest].value < a[c].value)\n\t\t\t{\n\t\t\t\tclosest = c;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (i; 0..half)\n\t{\n\t\task (closest);\n\t\tif (a[closest].value >= x)\n\t\t{\n\t\t\tanswer (a[closest].value);\n\t\t\treturn;\n\t\t}\n\t\tif (a[closest].next == NA)\n\t\t{\n\t\t\tanswer (NA);\n\t\t\treturn;\n\t\t}\n\t\tclosest = a[closest].next;\n\t}\n\n\tassert (false);\n}\n"}], "negative_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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tsort(d);\n\tauto pos = lowb(d, tuple(x, 0, 0)) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! -1\");\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. min(n - 1, 999))\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t}\n\twriteln(\"! \", h[0]);\n\tstdout.flush;\n}\n"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tsort(d);\n\tauto pos = lowb(d, tuple(x, 0, 0)) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! \", d[0][0]);\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. min(n - 1, 999))\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\tif (h[2] == -1)\n\t\t{\n\t\t\twriteln(\"! \", -1);\n\t\t\tstdout.flush;\n\t\t\treturn;\n\t\t}\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t}\n\twriteln(\"! \", h[0]);\n\tstdout.flush;\n}\n"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\tauto gen = Random(unpredictableSeed);\n\tforeach (_; 0 .. 999)\n\t{\n\t\tint id = uniform(1, n, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tsort(d);\n\tauto pos = lowb(d, tuple(x, 0, 0)) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! -1\");\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. 1000 - 1)\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t}\n\twriteln(h[1]);\n}\n"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\tif (val == -1)\n\t\t\tassert(0);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tauto f = sort(d);\n\tauto pos = cast(int)(f.lowerBound(tuple(x, 0, 0)).length) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! \", d[0][0]);\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. min(n - 1, 999))\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\tif (h[2] == -1)\n\t\t{\n\t\t\twriteln(\"! \", -1);\n\t\t\tstdout.flush;\n\t\t\treturn;\n\t\t}\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t\tif (h[0] == -1)\n\t\t\tassert(0);\n\t}\n\twriteln(\"! \", h[0]);\n\tstdout.flush;\n}\n"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tsort(d);\n\tauto pos = lowb(d, tuple(x, 0, 0)) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! \", d[0][0]);\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. min(n - 1, 999))\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\tif (h[2] == -1)\n\t\t{\n\t\t\twriteln(\"! \", -1);\n\t\t\tstdout.flush;\n\t\t\treturn;\n\t\t}\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t\tif (h[0] == -1)\n\t\t\tassert(0);\n\t}\n\twriteln(\"! \", h[0]);\n\tstdout.flush;\n}\n"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\tif (val == -1)\n\t\t\tassert(0);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tsort(d);\n\tauto pos = lowb(d, tuple(x, 0, 0)) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! \", d[0][0]);\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. min(n - 1, 999))\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\tif (h[2] == -1)\n\t\t{\n\t\t\twriteln(\"! \", -1);\n\t\t\tstdout.flush;\n\t\t\treturn;\n\t\t}\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t\tif (h[0] == -1)\n\t\t\tassert(0);\n\t}\n\twriteln(\"! \", h[0]);\n\tstdout.flush;\n}\n"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tsort(d);\n\tauto pos = lowb(d, tuple(x, 0, 0)) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! \", d[0][0]);\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. min(n - 1, 999))\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t}\n\twriteln(\"! \", h[0]);\n\tstdout.flush;\n}\n"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\tif (val == -1)\n\t\t\tassert(0);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tsort(d);\n\tauto pos = lowb(d, tuple(x, 0, 0)) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! \", d[0][0]);\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. min(n - 1, 999))\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\tif (h[2] == -1)\n\t\t{\n\t\t\twriteln(\"! \", -1);\n\t\t\tstdout.flush;\n\t\t\treturn;\n\t\t}\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t\tif (h[0] == -1)\n\t\t\tassert(0);\n\t}\n\twriteln(\"! \", h[0]);\n\tstdout.flush;\n}\n"}, {"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\t// freopen(\"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\t// int n;\n\t// loop: while (read(n))\n\t// {\n\n\t// }\n\tauto gen = Random(unpredictableSeed);\n\t/*foreach (i; 0 .. 4)\n\t{\n\t\twriteln(uniform(1, 6, gen));\n\t}*/\n\tint n, st, x;\n\tread(n, st, x);\n\twriteln(\"? \", st);\n\tTuple!(int, int, int)[] d;\n\tstdout.flush;\n\tint val, nx;\n\tread(val, nx);\n\td ~= tuple(val, st, nx);\n\n\tforeach (_; 0 .. min(n - 1, 999))\n\t{\n\t\tint id = uniform(1, n + 1, gen);\n\t\twriteln(\"? \", id);\n\t\tstdout.flush;\n\t\tread(val, nx);\n\t\td ~= tuple(val, st, nx);\n\t}\n\tsort(d);\n\tauto pos = lowb(d, tuple(x, 0, 0)) - 1;\n\tif (pos < 0)\n\t{\n\t\twriteln(\"! -1\");\n\t\tstdout.flush;\n\t\treturn;\n\t}\n\tauto h = d[pos];\n\tforeach (i; 0 .. min(n - 1, 999))\n\t{\n\t\tif (h[0] >= x)\n\t\t\tbreak;\n\t\twriteln(\"? \", h[2]);\n\t\tstdout.flush;\n\t\th[1] = h[2];\n\t\tread(h[0], h[2]);\n\t}\n\twriteln(\"! \", h[1]);\n\tstdout.flush;\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;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, s, x;\n sc.read(n, s, x); s--;\n int[] v = new int[n];\n int[] nx = new int[n];\n void query(int p) {\n writeln(\"? \", p+1);\n stdout.flush;\n sc.read(v[p], nx[p]);\n if (nx[p] != -1) nx[p]--;\n }\n void ans(int x) {\n writeln(\"! \", x);\n stdout.flush;\n }\n import std.random;\n auto gen = Random(unpredictableSeed);\n query(s);\n if (x <= v[s]) {\n ans(v[s]);\n return 0;\n }\n int ma = v[s], mp = s;\n foreach (ph; 0..2) {\n int p = uniform(0, n);\n query(p);\n if (ma < v[p] && v[p] < x) {\n ma = v[p];\n mp = p;\n }\n }\n while (mp != -1) {\n query(mp);\n if (x <= v[mp]) {\n ans(v[mp]);\n return 0;\n }\n mp = nx[mp];\n }\n ans(-1);\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"}, {"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;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, s, x;\n sc.read(n, s, x); s--;\n int[] v = new int[n];\n int[] nx = new int[n];\n void query(int p) {\n writeln(\"? \", p+1);\n stdout.flush;\n sc.read(v[p], nx[p]);\n }\n void ans(int x) {\n writeln(\"! \", x);\n stdout.flush;\n }\n import std.random;\n auto gen = Random(unpredictableSeed);\n query(s);\n if (x <= v[s]) {\n ans(v[s]);\n return 0;\n }\n int ma = v[s], mp = s;\n foreach (ph; 0..999) {\n int p = uniform(0, n);\n query(p);\n if (ma < v[p] && v[p] < x) {\n ma = v[p];\n mp = p;\n }\n }\n\n while (mp == -1 || v[mp] < x) {\n query(mp);\n mp = nx[mp];\n }\n if (mp == -1) ans(-1);\n else ans(v[mp]);\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"}, {"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;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, s, x;\n sc.read(n, s, x); s--;\n int[] v = new int[n];\n int[] nx = new int[n];\n void query(int p) {\n writeln(\"? \", p+1);\n stdout.flush;\n sc.read(v[p], nx[p]);\n }\n void ans(int x) {\n writeln(\"! \", x);\n }\n import std.random;\n auto gen = Random(unpredictableSeed);\n query(s);\n if (x <= v[s]) {\n ans(v[s]);\n return 0;\n }\n int ma = v[s], mp = s;\n foreach (ph; 0..999) {\n int p = uniform(0, n);\n query(p);\n if (ma < v[p] && v[p] < x) {\n ma = v[p];\n mp = p;\n }\n }\n\n while (mp == -1 || v[mp] < x) {\n query(mp);\n mp = nx[mp];\n }\n if (mp == -1) writeln(-1);\n else writeln(v[mp]);\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"}, {"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;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, s, x;\n sc.read(n, s, x); s--;\n int[] v = new int[n];\n int[] nx = new int[n];\n void query(int p) {\n writeln(\"? \", p+1);\n stdout.flush;\n sc.read(v[p], nx[p]); nx[p]--;\n }\n void ans(int x) {\n writeln(\"! \", x);\n stdout.flush;\n }\n import std.random;\n auto gen = Random(unpredictableSeed);\n query(s);\n if (x <= v[s]) {\n ans(v[s]);\n return 0;\n }\n int ma = v[s], mp = s;\n foreach (ph; 0..999) {\n int p = uniform(0, n);\n query(p);\n if (ma < v[p] && v[p] < x) {\n ma = v[p];\n mp = p;\n }\n }\n\n while (mp != -1) {\n query(mp);\n if (x <= v[mp]) {\n ans(v[mp]);\n return 0;\n }\n mp = nx[mp];\n }\n ans(-1);\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"}, {"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;\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, s, x;\n sc.read(n, s, x); s--;\n int[] v = new int[n];\n int[] nx = new int[n];\n void query(int p) {\n writeln(\"? \", p+1);\n stdout.flush;\n sc.read(v[p], nx[p]); nx[p]--;\n }\n void ans(int x) {\n writeln(\"! \", x);\n stdout.flush;\n }\n import std.random;\n auto gen = Random(unpredictableSeed);\n query(s);\n if (x <= v[s]) {\n ans(v[s]);\n return 0;\n }\n int ma = v[s], mp = s;\n foreach (ph; 0..999) {\n int p = uniform(0, n);\n query(p);\n if (ma < v[p] && v[p] < x) {\n ma = v[p];\n mp = p;\n }\n }\n\n while (mp == -1) {\n query(mp);\n if (x <= v[mp]) {\n ans(v[mp]);\n return 0;\n }\n mp = nx[mp];\n }\n ans(-1);\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"}, {"source_code": "module solution;\nimport std.algorithm;\nimport std.array;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\n\nimmutable int half = 999;\nimmutable int NA = -1;\n\nvoid main ()\n{\n\trndGen.seed (12526362);\n\tint n, start, x;\n\treadf (\" %s %s %s\", &n, &start, &x);\n\talias Node = Tuple !(int, q{value}, int, q{next});\n\tauto a = new Node [n + 1];\n\ta[] = Node (NA, NA);\n\tauto p = n.iota.array;\n\trandomShuffle (p);\n\tp[] += 1;\n\tp = p.take (min (half, n)).array;\n\n\tvoid ask (int c)\n\t{\n\t\tif (a[c].value != NA)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\twriteln (\"? \", c);\n\t\tstdout.flush ();\n\t\treadf (\" %s %s\", &a[c].value, &a[c].next);\n\t}\n\n\tvoid answer (int v)\n\t{\n\t\twriteln (\"! \", v);\n\t\tstdout.flush ();\n\t}\n\n\task (start);\n\tint closest = start;\n\tforeach (c; p)\n\t{\n\t\task (c);\n\t\tif (a[c].value < x)\n\t\t{\n\t\t\tif (a[closest].value < a[c].value)\n\t\t\t{\n\t\t\t\tclosest = c;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (i; 0..half)\n\t{\n\t\task (closest);\n\t\tif (a[closest].next == NA)\n\t\t{\n\t\t\tanswer (NA);\n\t\t\treturn;\n\t\t}\n\t\tif (a[closest].value >= x)\n\t\t{\n\t\t\tanswer (a[closest].value);\n\t\t\treturn;\n\t\t}\n\t\tclosest = a[closest].next;\n\t}\n\n\tassert (false);\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\nuint xrand() {\n static uint x = 314159265, y = 358979323, z = 846264338, w = 327950288;\n uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;\n}\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\nint N, S, X;\ndebug {\n int[] V, E;\n}\n\nalias List = Tuple!(int, \"value\", int, \"next\");\nList Ask(int i) {\n List ret;\n debug {\n ret.value = V[i];\n ret.next = E[i];\n } else {\n writeln(\"? \", i + 1);\n stdout.flush;\n ret.value = readInt();\n ret.next = readInt() - 1;\n }\n return ret;\n}\n\nvoid Answer(int v) {\n writeln(\"! \", v);\n stdout.flush;\n import core.stdc.stdlib;\n exit(0);\n}\n\nvoid main() {\n N = readInt();\n S = readInt() - 1;\n X = readInt();\n debug {\n V = new int[N];\n E = new int[N];\n foreach (i; 0 .. N) {\n V[i] = readInt();\n E[i] = readInt() - 1;\n }\n }\n \n auto list = new List[N];\n list[] = List(-58, -58);\n \n list[S] = Ask(S);\n if (list[S].value >= X) {\n Answer(list[S].value);\n }\n \n int[] perm = iota(N).array;\n foreach (j; 0 .. N) {\n swap(perm[xrand() % (j + 1)], perm[j]);\n }\n \n int im = S;\n const m = cast(int)(floorSqrt(N));\n foreach (j; 0 .. m) {\n const i = perm[j];\n list[i] = Ask(i);\n if (list[i].value < X) {\n if (im < list[i].value) {\n im = i;\n }\n }\n }\n \n for (int i = im; ; ) {\n i = list[i].next;\n if (i < 0) {\n Answer(-1);\n }\n list[i] = Ask(i);\n if (list[i].value >= X) {\n Answer(list[i].value);\n }\n }\n}\n"}], "src_uid": "8aba8c09ed1b1b25fa92cdad32d6fec3"} {"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 s = new string[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t\ts[i] = RD!string;\r\n\r\n\t\tif (m % 2)\r\n\t\t{\r\n\t\t\tforeach (i; 0..m+1)\r\n\t\t\t\tans[ti] ~= (i % 2) + 1;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tint[] a;\r\n\t\t\t(){\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\tif (s[i][j] == s[j][i])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ta = [i, j];\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\tif (!a.empty)\r\n\t\t\t{\r\n\t\t\t\tforeach (i; 0..m+1)\r\n\t\t\t\t\tans[ti] ~= a[i % 2] + 1;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t(){\r\n\t\t\t\tforeach (i; 0..n)\r\n\t\t\t\t{\r\n\t\t\t\t\tint x = -1, y = -1;\r\n\t\t\t\t\tforeach (j; 0..n)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (s[i][j] == 'a')\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tx = j;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tforeach (j; 0..n)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (s[j][i] == 'a')\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\ty = j;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (x != -1 && y != -1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tint z = -1;\r\n\t\t\t\t\t\tforeach (j; 0..n)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tif (s[j][y] == 'b' && s[x][j] == 'b')\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tz = j;\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\ta = [y, i, x, z];\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\tif (!a.empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tif ((m / 2) % 2)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tforeach (i; 0..m+1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tans[ti] ~= a[i%4] + 1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tforeach (i; 0..m+1)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tans[ti] ~= a[(i+1)%4] + 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}\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.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 n, m;\r\n\t\treadf !(\" %s %s\") (n, m);\r\n\t\treadln;\r\n\t\tstring [] a;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\ta ~= readln.strip;\r\n\t\t}\r\n\t\tif (m & 1)\r\n\t\t{\r\n\t\t\twriteln (\"YES\");\r\n\t\t\twritefln !(\"%(%s %)\") ([1, 2].cycle.take (m + 1));\r\n\t\t\tcontinue multitest_loop;\r\n\t\t}\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 (a[i][j] == a[j][i])\r\n\t\t\t\t{\r\n\t\t\t\t\twriteln (\"YES\");\r\n\t\t\t\t\twritefln !(\"%(%s %)\") ([i + 1, j + 1]\r\n\t\t\t\t\t .cycle.take (m + 1));\r\n\t\t\t\t\tcontinue multitest_loop;\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\tauto p = a[i].indexOf ('a');\r\n\t\t\tauto q = a[i].indexOf ('b');\r\n\t\t\tif (p >= 0 && q >= 0)\r\n\t\t\t{\r\n\t\t\t\tauto hi = [p, i].cycle.take (m / 2).array;\r\n\t\t\t\tauto lo = [q, i].cycle.take (m / 2).array;\r\n\t\t\t\twriteln (\"YES\");\r\n\t\t\t\twritefln !(\"%(%s %)\") (chain (lo.retro,\r\n\t\t\t\t only (i), hi).map !(q{a + 1}));\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": "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[][] G; get_lines(N, G);\r\n int[] res;\r\n \r\n if (M % 2 == 1) {\r\n foreach (i; 0..M+1) res ~= i % 2 + 1;\r\n goto ok;\r\n }\r\n\r\n if (N == 2 && (G == [\"*a\", \"b*\"] || G == [\"*b\", \"a*\"])) {\r\n writeln(\"NO\");\r\n continue;\r\n }\r\n\r\n foreach (i; 0..N-1) foreach (j; i+1..N) if (G[i][j] == G[j][i]) {\r\n auto pp = [i+1, j+1];\r\n foreach (k; 0..M+1) res ~= pp[k%2];\r\n goto ok;\r\n }\r\n\r\n foreach (k; 0..N) {\r\n int i = -1, j = -1;\r\n foreach (l; 0..N) {\r\n if (G[k][l] == 'a') {\r\n i = l;\r\n } else if (G[k][l] == 'b') {\r\n j = l;\r\n }\r\n\r\n if (i != -1 && j != -1) {\r\n if (M / 2 % 2 == 0) {\r\n res ~= k + 1;\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? i : k) + 1;\r\n } else {\r\n res ~= i + 1;\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? k : i) + 1;\r\n }\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? j : k) + 1;\r\n goto ok;\r\n }\r\n }\r\n }\r\n\r\n ok:\r\n writefln!\"YES\\n%(%d %)\"(res);\r\n continue;\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, M; get(N, M);\r\n char[][] G; get_lines(N, G);\r\n int[] res;\r\n\r\n if (M == 1) {\r\n writeln(\"YES\\n1 2\");\r\n continue;\r\n }\r\n\r\n if (N == 2 && (G == [\"*a\", \"b*\"] || G == [\"*b\", \"a*\"])) {\r\n writeln(\"NO\");\r\n continue;\r\n }\r\n\r\n if (M % 2 == 1) {\r\n foreach (i; 0..M+1) res ~= i % 2 + 1;\r\n goto ok;\r\n }\r\n\r\n foreach (i; 0..N-1) foreach (j; i+1..N) if (G[i][j] == G[j][i]) {\r\n auto pp = [i+1, j+1];\r\n foreach (k; 0..M+1) res ~= pp[k%2];\r\n goto ok;\r\n }\r\n\r\n foreach (k; 0..N) {\r\n int i = -1, j = -1;\r\n foreach (l; 0..N) {\r\n if (G[k][l] == 'a') {\r\n i = l;\r\n } else if (G[k][l] == 'b') {\r\n j = l;\r\n }\r\n\r\n if (i != -1 && j != -1) {\r\n if (M / 2 % 2 == 0) {\r\n res ~= k + 1;\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? i : k) + 1;\r\n } else {\r\n res ~= i + 1;\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? k : i) + 1;\r\n }\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? j : k) + 1;\r\n goto ok;\r\n }\r\n }\r\n }\r\n\r\n ok:\r\n writefln!\"YES\\n%(%d %)\"(res);\r\n continue;\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[][] G; get_lines(N, G);\r\n int[] res;\r\n\r\n if (N == 2 && (G == [\"*a\", \"b*\"] || G == [\"*b\", \"a*\"])) {\r\n writeln(\"NO\");\r\n continue;\r\n }\r\n\r\n if (M % 2 == 1) {\r\n foreach (i; 0..M+1) res ~= i % 2 + 1;\r\n goto ok;\r\n }\r\n\r\n foreach (i; 0..N-1) foreach (j; i+1..N) if (G[i][j] == G[j][i]) {\r\n auto pp = [i+1, j+1];\r\n foreach (k; 0..M+1) res ~= pp[k%2];\r\n goto ok;\r\n }\r\n\r\n foreach (k; 0..N) {\r\n int i = -1, j = -1;\r\n foreach (l; 0..N) {\r\n if (G[k][l] == 'a') {\r\n i = l;\r\n } else if (G[k][l] == 'b') {\r\n j = l;\r\n }\r\n }\r\n if (i != -1 && j != -1) {\r\n if (M / 2 % 2 == 0) {\r\n res ~= k + 1;\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? i : k) + 1;\r\n } else {\r\n res ~= i + 1;\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? k : i) + 1;\r\n }\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? j : k) + 1;\r\n goto ok;\r\n }\r\n }\r\n\r\n ok:\r\n writefln!\"YES\\n%(%d %)\"(res);\r\n continue;\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[][] G; get_lines(N, G);\r\n int[] res;\r\n\r\n if (N == 2 && (G == [\"*a\", \"b*\"] || G == [\"*b\", \"a*\"])) {\r\n writeln(\"NO\");\r\n continue;\r\n }\r\n\r\n if (M % 2 == 1) {\r\n foreach (i; 0..M+1) res ~= i % 2 + 1;\r\n goto ok;\r\n }\r\n\r\n foreach (i; 0..N-1) foreach (j; i+1..N) if (G[i][j] == G[j][i]) {\r\n auto pp = [i+1, j+1];\r\n foreach (k; 0..M+1) res ~= pp[k%2];\r\n goto ok;\r\n }\r\n\r\n foreach (k; 0..N) {\r\n int i = -1, j = -1;\r\n foreach (l; 0..N) {\r\n if (G[k][l] == 'a') {\r\n i = l;\r\n } else if (G[k][l] == 'b') {\r\n j = l;\r\n }\r\n }\r\n if (i != -1 && j != -1) {\r\n res ~= k + 1;\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? i : k) + 1;\r\n foreach (c; 0..M/2) res ~= (c % 2 == 0 ? j : k) + 1;\r\n goto ok;\r\n }\r\n }\r\n\r\n ok:\r\n writefln!\"YES\\n%(%d %)\"(res);\r\n continue;\r\n }\r\n}\r\n\r\n/*\r\n\r\na a\r\n\r\na b a b a\r\n\r\n*/"}], "src_uid": "79b629047e674883a9bc04b1bf0b7f09"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1405/problem/A\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\n while(t--) {\n int n = readln.chomp.to!int;\n int[] p = readln.split.map!(to!int).array;\n p.reverse;\n foreach(x; p)\n writef(\"%s \", x);\n \"\".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, 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 arr.reverse();\n foreach(el; arr){\n write(el, \" \");\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"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 p = RDA;\n\t\tp.reverse;\n\n\t\tans[ti] = p;\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": "1eaff8e0ec4614753699128af74b2471"} {"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\tlong cur = 0;\r\n\t\tlong res = 0;\r\n\t\tforeach_reverse (i; 0..n - 1)\r\n\t\t{\r\n\t\t\tcur += (a[i + 1] - a[i]) * (n - i - 1L);\r\n\t\t\tres += cur;\r\n\t\t}\r\n\t\twriteln (a.back - res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1541/problem/C\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[] d = readln.split.map!(to!long).array;\n d.sort;\n long ans = d[n - 1];\n long node = 0L;\n for(int i = 0; i < n; ++i) {\n ans -= d[i] * i - node;\n node += d[i];\n }\n ans.writeln;\n}\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 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!long;\r\n \r\n long answer = 0;\r\n long current = 0;\r\n \r\n sort(arr);\r\n foreach (i; 1 .. n) {\r\n auto w = arr[i] - arr[i - 1];\r\n answer += w;\r\n answer -= i * w + current;\r\n current += i * w;\r\n }\r\n \r\n writeln(answer);\r\n }\r\n}\r\n\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[] pref = [0];\n for(int i = 1; i < n; ++i){\n pref ~= pref.back + arr[i];\n }\n ll cost = 0;\n for(int i = 1; i < n; ++i){\n cost += (i - 1) * 1L * arr[i];\n if(i > 1) cost -= pref[i-2];\n }\n writeln(- cost);\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;\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\tlong cur = 0;\r\n\t\tlong res = 0;\r\n\t\tforeach_reverse (i; 0..n - 1)\r\n\t\t{\r\n\t\t\tcur += (a[i + 1] - a[i]) * (n - i - 1);\r\n\t\t\tres += cur;\r\n\t\t}\r\n\t\twriteln (a.back - res);\r\n\t}\r\n}\r\n"}], "src_uid": "7dfe0db5a99e6e4d71eb012fab07685b"} {"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\nll[1000] nn;\n\nvoid main() {\n GC.disable();\n\n int q;\n readf(\" %s\", q);\n\n\n foreach(i;0 ..q) {\n ll n;\n readf(\" %s\", n);\n ll c5=0;\n ll c3=0;\n ll c2=0;\n while(n % 5==0) {c5++; n /=5;}\n while(n % 3==0) {c3++; n /=3;}\n while(n % 2==0) {c2++; n /=2;}\n\n if (n != 1) writeln(-1);\n else writeln(c5 + c3 + 2*c5 + c3 + c2);\n }\n\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 q = RD!int;\n\tauto ans = new long[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto n = RD;\n\t\tlong cnt;\n\t\twhile (n != 1)\n\t\t{\n\t\t\tif (n % 2 == 0)\n\t\t\t{\n\t\t\t\tn /= 2;\n\t\t\t}\n\t\t\telse if ((n * 2) % 3 == 0)\n\t\t\t{\n\t\t\t\tn = (n * 2) / 3;\n\t\t\t}\n\t\t\telse if ((n * 4) % 5 == 0)\n\t\t\t{\n\t\t\t\tn = (n * 4) /5;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcnt = -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++cnt;\n\t\t}\n\t\tans[i] = cnt;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int nt;\n readf!\" %d\" (nt);\n while (--nt >= 0) {\n long x;\n int res;\n readf!\" %d\" (x);\n while (x > 1) {\n if (!(x % 2)) {\n x /= 2;\n ++res;\n } else if (!(x % 3)) {\n x /= 3;\n res += 2;\n } else if (!(x % 5)) {\n x /= 5;\n res += 3;\n } else {\n res = -1;\n break;\n }\n }\n writeln (res);\n }\n}\n\n"}], "negative_code": [], "src_uid": "ed5ea0e664aa986ab86e4e6746e8a1bf"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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, 2);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD;\n\t\tauto b = RD;\n\t\tauto c = RD;\n\n\t\tif (a < c)\n\t\t\tans[ti][0] = 1;\n\t\telse\n\t\t\tans[ti][0] = -1;\n\n\t\tif (a*b > c)\n\t\t\tans[ti][1] = b;\n\t\telse\n\t\t\tans[ti][1] = -1;\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}\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\tlong a, b, c;\n\t\treadf !(\" %s %s %s\") (a, b, c);\n\t\tauto res1 = (a < c) ? 1 : -1;\n\t\tauto res2 = (c < a * b) ? b : -1;\n\t\twriteln (res1, \" \", res2);\n\t}\n}\n"}], "negative_code": [], "src_uid": "002801f26568a1b3524d8754207d32c1"} {"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\nbool isPrime(long n) {\n\tif (n < 2) {\n\t\treturn false;\n\t}\n\tfor (long d = 2; d * d <= n; ++d) {\n\t\tif (n % d == 0) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nlong[] gs;\n\nbool isPrimitive(long p, long g) {\n\tgs = new long[0];\n\tgs ~= 1;\n\tforeach (i; 1 .. p - 1) {\n\t\tgs ~= (gs[$ - 1] * g) % p;\n\t}\n\tforeach (i; 1 .. p - 1) {\n\t\tif (gs[cast(size_t)(i)] == 1) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nlong N;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readLong;\n\t\t\n\t\tif (N == 1) {\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(1);\n\t\t} else if (N == 2) {\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(1);\n\t\t\twriteln(2);\n\t\t} else if (N == 4) {\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(1);\n\t\t\twriteln(3);\n\t\t\twriteln(2);\n\t\t\twriteln(4);\n\t\t} else if (isPrime(N)) {\n\t\t\tfor (long g = 2; ; ++g) {\n\t\t\t\tif (isPrimitive(N, g)) {\ndebug{\nwriteln(\"gs = \",gs);\n}\n\t\t\t\t\twriteln(\"YES\");\n\t\t\t\t\twriteln(1);\n\t\t\t\t\tforeach (i; 0 .. (N - 3) / 2) {\ndebug{\n// writeln(\"g^\",1+2*i);\n// writeln(\"g^\",N-3-2*i);\n}\n\t\t\t\t\t\twriteln(gs[cast(size_t)(1 + 2 * i)]);\n\t\t\t\t\t\twriteln(gs[cast(size_t)(N - 3 - 2 * i)]);\n\t\t\t\t\t}\ndebug{\n// writeln(\"g^\",N-2);\n}\n\t\t\t\t\twriteln(gs[cast(size_t)(N - 2)]);\n\t\t\t\t\twriteln(N);\n\t\t\t\t\tbreak;\n\t\t\t\t}\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": "/* submitted, so what? */\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;\nimport core.bitop;\n\nlong powmod (int a, int b, int c)\n{\n\tlong cur = a % c;\n\tlong res = 1 % c;\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = (res * cur) % c;\n\t\t}\n\t\tcur = (cur * cur) % c;\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\nmain_loop:\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tif (n == 4)\n\t\t{\n\t\t\twrite (\"YES\\n1\\n3\\n2\\n4\\n\");\n\t\t\tcontinue main_loop;\n\t\t}\n\n\t\tfor (int i = 2; i * i <= n; i++)\n\t\t{\n\t\t\tif (n % i == 0)\n\t\t\t{\n\t\t\t\twriteln (\"NO\");\n\t\t\t\tcontinue main_loop;\n\t\t\t}\n\t\t}\n\n\t\twriteln (\"YES\");\n\t\tif (n > 1)\n\t\t{\n\t\t\twriteln (1);\n\t\t}\n\t\tforeach (i; 2..n)\n\t\t{\n\t\t\twriteln ((i * powmod (i - 1, n - 2, n)) % n);\n\t\t}\n\t\twriteln (n);\n\t}\n}\n"}], "negative_code": [], "src_uid": "8b61e354ece0242eff539163f76cabde"} {"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, p;\n\twhile (readf (\" %s %s %s\", &n, &m, &p) > 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 b = new int [m];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\treadf (\" %s\", &b[j]);\n\t\t}\n\n\t\tint [] ans;\n\t\tif ((m - 1) * cast (long) p < n)\n\t\t{\n\t\t\tforeach (k; 0..p)\n\t\t\t{\n\t\t\t\tint [int] e;\n\t\t\t\tint d = m;\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\te[b[j]]++;\n\t\t\t\t}\n\n\t\t\t\tfor (int i = k, j = i - p * m; i < n;\n\t\t\t\t i += p, j += p)\n\t\t\t\t{\n\t\t\t\t\te[a[i]]--;\n\t\t\t\t\tint cur = e[a[i]];\n\t\t\t\t\tif (cur >= 0)\n\t\t\t\t\t{\n\t\t\t\t\t\td--;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\td++;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (j >= 0)\n\t\t\t\t\t{\n\t\t\t\t\t\te[a[j]]++;\n\t\t\t\t\t\tint prev = e[a[j]];\n\t\t\t\t\t\tif (prev <= 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\td--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\td++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tdebug {writeln (k, \" \", i, \" \",\n\t\t\t\t\t j, \" \", d);}\n\t\t\t\t\tif (d == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tans ~= j + p + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tans.sort !(\"a < b\", SwapStrategy.stable);\n\t\twritefln (\"%s\\n%(%s %)\", ans.length, ans);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int[] a, int[] b, int n, int m, int p)\n{\n int[int] cntb;\n foreach (v; b)\n {\n if (v !in cntb) cntb[v] = 1;\n else ++ cntb[v];\n }\n int[] res;\n foreach (i; 0 .. min(n, p))\n {\n auto d = m;\n int[int] cnta;\n int j;\n for (j = i; j < n && (j - i) / p < m; j += p)\n {\n if (a[j] !in cnta) cnta[a[j]] = 1;\n else ++ cnta[a[j]];\n if (a[j] !in cntb)\n {\n ++ d;\n }\n else\n {\n if (cnta[a[j]] <= cntb[a[j]]) -- d;\n else ++ d;\n }\n }\n if ((j - i) / p < m) continue;\n if (d == 0) res ~= i;\n for (int left = i, right = j; right < n; left += p, right += p)\n {\n if (a[left] != a[right])\n {\n -- cnta[a[left]];\n if (a[left] !in cntb)\n {\n -- d;\n }\n else\n {\n if (cnta[a[left]] < cntb[a[left]]) ++ d;\n else -- d;\n }\n ++ cnta[a[right]];\n if (a[right] !in cntb)\n {\n ++ d;\n }\n else\n {\n if (cnta[a[right]] <= cntb[a[right]]) -- d;\n else ++ d;\n }\n }\n if (d == 0) res ~= left + p;\n }\n }\n writeln(res.length);\n if (res.length > 0)\n {\n res.sort();\n foreach (v; res) write(v + 1, \" \");\n writeln();\n }\n}\n\nint main(string[] args)\n{\n int n, m, p;\n while (readf(\"%d %d %d\\n\", &n, &m, &p) == 3)\n {\n auto a = new int[n];\n auto b = new int[m];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n foreach (i; 0 .. m)\n {\n readf(\" %d\", &b[i]);\n }\n readln;\n solve(a, b, n, m, p);\n }\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid solve(int[] a, int[] b, int n, int m, int p)\n{\n int[int] cntb;\n foreach (v; b)\n {\n if (v !in cntb) cntb[v] = 1;\n else ++ cntb[v];\n }\n int[] res;\n foreach (i; 0 .. min(n, p))\n {\n auto d = m;\n int[int] cnta;\n int j;\n for (j = i; j < n && (j - i) / p < m; j += p)\n {\n if (a[j] !in cnta) cnta[a[j]] = 1;\n else ++ cnta[a[j]];\n if (a[j] !in cntb)\n {\n ++ d;\n }\n else\n {\n if (cnta[a[j]] <= cntb[a[j]]) -- d;\n else ++ d;\n }\n }\n if ((j - i) / p < m) continue;\n if (d == 0) res ~= i;\n for (int left = i, right = j; right < n; left += p, right += p)\n {\n if (a[left] != a[right])\n {\n -- cnta[a[left]];\n if (a[left] !in cntb)\n {\n -- d;\n }\n else\n {\n if (cnta[a[left]] < cntb[a[left]]) ++ d;\n else -- d;\n }\n ++ cnta[a[right]];\n if (a[right] !in cntb)\n {\n ++ d;\n }\n else\n {\n if (cnta[a[right]] <= cntb[a[right]]) -- d;\n else ++ d;\n }\n }\n if (d == 0) res ~= left + p;\n }\n }\n writeln(res.length);\n if (res.length > 0)\n {\n foreach (v; res) write(v + 1, \" \");\n writeln();\n }\n}\n\nint main(string[] args)\n{\n int n, m, p;\n while (readf(\"%d %d %d\\n\", &n, &m, &p) == 3)\n {\n auto a = new int[n];\n auto b = new int[m];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &a[i]);\n }\n readln;\n foreach (i; 0 .. m)\n {\n readf(\" %d\", &b[i]);\n }\n readln;\n solve(a, b, n, m, p);\n }\n return 0;\n}"}], "src_uid": "84cce147e8aadb140afaaa95917fdf0d"} {"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[3][6] perm =\n[\n [0, 1, 2],\n [0, 2, 1],\n [1, 0, 2],\n [1, 2, 0],\n [2, 0, 1],\n [2, 1, 0],\n];\n\nvoid main()\n{\n int n, m;\n readf!\" %d %d \"(n, m);\n auto s = readln.strip;\n int[][6] pf = [[0], [0], [0], [0], [0], [0]];\n int[6] sum;\n foreach (i ; 0 .. n) {\n int x = s[i] - 'a';\n foreach (j ; 0 .. 6) {\n sum[j] += (x != perm[j][i % 3]);\n pf[j] ~= sum[j];\n }\n }\n while (m--) {\n int l, r;\n readf!\" %d %d \"(l, r);\n int ans = int.max;\n foreach (j ; 0 .. 6) {\n ans = min(ans, pf[j][r] - pf[j][l - 1]);\n }\n writeln(ans);\n }\n}\n", "positive_code": [{"source_code": "import std;\n\nvoid main () {\n immutable q = readln.chomp.splitter(' ').dropOne.front.to!uint;\n immutable s = readln.chomp;\n\n auto costs = (){\n scope result = appender!(uint[]);\n result.reserve(6 * (s.length + 1));\n \n [\n \"abc\",\n \"acb\",\n \"bac\",\n \"bca\",\n \"cab\",\n \"cba\"\n ].map!(patt => patt.makePrefix(s))\n .each!(v => v.each!(a => result.put(a)));\n\n assert(result[].length == 6 * (s.length + 1));\n return result[].assumeUnique.chunks(s.length + 1);\n }();\n\n stdin\n .byLine\n .map!((char[] line) {\n uint[2] query = line\n .splitter(' ')\n .map!(to!uint)\n .staticArray!2;\n\n return tuple(query[0], query[1]);\n })\n .map!(query =>\n costs\n .map!(v => v[query[1]] - v[query[0] - 1])\n .minElement\n )\n .each!writeln;\n}\n\nauto makePrefix (in string patt, in string s) {\n return chain(\n [0u],\n zip(s.byCodeUnit, patt.byCodeUnit.cycle)\n .cumulativeFold!\"a + (b[0] != b[1])\"(0u)\n );\n}\n// \"\"\n"}, {"source_code": "import std;\n\nvoid main () {\n immutable q = readln.chomp.splitter(' ').dropOne.front.to!uint;\n immutable s = readln.chomp;\n\n auto costs = (){\n scope result = appender!(uint[]);\n [\n \"abc\",\n \"acb\",\n \"bac\",\n \"bca\",\n \"cab\",\n \"cba\"\n ].map!(patt => patt.makePrefix(s))\n .each!(v => v.each!(a => result.put(a)));\n\n assert(result[].length == 6 * (s.length + 1));\n return result[].assumeUnique.chunks(s.length + 1);\n }();\n\n stdin\n .byLine\n .map!((char[] line) {\n uint[2] query = line\n .splitter(' ')\n .map!(to!uint)\n .staticArray!2;\n\n return tuple(query[0], query[1]);\n })\n .map!(query =>\n costs\n .map!(v => v[query[1]] - v[query[0] - 1])\n .minElement\n )\n .each!writeln;\n}\n\nauto makePrefix (in string patt, in string s) {\n return chain(\n [0u],\n zip(s.byCodeUnit, patt.byCodeUnit.cycle)\n .cumulativeFold!\"a + (b[0] != b[1])\"(0u)\n );\n}\n// \"\"\n"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\n\nauto sum(R)(R r, size_t i, size_t j)\n{ \n\tif (i > j) return 0;\n\tif (i == 0) return r[j];\n\treturn r[j] - r[i-1];\n}\n\nvoid main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto s = readString.map!(c => cast(int)c - 'a').array;\n\tint[][] perm = new int[][](6, 3);\n\tint[] currp = [0, 1, 2];\n\t{\n\tsize_t i = 0;\n\tdo\n\t{\n\t\tperm[i++][] = currp;\n\t} while (nextPermutation(currp));\n\t}\n\tint[][] dist = new int[][](6, n);\n\tforeach(p; 0 .. 6)\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t{\n\t\t\tdist[p][i] = s[i] != perm[p][i%3];\n\t\t}\n\t}\n\tauto prefSum = new int[][](6);\n\tforeach(p; 0 .. 6)\n\t{\n\t\tprefSum[p] = dist[p].cumulativeFold!((a, b)=>a + b).array;\n\t}\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto l = readInt!int - 1;\n\t\tauto r = readInt!int - 1;\n\t\tiota(0, 6).map!(p => sum(prefSum[p], l, r)).fold!min.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"}], "negative_code": [], "src_uid": "b4183febe5ae61770368d2e16f273675"} {"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^^6 + 3;\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\nint gaussianElimination(ref long[][] org_mat, ref long[] ret) {\n int N = org_mat.length.to!int;\n \n auto mat = new long[][](N, N+1);\n foreach (i; 0..N)\n foreach (j; 0..N+1)\n mat[i][j] = org_mat[i][j];\n\n foreach (i; 0..N) {\n long maxval = 0;\n int maxrow = -1;\n foreach (j; i..N)\n if (abs(mat[j][i]) > maxval)\n maxval = abs(mat[j][i]), maxrow = j;\n if (maxval == 0)\n return -1;\n swap(mat[i], mat[maxrow]);\n\n foreach (j; i+1..N+1)\n mat[i][j] = mat[i][j] * powmod(mat[i][i], MOD-2, MOD) % MOD;\n mat[i][i] = 1;\n \n foreach (j; 0..N) {\n if (j == i) continue;\n long mul = mat[j][i];\n foreach (k; i..N+1) {\n (mat[j][k] -= mul * mat[i][k] % MOD) %= MOD;\n mat[j][k] = (mat[j][k] + MOD) % MOD;\n }\n }\n }\n\n foreach (i; 0..N)\n ret[i] = mat[i][N];\n\n return 0;\n}\n\nlong[] B;\n\nlong ask(long x) {\n writeln(\"? \", x);\n debug {\n long res = 0;\n foreach (i; 0..11) (res += B[i] * powmod(x, i, MOD) % MOD) %= MOD;\n return res;\n }\n stdout.flush;\n return readln.chomp.to!long;\n}\n\nvoid ans(long x) {\n writeln(\"! \", x);\n return;\n}\n\nvoid main() {\n debug {\n B = new long[](11);\n B[0] = 1000002;\n B[2] = 1;\n }\n\n int N = 11;\n auto mat = new long[][](N, N+1);\n \n foreach (i; 0..N) {\n foreach (j; 0..N) mat[i][j] = powmod(i, j, MOD);\n mat[i][N] = ask(i);\n }\n \n auto A = new long[](N);\n gaussianElimination(mat, A);\n\n foreach (i; 0..MOD) {\n long res = 0;\n foreach (j; 0..N) (res += A[j] * powmod(i, j, MOD) % MOD) %= MOD;\n if (res == 0) {\n ans(i);\n return;\n }\n }\n\n ans(-1);\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.exception;\n\nT gcd(T) (T a, T b) pure nothrow @nogc {\n if (a < b) {\n swap (a, b);\n }\n while (b) {\n T c = a % b; a = b; b = c;\n }\n return a;\n}\n\nT gcdext(T) (T a, T b, ref T x, ref T y) pure nothrow @nogc {\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n T res = gcdext (b, a % b, y, x);\n y -= x * (a / b);\n return res;\n}\n\nstruct IntM {\n enum q = 1_000_003;\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 opUnary (string op : \"++\")() pure nothrow @nogc {\n if (++v >= q) {\n v -= q;\n }\n return this;\n }\n ref IntM opUnary (string op : \"--\")() pure nothrow @nogc {\n if (--v < 0) {\n v += q;\n }\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 -= 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 int opCast(T : int)() const pure nothrow @nogc { return v; }\n int opCmp (const IntM rhs) const pure nothrow @nogc {\n if (v < rhs.v) {\n return -1;\n }\n if (v > rhs.v) {\n return 1;\n }\n return 0;\n }\n bool opEquals (const IntM rhs) const pure nothrow @nogc { return v == rhs.v; }\n string toString() const pure nothrow { return ((v < 0) ? v + q : v).text; }\n}\n\nvoid main() {\n IntM[][] a = new IntM[][] (11, 11);\n IntM[11] b;\n foreach (i; 0 .. 11) {\n IntM ii = i;\n writeln (\"? \", i); stdout.flush ();\n a[i][0] = 1;\n foreach (j; 1 .. 11) {\n a[i][j] = a[i][j-1] * ii;\n }\n int bi = readln.strip.to!int;\n b[i] = bi;\n }\n immutable IntM z = 0;\n foreach (i; 0 .. 11) {\n enforce (a[i][i] != z);\n foreach (j; i + 1 .. 11) {\n IntM aji = a[j][i];\n foreach (k; i .. 11) {\n a[j][k] *= a[i][i];\n a[j][k] -= a[i][k] * aji;\n }\n b[j] *= a[i][i];\n b[j] -= b[i] * aji;\n }\n }\n IntM[11] x;\n foreach_reverse (i; 0 .. 11) {\n x[i] = b[i];\n foreach (j; i + 1 .. 11) {\n x[i] -= a[i][j] * x[j];\n }\n x[i] *= a[i][i] ^^ (IntM.q - 2);\n }\n debug stderr.writeln (a);\n debug stderr.writeln (b);\n debug stderr.writeln (x);\n foreach (i; 0 .. IntM.q) {\n IntM r;\n IntM ii = i;\n foreach_reverse (j; 0 .. 11) {\n r *= ii;\n r += x[j];\n }\n if (r == z) {\n writeln (\"! \", i);\n return;\n }\n }\n writeln (\"! \", -1);\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\nimmutable long MOD = 10^^6 + 3;\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\nint gaussianElimination(ref long[][] org_mat, ref long[] ret) {\n int N = org_mat.length.to!int;\n \n auto mat = new long[][](N, N+1);\n foreach (i; 0..N)\n foreach (j; 0..N+1)\n mat[i][j] = org_mat[i][j];\n\n foreach (i; 0..N) {\n long maxval = 0;\n int maxrow = -1;\n foreach (j; i..N)\n if (abs(mat[j][i]) > maxval)\n maxval = abs(mat[j][i]), maxrow = j;\n if (maxval == 0)\n return -1;\n swap(mat[i], mat[maxrow]);\n\n foreach (j; i+1..N+1)\n mat[i][j] = mat[i][j] * powmod(mat[i][i], MOD-2, MOD) % MOD;\n mat[i][i] = 1;\n \n foreach (j; 0..N) {\n if (j == i) continue;\n long mul = mat[j][i];\n foreach (k; i..N+1) {\n (mat[j][k] -= mul * mat[i][k] % MOD) %= MOD;\n mat[j][k] = (mat[j][k] + MOD) % MOD;\n }\n }\n }\n\n foreach (i; 0..N)\n ret[i] = mat[i][N];\n\n return 0;\n}\n\nlong[] B;\n\nlong ask(long x) {\n writeln(\"? \", x);\n debug {\n long res = 0;\n foreach (i; 0..10) (res += B[i] * powmod(x, i, MOD) % MOD) %= MOD;\n return res;\n }\n stdout.flush;\n return readln.chomp.to!long;\n}\n\nvoid ans(long x) {\n writeln(\"! \", x);\n return;\n}\n\nvoid main() {\n debug {\n B = new long[](10);\n B[0] = 1000002;\n B[2] = 1;\n }\n\n int N = 10;\n auto mat = new long[][](N, N+1);\n \n foreach (i; 0..10) {\n foreach (j; 0..N) mat[i][j] = powmod(i, j, MOD);\n mat[i][N] = ask(i);\n }\n \n auto A = new long[](N);\n gaussianElimination(mat, A);\n\n foreach (i; 0..MOD) {\n long res = 0;\n foreach (j; 0..10) (res += A[j] * powmod(i, j, MOD) % MOD) %= MOD;\n if (res == 0) {\n ans(i);\n return;\n }\n }\n\n ans(-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;\n\nimmutable long MOD = 10^^6 + 3;\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\nint gaussianElimination(ref long[][] org_mat, ref long[] ret) {\n int N = org_mat.length.to!int;\n \n auto mat = new long[][](N, N+1);\n foreach (i; 0..N)\n foreach (j; 0..N+1)\n mat[i][j] = org_mat[i][j];\n\n foreach (i; 0..N) {\n long maxval = 0;\n int maxrow = -1;\n foreach (j; i..N)\n if (abs(mat[j][i]) > maxval)\n maxval = abs(mat[j][i]), maxrow = j;\n if (maxval == 0)\n return -1;\n swap(mat[i], mat[maxrow]);\n\n foreach (j; i+1..N+1)\n mat[i][j] = mat[i][j] * powmod(mat[i][i], MOD-2, MOD);\n mat[i][i] = 1;\n \n foreach (j; 0..N) {\n if (j == i) continue;\n long mul = mat[j][i];\n foreach (k; i..N+1) {\n (mat[j][k] -= mul * mat[i][k] % MOD) %= MOD;\n mat[j][k] = (mat[j][k] + MOD) % MOD;\n }\n }\n }\n\n foreach (i; 0..N)\n ret[i] = mat[i][N];\n\n return 0;\n}\n\nlong[] B;\n\nlong ask(long x) {\n writeln(\"? \", x);\n debug {\n long res = 0;\n foreach (i; 0..10) (res += B[i] * powmod(x, i, MOD) % MOD) %= MOD;\n return res;\n }\n stdout.flush;\n return readln.chomp.to!long;\n}\n\nvoid ans(long x) {\n writeln(\"! \", x);\n return;\n}\n\nvoid main() {\n debug {\n B = new long[](10);\n B[0] = 1000002;\n B[2] = 1;\n }\n\n int N = 10;\n auto mat = new long[][](N, N+1);\n \n foreach (i; 0..10) {\n foreach (j; 0..N) mat[i][j] = powmod(i, j, MOD);\n mat[i][N] = ask(i);\n }\n \n auto A = new long[](N);\n gaussianElimination(mat, A);\n\n foreach (i; 0..MOD) {\n long res = 0;\n foreach (j; 0..10) (res += A[j] * powmod(i, j, MOD) % MOD) %= MOD;\n if (res == 0) {\n ans(i);\n return;\n }\n }\n\n ans(-1);\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.exception;\n\nT gcd(T) (T a, T b) pure nothrow @nogc {\n if (a < b) {\n swap (a, b);\n }\n while (b) {\n T c = a % b; a = b; b = c;\n }\n return a;\n}\n\nT gcdext(T) (T a, T b, ref T x, ref T y) pure nothrow @nogc {\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n T res = gcdext (b, a % b, y, x);\n y -= x * (a / b);\n return res;\n}\n\nstruct IntM {\n enum q = 1_000_003;\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 opUnary (string op : \"++\")() pure nothrow @nogc {\n if (++v >= q) {\n v -= q;\n }\n return this;\n }\n ref IntM opUnary (string op : \"--\")() pure nothrow @nogc {\n if (--v < 0) {\n v += q;\n }\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 -= 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 int opCast(T : int)() const pure nothrow @nogc { return v; }\n int opCmp (const IntM rhs) const pure nothrow @nogc {\n if (v < rhs.v) {\n return -1;\n }\n if (v > rhs.v) {\n return 1;\n }\n return 0;\n }\n bool opEquals (const IntM rhs) const pure nothrow @nogc { return v == rhs.v; }\n string toString() const pure nothrow { return ((v < 0) ? v + q : v).text; }\n}\n\nvoid main() {\n IntM[][] a = new IntM[][] (11, 11);\n IntM[11] b;\n foreach (i; 0 .. 11) {\n IntM ii = i;\n writeln (\"? \", i); stdout.flush ();\n a[i][0] = 1;\n foreach (j; 1 .. 11) {\n a[i][j] = a[i][j-1] * ii;\n }\n int bi = readln.strip.to!int;\n b[i] = bi;\n }\n immutable IntM z = 0;\n foreach (i; 0 .. 11) {\n enforce (a[i][i] != z);\n foreach (j; i + 1 .. 11) {\n IntM aji = a[j][i];\n foreach (k; j .. 11) {\n a[j][k] *= a[i][i];\n a[j][k] -= a[i][k] * aji;\n }\n b[j] *= a[i][i];\n b[j] -= b[i] * aji;\n }\n }\n IntM[11] x;\n foreach_reverse (i; 0 .. 11) {\n x[i] = b[i];\n foreach (j; i + 1 .. 11) {\n x[i] -= a[i][j] * x[j];\n }\n x[i] *= a[i][i] ^^ (IntM.q - 2);\n }\n foreach (i; 0 .. IntM.q) {\n IntM r;\n IntM ii = i;\n foreach_reverse (j; 0 .. 11) {\n r *= ii;\n r += x[j];\n }\n if (r == z) {\n writeln (\"! \", i);\n return;\n }\n }\n writeln (\"! \", -1);\n}\n\n"}], "src_uid": "b26140f647eee09f5f0d6c428d99126d"} {"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 int N = readInt;\n int M = readInt;\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt;\n B[i] = readInt;\n }\n M += 2 * N;\n foreach (u; 1 .. N + 1) {\n A ~= 0;\n B ~= u;\n A ~= u;\n B ~= N + 1;\n }\n \n auto G = new int[][N + 2];\n auto H = new int[][N + 2];\n foreach (i; 0 .. M) {\n G[A[i]] ~= i;\n H[B[i]] ~= i;\n }\n \n auto fs = new int[N + 1];\n foreach (i; 0 .. M) {\n if (A[i] + 1 == B[i]) {\n fs[A[i]] = 1;\n }\n }\n auto fsSum = new int[N + 2];\n foreach (u; 0 .. N + 1) {\n fsSum[u + 1] = fsSum[u] + fs[u];\n }\n \n long ans;\n if (fsSum[N + 1] == N + 1) {\n ans = 1L * N * (N - 1) / 2;\n } else {\n int l = N + 1, r = 0;\n foreach (u; 0 .. N + 1) {\n if (!fs[u]) {\n chmin(l, u);\n chmax(r, u + 1);\n }\n }\n debug {\n writeln(\"fs = \", fs);\n writeln(\"l = \", l, \", r = \", r);\n }\n bool isGood(int u, int v) {\n return (u <= v && fsSum[v] - fsSum[u] == v - u);\n }\n \n // (u, u + 1) to (l, l + 1), parity of # of steps\n auto visL = new bool[2][N + 1];\n visL[l][0] = true;\n foreach_reverse (u; 0 .. l + 1) {\n foreach (i; H[u + 1]) {\n // v -> u + 1, v + 1 -> u\n const v = A[i];\n if (isGood(v + 1, u)) {\n if (visL[u][0]) visL[v][1] = true;\n if (visL[u][1]) visL[v][0] = true;\n }\n }\n }\n long[4] cntL;\n foreach (u; 0 .. l + 1) {\n int p;\n if (visL[u][0]) p |= 1 << 0;\n if (visL[u][1]) p |= 1 << 1;\n ++cntL[p];\n }\n \n // (l, l + 1) to (u, u + 1), parity of # of steps\n auto visR = new bool[2][N + 1];\n visR[l][0] = true;\n foreach (u; l .. N + 1) {\n foreach (i; G[u]) {\n // u -> v, u + 1 -> v - 1\n const v = B[i];\n if (isGood(u + 1, v - 1)) {\n if (visR[u][0]) visR[v - 1][1] = true;\n if (visR[u][1]) visR[v - 1][0] = true;\n }\n }\n }\n long[4] cntR;\n foreach (u; /*!!!*/r - 1 .. N + 1) {\n int p;\n if (visR[u][0]) p |= 1 << 0;\n if (visR[u][1]) p |= 1 << 1;\n ++cntR[p];\n }\n \n debug {\n writeln(\"visL = \", visL);\n writeln(\"cntL = \", cntL);\n writeln(\"visR = \", visR);\n writeln(\"cntR = \", cntR);\n }\n \n foreach (p; 0 .. 4) foreach (q; 0 .. 4) {\n if (p & q) {\n ans += cntL[p] * cntR[q];\n }\n }\n if (l + 1 == r) {\n ans -= 1;\n }\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, 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 int N = readInt;\n int M = readInt;\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt;\n B[i] = readInt;\n }\n M += 2 * N;\n foreach (u; 1 .. N + 1) {\n A ~= 0;\n B ~= u;\n A ~= u;\n B ~= N + 1;\n }\n \n auto graph = new int[][N + 2];\n auto graphRev = new int[][N + 2];\n foreach (i; 0 .. M) {\n graph[A[i]] ~= B[i];\n graphRev[B[i]] ~= A[i];\n }\n \n auto fs = new int[N + 1];\n foreach (i; 0 .. M) {\n if (A[i] + 1 == B[i]) {\n fs[A[i]] = 1;\n }\n }\n auto fsSum = new int[N + 2];\n foreach (u; 0 .. N + 1) {\n fsSum[u + 1] = fsSum[u] + fs[u];\n }\n \n long ans;\n if (fsSum[N + 1] == N + 1) {\n ans = 1L * N * (N - 1) / 2;\n } else {\n int l = N + 1, r = 0;\n foreach (u; 0 .. N + 1) {\n if (!fs[u]) {\n chmin(l, u);\n chmax(r, u + 1);\n }\n }\n debug {\n writeln(\"fs = \", fs);\n writeln(\"l = \", l, \", r = \", r);\n }\n bool isGood(int u, int v) {\n return (u <= v && fsSum[v] - fsSum[u] == v - u);\n }\n \n // (u, u + 1) to (l, l + 1), parity of # of steps\n auto visL = new bool[2][N + 1];\n visL[l][0] = true;\n foreach_reverse (u; 0 .. l + 1) {\n foreach (v; graphRev[u + 1]) {\n // v -> u + 1, v + 1 -> u\n if (isGood(v + 1, u)) {\n if (visL[u][0]) visL[v][1] = true;\n if (visL[u][1]) visL[v][0] = true;\n }\n }\n }\n long[4] cntL;\n foreach (u; 0 .. l + 1) {\n int p;\n if (visL[u][0]) p |= 1 << 0;\n if (visL[u][1]) p |= 1 << 1;\n ++cntL[p];\n }\n \n // (l, l + 1) to (u, u + 1), parity of # of steps\n auto visR = new bool[2][N + 1];\n visR[l][0] = true;\n foreach (u; l .. N + 1) {\n foreach (v; graph[u]) {\n // u -> v, u + 1 -> v - 1\n if (isGood(u + 1, v - 1)) {\n if (visR[u][0]) visR[v - 1][1] = true;\n if (visR[u][1]) visR[v - 1][0] = true;\n }\n }\n }\n long[4] cntR;\n foreach (u; /*!!!*/r - 1 .. N + 1) {\n int p;\n if (visR[u][0]) p |= 1 << 0;\n if (visR[u][1]) p |= 1 << 1;\n ++cntR[p];\n }\n \n debug {\n writeln(\"visL = \", visL);\n writeln(\"cntL = \", cntL);\n writeln(\"visR = \", visR);\n writeln(\"cntR = \", cntR);\n }\n \n foreach (p; 0 .. 4) foreach (q; 0 .. 4) {\n if (p & q) {\n ans += cntL[p] * cntR[q];\n }\n }\n if (l + 1 == r) {\n ans -= 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 int N = readInt;\n int M = readInt;\n auto A = new int[M];\n auto B = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt;\n B[i] = readInt;\n }\n M += 2 * N;\n foreach (u; 1 .. N + 1) {\n A ~= 0;\n B ~= u;\n A ~= u;\n B ~= N + 1;\n }\n \n auto G = new int[][N + 2];\n auto H = new int[][N + 2];\n foreach (i; 0 .. M) {\n G[A[i]] ~= i;\n H[B[i]] ~= i;\n }\n \n auto fs = new int[N + 1];\n foreach (i; 0 .. M) {\n if (A[i] + 1 == B[i]) {\n fs[A[i]] = 1;\n }\n }\n auto fsSum = new int[N + 2];\n foreach (u; 0 .. N + 1) {\n fsSum[u + 1] = fsSum[u] + fs[u];\n }\n \n long ans;\n if (fsSum[N + 1] == N + 1) {\n ans = 1L * N * (N - 1) / 2;\n } else {\n int l = N + 1, r = 0;\n foreach (u; 0 .. N + 1) {\n if (!fs[u]) {\n chmin(l, u);\n chmax(r, u + 1);\n }\n }\n debug {\n writeln(\"fs = \", fs);\n writeln(\"l = \", l, \", r = \", r);\n }\n bool isGood(int u, int v) {\n return (u <= v && fsSum[v] - fsSum[u] == v - u);\n }\n \n // (u, u + 1) to (l, l + 1), parity of # of steps\n auto visL = new bool[2][N + 1];\n visL[l][0] = true;\n foreach_reverse (u; 0 .. l + 1) {\n foreach (i; H[u + 1]) {\n // v -> u + 1, v + 1 -> u\n const v = A[i];\n if (isGood(v + 1, u)) {\n static foreach (s; 0 .. 2) {\n if (visL[u][s]) {\n visL[v][s ^ 1] = true;\n }\n }\n }\n }\n }\n long[4] cntL;\n foreach (u; 0 .. l + 1) {\n int p;\n foreach (s; 0 .. 2) {\n if (visL[u][s]) {\n p |= 1 << s;\n }\n }\n ++cntL[p];\n }\n \n // (l, l + 1) to (u, u + 1), parity of # of steps\n auto visR = new bool[2][N + 1];\n visR[l][0] = true;\n foreach (u; l .. N + 1) {\n foreach (i; G[u]) {\n // u -> v, u + 1 -> v - 1\n const v = B[i];\n if (isGood(u + 1, v - 1)) {\n static foreach (s; 0 .. 2) {\n if (visR[u][s]) {\n visR[v - 1][s ^ 1] = true;\n }\n }\n }\n }\n }\n long[4] cntR;\n foreach (u; /*!!!*/r - 1 .. N + 1) {\n int p;\n foreach (s; 0 .. 2) {\n if (visR[u][s]) {\n p |= 1 << s;\n }\n }\n ++cntR[p];\n }\n \n debug {\n writeln(\"visL = \", visL);\n writeln(\"cntL = \", cntL);\n writeln(\"visR = \", visR);\n writeln(\"cntR = \", cntR);\n }\n \n foreach (p; 0 .. 4) foreach (q; 0 .. 4) {\n if (p & q) {\n ans += cntL[p] * cntR[q];\n }\n }\n if (l + 1 == r) {\n ans -= 1;\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "ce3f65acc33d624ed977e1d8f3494597"} {"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 solve() {\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 long mx = -1;\n int mxi = -1;\n long sm = 0;\n bool erased = false;\n int skipped = -1;\n foreach (i, a; A) {\n if (sm + a <= M) {\n sm += a;\n if (a >= mx) {\n mx = a;\n mxi = i.to!int;\n }\n } else if (!erased) {\n if (a >= mx) {\n mx = a;\n mxi = i.to!int;\n }\n if (sm + a - mx <= M) {\n sm += a - mx;\n erased = true;\n skipped = mxi;\n } else {\n break;\n }\n } else {\n break;\n }\n }\n writeln(skipped + 1);\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) solve;\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\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 Ans = Tuple!(int, int);\n\nvoid main() {\n auto r = new InputReader;\n auto nt = r.next!uint;\n foreach (tid; 0 .. nt) {\n immutable n = r.next!uint.to!int;\n immutable s = r.next!uint;\n auto a = r.nextA!ulong(n);\n auto b = chain (only (0UL), a.cumulativeFold!((acc, x) => acc + x)).array;\n auto ans = Ans (0, 0);\n foreach (i; 1 .. n + 1) {\n if (b[i] <= s) ans = Ans (i, 0);\n }\n debug stderr.writeln (ans);\n auto e = assumeSorted (b);\n foreach (i; 0 .. n) {\n ulong x = s + a[i];\n auto rng = e.lowerBound (s + a[i] + 1);\n auto k = rng.length - 1;\n if (k >= (i + 1)) {\n auto cur = Ans ((k-1).to!int, (i + 1));\n if (ans[0] < cur[0]) ans = cur;\n }\n debug stderr.writeln (i, ' ', ans);\n }\n debug stderr.writeln (ans);\n writeln (ans[1]);\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 s = rlong;\n\t\tlong[] as = rlong(n);\n\n\t\tlong[] sums = [0];\n\t\tforeach(a; as) sums ~= sums[$ - 1] + a;\n\t\tlong[] maxs = [0];\n\t\tforeach(a; as) maxs ~= max(maxs[$ - 1], a);\n\n\t\tif(sums[n] <= s) 0.writeln;\n\t\telse{\n\t\t\tint right = 1;\n\t\t\tlong best = 0;\n\t\t\tforeach(i; 0 .. n + 1){\n\t\t\t\tlong tmp = sums[i] - maxs[i];\n\t\t\t\tif(tmp <= s && best < i - 1){\n\t\t\t\t\tbest = i - 1;\n\t\t\t\t\tright = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint ans = 0;\n\t\t\tforeach(i; 0 .. right) if(as[i] == maxs[right]) ans = i + 1;\n\t\t\tans.writeln;\n\t\t}\n\t\t\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 int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!int;\n\t\tauto a = RDA;\n\t\tauto b = new long[](n+1);\n\t\tauto c = new long[][](n+1, 2);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb[i+1] = b[i] + a[i];\n\t\t\tc[i+1] = c[i].dup;\n\t\t\tif (a[i] > c[i+1][0])\n\t\t\t\tc[i+1] = [a[i], i+1];\n\t\t}\n\t\tlong best;\n\t\tint pos;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i+1] <= s)\n\t\t\t{\n\t\t\t\tbest = i+1;\n\t\t\t\tpos = 0;\n\t\t\t}\n\t\t\telse if (b[i+1] - c[i+1][0] <= s)\n\t\t\t{\n\t\t\t\tbest = i;\n\t\t\t\tpos = cast(int)c[i+1][1];\n\t\t\t}\n\t\t}\n\t\tans[ti] = pos;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "0924971933265f4be34710149a541087"} {"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\tA[] as;\n\t\tB[] bs;\n\t\tforeach(i; 0 .. n){\n\t\t\tlong l = rlong * 2, r = rlong * 2 + 1;\n\t\t\tas ~= A(l, r);\n\t\t\tbs ~= B(l, 1);\n\t\t\tbs ~= B(r, 2);\n\t\t}\n\t\tbs.sort!((a, b) => a.x < b.x)();\n\t\tlog(\"as:\", as);\n\t\tlog(\"bs:\", bs);\n\n\t\tint[long] za;\n\t\tint zt = -1, f = 0;\n\t\tforeach(b; bs){\n\t\t\tif(f == b.f) za[b.x] = zt;\n\t\t\telse f = b.f, za[b.x] = (++ zt);\n\t\t}\n\t\tlog(\"za:\", za);\n\n\t\tint zmax = zt + 1;\n\n\t\tlong[] us = new long[](zmax);\n\t\tforeach(b; bs) us[za[b.x]] += [0, 1, -1][b.f];\n\t\tlog(\"us:\", us);\n\n\t\tlong[] vs = [0];\n\t\tforeach(u; us) vs ~= vs[$ - 1] + u;\n\t\tlog(\"vs:\", vs);\n\n\t\tint vcnt = 0;\n\t\tlong oldv = 0;\n\t\tforeach(v; vs){\n\t\t\tif(oldv == 0 && v > 0) vcnt += 1;\n\t\t\toldv = v;\n\t\t}\n\t\tlog(\"vcnt:\", vcnt);\n\n\t\tlong[] ws = [0];\n\t\tlong[] ws2 = [0];\n\t\tforeach(i; 1 .. zmax){\n\t\t\tif(vs[i - 1] > 1 && vs[i] == 1 && vs[i + 1] > 1) ws ~= ws[$ - 1] + 1;\n\t\t\telse ws ~= ws[$ - 1];\n\t\t\tif(vs[i - 1] == 0 && vs[i] == 1 && vs[i + 1] == 0) ws2 ~= ws2[$ - 1] + 1;\n\t\t\telse ws2 ~= ws2[$ - 1];\n\t\t}\n\t\tws ~= ws[$ - 1];\n\t\tws2 ~= ws2[$ - 1];\n\t\tlog(\"ws:\", ws);\n\t\tlog(\"ws2:\", ws2);\n\n\t\tlong ans;\n\t\tforeach(a; as){\n\t\t\tlog(\"a:\", a);\n\t\t\tlong tmp = vcnt + (ws[za[a.r]] - ws[za[a.l]]) - (ws2[za[a.r]] - ws2[za[a.l]]);\n\t\t\tlog(\"a:\", a, \"tmp:\", tmp);\n\t\t\tans.chmax(tmp);\n\t\t}\n\n\t\tans.writeln;\n\n\t}\n}\n\nstruct A{\n\tlong l, r;\n}\nstruct B{\n\tlong x;\n\tint f; // 1 = opening, 2 = closing\n}", "positive_code": [{"source_code": "import std.algorithm : maxElement, sort, swap;\nimport std.conv : to;\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 T = readInt;\n while (T--)\n {\n int n = readInt;\n auto a = new Tuple!(int, int)[n];\n for (int i = 0; i < n; ++i)\n {\n a[i][0] = readInt;\n a[i][1] = readInt;\n }\n sort(a);\n int result = 0, mx0 = -1, mx1 = -1;\n int[] delta = new int[n];\n for (int i = 0; i < n; ++i)\n {\n if (mx0 == -1 || a[mx0][1] < a[i][0])\n result++, delta[i] = -1;\n else\n {\n delta[i] = 0;\n if (mx1 == -1 || a[mx1][1] < a[i][0])\n delta[mx0]++;\n }\n int x = i;\n if (mx0 == -1 || a[x][1] > a[mx0][1])\n swap(mx0, x);\n if (~x && (mx1 == -1 || a[x][1] > a[mx1][1]))\n mx1 = x;\n }\n writeln(result + delta.maxElement);\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 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\tA[] as;\n\t\tB[] bs;\n\t\tforeach(i; 0 .. n){\n\t\t\tlong l = rlong * 2, r = rlong * 2 + 1;\n\t\t\tas ~= A(l, r);\n\t\t\tbs ~= B(l, 1);\n\t\t\tbs ~= B(r, 2);\n\t\t}\n\t\tbs.sort!((a, b) => a.x < b.x)();\n\t\tlog(\"as:\", as);\n\t\tlog(\"bs:\", bs);\n\n\t\tint[long] za;\n\t\tint zt = -1, f = 0;\n\t\tforeach(b; bs){\n\t\t\tif(f == b.f) za[b.x] = zt;\n\t\t\telse f = b.f, za[b.x] = (++ zt);\n\t\t}\n\t\tlog(\"za:\", za);\n\n\t\tint zmax = zt + 1;\n\n\t\tlong[] us = new long[](zmax);\n\t\tforeach(b; bs) us[za[b.x]] += [0, 1, -1][b.f];\n\t\tlog(\"us:\", us);\n\n\t\tlong[] vs = [0];\n\t\tforeach(u; us) vs ~= vs[$ - 1] + u;\n\t\tlog(\"vs:\", vs);\n\n\t\tint vcnt = 0;\n\t\tlong oldv = 0;\n\t\tforeach(v; vs){\n\t\t\tif(oldv == 0 && v > 0) vcnt += 1;\n\t\t\toldv = v;\n\t\t}\n\t\tlog(\"vcnt:\", vcnt);\n\n\t\tlong[] ws = [0];\n\t\tforeach(i; 1 .. zmax - 1){\n\t\t\tif(vs[i - 1] > 1 && vs[i] == 1 && vs[i + 1] > 1) ws ~= ws[$ - 1] + 1;\n\t\t\telse ws ~= ws[$ - 1];\n\t\t}\n\t\tws ~= ws[$ - 1];\n\t\tlog(\"ws:\", ws);\n\n\t\tlong ans;\n\t\tforeach(a; as){\n\t\t\tlog(\"a:\", a);\n\t\t\tlong tmp = vcnt + ws[za[a.r]] - ws[za[a.l]];\n\t\t\tlog(\"a:\", a, \"tmp:\", tmp);\n\t\t\tans.chmax(tmp);\n\t\t}\n\n\t\tans.writeln;\n\n\t}\n}\n\nstruct A{\n\tlong l, r;\n}\nstruct B{\n\tlong x;\n\tint f; // 1 = opening, 2 = closing\n}"}], "src_uid": "58d7066178839b400b08f39b680da140"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 x = RD-1L;\n\t\tauto y = RD;\n\t\tauto k = RD;\n\n\t\tauto a = k*y;\n\t\tauto b = k + a - 1;\n\t\tans[ti] = (b+x-1) / x + k;\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 ll x, y, k, s;\n x = rd; y = rd; k = rd;\n x -= 1;\n ll totake = (k*y + k - 1);\n ll trade = totake/x + (totake % x != 0) + k;\n writeln(trade);\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 ll x, y, k;\n x = rd; y = rd; k = rd;\n x -= 1;\n ll trade = 0;\n ll s = 1;\n ll left = k*y; \n trade += left/x + (left % x != 0);\n if(left % x != 0){ s = left % x; }\n left = k - s;\n trade += left/x + (left % x != 0);\n trade += k;\n writeln(trade);\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 ll x, y, k, s;\n x = rd; y = rd; k = rd;\n if(k == 1){\n writeln(0);\n }\n x -= 1;\n ll trade = 1;\n ll left = k*y - x - 1; \n trade += left/x + (left % x != 0);\n if(left % x != 0){ s = x - (left % x); }\n left = max(k - s, 0);\n debug writeln(\" L \", left);\n trade += left/x + (left % x != 0);\n trade += k;\n writeln(trade);\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 ll x, y, k, s;\n x = rd; y = rd; k = rd;\n x -= 1;\n ll trade = 1;\n ll left = k*y - x - 1; \n trade += left/x + (left % x != 0);\n if(left % x != 0){ s = x - (left % x); }\n left = max(k - s, 0);\n trade += left/x + (left % x != 0);\n trade += k;\n writeln(trade);\n}\n\nvoid main(){\n long t = 1;\n t = rd;\n while(t--) solve();\n stdout.flush;\n}\n\n"}], "src_uid": "28610d192329c78580db354f8dfc4094"} {"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 s = readln.strip;\n long ans;\n foreach (i ; 0 .. s.length) {\n int used = 0;\n int distinct = 0;\n int[10] cnt;\n foreach (j ; i .. s.length) {\n int digit = cast(int)(s[j] - '0');\n// writeln(digit);\n if ((used & (1 << digit)) == 0)\n distinct++;\n used |= (1 << digit);\n if (++cnt[digit] > 10)\n break;\n bool good = true;\n// writeln(cnt);\n foreach (x ; cnt) {\n if (x > distinct) {\n good = false;\n break;\n }\n }\n if (good)\n ans++;\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\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 = readln.strip();\r\n long res;\r\n foreach(i; 0 .. n) {\r\n int[10] num;\r\n int cnt, maxNum;\r\n foreach(k; i .. n) {\r\n auto t = s[k] - '0';\r\n if (num[t] >= 10)\r\n break;\r\n if(!num[t]) ++cnt;\r\n num[t]++;\r\n maxNum = max(maxNum, num[t]);\r\n if (maxNum <= cnt)\r\n ++res;\r\n }\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": [{"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 = readln.strip();\r\n long res, max_freq;\r\n foreach(i; 0 .. n)\r\n foreach(k; i .. n) {\r\n max_freq = 0;\r\n if (k - i > 1) {\r\n auto tmp = s[i..k].array.sort;\r\n auto dist = tmp.uniq.array.length;\r\n auto freq = tmp.group;\r\n max_freq = (freq.maxElement!\"a[1]\")[1];\r\n if (max_freq <= dist)\r\n res++;\r\n }\r\n else if (k - i == 1)\r\n res++;\r\n if (max_freq > 10)\r\n break;\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.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 = readln.strip();\r\n long res, max_freq;\r\n foreach(i; 0 .. n + 1)\r\n foreach(k; i .. n + 1) {\r\n if (k - i > 1) {\r\n auto tmp = s[i..k].array.sort;\r\n auto dist = tmp.uniq.array.length;\r\n auto freq = tmp.group;\r\n max_freq = (freq.maxElement!\"a[1]\")[1];\r\n if (max_freq <= dist)\r\n res++;\r\n }\r\n else if (k - i == 1)\r\n res++;\r\n if (max_freq > 10)\r\n break;\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.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 = readln.strip();\r\n long res, max_freq;\r\n foreach(i; 0 .. n)\r\n foreach(k; i .. n + 1) {\r\n auto tmp = s[i..k].array.sort;\r\n if (k - i > 1) {\r\n auto dist = tmp.uniq.array.length;\r\n auto freq = tmp.group;\r\n max_freq = (freq.maxElement!\"a[1]\")[1];\r\n if (max_freq <= dist)\r\n res++;\r\n }\r\n else if (k - i == 1)\r\n res++;\r\n if (max_freq > 10)\r\n break;\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"}], "src_uid": "e7f84300e9480a94a2399fcd5f47ecec"} {"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 = new int[n];\n\tfor(int i = 0; i to!int(a)).array;\n\n int w = 1;\n int prev = -1;\n bool ok = true;\n foreach (i; 1 .. n)\n {\n if (p[i - 1] == p[i])\n {\n w++;\n }\n else\n {\n ok &= prev < 0 || prev == w;\n prev = w;\n w = 1;\n }\n }\n ok &= prev < 0 || prev == w;\n\n writeln(ok ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tint curr;\n\tint firstPeriod;\n\tint currentPeriod;\n\tscanf(\"%d\", &n);\n\tfirstPeriod = 0;\n\tcurrentPeriod= 0;\n\tfor(int i = 0; i1) {if (a[i]!=a[i-1])\n\t\t{\n\t\t if (x==0)\n\t\t {\n\t\t x=i-1;\n\t\t y=i;\n\t\t }\n\t\t else {if (i-y==x) y=i;\n\t\t else {printf(\"NO\");return 0;}}\n\t\t}\n\t\t}\n\t\t\n\t}\n\tif (dp[n]==0) {printf(\"YES\");return 0;}\n\tif (dp[n]==n) {printf(\"YES\");return 0;}\n\tif (n-y==x-1)\n\tprintf(\"YES\");\n\telse printf(\"NO\");\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\nimport std.regex;\n\nvoid main() {\n\tint n, x;\n\tint ans = 1;\n\tint a=0, b=0;\n\tint c=0, d=-1;\n\tscanf(\"%d\", &n );\n\tfor( int i = 1; i <= n; i ++ )\n\t{\n\t scanf( \"%d\", &x );\n\t if( d == -1 )\n\t {\n\t d = x;\n\t }\n\t if( d == x )\n\t {\n\t c ++;\n\t }\n\t else \n\t {\n\t if( x == 1 )\n\t {\n\t if( a == 0 ) \n\t a = c;\n\t if( a != c ) \n\t ans = 0;\n\t }\n\t else \n\t {\n\t if( b == 0 )\n\t b = c;\n\t if( b != c )\n\t ans = 0;\n\t }\n\t d = x;\n\t c = 1;\n\t }\n }\n\tif( d == 0 )\n\t{\n \tif( a == 0 )\n \t a = c;\n \t if( a != c ) \n \t ans = 0;\n\t}\n\telse \n {\n if( b == 0 )\n b = c;\n\t if( b != c )\n\t ans = 0;\n\t}\n\tif( a == 0 )\n\t a = b;\n\tif( b == 0 )\n\t b = a;\n\tif( a != b )\n\t ans = 0;\n\tif( ans == 1 )\n\t printf( \"YES\" );\n\telse \n\t printf( \"NO\" );\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int cnt = 0, temp = 0, last = -1;\n int n;\n readf(\"%d\\n\", &n);\n int a;\n int ok = 1;\n for (int i = 0; i < n; i++) {\n readf(\"%d \", &a);\n \n if (a == last) {\n temp++;\n } else {\n last = a;\n if (cnt > 0 && cnt != temp) {\n ok = 2;\n break;\n } else {\n cnt = temp;\n temp = 1;\n }\n }\n }\n if (cnt > 0 && cnt != temp) {\n ok = 2;\n }\n if (ok == 1) {\n write(\"YES\\n\");\n } else {\n write(\"NO\\n\");\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\t printf(\"YES\");\n\t return 0;\n\t} else {\n \tint[] array = new int[n];\n \tfor(int i = 0; i < n; i++) {\n \t\tscanf(\"%d\", &array[i]);\n \t}\n \tint j = 1;\n \tfor (; j < n && array[j] == array[j - 1]; ++j) {}\n \tif (j == n) {\n \t printf(\"YES\");\n \t return 0;\n \t}\n \tif (n % j != 0) {\n \t printf(\"NO\");\n \t return 0;\n \t}\n\t for(int i = 0; i < n; i += j) {\n\t if (i > 0 && array[i] == array[i - 1]) {\n\t printf(\"NO\");\n\t return 0;\n\t }\n\t for(int k = i + 1; k < i + j; ++k) {\n\t if (array[k] != array[k - 1]) {\n\t printf(\"NO\");\n\t return 0;\n\t }\n\t }\n\t }\n\t printf(\"YES\");\n\t return 0;\n\t}\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 [] arr = new int[n];\n\tfor(int i = 0; i0 && a[i]!=a[i-1])\n {\n if (col==0)\n col=x;\n if (col!=x)\n {\n printf(\"NO\");\n return ;\n }\n x=0;\n }\n x++;\n }\n if (x!=0 && x!=col && col!=0)\n {\n printf(\"NO\");\n return ;\n }\n printf(\"YES\");\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 [] arr = new int[n];\n\tfor(int i = 0; i 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\n\t\tvoid perform (int [] cuts)\n\t\t{\n\t\t\tint [] res;\n\t\t\tforeach_reverse (i; 1..cuts.length)\n\t\t\t{\n\t\t\t\tres ~= p[cuts[i - 1]..cuts[i]];\n\t\t\t}\n\t\t\tp = res;\n\t\t}\n\n\t\tint [] [] answer;\n\t\twhile (!p.isSorted)\n\t\t{\n\t\t\tauto q = new int [n];\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tq[p[i]] = i;\n\t\t\t}\n\t\t\tforeach (v; 0..n - 1)\n\t\t\t{\n\t\t\t\tif (q[v + 1] < q[v] + 1)\n\t\t\t\t{\n\t\t\t\t\tauto pos = q[v + 1];\n\t\t\t\t\twhile (p[pos + 1] == p[pos] + 1)\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\tauto cuts = only (0, q[v + 1],\n\t\t\t\t\t pos + 1, q[v] + 1, n).uniq.array;\n\t\t\t\t\tperform (cuts);\n\t\t\t\t\tanswer ~= cuts.zip (cuts[1..$])\n\t\t\t\t\t .map !(q{a[1] - a[0]}).array;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\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", "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 c = RDA(-1);\n\n\tint[][] lrp;\n\tint[][] ans;\n\tforeach (_; 0..n)\n\t{\n\t\t{\n\t\t\tlrp.length = 0;\n\t\t\tint l;\n\t\t\tforeach (i; 0..n-1)\n\t\t\t{\n\t\t\t\tif (c[i]+1 == c[i+1]) continue;\n\t\t\t\tlrp ~= [c[l], c[i], l];\n\t\t\t\tl = i+1;\n\t\t\t}\n\t\t\tlrp ~= [c[l], c[$-1], l];\n\t\t}\n\t\tdebug writeln(lrp);\n\t\tif (lrp.length == 1) break;\n\n\t\tint[int] list;\n\t\tforeach (int j, ref e; lrp)\n\t\t{\n\t\t\tauto pos = list.get(e[1]+1, -1);\n\t\t\tif (pos != -1)\n\t\t\t{\n\t\t\t\tdebug writeln(e, \" \", lrp[pos]);\n\t\t\t\tauto ee = lrp[pos];\n\t\t\t\tauto l = ee[0];\n\t\t\t\tauto r = ee[1];\n\t\t\t\tauto p = ee[2];\n\t\t\t\tauto len = e[1] - e[0] + 1;\n\t\t\t\tdebug writeln(\"len:\", len);\n\t\t\t\tint[] tmp;\n\t\t\t\tif (p != 0)\n\t\t\t\t\ttmp ~= p;\n\t\t\t\ttmp ~= e[2] - p;\n\t\t\t\ttmp ~= len;\n\t\t\t\tif (e[2]+len < n)\n\t\t\t\t\ttmp ~= n - (e[2]+len);\n\t\t\t\tans ~= cast(int)tmp.length ~ tmp;\n\t\t\n\t\t\t\tint[] next;\n\t\t\t\tint cnt = n;\n\t\t\t\tforeach_reverse (t; tmp)\n\t\t\t\t{\n\t\t\t\t\tnext ~= c[cnt-t..cnt];\n\t\t\t\t\tcnt -= t;\n\t\t\t\t}\n\t\t\t\tc = next;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlist[e[0]] = j;\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(ans.length);\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\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 C = new int[N];\n foreach (i; 0 .. N) {\n C[i] = readInt() - 1;\n }\n \n auto cs = C.dup;\n int[][] dss;\n int cnt;\n foreach (i; 0 .. N) {\n if (cs[i] != i) {\n foreach (j; 0 .. N) {\n if (cs[j] == i) {\n int[] ds;\n foreach (k; 0 .. i) {\n ds ~= 1;\n }\n ds ~= (j + 1) - i;\n foreach (k; j + 1 .. N) {\n ds ~= 1;\n }\n if (cnt % 2 != 0) {\n ds.reverse;\n }\n ++cnt;\n if (ds.length > 1) {\n dss ~= ds;\n }\n cs[i .. j + 1].reverse;\n break;\n }\n }\n }\n }\n if (cnt % 2 != 0) {\n int[] ds;\n foreach (i; 0 .. N) {\n ds ~= 1;\n }\n ds.reverse;\n if (ds.length > 1) {\n dss ~= ds;\n }\n }\n \n writeln(dss.length);\n foreach (ds; dss) {\n write(ds.length);\n foreach (d; ds) {\n write(\" \", d);\n }\n writeln;\n }\n \n debug {\n cs = C.dup;\n foreach (ds; dss) {\n int[][] blocks;\n int i;\n foreach (d; ds) {\n blocks ~= cs[i .. i + d];\n i += d;\n }\n assert(i == N);\n blocks.reverse;\n cs = [];\n foreach (block; blocks) {\n cs ~= block;\n }\n }\n assert(cs == iota(N).array, format(\"C = %s, cs = %s\", C, cs));\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 C = new int[N];\n foreach (i; 0 .. N) {\n C[i] = readInt() - 1;\n }\n \n auto cs = C.dup;\n int[][] dss;\n foreach (i; 0 .. N) {\n if (cs[i] != i) {\n foreach (j; 0 .. N) {\n if (cs[j] == i) {\n int[] ds;\n foreach (k; 0 .. i) {\n ds ~= 1;\n }\n ds ~= (j + 1) - i;\n foreach (k; j + 1 .. N) {\n ds ~= 1;\n }\n if (ds.length > 1) {\n dss ~= ds;\n }\n cs[i .. j + 1].reverse;\n break;\n }\n }\n }\n }\n if (dss.length % 2 != 0) {\n int[] ds;\n foreach (i; 0 .. N) {\n ds ~= 1;\n }\n if (ds.length > 1) {\n dss ~= ds;\n }\n }\n \n writeln(dss.length);\n foreach (ds; dss) {\n write(ds.length);\n foreach (d; ds) {\n write(\" \", d);\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 N = readInt();\n auto C = new int[N];\n foreach (i; 0 .. N) {\n C[i] = readInt() - 1;\n }\n \n auto cs = C.dup;\n int[][] dss;\n int cnt;\n foreach (i; 0 .. N) {\n if (cs[i] != i) {\n foreach (j; 0 .. N) {\n if (cs[j] == i) {\n int[] ds;\n foreach (k; 0 .. i) {\n ds ~= 1;\n }\n ds ~= (j + 1) - i;\n foreach (k; j + 1 .. N) {\n ds ~= 1;\n }\n ++cnt;\n if (ds.length > 1) {\n dss ~= ds;\n }\n cs[i .. j + 1].reverse;\n break;\n }\n }\n }\n }\n if (cnt % 2 != 0) {\n int[] ds;\n foreach (i; 0 .. N) {\n ds ~= 1;\n }\n if (ds.length > 1) {\n dss ~= ds;\n }\n }\n \n writeln(dss.length);\n foreach (ds; dss) {\n write(ds.length);\n foreach (d; ds) {\n write(\" \", d);\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 N = readInt();\n auto C = new int[N];\n foreach (i; 0 .. N) {\n C[i] = readInt() - 1;\n }\n \n auto cs = C.dup;\n int[][] dss;\n foreach (i; 0 .. N) {\n if (cs[i] != i) {\n foreach (j; 0 .. N) {\n if (cs[j] == i) {\n int[] ds;\n foreach (k; 0 .. i) {\n ds ~= 1;\n }\n ds ~= (j + 1) - i;\n foreach (k; j + 1 .. N) {\n ds ~= 1;\n }\n dss ~= ds;\n cs[i .. j + 1].reverse;\n break;\n }\n }\n }\n }\n if (dss.length % 2 != 0) {\n int[] ds;\n foreach (i; 0 .. N) {\n ds ~= 1;\n }\n dss ~= ds;\n }\n \n writeln(dss.length);\n foreach (ds; dss) {\n write(ds.length);\n foreach (d; ds) {\n write(\" \", d);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "07bc926194f45da75e4c534a7fd3656b"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tint l, r;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[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 (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 1)\n\t\t\t{\n\t\t\t\tr = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tforeach (i; l..r)\n\t\t{\n\t\t\tif (a[i] == 0)\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}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n int ix = -1, rix = -1;\n foreach(i; 0..n){\n if(arr[i] == 1){ ix = i; break; }\n }\n foreach_reverse(i; 0..n){\n if(arr[i] == 1){ rix = i; break; }\n }\n if(ix == -1){\n writeln(0);\n return;\n }\n int cnt = 0;\n foreach(i; ix..rix+1){\n cnt += (arr[i] == 0);\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;\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.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\twhile (!a.front)\n\t\t{\n\t\t\ta.popFront ();\n\t\t}\n\t\twhile (!a.back)\n\t\t{\n\t\t\ta.popBack ();\n\t\t}\n\t\twriteln (a.length - a.sum);\n\t}\n}\n"}], "negative_code": [], "src_uid": "1c07882651ef6ebfc05e777d562e28b9"} {"source_code": "module main;\n\nimport std.stdio, std.string;\n\nvoid solve(int[] w, int[] h)\n{\n int maxs = 0, cnt = 0, smaxs = 0;\n long sum = 0;\n foreach (i; 0 .. w.length)\n {\n\tif (h[i] > maxs)\n\t{\n\t if (maxs != 0)\n\t {\n\t\tsmaxs = maxs;\n\t }\n\t maxs = h[i];\n\t cnt = 1;\n\t}\n\telse if (h[i] == maxs)\n\t{\n\t smaxs = h[i];\n\t ++ cnt;\n\t}\n\telse if (h[i] > smaxs)\n\t{\n\t smaxs = h[i];\n\t}\n\tsum += w[i];\n }\n foreach (i; 0 .. w.length)\n {\n\tif (h[i] == maxs)\n\t{\n\t if (cnt == 1)\n\t {\n\t\twritef(\"%d \", (sum - w[i]) * smaxs);\n\t }\n\t else\n\t {\n\t\twritef(\"%d \", (sum - w[i]) * maxs);\n\t }\n\t}\n\telse\n\t{\n\t writef(\"%d \", (sum - w[i]) * maxs);\n\t}\n }\n writeln();\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n\tauto w = new int[n];\n\tauto h = new int[n];\n\tforeach (i; 0 .. n)\n\t{\n\t scanf(\"%d%d\", &w[i], &h[i]);\n\t}\n\tsolve(w, h);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\n\tint n;\n\tubyte w;\n\tushort h;\n\n\tscanf(\"%d\", &n);\n\n\tint[] W;\n\tushort[] H;\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %s %s\", &w, &h);\n\t\tW ~= w, H ~= h;\n\t}\n\n\tushort[] tmpH = H.dup;\n\tsort(tmpH);\n\tushort max1 = tmpH[$ - 1], max2 = tmpH[$ - 2];\n\n\tint sum = W.reduce!\"a + b\";\n\n\tforeach (i, elem; W)\n\t\twrite((H[i] != max1) ? ((sum - elem) * max1) : ((sum - elem) * max2), ' ');\n\n\twriteln;\n}"}, {"source_code": "import std.stdio;\n\nint n;\nshort[] a;\n\nulong sumW() {\n\tulong sum;\n\tfor (size_t i = 0; i < 2 * n; i += 2)\n\t\t\tsum += a[i];\n\treturn sum;\n}\n\nsize_t j, k, t;\n\nshort maxH() {\n\tshort max;\n\tfor (size_t i = 1; i < 2 * n; i += 2)\n\t\t\tif ((a[i] > max) && (i != j)) {\n\t\t\t\tmax = a[i];\n\t\t\t\tk = i;\n\t\t\t}\n\n\tif (t < 1)\n\t\tj = k;\n\n\t++t;\n\n\treturn max;\n}\n\nvoid main() {\n\n\tscanf(\"%d\", &n);\n\n\tshort w, h;\n\tforeach (i; 0 .. n) {\n\t\tscanf(\"%hd%hd\", &w, &h);\n\t\ta ~= w,\ta ~= h;\n\t}\n\n\tulong sum = sumW();\n\tshort max1 = maxH();\n\tshort max2 = maxH();\n\n\tfor (size_t i = 0; i < 2 * n; i += 2)\n\t\tif (i != j - 1)\n\t\t\twrite((sum - a[i]) * max1, ' ');\n\t\telse\n\t\t\twrite((sum - a[i]) * max2, ' ');\n\n\tputchar('\\n');\n}"}], "negative_code": [], "src_uid": "e1abc81cea4395ba675cf6ca93261ae8"} {"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 auto Y = A.dup;\r\n\r\n auto used = new bool[N];\r\n\r\n int s = 0;\r\n int[] X;\r\n for (int i = 0; i < 32; i++) {\r\n int m = -1;\r\n int x = 0;\r\n for (int j = 0; j < N; j++) {\r\n if (used[j]) continue;\r\n if (x < Y[j]) {\r\n x = Y[j];\r\n m = j;\r\n }\r\n }\r\n if (m < 0) continue;\r\n used[m] = true;\r\n X ~= A[m];\r\n s |= A[m];\r\n foreach (ref a; Y) {\r\n a = a & ~s;\r\n }\r\n }\r\n for (int i = 0; i < N; i++) {\r\n if (used[i]) continue;\r\n X ~= A[i];\r\n }\r\n writefln(\"%(%s %)\", X);\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!int).array;\n int mask = 0;\n size_t i = 0;\n while (i < a.length) {\n a[i .. $].sort!((x, y) => (y & ~mask) < (x & ~mask));\n if ((a[i] & ~mask) == 0)\n break;\n mask |= a[i];\n i++;\n }\n writefln(\"%(%s %)\", a);\n }\n}\n"}], "negative_code": [], "src_uid": "64458fc3c2bf40ca911b566092f544e8"} {"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);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, k, lim;\n\t\treadf !(\" %s %s %s\") (n, k, lim);\n\t\treadln;\n\t\tauto d = readln.splitter.map !(to !(int)).array;\n\t\td[] = lim - d[];\n\t\tif (d.any !(q{a < 0}))\n\t\t{\n\t\t\twriteln (\"No\");\n\t\t\tcontinue multitest_loop;\n\t\t}\n\t\tint cur = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tcur += 1;\n\t\t\tif (d[i] >= k)\n\t\t\t{\n\t\t\t\tcur = -1;\n\t\t\t}\n\t\t\telse if (cur < k)\n\t\t\t{\n\t\t\t\tcur = max (cur, k - d[i]);\n\t\t\t}\n\t\t\telse if (d[i] < k && cur > k + d[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\t\twriteln (\"Yes\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nclass Input\n{\nstatic:\n import std.container: DList, make;\n DList!string words;\n T next(alias T)()\n {\n import std.conv: to;\n import std.string: split;\n while (words.empty)\n {\n string line = stdin.readln;\n foreach(word; line.split)\n words.insertFront(word);\n }\n string nextWord = words.back;\n words.removeBack;\n return to!T(nextWord);\n }\n void read(Args...)(ref Args args)\n {\n static foreach(i, arg; args)\n arg = next!(Args[i])();\n }\n}\n\nstruct Interval(string type)\n{\n long lowerBound, higherBound;\n bool empty()\n {\n static if (type == \"[]\")\n return !(lowerBound <= higherBound);\n else\n static assert(false);\n }\n}\n\nInterval!type intersect(string type)(Interval!type a, Interval!type b)\n{\n import std.algorithm: min, max;\n return Interval!type(max(a.lowerBound, b.lowerBound),\n min(a.higherBound, b.higherBound));\n}\n\nauto intersect(IntervalRange1, IntervalRange2)(IntervalRange1 a, IntervalRange2 b)\n if (isInputRange!IntervalRange1 && isInputRange!IntervalRange2)\n{\n import std.algorithm.setops: cartesianProduct;\n import std.algorithm: map, filter;\n\n return cartesianProduct(a.filter!(i=>!i.empty), b.filter!(i=>!i.empty))\n .map!(t => intersect(t[0], t[1]))\n .filter!(i => !i.empty)();\n}\n\nimport std.range.primitives: isInputRange;\nauto simplifyIntervals(IntervalRange)(IntervalRange range)\n if (isInputRange!IntervalRange)\n {\n struct Event\n {\n long position;\n int type;\n }\n auto less = (Event e1, Event e2)\n {\n if (e1.position < e2.position)\n return true;\n if (e1.position > e2.position)\n return false;\n return e1.type > e2.type;\n };\n import std.algorithm: sort;\n import std.array: appender;\n\n long[long] events;\n foreach(interval; range)\n {\n events[interval.lowerBound]++;\n events[interval.higherBound + 1]--;\n }\n long start = int.min;\n long cnt = 0;\n auto result = appender!(Interval!\"[]\"[])();\n result.reserve(range.length);\n foreach(position; sort(events.keys()))\n {\n auto delta = events[position];\n import std.conv;\n assert(cnt >= 0, text(\"Failed with range \", range, \" with events \", events));\n if (cnt == 0)\n {\n cnt += delta;\n start = position;\n }\n else\n {\n cnt += delta;\n if (cnt == 0)\n result.put(Interval!\"[]\"(start, position - 1));\n }\n }\n return result[];\n }\nint main()\n{\n long t;\n Input.read(t);\n testCase:while(t--)\n {\n import std.algorithm: min;\n long n, k, l;\n Input.read(n, k, l);\n long mod = 2 * k;\n auto d = new long[cast(size_t)n];\n foreach(ref di; d)\n Input.read(di);\n auto sealimit = new long[cast(size_t)n];\n foreach(i, di; d)\n {\n long maxsea = l - di;\n if (maxsea < 0)\n {\n writeln(\"No\");\n continue testCase;\n }\n if (maxsea < k)\n sealimit[i] = maxsea;\n else\n sealimit[i] = -1;\n }\n \n Interval!\"[]\"[] activeIntervals = [Interval!\"[]\"(0, 2 * k - 1)];\n foreach(i, limit; sealimit)\n {\n import std.array: appender;\n auto newActive = appender!(Interval!\"[]\"[])();\n foreach(ref interval; activeIntervals) with(interval)\n {\n assert(!interval.empty);\n lowerBound++;\n lowerBound %= 2 * k;\n higherBound++;\n higherBound %= 2 * k;\n if (lowerBound > higherBound)\n {\n newActive.put(Interval!\"[]\"(lowerBound, 2 * k - 1));\n newActive.put(Interval!\"[]\"(0, higherBound));\n }\n else\n {\n newActive.put(interval);\n }\n }\n activeIntervals = simplifyIntervals(newActive[]);\n if (limit == -1)\n {\n activeIntervals = [Interval!\"[]\"(0, 2 * k - 1)];\n continue;\n }\n import std.array: array;\n activeIntervals = intersect([Interval!\"[]\"(0, limit), Interval!\"[]\"(2 * k - limit, 2 * k - 1)], activeIntervals).array;\n if (activeIntervals.length == 0)\n {\n writeln(\"No\");\n continue testCase;\n }\n }\n long totalLength = 0;\n import std.algorithm: max;\n foreach(interval; activeIntervals)\n totalLength += max(0, interval.higherBound - interval.lowerBound + 1);\n if (totalLength > 0)\n writeln(\"Yes\");\n else\n writeln(\"No\");\n }\n return 0;\n}\n"}], "negative_code": [], "src_uid": "7671925bc31f80b5ff875dd285d85d32"} {"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 x = readln.splitter.map !(to !(int)).array;\n\t\tforeach (i; x)\n\t\t{\n\t\t\tforeach (j; x)\n\t\t\t{\n\t\t\t\tforeach (k; x)\n\t\t\t\t{\n\t\t\t\t\tif (max (i, j) == x[0] &&\n\t\t\t\t\t max (i, k) == x[1] &&\n\t\t\t\t\t max (j, k) == x[2])\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"YES\");\n\t\t\t\t\t\twriteln (i, \" \", j, \" \", k);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (\"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm : max, min;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n long x, y, z;\n readf!\"%d %d %d\\n\"(x, y, z);\n\n // trivial case\n if (x == y && y == z) {\n writefln(\"YES\\n%d %d %d\", x, x, x);\n continue;\n }\n\n // otherwise, 2 of 3 have to be max\n auto m = max(x, y, z);\n auto n = min(x, y, z);\n if ((x == m && y == m) || (x == m && z == m) || (y == m && z == m)) {\n writefln(\"YES\\n%d %d %d\", n, n, m);\n continue;\n }\n\n writeln(\"NO\");\n }\n}"}], "negative_code": [], "src_uid": "f4804780d9c63167746132c35b2bdd02"} {"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 + 1];\n\t\tauto b = new int [n + 1];\n\t\tauto s = new long [n + 1];\n\t\tint [] [int] x;\n\t\ts[0] = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t\tb[i] = max (a[i], 0);\n\t\t\ts[i] = s[i - 1] + b[i];\n\t\t\tx[a[i]] ~= i;\n\t\t}\n\n\t\tlong res = long.min;\n\t\tint bu, bv;\n\t\tforeach (i, c; x)\n\t\t{\n\t\t\tif (c.length >= 2)\n\t\t\t{\n\t\t\t\tint u = c[0];\n\t\t\t\tint v = c[$ - 1];\n\t\t\t\tlong cur = i * 2 + s[v - 1] - s[u];\n\t\t\t\tif (res < cur)\n\t\t\t\t{\n\t\t\t\t\tres = cur;\n\t\t\t\t\tbu = u;\n\t\t\t\t\tbv = v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint [] ans;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tif (i < bu || bv < i ||\n\t\t\t (i != bu && i != bv && a[i] < 0))\n\t\t\t{\n\t\t\t\tans ~= i;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%s %s\", res, ans.length);\n\t\twritefln (\"%(%s %)\", ans);\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 = new int [n + 1];\n\t\tauto b = new int [n + 1];\n\t\tauto s = new long [n + 1];\n\t\tint [] [int] x;\n\t\ts[0] = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t\tb[i] = max (a[i], 0);\n\t\t\ts[i] = s[i - 1] + b[i];\n\t\t\tx[a[i]] ~= i;\n\t\t}\n\n\t\tlong res = long.min;\n\t\tint bu, bv;\n\t\tforeach (i, c; x)\n\t\t{\n\t\t\tif (c.length >= 2)\n\t\t\t{\n\t\t\t\tint u = c[0];\n\t\t\t\tint v = c[$ - 1];\n\t\t\t\tlong cur = i * 2 + s[v - 1] - s[u];\n\t\t\t\tif (res < cur)\n\t\t\t\t{\n\t\t\t\t\tres = cur;\n\t\t\t\t\tbu = u;\n\t\t\t\t\tbv = v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint [] ans;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tif (i < bu || bv < i ||\n\t\t\t (i != bu && i != bv && a[i] < 0))\n\t\t\t{\n\t\t\t\tans ~= i;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%s %s\", res, ans.length);\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "negative_code": [], "src_uid": "b3418f53720fb9eb990d6e99b07fd61b"} {"source_code": "/+ dub.sdl:\n name \"D\"\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.numeric.prime;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n\n debug {\n foreach (n; 3..1001) {\n bool ok = false;\n foreach (m; n..(n + n / 4 * 2) + 1) {\n if (isPrime(m)) {\n ok = true;\n writefln(\"find %d : %d\", n, m);\n stdout.flush;\n break;\n }\n }\n if (!ok) {\n writeln(\"ERROR \", n);\n return 0;\n }\n }\n }\n\n int n;\n sc.read(n); \n foreach (m; n..(n + n / 4 * 2) + 1) {\n if (isPrime(m)) {\n\n int[2][] edges;\n foreach (i; 0..n) {\n edges ~= [i, (i + 1) % n];\n }\n foreach (i; 0..n) {\n if (i % 4 >= 2) continue;\n if (edges.length.to!int >= m) break;\n edges ~= [i, (i + 2) % n];\n }\n\n writeln(m);\n foreach (d; edges) {\n writeln(d[0] + 1, \" \", d[1] + 1);\n }\n return 0;\n }\n }\n\n\n return 0;\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/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/numeric/prime.d */\n// module dkh.numeric.prime;\n\nimport std.traits;\n// import dkh.int128;\n\n \nulong ulongPowMod(U)(ulong x, U n, ulong md)\nif (isIntegral!U || is(U == BigInt)) {\n x %= md;\n ulong r = 1;\n while (n) {\n if (n & 1) {\n r = mul128(r, x).mod128(md);\n }\n x = mul128(x, x).mod128(md);\n n >>= 1;\n }\n return r % md;\n}\n\n \nT[] divisorList(T)(T x) {\n import std.algorithm : sort;\n T[] res;\n for (T i = 1; i*i <= x; i++) {\n if (x%i == 0) {\n res ~= i;\n if (i*i != x) res ~= x/i;\n }\n }\n sort(res);\n return res;\n}\n\n \n \n\n \nT[] factorList(T)(T x) {\n T[] res;\n for (T i = 2; i*i <= x; i++) {\n while (x % i == 0) {\n res ~= i;\n x /= i;\n }\n }\n if (x > 1) res ~= x;\n \n return res;\n}\n\n \n \n\n// import dkh.numeric.primitive;\n\n \nbool isPrime(ulong n) {\n// import dkh.int128;\n if (n <= 1) return false;\n if (n == 2) return true;\n if (n % 2 == 0) return false;\n ulong d = n-1;\n while (d % 2 == 0) d /= 2;\n ulong[] alist = [2,3,5,7,11,13,17,19,23,29,31,37];\n foreach (a; alist) {\n if (n <= a) break;\n ulong y = ulongPowMod(a, d, n);\n ulong t = d;\n while (t != n-1 && y != 1 && y != n-1) {\n y = mul128(y, y).mod128(n);\n t <<= 1;\n }\n if (y != n-1 && t % 2 == 0) {\n return false;\n }\n }\n return true;\n}\n\n \n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/numeric/primitive.d */\n// module dkh.numeric.primitive;\n\nimport std.traits, std.bigint;\n\n \nT lcm(T)(in T a, in T b) {\n import std.numeric : gcd;\n return a / gcd(a,b) * b;\n}\n\n \n \n\n \nUnqual!T pow(T, U)(T x, U n)\nif (!isFloatingPoint!T && (isIntegral!U || is(U == BigInt))) {\n return pow(x, n, T(1));\n}\n\n \nUnqual!T pow(T, U, V)(T x, U n, V e)\nif ((isIntegral!U || is(U == BigInt)) && is(Unqual!T == Unqual!V)) {\n Unqual!T b = x, v = e;\n Unqual!U m = n;\n while (m) {\n if (m & 1) v *= b;\n b *= b;\n m /= 2;\n }\n return v;\n}\n\n \n\n \nT powMod(T, U, V)(T x, U n, V md)\nif (isIntegral!U || is(U == BigInt)) {\n T r = T(1);\n Unqual!U m = n;\n while (m) {\n if (m & 1) r = (r*x)%md;\n x = (x*x)%md;\n m >>= 1;\n }\n return r % md;\n}\n\n \n\n \n \nT[3] extGcd(T)(in T a, in T b) \nif (!isIntegral!T || isSigned!T) \n{\n if (b==0) {\n return [T(1), T(0), a];\n } else {\n auto e = extGcd(b, a%b);\n return [e[1], e[0]-a/b*e[1], e[2]];\n }\n}\n\n \n \n\n \nT invMod(T)(T x, T md) {\n auto r = extGcd!T(x, md);\n assert(r[2] == 1);\n auto z = r[0];\n return (z % md + md) % md;\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/ldc/inline.d */\n// module dkh.ldc.inline;\n\nversion(LDC) {\n pragma(LDC_inline_ir) R inlineIR(string s, R, P...)(P);\n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/int128.d */\n \n\n// module dkh.int128;\n\nversion(LDC) {\n// import dkh.ldc.inline;\n}\n\nversion(LDC) version(X86_64) {\n version = LDC_IR;\n}\n\n \nulong[2] mul128(ulong a, ulong b) {\n ulong[2] res;\n version(LDC_IR) {\n ulong upper, lower;\n inlineIR!(`\n %r0 = zext i64 %0 to i128 \n %r1 = zext i64 %1 to i128\n %r2 = mul i128 %r1, %r0\n %r3 = trunc i128 %r2 to i64\n %r4 = lshr i128 %r2, 64\n %r5 = trunc i128 %r4 to i64\n store i64 %r3, i64* %2\n store i64 %r5, i64* %3`, void)(a, b, &lower, &upper);\n return [lower, upper];\n } else version(D_InlineAsm_X86_64) {\n ulong upper, lower;\n asm {\n mov RAX, a;\n mul b;\n mov lower, RAX;\n mov upper, RDX;\n }\n return [lower, upper];\n } else {\n ulong B = 2UL^^32;\n ulong[2] a2 = [a % B, a / B];\n ulong[2] b2 = [b % B, b / B];\n ulong[4] c;\n foreach (i; 0..2) {\n foreach (j; 0..2) {\n c[i+j] += a2[i] * b2[j] % B;\n c[i+j+1] += a2[i] * b2[j] / B;\n }\n }\n foreach (i; 0..3) {\n c[i+1] += c[i] / B;\n c[i] %= B;\n }\n return [c[0] + c[1] * B, c[2] + c[3] * B];\n }\n}\n\n \n\n \nulong div128(ulong[2] a, ulong b) {\n version(LDC_IR) {\n return inlineIR!(`\n %r0 = zext i64 %0 to i128\n %r1 = zext i64 %1 to i128\n %r2 = shl i128 %r1, 64\n %r3 = add i128 %r0, %r2\n %r4 = zext i64 %2 to i128\n %r5 = udiv i128 %r3, %r4\n %r6 = trunc i128 %r5 to i64\n ret i64 %r6`,ulong)(a[0], a[1], b);\n } else version(D_InlineAsm_X86_64) {\n ulong upper = a[1], lower = a[0];\n ulong res;\n asm {\n mov RDX, upper;\n mov RAX, lower;\n div b;\n mov res, RAX;\n }\n return res;\n } else {\n if (b == 1) return a[0];\n while (!(b & (1UL << 63))) {\n a[1] <<= 1;\n if (a[0] & (1UL << 63)) a[1] |= 1;\n a[0] <<= 1;\n b <<= 1;\n }\n ulong ans = 0;\n foreach (i; 0..64) {\n bool up = (a[1] & (1UL << 63)) != 0;\n a[1] <<= 1;\n if (a[0] & (1UL << 63)) a[1] |= 1;\n a[0] <<= 1;\n\n ans <<= 1;\n if (up || b <= a[1]) {\n a[1] -= b;\n ans++;\n }\n }\n return ans;\n }\n}\n\n\n \nulong mod128(ulong[2] a, ulong b) {\n version(D_InlineAsm_X86_64) {\n ulong upper = a[1], lower = a[0];\n ulong res;\n asm {\n mov RDX, upper;\n mov RAX, lower;\n div b;\n mov res, RDX;\n }\n return res;\n } else {\n return a[0] - div128(a, b) * b;\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\nenum LIM = 10^^5;\nbool[] isnp;\n\nvoid main() {\n 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 \n debug {\n for (int n = 3; n <= 1000; ++n) {\n bool found;\n foreach (p; n .. n + n / 2) {\n if (p >= 2 && !isnp[p]) {\n found = true;\n }\n }\n if (!found) {\n writeln(\"failed \", n);\n }\n }\n }\n \n try {\n for (; ; ) {\n const N = readInt();\n \n int k;\n for (k = 0; k < N / 2; ++k) {\n if (N + k >= 2 && !isnp[N + k]) {\n break;\n }\n }\n debug {\n writeln(\"N = \", N, \": k = \", k);\n }\n \n int[] as, bs;\n foreach (i; 0 .. N) {\n as ~= i;\n bs ~= (i + 1) % N;\n }\n foreach (i; 0 .. k) {\n as ~= i;\n bs ~= (i + N / 2) % N;\n }\n \n writeln(N + k);\n foreach (i; 0 .. N + k) {\n writeln(as[i] + 1, \" \", bs[i] + 1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "17d29a0c2ab4e4be14fe3bdeb10d1e55"} {"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\nint ask(int q) {\n writeln(\"? \", q);\n stdout.flush();\n return readln.chomp.to!int;\n}\n\nvoid answer(int x) {\n writeln(\"! \", x);\n stdout.flush();\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n if (n % 2 == 1) {\n answer(-1);\n return;\n }\n \n n /= 2;\n auto stdiff = ask(1) - ask(n+1);\n \n if (stdiff % 2 == 1) {\n answer(-1);\n return;\n } else if (stdiff == 0) {\n answer(1);\n return;\n }\n \n auto lo = 2, hi = n;\n while (lo < hi) {\n auto med = (lo + hi) / 2;\n auto d = ask(med) - ask(n+med);\n if (d == 0) {\n answer(med);\n return;\n }\n \n if (sgn(d) == sgn(stdiff)) lo = med + 1;\n else hi = med - 1;\n }\n \n if (ask(lo) - ask(lo + n) == 0) {\n answer(lo);\n } else {\n answer(-1);\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\n\tint ask (int pos)\n\t{\n\t\tint x, y;\n\n\t\twriteln (\"? \", pos);\n\t\tstdout.flush ();\n\t\treadf (\" %s\", &x);\n\n\t\twriteln (\"? \", pos + n / 2);\n\t\tstdout.flush ();\n\t\treadf (\" %s\", &y);\n\n\t\treturn x - y;\n\t}\n\n\tvoid go (int lo, int hi, int valLo, int valHi)\n\t{\n\t\tint me = (lo + hi) / 2;\n\t\tauto d = ask (me);\n\t\tif (d == 0)\n\t\t{\n\t\t\twriteln (\"! \", me);\n\t\t\tstdout.flush ();\n\t\t}\n\t\telse if (d * 1L * valLo < 0)\n\t\t{\n\t\t\tgo (lo, me, valLo, d);\n\t\t}\n\t\telse if (d * 1L * valHi < 0)\n\t\t{\n\t\t\tgo (me, hi, d, valHi);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tassert (false);\n\t\t}\n\t}\n\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tif (n % 4 == 0)\n\t\t{\n\t\t\tauto d = ask (1);\n\t\t\tif (d == 0)\n\t\t\t{\n\t\t\t\twriteln (\"! \", 1);\n\t\t\t\tstdout.flush ();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tgo (1, n / 2 + 1, +d, -d);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"! \", -1);\n\t\t\tstdout.flush ();\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\nint N;\nlong[] A;\n\nlong Ask(int i) {\n debug {\n return A[i];\n } else {\n writefln(\"? %s\", i + 1);\n stdout.flush;\n const res = readLong();\n return res;\n }\n}\nvoid Answer(int i) {\n writefln(\"! %s\", i + 1);\n stdout.flush;\n import core.stdc.stdlib;\n exit(0);\n}\n\nvoid main() {\n N = readInt();\n debug {\n A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n }\n \n if (N % 4 != 0) {\n Answer(-2);\n }\n \n const a = Ask(0);\n const b = Ask(N / 2);\n if (a == b) {\n Answer(0);\n }\n int lo = 0, hi = N / 2;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n const c = Ask(mid);\n const d = Ask(mid + N / 2);\n if (c == d) {\n Answer(mid);\n }\n (((a < b) == (c < d)) ? lo : hi) = mid;\n }\n Answer(hi);\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\nint ask(int q) {\n writeln(\"? \", q);\n stdout.flush();\n return readln.chomp.to!int;\n}\n\nvoid answer(int x) {\n writeln(\"! \", x);\n stdout.flush();\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n if (n % 2 == 1) {\n answer(-1);\n return;\n }\n \n n /= 2;\n auto stdiff = ask(1) - ask(n+1);\n \n if (stdiff % 2 == 1) {\n answer(-1);\n return;\n } else if (stdiff == 0) {\n answer(1);\n return;\n }\n \n auto lo = 2, hi = n;\n while (lo < hi) {\n auto med = (lo + hi) / 2;\n auto d = ask(med) - ask(n+med);\n if (d == 0) {\n answer(med);\n return;\n }\n \n if (sgn(d) == sgn(stdiff)) lo = med + 1;\n else hi = med - 1;\n }\n \n answer(lo);\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\nint ask(int q) {\n writeln(\"? \", q);\n stdout.flush();\n return readln.chomp.to!int;\n}\n\nvoid answer(int x) {\n writeln(\"! \", x);\n stdout.flush();\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n if (n % 2 == 1) {\n answer(-1);\n return;\n }\n \n n /= 2;\n auto stdiff = ask(1) - ask(n+1);\n \n if (stdiff % 2 == 1) {\n answer(-1);\n return;\n } else if (stdiff == 0) {\n answer(1);\n return;\n }\n \n auto lo = 2, hi = n;\n while (lo < hi) {\n auto med = (lo + hi) / 2;\n auto d = ask(med) - ask(n+med);\n if (d == 0) {\n answer(med);\n return;\n }\n \n if (sgn(d) == sgn(stdiff)) lo = med + 1;\n else hi = med - 1;\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;\nlong[] A;\n\nlong Ask(int i) {\n debug {\n return A[i];\n } else {\n writefln(\"? %s\", i + 1);\n stdout.flush;\n const res = readLong();\n return res;\n }\n}\nvoid Answer(int i) {\n writefln(\"! %s\", i + 1);\n stdout.flush;\n import core.stdc.stdlib;\n exit(0);\n}\n\nvoid main() {\n N = readInt();\n debug {\n A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n }\n \n if (N % 4 != 0) {\n Answer(-2);\n }\n \n const a = Ask(0);\n const b = Ask(N / 2);\n if (a == b) {\n Answer(0);\n }\n int lo = 0, hi = N / 2;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n const c = Ask(mid);\n const d = Ask(mid + N / 2);\n (((a < b) == (c < d)) ? lo : hi) = mid;\n }\n Answer(hi);\n}\n"}], "src_uid": "49846b8fb0aea6b21e7986e19b8c8316"} {"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 auto arr = readln.chomp.split.map!(to!int).array;\n \n arr = arr.uniq.array;\n \n debug { arr.writeln; }\n \n auto dp = new int[][] (arr.length, arr.length);\n \n int go(int le, int r) {\n if (dp[le][r]) { return dp[le][r]; }\n \n if (le == r) { return 0; }\n \n dp[le][r] = 1 + (arr[le] == arr[r] ?\n go(le+1, r-1) : min(go(le+1, r), go(le, r-1)));\n \n return dp[le][r];\n }\n \n int ans = go(0, arr.length.to!int - 1);\n \n ans.writeln;\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;\nimport std.functional;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n int n;\n @Dim(\"n\") int[] c;\n\n void solve(long tc = -1)\n {\n auto comps = new int[](1);\n comps[0] = c[0];\n foreach(ci; c[1 .. $])\n if (comps[$ - 1] != ci)\n comps ~= ci;\n auto dp = new int[][](comps.length + 1, comps.length + 1);\n foreach(prefix; 0 .. cast(int) comps.length)\n {\n foreach(suffix; 0 .. cast(int) comps.length)\n {\n if (prefix == 0)\n dp[prefix][suffix] = suffix;\n else if (suffix == 0)\n dp[prefix][suffix] = prefix;\n else if (comps[prefix - 1] == comps[$ - suffix])\n dp[prefix][suffix] = 1 + dp[prefix - 1][suffix - 1];\n else\n dp[prefix][suffix] = 1 + min(dp[prefix - 1][suffix], dp[prefix][suffix - 1]);\n }\n }\n iota(0, cast(int)comps.length).map!(i => dp[i][cast(int)comps.length - i - 1]).fold!min.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": "4ee194d8dc1d25eb8b186603ee71125e"} {"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)).array;\n\t\tint res = 0;\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\tres = max (res, abs (i - 0));\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] != a[n - 1])\n\t\t\t{\n\t\t\t\tres = max (res, abs (i - (n - 1)));\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\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 a = readln.split.to!(int[]);\n\n if (a[0] != a[$ - 1]) {\n writeln(n - 1);\n return;\n }\n int mx = 1;\n foreach (i; 1 .. n) {\n if (a[0] != a[i]) {\n mx = max(mx, i, n - i - 1);\n }\n }\n writeln(mx);\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 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\nint N;\nint[] C;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n C = new int[N];\n foreach (i; 0 .. N) {\n C[i] = readInt();\n }\n \n int l, r;\n for (l = 0; l < N && C[0] == C[l]; ++l) {}\n for (r = N - 1; r >= 0 && C[N - 1] == C[r]; --r) {}\n assert(l < N);\n assert(r >= 0);\n \n int ans;\n foreach (i; 0 .. N) {\n chmax(ans, abs(i - ((C[0] == C[i]) ? l : 0)));\n chmax(ans, abs(i - ((C[N - 1] == C[i]) ? r : (N - 1))));\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "101fec8d8e169f941e71281048468121"} {"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\nclass UnionFind {\n import std.range;\n import std.algorithm;\n\n private size_t[] par, rank;\n\n ///\n this(size_t n)\n {\n rank.length = n;\n rank[] = 1;\n par = iota(0,n).array;\n }\n\n ///\n size_t find(size_t a) nothrow pure @nogc @safe\n {\n if (par[a] == a) return a;\n else return par[a] = find(par[a]);\n }\n\n ///\n void unite(size_t a, size_t b) nothrow pure @nogc @safe\n {\n a = find(a), b = find(b);\n\n if (a == b) return;\n\n if (rank[a] < rank[b]) {\n par[a] = b;\n } else {\n par[b] = a;\n if (rank[a] == rank[b]) {\n rank[a]++;\n }\n }\n }\n\n ///\n bool same(size_t a, size_t b) nothrow pure @nogc @safe\n {\n return find(a) == find(b);\n }\n}\n\n\nalias Edge = Tuple!(long,int,int);\n\nvoid main()\n{\n int n = readln.strip.to!int;\n\n long[] x,y;\n x.length = y.length = n+1;\n\n foreach (i; 1 .. n+1) {\n auto xy = readln.strip.split.map!(to!long);\n x[i] = xy[0], y[i] = xy[1];\n }\n\n long[] c = [0L] ~ readln.strip.split.map!(to!long).array;\n long[] k = [0L] ~ readln.strip.split.map!(to!long).array;\n\n Edge[] edges;\n\n foreach (i; 1 .. n+1) {\n edges ~= tuple(c[i], 0, i);\n }\n\n foreach (i; 1 .. n+1) {\n foreach (j; i+1 .. n+1) {\n edges ~= tuple((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])), i, j);\n }\n }\n\n edges.sort();\n\n auto uf = new UnionFind(n+1);\n\n long total = 0;\n int[] es;\n Tuple!(int,int)[] cs;\n\n foreach (e; edges) {\n if (uf.same(e[1], e[2])) continue;\n\n total += e[0];\n uf.unite(e[1], e[2]);\n\n if (e[1] == 0)\n es ~= e[2];\n else\n cs ~= tuple(e[1], e[2]);\n }\n\n writeln(total);\n\n writeln(es.length);\n foreach (e; es) {\n writef!\"%s \"(e);\n }\n writeln();\n\n writeln(cs.length);\n foreach (v; cs) {\n writefln!\"%s %s\"(v[0],v[1]);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.math;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nclass UnionFind {\n import std.range;\n import std.algorithm;\n\n private size_t[] par, rank;\n\n ///\n this(size_t n)\n {\n rank.length = n;\n rank[] = 1;\n par = iota(0,n).array;\n }\n\n ///\n size_t find(size_t a) nothrow pure @nogc @safe\n {\n if (par[a] == a) return a;\n else return par[a] = find(par[a]);\n }\n\n ///\n void unite(size_t a, size_t b) nothrow pure @nogc @safe\n {\n a = find(a), b = find(b);\n\n if (a == b) return;\n\n if (rank[a] < rank[b]) {\n par[a] = b;\n } else {\n par[b] = a;\n if (rank[a] == rank[b]) {\n rank[a]++;\n }\n }\n }\n\n ///\n bool same(size_t a, size_t b) nothrow pure @nogc @safe\n {\n return find(a) == find(b);\n }\n}\n\n\nalias Edge = Tuple!(long,int,int);\n\nvoid main()\n{\n int n = readln.strip.to!int;\n\n long[] x,y,c,k;\n x.length = y.length = c.length = k.length = n+1;\n\n foreach (i; 1 .. n+1) {\n readf!\" %s %s \"(x[i],y[i]);\n }\n\n foreach (i; 1 .. n+1) {\n readf!\" %s \"(c[i]);\n }\n\n foreach (i; 1 .. n+1) {\n readf!\" %s \"(k[i]);\n }\n\n Edge[] edges;\n\n foreach (i; 1 .. n+1) {\n edges ~= tuple(c[i], 0, i);\n }\n\n foreach (i; 1 .. n+1) {\n foreach (j; i+1 .. n+1) {\n edges ~= tuple((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])), i, j);\n }\n }\n\n edges.sort();\n\n auto uf = new UnionFind(n+1);\n\n long total = 0;\n int[] es;\n Tuple!(int,int)[] cs;\n\n foreach (e; edges) {\n if (uf.same(e[1], e[2])) continue;\n\n total += e[0];\n uf.unite(e[1], e[2]);\n\n if (e[1] == 0)\n es ~= e[2];\n else\n cs ~= tuple(e[1], e[2]);\n }\n\n writeln(total);\n\n writeln(es.length);\n foreach (e; es) {\n writef!\"%s \"(e);\n }\n writeln();\n\n writeln(cs.length);\n foreach (v; cs) {\n writefln!\"%s %s\"(v[0],v[1]);\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\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\nclass Heap(T) {\n private:\n T [] a;\n int [] h;\n int [] g;\n int n;\n int size;\n final void heapify_front (int k) {\n immutable he = h[k];\n int i = k;\n int j = i << 1;\n while (j <= size) {\n if (j < size && a[h[j+1]] < a[h[j]]) {\n j++;\n }\n if (a[h[j]] >= a[he]) {\n break;\n }\n h[i] = h[j];\n g[h[i]] = i;\n i = j;\n j = i << 1;\n }\n if (i != k) {\n h[i] = he;\n g[he] = i;\n }\n }\n final void heapify_back (int k) {\n immutable he = h[k];\n int i = k;\n while (i > 1) {\n int j = i >> 1;\n if (a[he] >= a[h[j]]) {\n break;\n }\n h[i] = h[j];\n g[h[i]] = i;\n i = j;\n }\n if (i != k) {\n h[i] = he;\n g[he] = i;\n }\n }\n final void insert (int i) {\n h[++size] = i;\n g[i] = size;\n heapify_back (size);\n }\n public:\n final void update (int k, T value) in {\n assert (k >= 0 && k < n);\n } body {\n immutable pos = g[k];\n if (pos < 0) {\n a[k] = value;\n insert (k);\n } else if (value < a[k]) {\n a[k] = value;\n heapify_back (pos);\n } else if (value > a[k]) {\n a[k] = value;\n heapify_front (pos);\n }\n }\n final int extract_min () {\n assert (size > 0);\n immutable he = h[1];\n g[he] = -1;\n h[1] = h[size--];\n g[h[1]] = 1;\n if (size) {\n heapify_front (1);\n }\n return he;\n }\n\n inout(T) opIndex (size_t index) inout {\n return a[index];\n }\n\n @property\n bool empty () const { return size == 0; }\n\n this (int n_, T default_value) {\n n = n_;\n size = 0;\n a = new T[n];\n a[] = default_value;\n h = new int[n+1];\n g = new int[n];\n g[] = -1;\n }\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable m = r.next!uint;\n immutable n = m + 1;\n auto x = new int[n];\n auto y = new int[n];\n foreach (i; 1 .. n) {\n x[i] = r.next!uint;\n y[i] = r.next!uint;\n }\n auto c = new int[n];\n foreach (i; 1 .. n) {\n c[i] = r.next!uint;\n }\n auto kt = new int[n];\n foreach (i; 1 .. n) {\n kt[i] = r.next!uint;\n }\n auto h = new Heap!long (n, long.max);\n h.update (0, 0);\n auto p = new int[n];\n auto b = new bool[n];\n p[] = -1;\n while (!h.empty) {\n immutable i = h.extract_min ();\n b[i] = true;\n debug stderr.writefln (\"i: %d, h[i]: %d\", i+1, h[i]);\n if (i == 0) {\n foreach (j; 1 .. n) {\n assert (!b[j]);\n immutable w = c[j];\n if (w < h[j]) {\n h.update (j, w);\n p[j] = i;\n }\n }\n } else {\n immutable xi = x[i], yi = y[i], ki = kt[i];\n foreach (j; 1 .. n) {\n if (b[j]) {\n continue;\n }\n long w = abs (xi - x[j]) + abs (yi - y[j]);\n w *= ki + kt[j];\n if (w < h[j]) {\n h.update (j, w);\n p[j] = i;\n }\n }\n }\n }\n iota (0, n).map! (i => h[i]).sum.writeln;\n int[] u;\n Tuple!(int, int)[] d;\n foreach (i; 1 .. n) {\n if (p[i] == 0) {\n u ~= i;\n } else {\n d ~= tuple (i.to!int, p[i]);\n }\n }\n writeln (u.length);\n writefln (\"%(%s %)\", u);\n writeln (d.length);\n foreach (q; d) {\n if (q[0] > q[1]) swap (q[0], q[1]); \n writeln (q[0], ' ', q[1]);\n }\n \n\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.math;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nclass UnionFind {\n import std.range;\n import std.algorithm;\n\n private size_t[] par, rank;\n\n ///\n this(size_t n)\n {\n rank.length = n;\n rank[] = 1;\n par = iota(0,n).array;\n }\n\n ///\n size_t find(size_t a) nothrow pure @nogc @safe\n {\n if (par[a] == a) return a;\n else return par[a] = find(par[a]);\n }\n\n ///\n void unite(size_t a, size_t b) nothrow pure @nogc @safe\n {\n a = find(a), b = find(b);\n\n if (a == b) return;\n\n if (rank[a] < rank[b]) {\n par[a] = b;\n } else {\n par[b] = a;\n if (rank[a] == rank[b]) {\n rank[a]++;\n }\n }\n }\n\n ///\n bool same(size_t a, size_t b) nothrow pure @nogc @safe\n {\n return find(a) == find(b);\n }\n}\n\n\nalias Edge = Tuple!(long,int,int);\n\nvoid main()\n{\n int n = readln.strip.to!int;\n\n long[] x,y,c,k;\n x.length = y.length = c.length = k.length = n+1;\n\n foreach (i; 1 .. n+1) {\n readf!\" %s %s \"(x[i],y[i]);\n }\n\n foreach (i; 1 .. n+1) {\n readf!\" %s \"(c[i]);\n }\n\n foreach (i; 1 .. n+1) {\n readf!\" %s \"(k[i]);\n }\n\n Edge[] edges;\n edges.reserve(n*n+n);\n\n foreach (i; 1 .. n+1) {\n edges ~= tuple(c[i], 0, i);\n }\n\n foreach (i; 1 .. n+1) {\n foreach (j; i+1 .. n+1) {\n edges ~= tuple((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])), i, j);\n }\n }\n\n edges.sort();\n\n auto uf = new UnionFind(n+1);\n\n long total = 0;\n int[] es;\n Tuple!(int,int)[] cs;\n es.reserve(n);\n cs.reserve(n);\n\n foreach (e; edges) {\n if (uf.same(e[1], e[2])) continue;\n\n total += e[0];\n uf.unite(e[1], e[2]);\n\n if (e[1] == 0)\n es ~= e[2];\n else\n cs ~= tuple(e[1], e[2]);\n }\n\n writeln(total);\n\n writeln(es.length);\n foreach (e; es) {\n writef!\"%s \"(e);\n }\n writeln();\n\n writeln(cs.length);\n foreach (v; cs) {\n writefln!\"%s %s\"(v[0],v[1]);\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.math;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nclass UnionFind {\n import std.range;\n import std.algorithm;\n\n private size_t[] par, rank;\n\n ///\n this(size_t n)\n {\n rank.length = n;\n rank[] = 1;\n par = iota(0,n).array;\n }\n\n ///\n size_t find(size_t a) nothrow pure @nogc @safe\n {\n if (par[a] == a) return a;\n else return par[a] = find(par[a]);\n }\n\n ///\n void unite(size_t a, size_t b) nothrow pure @nogc @safe\n {\n a = find(a), b = find(b);\n\n if (a == b) return;\n\n if (rank[a] < rank[b]) {\n par[a] = b;\n } else {\n par[b] = a;\n if (rank[a] == rank[b]) {\n rank[a]++;\n }\n }\n }\n\n ///\n bool same(size_t a, size_t b) nothrow pure @nogc @safe\n {\n return find(a) == find(b);\n }\n}\n\n\nalias Edge = Tuple!(long,int,int);\n\nvoid main()\n{\n int n = readln.strip.to!int;\n\n long[] x,y,c,k;\n x.length = y.length = c.length = k.length = n+1;\n\n foreach (i; 1 .. n+1) {\n readf!\" %s %s \"(x[i],y[i]);\n }\n\n foreach (i; 1 .. n+1) {\n readf!\" %s \"(c[i]);\n }\n\n foreach (i; 1 .. n+1) {\n readf!\" %s \"(k[i]);\n }\n\n Array!Edge edges;\n\n foreach (i; 1 .. n+1) {\n edges ~= tuple(c[i], 0, i);\n }\n\n foreach (i; 1 .. n+1) {\n foreach (j; i+1 .. n+1) {\n edges ~= tuple((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])), i, j);\n }\n }\n\n edges[].sort();\n\n auto uf = new UnionFind(n+1);\n\n long total = 0;\n Array!int es;\n Array!(Tuple!(int,int)) cs;\n\n foreach (e; edges) {\n if (uf.same(e[1], e[2])) continue;\n\n total += e[0];\n uf.unite(e[1], e[2]);\n\n if (e[1] == 0)\n es ~= e[2];\n else\n cs ~= tuple(e[1], e[2]);\n }\n\n writeln(total);\n\n writeln(es.length);\n foreach (e; es) {\n writef!\"%s \"(e);\n }\n writeln();\n\n writeln(cs.length);\n foreach (v; cs) {\n writefln!\"%s %s\"(v[0],v[1]);\n }\n}\n"}, {"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\n\nvoid main()\n{\n int n = readln.strip.to!int;\n\n long[] x,y;\n x.length = y.length = n+1;\n\n foreach (i; 0 .. n) {\n readf!\" %s %s \"(x[i],y[i]);\n }\n\n long[] c = readln.strip.split.map!(to!long).array;\n long[] k = readln.strip.split.map!(to!long).array;\n\n int[] b = new int[n];\n b[] = -1;\n\n long total;\n int[] es;\n Tuple!(int,int)[] cs;\n\n foreach (_; 0 .. n) {\n auto i = minIndex(c).to!int;\n total += c[i];\n\n if (b[i] >= 0) {\n cs ~= tuple(i+1,b[i]+1);\n } else {\n es ~= i+1;\n }\n\n foreach (j; 0 .. n) {\n if (c[j] != long.max) {\n long v = (k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j]));\n if (v < c[j]) {\n c[j] = v;\n b[j] = i;\n }\n }\n }\n c[i] = long.max;\n }\n\n writeln(total);\n\n writeln(es.length);\n writefln!\"%(%s %)\"(es);\n\n writeln(cs.length);\n foreach (p; cs)\n writefln!\"%s %s\"(p[0],p[1]);\n}\n"}, {"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\n\nalias Edge = Tuple!(long,int,int);\n\nvoid main()\n{\n int n = readln.strip.to!int;\n\n long[] x,y;\n x.length = y.length = n+1;\n\n foreach (i; 1 .. n+1) {\n auto xy = readln.strip.split.map!(to!long);\n x[i] = xy[0], y[i] = xy[1];\n }\n\n long[] c = [0L] ~ readln.strip.split.map!(to!long).array;\n long[] k = [0L] ~ readln.strip.split.map!(to!long).array;\n\n Edge[] edges;\n\n alias pair = Tuple!(long,int);\n\n long total = 0;\n int[] es;\n Tuple!(int,int)[] cs;\n\n bool[] use = new bool[n+1];\n auto q = BinaryHeap!(pair[],\"b < a\")([]);\n foreach (i, v; c) {\n q.insert(tuple(v,to!int(i)));\n }\n\n use[0] = true;\n int[] b = new int[n+1];\n b[] = -1;\n\n int v = 0;\n while (!q.empty && v < n) {\n auto p = q.front; q.removeFront();\n\n int i = p[1];\n if (c[i] < p[0] || use[i]) continue;\n\n use[i] = true;\n\n if (b[i] >= 0)\n cs ~= tuple(i,b[i]);\n else\n es ~= i;\n\n v++;\n\n total += p[0];\n\n foreach (j; 1 .. n+1) {\n long newCost = (k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j]));\n if (c[j] > newCost) {\n c[j] = newCost;\n q.insert(tuple(newCost, j));\n b[j] = i;\n }\n }\n }\n\n writeln(total);\n\n writeln(es.length);\n writefln!\"%(%s %)\"(es);\n\n writeln(cs.length);\n foreach (p; cs) {\n writefln!\"%s %s\"(p[0],p[1]);\n }\n}\n"}], "negative_code": [], "src_uid": "4750f5a5aaa1ef727ebf2376641bd8ed"} {"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, a, b, da, db;\n\t\treadf !(\" %s %s %s %s %s\") (n, a, b, da, db);\n\t\ta -= 1;\n\t\tb -= 1;\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\n\t\tauto d = new int [n];\n\n\t\tvoid recur (int v, int p, int dist)\n\t\t{\n\t\t\td[v] = dist;\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, dist + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (b, -1, 0);\n\t\tif (d[a] <= da)\n\t\t{\n\t\t\twriteln (\"Alice\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto c = to !(int) (d.length - d.maxPos.length);\n\n\t\trecur (c, -1, 0);\n\t\tauto diameter = d.maxElement;\n\t\tauto canCatch = (da * 2 >= db);\n\t\tauto canCenter = (da * 2 >= diameter);\n\t\twriteln ((canCatch || canCenter) ? \"Alice\" : \"Bob\");\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, A, B, C, D;\nint[] U, V;\n\nint[][] G;\nint[] dep;\n\nvoid dfs(int u, int p) {\n dep[u] = (p == -1) ? 0 : (dep[p] + 1);\n foreach (i; G[u]) {\n const v = U[i] ^ V[i] ^ u;\n if (v != p) {\n dfs(v, u);\n }\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n N = readInt();\n A = readInt() - 1;\n B = readInt() - 1;\n C = readInt();\n D = 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]] ~= i;\n G[V[i]] ~= i;\n }\n \n int ans;\n \n dep = new int[N];\n dfs(A, -1);\n if (dep[B] <= C) {\n ans = 1;\n } else {\n const r = cast(int)(dep.maxIndex);\n dfs(r, -1);\n const diam = dep.maxElement;\n if (2 * C >= min(D, diam)) {\n ans = 1;\n } else {\n ans = 0;\n }\n }\n \n writeln(ans ? \"Alice\" : \"Bob\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1405/problem/D\n// dfs, graph, bfs, tree\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nint n, a, b, da, db;\nint[][] tree;\n\nint[] depth;\nint diameter;\n\nint dfs(int x, int p) {\n int len = 0;\n\n foreach(child; tree[x]) {\n if(child != p) {\n depth[child] = depth[x] + 1;\n int cur = 1 + dfs(child, x);\n diameter = max(diameter, cur + len);\n len = max(len, cur);\n }\n }\n\n return len;\n}\n\nvoid main() {\n int t = readln.chomp.to!int;\n\n while(t--) {\n readf(\"%s %s %s %s %s\", &n, &a, &b, &da, &db);\n readln;\n\n tree = new int[][](n+1);\n depth = new int[n+1];\n diameter = 0;\n\n foreach(_; 1..n) {\n int u, v;\n readf(\"%s %s\", &u, &v);\n readln;\n tree[u] ~= v;\n tree[v] ~= u;\n }\n\n depth[a] = 0;\n dfs(a, -1);\n\n if(2 * da >= min(diameter, db) || depth[b] <= da)\n \"Alice\".writeln;\n else\n \"Bob\".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 bool[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RD!int-1;\n\t\tauto b = RD!int-1;\n\t\tauto da = RD!int;\n\t\tauto db = 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\n\t\tif (db <= da*2)\n\t\t{\n\t\t\tans[ti] = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tbool dfs1(int pos, int last, int depth)\n\t\t{\n\t\t\tif (pos == b) return true;\n\t\t\tif (depth == da) return false;\n\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tauto res = dfs1(v, pos, depth+1);\n\t\t\t\tif (res) return true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\tauto otk = dfs1(a, -1, 0);\n\t\tif (otk)\n\t\t{\n\t\t\tans[ti] = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tint[] dfs2(int pos, int last, int depth)\n\t\t{\n\t\t\tint[] res = [depth, pos];\n\t\t\tforeach (v; edges[pos])\n\t\t\t{\n\t\t\t\tif (v == last) continue;\n\t\t\t\tauto r = dfs2(v, pos, depth+1);\n\t\t\t\tif (r[0] > res[0])\n\t\t\t\t{\n\t\t\t\t\tres = r;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tauto r = dfs2(0, -1, 0);\n\t\tauto r2 = dfs2(r[1], -1, 0);\n\t\tans[ti] = r2[0] <= da*2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"Alice\" : \"Bob\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "2bfd566ef883efec5211b01552b45218"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tauto cnt = new long[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\t++cnt[a[i]];\n\t\t}\n\n\t\tlong x = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (cnt[i] == 1)\n\t\t\t{\n\t\t\t\tx = i;\n\t\t\t\tbreak;\n\t\t\t}\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)\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}\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\tint [] [int] b;\n\t\tforeach (i, c; a)\n\t\t{\n\t\t\tb[c] ~= i + 1;\n\t\t}\n\t\tauto f = b.byKey.filter !(c => b[c].length == 1);\n\t\twriteln (f.empty ? -1 : b[f.minElement].front);\n\t}\n}\n"}], "negative_code": [], "src_uid": "99d2b0386d101da802ac508ef8f7325b"} {"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\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\tif (n > m)\n\t\t{\n\t\t\tauto b = new int [] [] (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][i] = a[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tswap (n, m);\n\t\t\ta = b;\n\t\t}\n\t\tassert (n <= m);\n\n\t\tint [2] [] s = new int [2] [m];\n\t\tint res = k + 1;\n\t\tint cur = k + 1;\n\n\t\tvoid recur (int i)\n\t\t{\n\t\t\tdebug {writeln (i, ' ', cur);}\n\t\t\tif (i >= n)\n\t\t\t{\n\t\t\t\tres = min (res, cur);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// put 0\n\t\t\tcur = 0;\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\ts[j][0] += (a[i][j] != 0);\n\t\t\t\ts[j][1] += (a[i][j] != 1);\n\t\t\t\tcur += min (s[j][0], s[j][1]);\n\t\t\t}\n\t\t\tif (cur <= k)\n\t\t\t{\n\t\t\t\trecur (i + 1);\n\t\t\t}\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\ts[j][0] -= (a[i][j] != 0);\n\t\t\t\ts[j][1] -= (a[i][j] != 1);\n\t\t\t}\n\n\t\t\t// put 1\n\t\t\tcur = 0;\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\ts[j][0] += (a[i][j] != 1);\n\t\t\t\ts[j][1] += (a[i][j] != 0);\n\t\t\t\tcur += min (s[j][0], s[j][1]);\n\t\t\t}\n\t\t\tif (cur <= k)\n\t\t\t{\n\t\t\t\trecur (i + 1);\n\t\t\t}\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\ts[j][0] -= (a[i][j] != 1);\n\t\t\t\ts[j][1] -= (a[i][j] != 0);\n\t\t\t}\n\t\t}\n\n\t\trecur (0);\n\t\tif (res > k)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\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, 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 M, N, K;\nint[][] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tK = readInt;\n\t\tA = new int[][](M, N);\n\t\tforeach (x; 0 .. M) foreach (y; 0 .. N) {\n\t\t\tA[x][y] = readInt;\n\t\t}\n\t\t\n\t\tint ans = int.max;\n\t\t\n\t\tif (M > K) {\n\t\t\tforeach (sx; 0 .. M) {\n\t\t\t\tint sum;\n\t\t\t\tforeach (x; 0 .. M) {\n\t\t\t\t\tint cnt;\n\t\t\t\t\tforeach (y; 0 .. N) {\n\t\t\t\t\t\tif (A[sx][y] != A[x][y]) {\n\t\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsum += min(cnt, N - cnt);\n\t\t\t\t}\n\t\t\t\tchmin(ans, sum);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (N > K) {\n\t\t\tforeach (sy; 0 .. N) {\n\t\t\t\tint sum;\n\t\t\t\tforeach (y; 0 .. N) {\n\t\t\t\t\tint cnt;\n\t\t\t\t\tforeach (x; 0 .. M) {\n\t\t\t\t\t\tif (A[x][sy] != A[x][y]) {\n\t\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tsum += min(cnt, M - cnt);\n\t\t\t\t}\n\t\t\t\tchmin(ans, sum);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (M <= K && N <= K) {\n\t\t\tforeach (p; 0 .. 1 << M) foreach (q; 0 .. 1 << N) {\n\t\t\t\tint cnt;\n\t\t\t\tforeach (x; 0 .. M) foreach (y; 0 .. N) {\n\t\t\t\t\tif (A[x][y] != (((p >> x) & 1) ^ ((q >> y) & 1))) {\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tchmin(ans, cnt);\n\t\t\t}\n\t\t}\n\t\t\n// writeln(\"ans = \",ans);\n\t\tif (ans > K) {\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"}, {"source_code": "import std.algorithm, std.stdio;\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 int [] [] (min (n, m), max (n, m));\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..m)\n\t\t\t\treadf (\" %s\", n > m ? &a[j][i] : &a[i][j]);\n\t\tif (n > m)\n\t\t\tswap (n, m);\n\n\t\tauto s = new int [2] [m];\n\t\tint res = k + 1;\n\t\tint cur;\n\n\t\tvoid recur (int i)\n\t\t{\n\t\t\tif (i >= n)\n\t\t\t{\n\t\t\t\tres = min (res, cur);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tforeach (v; 0..2)\n\t\t\t{\n\t\t\t\tcur = 0;\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\ts[j][0] += a[i][j] ^ v;\n\t\t\t\t\ts[j][1] += a[i][j] ^ !v;\n\t\t\t\t\tcur += min (s[j][0], s[j][1]);\n\t\t\t\t}\n\t\t\t\tif (cur <= k)\n\t\t\t\t\trecur (i + 1);\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\ts[j][0] -= a[i][j] ^ v;\n\t\t\t\t\ts[j][1] -= a[i][j] ^ !v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0);\n\t\twriteln (res > k ? -1 : res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "bc937cacda9ebff9ec0b7f00f0f97508"} {"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\tauto k = RD!int;\n\tauto id = RDA;\n\tlong[] ans;\n\tbool[long] flag;\n\tforeach (i; 0..n)\n\t{\n\t\tif (flag.get(id[i], false)) continue;\n\t\tans ~= id[i];\n\t\tflag[id[i]] = true;\n\t\tif (ans.length > k)\n\t\t{\n\t\t\tflag[ans.front] = false;\n\t\t\tans.popFront;\n\t\t}\n\t}\n\tans.reverse;\n\twriteln(ans.length);\n\tans.map!(to!string).join(\" \").writeln;\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 n = RD!int;\n\tauto k = RD!int;\n\tauto id = RDA;\n\tlong[] ans;\n\tbool[long] flag;\n\tforeach (i; 0..n)\n\t{\n\t\tif (flag.get(id[i], false)) continue;\n\t\tans ~= id[i];\n\t\tflag[id[i]] = true;\n\t\tif (ans.length > k)\n\t\t{\n\t\t\tflag[ans.front] = false;\n\t\t\tans.popFront;\n\t\t}\n\t}\n\tans.reverse;\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.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\tauto k = RD!int;\n\tauto id = RDA;\n\tlong[] ans;\n\tbool[long] flag;\n\tforeach (i; 0..n)\n\t{\n\t\tif (flag.get(id[i], false)) continue;\n\t\tans ~= id[i];\n\t\tflag[id[i]] = true;\n\t\tif (ans.length > k)\n\t\t{\n\t\t\tflag[ans.front] = false;\n\t\t\tans.popFront;\n\t\t}\n\t}\n\tans.reverse;\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; }\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\tauto k = RD!int;\n\tauto id = RDA;\n\tlong[] ans;\n\tbool[long] flag;\n\tforeach (i; 0..n)\n\t{\n\t\tif (flag.get(id[i], false)) continue;\n\t\tans ~= id[i];\n\t\tflag[id[i]] = true;\n\t\tif (ans.length > k)\n\t\t{\n\t\t\tflag[ans.front] = false;\n\t\t\tans.popFront;\n\t\t}\n\t}\n\tans.reverse;\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "485a1ecf8f569b85327b99382bda9466"} {"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 + 1];\n foreach (i; 1 .. N + 1) {\n A[i] = readInt;\n }\n \n auto ans = new int[N + 1];\n foreach (i; 1 .. N + 1) {\n ans[A[i]] = i + 1;\n }\n ans[A[N]] = 1;\n \n foreach (j; 1 .. N + 1) {\n if (j > 1) write(\" \");\n write(ans[j]);\n }\n writeln;\n \n debug {\n auto as = A.dup;\n writeln(as);\n foreach (j; 1 .. N + 1) {\n as[ans[j] .. N + 1] += j;\n writeln(as);\n }\n }\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\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 q = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tq[n - p[i]] = i + 1;\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (q);\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 p = readln.splitter.map !(to !(int)).array;\r\n\t\tp[] -= 1;\r\n\t\tauto q = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tq[p[i]] = i;\r\n\t\t}\r\n\t\tq[] = n - q[];\r\n\t\twritefln !(\"%(%s %)\") (q);\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 int[N + 1];\n foreach (i; 1 .. N + 1) {\n A[i] = readInt;\n }\n \n auto ans = new int[N + 1];\n foreach (i; 1 .. N + 1) {\n ans[A[i]] = N - i;\n }\n ans[A[N]] = N;\n \n foreach (j; 1 .. N + 1) {\n if (j > 1) write(\" \");\n write(ans[j]);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "188c9dbb3e1851b7b762ed6b4b23d1bd"} {"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 h1 = RDA;\n\tauto h2 = RDA;\n\n\tauto dp = new long[][](n+1, 3);\n\tforeach (i; 0..n)\n\t{\n\t\tdp[i+1][0] = max(dp[i][1], dp[i][2]) + h1[i];\n\t\tdp[i+1][1] = max(dp[i][0], dp[i][2]) + h2[i];\n\t\tdp[i+1][2] = max(dp[i][0], max(dp[i][1], dp[i][2]));\n\t}\n\n\twriteln(max(dp[n][0], max(dp[n][1], dp[n][2])));\n\tstdout.flush();\n\tdebug readln();\n}", "positive_code": [{"source_code": "/// https://codeforces.com/problemset/problem/1195/c\n/// PS> dmd cf.d; if($?) {cat in.txt | .\\cf.exe}\nimport std.stdio : stdin, writeln;\nimport std.array : array, split;\nimport std.conv : to;\nimport std.algorithm : map, max;\n\nvoid main()\n{\n int n, q, sum = 0;\n stdin.readf!\"%d\\n\"(n);\n\n int[] a = stdin.readln().split().map!(to!int).array;\n int[] b = stdin.readln().split().map!(to!int).array;\n\n long m1 = 0, m2 = 0, _m1, _m2;\n for (int i = 0; i < n; i++) {\n _m1 = max(m1, m2 + a[i]);\n _m2 = max(m2, m1 + b[i]);\n m1 = _m1; m2 = _m2;\n }\n\n writeln(max(m1, m2));\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, bs;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\tforeach(i; 0 .. n) bs ~= read.to!long;\n\t\n\tlong[] xs, ys;\n\tforeach(i; 0 .. n){\n\t\tif(i == 0) xs ~= as[0], ys ~= bs[0];\n\t\telse{\n\t\t\txs ~= max(ys[i - 1] + as[i], xs[i - 1]);\n\t\t\tys ~= max(xs[i - 1] + bs[i], ys[i - 1]);\n\t\t}\n\t}\n\t\n\tlong ans = max(xs[n - 1], ys[n - 1]);\n\tans.writeln;\n\t\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int MAX = 100005;\nint[2][MAX] h;\nlong[2][MAX] f;\n\nvoid main() {\n int n;\n readf(\" %s\", n);\n foreach(j; 0..2) {\n foreach(i; 0..n) {\n readf(\" %s\", h[i][j]);\n }\n }\n\n f[0][0] = h[0][0];\n f[0][1] = h[0][1];\n foreach(i; 1..n) {\n foreach(j; 0..2) {\n f[i][j] = max(f[i-1][j], f[i-1][(j+1)%2] + h[i][j]);\n }\n }\n writeln(max(f[n-1][0], f[n-1][1]));\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int MAX = 100005;\nint[2][MAX] h;\nint[2][MAX] f;\n\nvoid main() {\n int n;\n readf(\" %s\", n);\n foreach(j; 0..2) {\n foreach(i; 0..n) {\n readf(\" %s\", h[i][j]);\n }\n }\n\n f[0][0] = h[0][0];\n f[0][1] = h[0][1];\n foreach(i; 1..n) {\n foreach(j; 0..2) {\n f[i][j] = max(f[i-1][j], f[i-1][(j+1)%2] + h[i][j]);\n }\n }\n writeln(max(f[n-1][0], f[n-1][1]));\n}\n"}, {"source_code": "/// https://codeforces.com/problemset/problem/1195/c\n/// PS> dmd cf.d; if($?) {cat in.txt | .\\cf.exe}\nimport std.stdio : stdin, writeln;\nimport std.array : array, split;\nimport std.conv : to;\nimport std.algorithm : map, max;\n\nvoid main()\n{\n int n, q, sum = 0;\n stdin.readf!\"%d\\n\"(n);\n\n int[] a = stdin.readln().split().map!(to!int).array;\n int[] b = stdin.readln().split().map!(to!int).array;\n\n int m1 = 0, m2 = 0, _m1, _m2;\n for (int i = 0; i < n; i++) {\n _m1 = max(m1, m2 + a[i]);\n _m2 = max(m2, m1 + b[i]);\n m1 = _m1; m2 = _m2;\n }\n\n writeln(max(m1, m2));\n}"}], "src_uid": "667e8938b964d7a24500003f6b89717b"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int logHalf = 20;\nimmutable int half = 1 << logHalf;\nimmutable int limit = half << 1;\n\nstruct Tree\n{\n\tint [] d;\n\tint [] tMin;\n\tint [] tMax;\n\n\tthis (int _)\n\t{\n\t\td = new int [limit];\n\t\ttMin = new int [limit];\n\t\ttMax = new int [limit];\n\t}\n\n\tvoid relax (int tv)\n\t{\n\t\tif (d[tv] == 0)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tif (tv < half)\n\t\t{\n\t\t\td[tv * 2 + 0] += d[tv];\n\t\t\td[tv * 2 + 1] += d[tv];\n\t\t\ttMin[tv * 2 + 0] += d[tv];\n\t\t\ttMin[tv * 2 + 1] += d[tv];\n\t\t\ttMax[tv * 2 + 0] += d[tv];\n\t\t\ttMax[tv * 2 + 1] += d[tv];\n\t\t}\n\t\td[tv] = 0;\n\t}\n\n\tvoid recalc (int tv)\n\t{\n\t\tif (tv < half)\n\t\t{\n\t\t\ttMin[tv] = min (tMin[tv * 2 + 0], tMin[tv * 2 + 1]);\n\t\t\ttMax[tv] = max (tMax[tv * 2 + 0], tMax[tv * 2 + 1]);\n\t\t}\n\t}\n\n\tvoid add (int lo, int tv, int tlo, int thi, int value)\n\t{\n\t\tif (thi <= lo)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tif (lo <= tlo)\n\t\t{\n\t\t\td[tv] += value;\n\t\t\ttMin[tv] += value;\n\t\t\ttMax[tv] += value;\n\t\t\treturn;\n\t\t}\n\t\trelax (tv);\n\t\tauto tme = (tlo + thi) >> 1;\n\t\tadd (lo, tv * 2 + 0, tlo, tme, value);\n\t\tadd (lo, tv * 2 + 1, tme, thi, value);\n\t\trecalc (tv);\n\t}\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto commands = readln.strip;\n\t\tint pos = 0;\n\t\tint total = 0;\n\t\tauto s = new char [half];\n\t\tauto t = Tree (-1);\n\n\t\tvoid go (int pos, int delta)\n\t\t{\n\t\t\ttotal += delta;\n\t\t\tt.add (pos, 1, 0, half, delta);\n\t\t}\n\n\t\tauto ans = new int [n];\n\t\tans[] = -1;\n\t\tforeach (i, const ref char c; commands)\n\t\t{\n\t\t\tif (c == 'L')\n\t\t\t{\n\t\t\t\tpos = max (0, pos - 1);\n\t\t\t}\n\t\t\telse if (c == 'R')\n\t\t\t{\n\t\t\t\tpos += 1;\n\t\t\t}\n\t\t\telse if (s[pos] != c)\n\t\t\t{\n\t\t\t\tint delta = 0;\n\t\t\t\tdelta -= (s[pos] == '(');\n\t\t\t\tdelta += (s[pos] == ')');\n\t\t\t\tdelta += (c == '(');\n\t\t\t\tdelta -= (c == ')');\n\t\t\t\tif (delta != 0)\n\t\t\t\t{\n\t\t\t\t\tgo (pos, delta);\n\t\t\t\t}\n\t\t\t\ts[pos] = c;\n\t\t\t}\n\n\t\t\tif (total == 0)\n\t\t\t{\n\t\t\t\tif (t.tMin[1] >= 0)\n\t\t\t\t{\n\t\t\t\t\tans[i] = t.tMax[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\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 logHalf = 20;\nimmutable int half = 1 << logHalf;\nimmutable int limit = half << 1;\n\nstruct Tree\n{\n\tint [] d;\n\tint [] tMin;\n\tint [] tMax;\n\n\tthis (int _)\n\t{\n\t\td = new int [limit];\n\t\ttMin = new int [limit];\n\t\ttMax = new int [limit];\n\t}\n\n\tvoid relax (int tv)\n\t{\n\t\tif (d[tv] == 0)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tif (tv < half)\n\t\t{\n\t\t\td[tv * 2 + 0] += d[tv];\n\t\t\td[tv * 2 + 1] += d[tv];\n\t\t\ttMin[tv * 2 + 0] += d[tv];\n\t\t\ttMin[tv * 2 + 1] += d[tv];\n\t\t\ttMax[tv * 2 + 0] += d[tv];\n\t\t\ttMax[tv * 2 + 1] += d[tv];\n\t\t}\n\t\td[tv] = 0;\n\t}\n\n\tvoid recalc (int tv)\n\t{\n\t\tif (tv < half)\n\t\t{\n\t\t\ttMin[tv] = min (tMin[tv * 2 + 0], tMin[tv * 2 + 1]);\n\t\t\ttMax[tv] = max (tMax[tv * 2 + 0], tMax[tv * 2 + 1]);\n\t\t}\n\t}\n\n\tvoid add (int lo, int tv, int tlo, int thi, int value)\n\t{\n\t\tif (thi <= lo)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tif (lo <= tlo)\n\t\t{\n\t\t\td[tv] += value;\n\t\t\ttMin[tv] += value;\n\t\t\ttMax[tv] += value;\n\t\t\treturn;\n\t\t}\n\t\trelax (tv);\n\t\tauto tme = (tlo + thi) >> 1;\n\t\tadd (lo, tv * 2 + 0, tlo, tme, value);\n\t\tadd (lo, tv * 2 + 1, tme, thi, value);\n\t\trecalc (tv);\n\t}\n\n\tauto ask (int lo, int tv, int tlo, int thi)\n\t{\n\t\tif (thi <= lo)\n\t\t{\n\t\t\treturn tuple (0, 0);\n\t\t}\n\t\tif (lo <= tlo)\n\t\t{\n\t\t\treturn tuple (tMin[tv], tMax[tv]);\n\t\t}\n\t\trelax (tv);\n\t\tauto tme = (tlo + thi) >> 1;\n\t\tauto x = ask (lo, tv * 2 + 0, tlo, tme);\n\t\tauto y = ask (lo, tv * 2 + 1, tme, thi);\n\t\trecalc (tv);\n\t\treturn tuple (min (x[0], y[0]), max (x[1], y[1]));\n\t}\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto commands = readln.strip;\n\t\tint pos = 0;\n\t\tint total = 0;\n\t\tauto s = new char [half];\n\t\tauto t = Tree (-1);\n\n\t\tvoid go (int pos, int delta)\n\t\t{\n\t\t\ttotal += delta;\n\t\t\tt.add (pos, 1, 0, half, delta);\n\t\t}\n\n\t\tauto ans = new int [n];\n\t\tans[] = -1;\n\t\tforeach (i, const ref char c; commands)\n\t\t{\n\t\t\tif (c == 'L')\n\t\t\t{\n\t\t\t\tpos = max (0, pos - 1);\n\t\t\t}\n\t\t\telse if (c == 'R')\n\t\t\t{\n\t\t\t\tpos += 1;\n\t\t\t}\n\t\t\telse if (s[pos] != c)\n\t\t\t{\n\t\t\t\tint delta = 0;\n\t\t\t\tdelta -= (s[pos] == '(');\n\t\t\t\tdelta += (s[pos] == ')');\n\t\t\t\tdelta += (c == '(');\n\t\t\t\tdelta -= (c == ')');\n\t\t\t\tgo (pos, delta);\n\t\t\t\ts[pos] = c;\n\t\t\t}\n\n\t\t\tif (total == 0)\n\t\t\t{\n\t\t\t\tauto cur = t.ask (0, 1, 0, half);\n\t\t\t\tif (cur[0] >= 0)\n\t\t\t\t{\n\t\t\t\t\tans[i] = cur[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "negative_code": [], "src_uid": "80182142a917c19da8d8d405973b410d"} {"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 auto s = readln.strip;\r\n auto z = count(s, '0');\r\n auto o = s.length - z;\r\n if (z == 0 || o == 0)\r\n writeln(0);\r\n else if (o == z)\r\n if (s.length > 2)\r\n writeln(o - 1);\r\n else\r\n writeln(0);\r\n else\r\n writeln(min(o, z));\r\n }\r\n}\r\n", "positive_code": [{"source_code": "// cheese-cracker [2022-01-31]\n\nvoid solve(){\n auto s = scan!(dchar[]);\n long on = 0;\n long off = 0;\n long res = 0;\n foreach(c; s){\n on += (c == '1');\n off += (c == '0');\n if(max(on, off) > min(on, off) && max(on, off) > 1){\n res = max(res, min(on, off));\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, 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": "62f5798bdcea237c0df9b4cd288b97de"} {"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\npure nothrow @nogc\nT gcdext(T) (T a, T b, ref T x, ref T y) {\n if (!b) {\n x = 1;\n y = 0;\n return a;\n }\n T res = gcdext (b, a % b, y, x);\n y -= x * (a / b);\n return res;\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\nstruct IntM(int q = 1_000_000_007) {\n alias N = IntM!q;\n private:\n int v;\n //invariant () { assert (v >= 0 && v < q); }\n pure nothrow @nogc\n static int from(T) (const T m) if (isIntegral!T) {\n int v = m % q;\n static if (isSigned!T) {\n if (v < 0) {\n v += q;\n }\n }\n return v;\n }\n public:\n pure nothrow @nogc\n this(T) (const T m) if (isIntegral!T) {\n v = from!T (m);\n }\n pure nothrow @nogc\n N opAssign(T) (const T m) if (isIntegral!T) {\n v = from!T (m);\n return this;\n }\n pure nothrow @nogc\n N opUnary (string op : \"-\")() const {\n return N (-v);\n }\n pure nothrow @nogc\n ref N opUnary (string op : \"++\")() {\n if (++v >= q) {\n v -= q;\n }\n return this;\n }\n pure nothrow @nogc\n ref N opUnary (string op : \"--\")() {\n if (--v < 0) {\n v += q;\n }\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"+\")(in N rhs) {\n v = (v + rhs.v) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"-\")(in N rhs) {\n v = (v - rhs.v + q) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"*\")(in N rhs) {\n v = (v.to!(long) * rhs.v) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"/\")(in N rhs) {\n return this *= rhs.inversion ();\n }\n pure nothrow @nogc\n ref N opOpAssign (string op)(in int rhs) if (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\") {\n mixin (\"return this \" ~ op ~ \"= N(rhs);\");\n }\n pure nothrow @nogc\n N opBinary (string op)(in N rhs) const if (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\") {\n N t = this;\n mixin (\"t \" ~ op ~ \"= rhs;\");\n return t;\n }\n pure nothrow @nogc\n N opBinary(string op,T)(const T rhs) const if (isIntegral!T && (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\")) {\n mixin (\"return this \" ~ op ~ \" N(rhs);\");\n }\n pure nothrow @nogc\n N opBinaryRight(string op,T)(const T rhs) const if (isIntegral!T && (op == \"+\" || op == \"*\")) {\n mixin (\"return this \" ~ op ~ \" N(rhs);\");\n }\n pure nothrow @nogc\n N inversion () const {\n int x, y;\n immutable g = gcdext!int (v, q, x, y);\n assert (g == 1);\n return N (x);\n }\n pure nothrow @nogc\n N opBinary (string op : \"^^\")(in ulong rhs) const {\n return genericPower! (\"a * b\", N, ulong) (this, rhs);\n }\n pure nothrow @nogc\n int opCast(T : int)() const { return v; }\n pure nothrow @nogc\n int opCmp (const N rhs) const {\n if (v < rhs.v) {\n return -1;\n }\n if (v > rhs.v) {\n return 1;\n }\n return 0;\n }\n pure nothrow\n string toString() const { return v.text; }\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\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 N = IntM!998244353;\n\nvoid main() {\n auto r = new InputReader;\n auto n = r.next!uint;\n auto a = new uint[][n];\n uint maxA;\n size_t maxL;\n foreach (i; 0 .. n) {\n a[i] = r.nextA!uint(r.next!uint);\n foreach (x; a[i]) {\n if (maxA < x) maxA = x;\n }\n if (maxL < a[i].length) maxL = a[i].length;\n }\n auto c = new int[maxA+1];\n auto il = new N[maxL+1];\n foreach (i; 0 .. n) {\n foreach (x; a[i]) ++c[x];\n auto l = a[i].length;\n if (il[l].v == 0) il[l] = N (l.to!int).inversion ();\n }\n auto invN = N (n).inversion();\n N res = 0;\n foreach (i; 0 .. n) {\n N t = 0;\n foreach (x; a[i]) {\n N u;\n u.v = c[x];\n t += u * invN;\n }\n res += t * il[a[i].length];\n }\n writeln (res * invN);\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\nint N = 1_000_099;\n\nvoid solve(){\n\tint n = rint;\n\tFinite[] ps;\n\tforeach(i; 0 .. N) ps ~= Finite(0);\n\tlong[] us = new long[](N);\n\tforeach(i; 0 .. n){\n\t\tint k = rint;\n\t\tint[] as = rint(k).map!(x => x - 1).array;\n\t\tforeach(a; as){\n\t\t\tps[a] += Finite(1) / k;\n\t\t\tus[a] += 1;\n\t\t}\n\t}\n\tFinite ans = Finite(0);\n\tforeach(a; 0 .. N) ans += ps[a] * us[a] / n / n;\n\n\tans.writeln;\n}\n\nimport std.conv;\nstruct Finite{\n\tlong value; static long mod = 998244353;\n\tprivate static long[] _inv = [0, 1], _frac = [1, 1], _invfrac = [1, 1];\n\tthis(long v){ value = val(v); }\n\tstatic long val(long v){\n\t\tif(v >= 0) return v % mod;\n\t\telse return (v + mod - (v / mod) * mod) % mod;\n\t}\n\tbool opCast(T: bool)(){ return value != 0; }\n\tFinite opUnary(string s){ long 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)(long u){ long 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)(long u){ long 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(long 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)(long 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\tlong inv(long v){\n\t\tv = val(v);\n\t\twhile(v >= _inv.length){\n\t\t\t_inv ~= _inv[(mod % $).to!int] * (mod - mod / _inv.length) % mod;\n\t\t}\n\t\treturn _inv[v.to!int];\n\t}\n\tlong invvalue(){\n\t\treturn inv(value);\n\t}\n\tstatic Finite opCall(long v){ return Finite(val(v)); }\n\t\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\npure nothrow @nogc\nT gcdext(T) (T a, T b, ref T x, ref T y) {\n if (!b) {\n x = 1;\n y = 0;\n return a;\n }\n T res = gcdext (b, a % b, y, x);\n y -= x * (a / b);\n return res;\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\nstruct IntM(int q = 1_000_000_007) {\n alias N = IntM!q;\n private:\n int v;\n //invariant () { assert (v >= 0 && v < q); }\n pure nothrow @nogc\n static int from(T) (const T m) if (isIntegral!T) {\n int v = m % q;\n static if (isSigned!T) {\n if (v < 0) {\n v += q;\n }\n }\n return v;\n }\n public:\n pure nothrow @nogc\n this(T) (const T m) if (isIntegral!T) {\n v = from!T (m);\n }\n pure nothrow @nogc\n N opAssign(T) (const T m) if (isIntegral!T) {\n v = from!T (m);\n return this;\n }\n pure nothrow @nogc\n N opUnary (string op : \"-\")() const {\n return N (-v);\n }\n pure nothrow @nogc\n ref N opUnary (string op : \"++\")() {\n if (++v >= q) {\n v -= q;\n }\n return this;\n }\n pure nothrow @nogc\n ref N opUnary (string op : \"--\")() {\n if (--v < 0) {\n v += q;\n }\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"+\")(in N rhs) {\n v = (v + rhs.v) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"-\")(in N rhs) {\n v = (v - rhs.v + q) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"*\")(in N rhs) {\n v = (v.to!(long) * rhs.v) % q;\n return this;\n }\n pure nothrow @nogc\n ref N opOpAssign (string op : \"/\")(in N rhs) {\n return this *= rhs.inversion ();\n }\n pure nothrow @nogc\n ref N opOpAssign (string op)(in int rhs) if (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\") {\n mixin (\"return this \" ~ op ~ \"= N(rhs);\");\n }\n pure nothrow @nogc\n N opBinary (string op)(in N rhs) const if (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\") {\n N t = this;\n mixin (\"t \" ~ op ~ \"= rhs;\");\n return t;\n }\n pure nothrow @nogc\n N opBinary(string op,T)(const T rhs) const if (isIntegral!T && (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\")) {\n mixin (\"return this \" ~ op ~ \" N(rhs);\");\n }\n pure nothrow @nogc\n N opBinaryRight(string op,T)(const T rhs) const if (isIntegral!T && (op == \"+\" || op == \"*\")) {\n mixin (\"return this \" ~ op ~ \" N(rhs);\");\n }\n pure nothrow @nogc\n N inversion () const {\n int x, y;\n immutable g = gcdext!int (v, q, x, y);\n assert (g == 1);\n return N (x);\n }\n pure nothrow @nogc\n N opBinary (string op : \"^^\")(in ulong rhs) const {\n return genericPower! (\"a * b\", N, ulong) (this, rhs);\n }\n pure nothrow @nogc\n int opCast(T : int)() const { return v; }\n pure nothrow @nogc\n int opCmp (const N rhs) const {\n if (v < rhs.v) {\n return -1;\n }\n if (v > rhs.v) {\n return 1;\n }\n return 0;\n }\n pure nothrow\n string toString() const { return v.text; }\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\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 N = IntM!998244353;\n\nvoid main() {\n auto r = new InputReader;\n auto n = r.next!uint;\n auto a = new uint[][n];\n uint maxA;\n foreach (i; 0 .. n) {\n a[i] = r.nextA!uint(r.next!uint);\n foreach (x; a[i]) {\n if (maxA < x) maxA = x;\n }\n }\n auto c = new int[maxA+1];\n auto il = new N[n+1];\n foreach (i; 0 .. n) {\n foreach (x; a[i]) ++c[x];\n auto l = a[i].length;\n if (il[l].v == 0) il[l] = N (l.to!int).inversion ();\n }\n auto invN = N (n).inversion();\n N res = 0;\n foreach (i; 0 .. n) {\n N t = 0;\n foreach (x; a[i]) {\n N u;\n u.v = c[x];\n t += u * invN;\n }\n res += t * il[a[i].length];\n }\n writeln (res * invN);\n}\n\n"}], "src_uid": "b4f8a6f5b1d1fa641514e10d18c316f7"} {"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 k = next!long;\n auto a = next!long(n);\n auto origA = a.dup;\n int[11] pot;\n pot[0] = 1;\n foreach(i; 1 .. 11)\n {\n pot[i] = (pot[i - 1] * 10) % k;\n }\n int[int][11] cnt;\n foreach(p; 0 .. 11)\n {\n foreach(ref ai; a)\n\t{\n\t ai %= k;\n\t}\n foreach(ref ai; a)\n\t{\n\t cnt[p].require(cast(int)ai, 0)++;\n\t ai *= 10;\n\t}\n }\n long totalCount = 0;\n foreach(ref ai; origA)\n {\n auto digs = noDigs(ai);\n long req = (((-ai) % k + k))%k;\n debug writeln(\"I require \", req, \" in \", digs);\n if (cast(int)req in cnt[digs])\n\t{\n\t totalCount += cnt[digs][cast(int)req];\n\t if ((pot[digs] * (ai % k) + ai % k) % k == 0)\n\t totalCount --;\n\t}\n }\n totalCount.writeln;\n}\n\nauto noDigs(long num)\n{\n auto res = int(0);\n while(num)\n {\n num /= 10;\n res++;\n }\n return res;\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.string;\nimport std.math;\n\nint calcLength(int num)\n{\n auto res = 0;\n while (num)\n {\n num /= 10;\n ++ res;\n }\n return res;\n}\n\nvoid solve(int[] a, int n, int k)\n{\n auto h = new int[int][10];\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n foreach (j; 0 .. 10)\n {\n num = cast(int)((cast(long)num * 10) % k);\n if (num !in h[j])\n {\n h[j][num] = 1;\n }\n else\n {\n ++ h[j][num];\n }\n }\n }\n long res = 0;\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n auto L = calcLength(a[i]);\n auto target = (k - num) % k;\n if (target in h[L - 1])\n {\n res += h[L - 1][target];\n }\n num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, L) % k)) % k);\n num = (num + (a[i] % k)) % k;\n if (num == 0)\n {\n -- res;\n }\n }\n writeln(res);\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, n, k);\n }\n return 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, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array; \n \n int [int][int] cnt;\n void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }\n \n foreach (e; arr) {\n add(e, 1);\n }\n \n debug { cnt.writeln; }\n \n auto ans = 0L;\n foreach (e; arr) {\n add(e, -1);\n auto r = e % k;\n foreach (d; 1 .. 11) {\n r = cast(long)r * 10 % k;\n debug { r.writeln; }\n if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];\n }\n add(e, 1);\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, 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 A = readln.split.map!(to!long).array;\n\n long ans = 0;\n auto cnt = new long[long][](11);\n foreach (a; A) {\n auto v = a;\n foreach (i; 0..11) {\n cnt[i][v] += 1;\n v = v * 10 % m;\n }\n }\n\n foreach (a; A) {\n long keta = a.to!string.length.to!long;\n long target = (m - a % m) % m;\n if (target in cnt[keta.to!int]) ans += cnt[keta.to!int][target];\n if ((powmod(10, keta, m) * a % m + a) % m == 0) ans -= 1;\n }\n\n ans.writeln;\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}"}, {"source_code": "import std.stdio, std.string;\nimport std.math;\n\nint calcLength(int num)\n{\n auto res = 0;\n while (num)\n {\n num /= 10;\n ++ res;\n }\n return res;\n}\n\nvoid solve(int[] a, int n, int k)\n{\n auto h = new int[int][10];\n foreach (i; 0 .. n)\n {\n foreach (j; 0 .. 10)\n {\n auto num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, j + 1) % k)) % k);\n if (num !in h[j])\n {\n h[j][num] = 1;\n }\n else\n {\n ++ h[j][num];\n }\n }\n }\n long res = 0;\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n auto L = calcLength(a[i]);\n auto target = (k - num) % k;\n if (target in h[L - 1])\n {\n res += h[L - 1][target];\n }\n num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, L) % k)) % k);\n num = (num + (a[i] % k)) % k;\n if (num == 0)\n {\n -- res;\n }\n }\n writeln(res);\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, n, k);\n }\n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.math;\n\nint calcLength(int num)\n{\n auto res = 0;\n while (num)\n {\n num /= 10;\n ++ res;\n }\n return res;\n}\n\nvoid solve(int[] a, int n, int k)\n{\n auto h = new int[int][10];\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n foreach (j; 0 .. 10)\n {\n num = cast(int)((cast(long)num * 10) % k);\n if (num !in h[j])\n {\n h[j][num] = 1;\n }\n else\n {\n ++ h[j][num];\n }\n }\n }\n long res = 0;\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n auto L = calcLength(a[i]);\n auto target = (k - num) % k;\n if (target in h[L - 1])\n {\n res += h[L - 1][target];\n }\n num = cast(int)((cast(long)a[i] * (pow(10, L) % k)) % k);\n num = (num + (a[i] % k)) % k;\n if (num == 0)\n {\n -- res;\n }\n }\n writeln(res);\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, n, k);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.math;\n\nint calcLength(int num)\n{\n auto res = 0;\n while (num)\n {\n num /= 10;\n ++ res;\n }\n return res;\n}\n\nvoid solve(int[] a, int n, int k)\n{\n auto h = new int[int][10];\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n foreach (j; 0 .. 10)\n {\n num = (num * 10) % k;\n if (num !in h[j])\n {\n h[j][num] = 1;\n }\n else\n {\n ++ h[j][num];\n }\n }\n }\n long res = 0;\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n auto L = calcLength(a[i]);\n auto target = (k - num) % k;\n if (target in h[L - 1])\n {\n res += h[L - 1][target];\n }\n num = cast(int)((cast(long)a[i] * (pow(10, L) % k)) % k);\n num = (num + (a[i] % k)) % k;\n if (num == 0)\n {\n -- res;\n }\n }\n writeln(res);\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, n, k);\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.math;\n\nint calcLength(int num)\n{\n auto res = 0;\n while (num)\n {\n num /= 10;\n ++ res;\n }\n return res;\n}\n\nvoid solve(int[] a, int n, int k)\n{\n auto h = new int[int][10];\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n foreach (j; 0 .. 10)\n {\n num = cast(int)((cast(long)num * 10) % k);\n if (num !in h[j])\n {\n h[j][num] = 1;\n }\n else\n {\n ++ h[j][num];\n }\n }\n }\n long res = 0;\n foreach (i; 0 .. n)\n {\n auto num = a[i] % k;\n auto L = calcLength(a[i]);\n auto target = (k - num) % k;\n if (target in h[L - 1])\n {\n res += h[L - 1][target];\n }\n num = cast(int)((cast(long)(a[i] % k) * (cast(long)pow(10, L) % k)) % k);\n num = (num + (a[i] % k)) % k;\n if (num == 0)\n {\n -- res;\n }\n }\n writeln(res);\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, n, k);\n }\n return 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, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array; \n \n int [int][int] cnt;\n void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }\n \n foreach (e; arr) {\n add(e, 1);\n }\n \n debug { cnt.writeln; }\n \n auto ans = 0L;\n foreach (e; arr) {\n add(e, -1);\n auto r = e % k;\n foreach (d; 1 .. 10) {\n r = r * 10 % k;\n if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];\n }\n add(e, 1);\n }\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, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array; \n \n int [int][int] cnt;\n void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }\n \n foreach (e; arr) {\n add(e, 1);\n }\n \n debug { cnt.writeln; }\n \n auto ans = 0L;\n foreach (e; arr) {\n add(e, -1);\n auto r = e % k;\n foreach (d; 1 .. 11) {\n r = r * 10 % k;\n if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];\n }\n add(e, 1);\n }\n \n ans.writeln;\n}"}], "src_uid": "1eb41e764a4248744edce6a9e7e3517a"} {"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 char[][][](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto h = RD!int;\r\n\t\tauto w = RD!int;\r\n\r\n\t\tans[ti].length = h;\r\n\t\tforeach (i; 0..h)\r\n\t\t{\r\n\t\t\tans[ti][i].length = w;\r\n\t\t\tforeach (j; 0..w)\r\n\t\t\t{\r\n\t\t\t\tans[ti][i][j] = '0';\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (i; 0..w)\r\n\t\t{\r\n\t\t\tif (i % 2 == 0)\r\n\t\t\t{\r\n\t\t\t\tans[ti][0][i] = '1';\r\n\t\t\t\tans[ti][h-1][i] = '1';\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (i; 2..h-2)\r\n\t\t{\r\n\t\t\tif (i % 2 == 0)\r\n\t\t\t{\r\n\t\t\t\tans[ti][i][0] = '1';\r\n\t\t\t\tans[ti][i][w-1] = '1';\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);\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}\n\nvoid solve()\n{\n\tint h = readInt!int;\n\tint w = readInt!int;\n\tif (w % 2 == 1 && h % 2 == 1)\n\t{\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\twrite((i + j + 1)%2);\n\t\t\t\t}\n\t\t\t\telse write(0);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t\twriteln;\n\t\treturn;\n\t}\n\telse if (w % 2 == 0 && h % 2 == 0)\n\t{\n\t\tauto ans = new int[][](h, w);\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif(i == 0 || i == h - 1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = (i + j)%2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = (i + j + 1)%2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;\n\t\tforeach(row; ans) { row.each!write; writeln; }\n\t\twriteln;\n\t\treturn;\n\t}\n\tforeach(i; 0 .. h)\n\t{\n\t\tforeach(j; 0 .. w)\n\t\t{\n\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t{\n\t\t\t\tint ch = w%2;\n\t\t\t\tif (i == 0 && j == 0 || i == h - 1 && j == w - 1) {0.write; continue;}\n\t\t\t\tif (i == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\t((i+j+ch)%2).write;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t((i + j + 1+ch)%2).write;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse 0.write;\n\t\t}\n\t\twriteln;\n\t}\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"}, {"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); }\n\nvoid main() {\n int t;\n read(t);\n \n while (t--) {\n int h, w;\n read(h, w);\n \n auto table = new int[][](h, w);\n \n table[0][0] = table[0][w - 1] = table[h - 1][0] = table[h - 1][w - 1] = 1;\n \n foreach (i; 0 .. (h - 3) / 2) {\n table[i * 2 + 2][0] = table[i * 2 + 2][w - 1] = 1;\n }\n \n foreach (i; 0 .. (w - 3) / 2) {\n table[0][i * 2 + 2] = table[h - 1][i * 2 + 2] = 1;\n }\n \n foreach (i; 0 .. h) {\n foreach (j; 0 .. w) {\n write(table[i][j]);\n }\n writeln;\n }\n 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 while(tests--) {\r\n int n, m;\r\n readf!\"%s %s\\n\"(n, m);\r\n bool[][] a = new bool[][](n, m);\r\n foreach(i; 0 .. n) {\r\n foreach(j; 0 .. m) {\r\n if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {\r\n if (i > 0 && a[i - 1][j]) continue;\r\n if (i > 0 && j > 0 && a[i - 1][j - 1]) continue;\r\n if (j > 0 && a[i][j - 1]) continue;\r\n if (i > 0 && j + 1 < m && a[i - 1][j + 1]) continue;\r\n a[i][j] = true;\r\n }\r\n }\r\n }\r\n writefln!\"%(%(%d%)\\n%)\"(a);\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\nbool good(int x, int y, int w, int h, int[][] a)\n{\n if (x > 0 && a[x - 1][y])\n return false;\n if (x + 1 < w && a[x + 1][y])\n return false;\n if (y > 0 && a[x][y - 1])\n return false;\n if (y + 1 < h && a[x][y + 1])\n return false;\n\n if (x > 0 && y > 0 && a[x - 1][y - 1])\n return false;\n if (x + 1 < w && y > 0 && a[x + 1][y - 1])\n return false;\n if (x > 0 && y + 1 < h && a[x - 1][y + 1])\n return false;\n if (x + 1 < w && y + 1 < h && a[x + 1][y + 1])\n return false;\n\n return true;\n}\n\nlong solve(int x, int y, int w, int h, int[][] a)\n{\n long result = 0;\n while (x < w) {\n if (good(x, y, w, h, a)) {\n result++;\n a[x][y] = 1;\n }\n x++;\n }\n x = w - 1;\n while (y < h) {\n if (good(x, y, w, h, a)) {\n result++;\n a[x][y] = 1;\n }\n y++;\n }\n y = h - 1;\n while (x >= 0) {\n if (good(x, y, w, h, a)) {\n result++;\n a[x][y] = 1;\n }\n x--;\n }\n x = 0;\n while (y >= 0) {\n if (good(x, y, w, h, a)) {\n result++;\n a[x][y] = 1;\n }\n y--;\n }\n return result;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n int h, w;\n readf!\" %d %d \"(h, w);\n auto a1 = new int[][](w, h);\n auto a2 = new int[][](w, h);\n a1[0][0] = 1;\n a2[1][0] = 1;\n long result1 = solve(0, 0, w, h, a1);\n long result2 = solve(0, 0, w, h, a2);\n if (result1 > result2) {\n foreach (row ; a1.transposed) {\n writeln(row.map!text.joiner(\"\"));\n }\n writeln;\n } else {\n foreach (row ; a2.transposed) {\n writeln(row.map!text.joiner(\"\"));\n }\n writeln;\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 numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const M = readInt();\n const N = readInt();\n \n auto ans = new char[][](M, N);\n foreach (x; 0 .. M) {\n ans[x][] = '0';\n }\n ans[0][0] = ans[0][N - 1] = ans[M - 1][0] = ans[M - 1][N - 1] = '1';\n for (int y = 2; y < N - 2; y += 2) {\n ans[0][y] = ans[M - 1][y] = '1';\n }\n for (int x = 2; x < M - 2; x += 2) {\n ans[x][0] = ans[x][N - 1] = '1';\n }\n \n foreach (x; 0 .. M) {\n writeln(ans[x]);\n }\n writeln;\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\tint rows, cols;\r\n\t\treadf !(\" %s %s\") (rows, cols);\r\n\t\tauto s = new bool [] [] (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\tif (row == 0 || row == rows - 1 ||\r\n\t\t\t\t col == 0 || col == cols - 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (row > 0 && s[row - 1][col])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (row > 0 && col > 0 &&\r\n\t\t\t\t\t s[row - 1][col - 1])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (col > 0 && s[row][col - 1])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (row > 0 && col + 1 < cols &&\r\n\t\t\t\t\t s[row - 1][col + 1])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\ts[row][col] = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%(%d%)\\n%)\\n\") (s);\r\n\t}\r\n}\r\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\n}\n\nvoid solve()\n{\n\tint h = readInt!int;\n\tint w = readInt!int;\n\tif (w % 2 == 1 && h % 2 == 1)\n\t{\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\twrite((i + j + 1)%2);\n\t\t\t\t}\n\t\t\t\telse write(0);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t\twriteln;\n\t\treturn;\n\t}\n\telse if (w % 2 == 0 && h % 2 == 0)\n\t{\n\t\tauto ans = new int[][](h, w);\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif(i == 0 || i == h - 1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = (i + j)%2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = (i + j + 1)%2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;\n\t\tforeach(row; ans) { row.each!write; writeln; }\n\t\twriteln;\n\t\treturn;\n\t}\n\tforeach(i; 0 .. h)\n\t{\n\t\tforeach(j; 0 .. w)\n\t\t{\n\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t{\n\t\t\t\tint ch = w%2;\n\t\t\t\tif (j > i)\n\t\t\t\t{\n\t\t\t\t\t((i+j+ch)%2).write;\n\t\t\t\t}\n\t\t\t\telse if (i > j)\n\t\t\t\t{\n\t\t\t\t\t((i + j + 1+ch)%2).write;\n\t\t\t\t}\n\t\t\t\telse \n\t\t\t\t{\n\t\t\t\t\t0.write;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse 0.write;\n\t\t}\n\t\twriteln;\n\t}\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"}, {"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}\n\nvoid solve()\n{\n\tint h = readInt!int;\n\tint w = readInt!int;\n\tif (w % 2 == 1 && h % 2 == 1)\n\t{\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\twrite((i + j + 1)%2);\n\t\t\t\t}\n\t\t\t\telse write(0);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t\twriteln;\n\t\treturn;\n\t}\n\telse if (w % 2 == 0 && h % 2 == 0)\n\t{\n\t\tauto ans = new int[][](h, w);\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif(i == 0 || i == h - 1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = (i + j)%2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = (i + j + 1)%2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;\n\t\tforeach(row; ans) { row.each!write; writeln; }\n\t\twriteln;\n\t\treturn;\n\t}\n\tforeach(i; 0 .. h)\n\t{\n\t\tforeach(j; 0 .. w)\n\t\t{\n\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t{\n\t\t\t\tif (j > i)\n\t\t\t\t{\n\t\t\t\t\t((i+j)%2).write;\n\t\t\t\t}\n\t\t\t\telse if (i > j)\n\t\t\t\t{\n\t\t\t\t\t((i + j + 1)%2).write;\n\t\t\t\t}\n\t\t\t\telse \n\t\t\t\t{\n\t\t\t\t\t0.write;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse 0.write;\n\t\t}\n\t\twriteln;\n\t}\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"}, {"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}\n\nvoid solve()\n{\n\tint h = readInt!int;\n\tint w = readInt!int;\n\tif (w % 2 == 1 && h % 2 == 1)\n\t{\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\twrite((i + j + 1)%2);\n\t\t\t\t}\n\t\t\t\telse write(0);\n\t\t\t}\n\t\t\twriteln;\n\t\t}\n\t\twriteln;\n\t\treturn;\n\t}\n\telse if (w % 2 == 0 && h % 2 == 0)\n\t{\n\t\tauto ans = new int[][](h, w);\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif(i == 0 || i == h - 1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = (i + j)%2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\tans[i][j] = (i + j + 1)%2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans[0][0] = ans[0][h-1] = ans[w-1][0] = ans[w-1][h-1] = 0;\n\t\tforeach(row; ans) { row.each!write; writeln; }\n\t\twriteln;\n\t}\n\tforeach(i; 0 .. h)\n\t{\n\t\tforeach(j; 0 .. w)\n\t\t{\n\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t{\n\t\t\t\tif (j > i)\n\t\t\t\t{\n\t\t\t\t\t((i+j)%2).write;\n\t\t\t\t}\n\t\t\t\telse if (i > j)\n\t\t\t\t{\n\t\t\t\t\t((i + j + 1)%2).write;\n\t\t\t\t}\n\t\t\t\telse \n\t\t\t\t{\n\t\t\t\t\t0.write;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse 0.write;\n\t\t}\n\t\twriteln;\n\t}\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"}, {"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}\n\nvoid solve()\n{\n\tint h = readInt!int;\n\tint w = readInt!int;\n\tint l = 2 * h + 2 * w - 4;\n\tint m = l - l/2;\n\tint[][] fm;\n\tbool tryF(int x)\n\t{\n\t\tint t = 0;\n\t\tfm = new int[][](h, w);\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\tfm[i][j] = (i + j + x)%2; \n\t\t\t\t\tt += fm[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (t == m) return true;\n\t\treturn false;\n\t}\n\tif (tryF(1)) goto print;\n\tif (tryF(0)) goto print; \n\tassert(0);\nprint:\n\tforeach(row; fm)\n\t{\n\t\trow.each!write; writeln;\n\t}\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"}, {"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}\n\nvoid solve()\n{\n\tint h = readInt!int;\n\tint w = readInt!int;\n\tint l = 2 * h + 2 * w - 4;\n\tint m = l - l/2;\n\tint[][] fm;\n\tbool tryF(int x)\n\t{\n\t\tint t = 0;\n\t\tfm = new int[][](h, w);\n\t\tforeach(i; 0 .. h)\n\t\t{\n\t\t\tforeach(j; 0 .. w)\n\t\t\t{\n\t\t\t\tif (i == 0 || i == h - 1 || j == 0 || j == w - 1)\n\t\t\t\t{\n\t\t\t\t\tfm[i][j] = (i + j + x)%2; \n\t\t\t\t\tt += fm[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (t == m) return true;\n\t\treturn false;\n\t}\n\tif (tryF(0)) goto print;\n\tif (tryF(1)) goto print; \n\tassert(0);\nprint:\n\tforeach(row; fm)\n\t{\n\t\trow.each!write; writeln;\n\t}\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"}], "src_uid": "730cc4be2656c1dcdbda220b8778cdbf"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\nint[] primes;\nvoid prime_sieve(){\n const int sz = 100;\n auto isPrime = new bool[](sz + 1);\n isPrime[] = 1;\n foreach(p; 2..15){\n if(isPrime[p]){\n for(ll divi = p*p; divi <= sz; divi += p){\n isPrime[divi.to!int] = 0;\n }\n }\n }\n isPrime[0] = 0; isPrime[1] = 0;\n primes = isPrime.enumerate.filter!(a => a[1]).map!(a => a[0].to!(int)).array;\n foreach(k; 2..sz+1){\n if(isPrime[k]) primes ~= k;\n }\n}\n\n\nvoid theCode(){\n ll k = scan;\n auto n = scan!(dchar[]);\n auto w = \"2357\".to!(dchar[]);\n ll[4] freq;\n foreach(c; n){\n bool f = 1;\n for(int i = 0; i < 4; ++i){\n dchar d = w[i];\n if(c == d){\n ++freq[i];\n f = 0;\n break;\n }\n }\n if(f){\n writeln(1);\n writeln(c);\n return;\n }\n }\n for(int i = 0; i < k; ++i){\n int d1 = n[i] - '0';\n for(int j = i+1; j < k; ++j){\n int d2 = n[j] - '0';\n int num = d1* 10 + d2;\n bool f = 1;\n foreach(pm; primes){\n if(num == pm){\n f = 0;\n }\n }\n if(f){\n writeln(2);\n writeln(num);\n return;\n }\n }\n }\n}\n\nvoid main(){\n prime_sieve;\n show(primes);\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.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 k = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tauto cnt = new long[](10);\r\n\t\tforeach (c; s)\r\n\t\t{\r\n\t\t\t++cnt[c-'0'];\r\n\t\t}\r\n\r\n\t\tauto set = [1:true, 4:true, 6:true, 8:true, 9:true];\r\n\t\tbool ok;\r\n\t\tforeach (i; 0..10)\r\n\t\t{\r\n\t\t\tif (set.get(i, false) == false) continue;\r\n\t\t\tif (cnt[i] > 0)\r\n\t\t\t{\r\n\t\t\t\tok = true;\r\n\t\t\t\tans[ti] = [cast(char)('0'+i)];\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\tforeach (i; 0..10)\r\n\t\t{\r\n\t\t\tif (cnt[i] >= 2)\r\n\t\t\t{\r\n\t\t\t\tok = true;\r\n\t\t\t\tans[ti] ~= [cast(char)('0'+i)];\r\n\t\t\t\tans[ti] ~= [cast(char)('0'+i)];\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\tforeach (i; 1..2^^k)\r\n\t\t{\r\n\t\t\tstring str;\r\n\t\t\tforeach (j; 0..k)\r\n\t\t\t{\r\n\t\t\t\tauto bit = 1L << j;\r\n\t\t\t\tif (i & bit)\r\n\t\t\t\t{\r\n\t\t\t\t\tstr ~= s[j];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tauto x = str.to!long;\r\n\t\t\tfor (long j = 2; j*j <= x; ++j)\r\n\t\t\t{\r\n\t\t\t\tif (x % j) continue;\r\n\t\t\t\tok = true;\r\n\t\t\t\tans[ti] = str;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif (ok) break;\r\n\t\t}\r\n\t}\r\n\tdebug writeln(ans);\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e.length);\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.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;\n\nbool check_subsequence(string main, string sub)\n{\n int i, j;\n while (i < main.length && j < sub.length) {\n if (main[i] == sub[j]) {\n i++;\n j++;\n continue;\n }\n i++;\n }\n return j == sub.length;\n}\n\nvoid main()\n{\n auto nonprimes = [\"1\", \"4\", \"6\", \"8\", \"9\", \"20\", \"22\", \"25\", \"27\", \"30\", \"32\", \"33\", \"35\", \"50\", \"52\", \"55\", \"57\", \"70\", \"72\", \"75\", \"77\"];\n long t;\n readf!\" %d \"(t);\n while (t--) {\n long n;\n readln.formattedRead!\" %d \"(n);\n string s = readln.strip;\n bool good = false;\n foreach (nonprime ; nonprimes) {\n if (check_subsequence(s, nonprime)) {\n writeln(nonprime.length);\n writeln(nonprime);\n good = true;\n break;\n }\n }\n if (!good)\n writeln(-1);\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 string[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto k = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tauto cnt = new long[](10);\r\n\t\tforeach (c; s)\r\n\t\t{\r\n\t\t\t++cnt[c-'0'];\r\n\t\t}\r\n\r\n\t\tauto set = [1:true, 4:true, 6:true, 8:true];\r\n\t\tbool ok;\r\n\t\tforeach (i; 0..10)\r\n\t\t{\r\n\t\t\tif (set.get(i, false) == false) continue;\r\n\t\t\tif (cnt[i] > 0)\r\n\t\t\t{\r\n\t\t\t\tok = true;\r\n\t\t\t\tans[ti] = [cast(char)('0'+i)];\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\tforeach (i; 0..10)\r\n\t\t{\r\n\t\t\tif (cnt[i] >= 2)\r\n\t\t\t{\r\n\t\t\t\tok = true;\r\n\t\t\t\tans[ti] ~= [cast(char)('0'+i)];\r\n\t\t\t\tans[ti] ~= [cast(char)('0'+i)];\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\tforeach (i; 1..2^^k)\r\n\t\t{\r\n\t\t\tstring str;\r\n\t\t\tforeach (j; 0..k)\r\n\t\t\t{\r\n\t\t\t\tauto bit = 1L << j;\r\n\t\t\t\tif (i & bit)\r\n\t\t\t\t{\r\n\t\t\t\t\tstr ~= s[j];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tauto x = str.to!long;\r\n\t\t\tfor (long j = 2; j*j <= x; ++j)\r\n\t\t\t{\r\n\t\t\t\tif (x % j) continue;\r\n\t\t\t\tok = true;\r\n\t\t\t\tans[ti] = str;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tif (ok) break;\r\n\t\t}\r\n\t}\r\n\tdebug writeln(ans);\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e.length);\r\n\t\twriteln(e);\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "22c0489eec3d8e290fcbcf1aeb3bb66c"} {"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 Add(int n, ref int[] arr, int m) {\n if (n / m == 0) return;\n Add(n, arr, m*2);\n auto v = n / m;\n while (arr.length < v) arr ~= m;\n}\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n if (n <= 3) {\n auto ans = [n].padLeft(1, n);\n \n ans.writefln!(\"%(%s %)\");\n return;\n }\n \n int[] ans;\n Add(n, ans, 1);\n if (ans[1] == ans[2]) ans[0] += ans[1];\n ans.reverse();\n \n ans.writefln!(\"%(%s %)\");\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 int n;\n scan(n);\n\n int m = n;\n int p = 1;\n int[] ans;\n\n while (m > 0) {\n if (m == 3) {\n ans ~= p;\n ans ~= p;\n ans ~= p * 3;\n break;\n }\n foreach (i ; 0 .. (m + 1) / 2) {\n ans ~= p;\n }\n m -= (m + 1) / 2;\n p *= 2;\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\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 int g = 1;\n int[] ans;\n while (n) {\n if (n == 3) {\n ans ~= g;\n ans ~= g;\n ans ~= g * 3;\n break;\n }\n int k = (n + 1) / 2;\n n -= k;\n foreach (_; 0 .. k)\n ans ~= g;\n g *= 2;\n }\n writefln(\"%(%s %)\", ans);\n\n}\n\n// 5 => 1 1 1 2 4\n// 6 => 1 1 1 2 2 6\n// 7 => 1 1 1 1 2 2 6\n// 8 => 1 1 1 1 2 2 4 8\n// 10 => 1 1 1 1 1 2 2 2 4 8\n// 12 => 1 1 1 1 1 1 2 2 2 4 4 12\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;\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;\n readf(\"%s\", &n);\n readln;\n \n if (n <= 3) {\n auto ans = [n].padLeft(1, n);\n \n ans.writefln!(\"%(%s %)\");\n return;\n }\n \n auto pws = recurrence!((a,n) => a[n-1] * 2)(2).until!(x => x > n).array;\n \n auto ans = pws.padLeft(1, n);\n \n ans.writefln!(\"%(%s %)\");\n}"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n;\n rd(n);\n import std.range : iota;\n import std.array : array;\n import std.numeric : gcd;\n\n auto a = iota(1, n + 1).filter!((val) => val % 2 == 0).array;\n int[] result;\n foreach (_; 0 .. (n - a.length))\n result ~= 1;\n while (result.length < n) {\n int[] b;\n if (a.length <= 2) {\n auto g = gcd(a[0], a[$ - 1]);\n result ~= g;\n if (a.length > 1) {\n b ~= a[$ - 1];\n }\n } else {\n auto g = reduce!((gg, val) => gcd(gg, val))(0, a);\n result ~= g;\n foreach (val; a[1 .. $]) {\n if (val % g == 0) {\n b ~= val;\n }\n }\n int[] b2;\n foreach (val; a[1 .. $]) {\n if (val % a[1] == 0) {\n b2 ~= val;\n }\n }\n if (b2.length >= 2) {\n b = b2.dup;\n }\n foreach (_; 0 .. (a.length - b.length - 1)) {\n result ~= g;\n }\n }\n a.swap(b);\n }\n writefln(\"%(%s %)\", result);\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": "cadff0864835854f4f1e0234f2fd3edf"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1537/problem/A\n// simple 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\nwhile(t--) {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n long sum = a.sum;\n\n if(sum < n) {\n \"1\".writeln;\n continue;\n }\n writefln(\"%s\", sum - n);\n}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string;\n\nvoid main()\n{\n long t, n;\n readf!\" %d \"(t);\n\n while (t--) {\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!long);\n long sum = a.sum;\n long result = 0;\n if (sum - n >= 0) {\n writeln(sum - n);\n } else {\n writeln(1);\n }\n }\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1537/problem/A\n// simple 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\nwhile(t--) {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n long sum = a.sum;\n\n if(sum <= 0) {\n \"1\".writeln;\n continue;\n }\n writefln(\"%s\", sum - n);\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1537/problem/A\n// simple 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 = readln.chomp.to!int;\n int[] a = readln.split.map!(to!int).array;\n long sum = a.sum;\n\n if(sum <= 0) {\n \"1\".writeln;\n continue;\n }\n writefln(\"%s\", sum - n);\n}\n}\n"}], "src_uid": "b5985b619652e606ac96554ecfb9346a"} {"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;\nvoid main(){\n\tn.next;\n\tk.next;\n\t\n\tint cnt;\n\tforeach(i; n.iota){\n\t\tstring str = next!string();\n\t\tint con;\n\t\tforeach(c; str){\n\t\t\tif( c == '4' || c == '7' ) ++con;\n\t\t}\n\t\tif( con <= k ) ++cnt;\n\t}\n\t\n\tcnt.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", "positive_code": [{"source_code": "import std.stdio;\n\nint main() {\n int N, K;\n readf(\" %s %s\", &N, &K);\n int ans = 0;\n foreach (i; 0..N) {\n int n;\n readf(\" %s\", &n); \n int nd = 0;\n while (n > 0) {\n int d = n % 10;\n n /= 10;\n if (d == 4 || d == 7) {\n nd++;\n }\n }\n if (nd <= K) {\n ans++;\n }\n }\n writefln(\"%s\", ans);\n return 0;\n}\n"}], "negative_code": [], "src_uid": "6bb26991c9ea70e51a6bda5653de8131"} {"source_code": "import 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.string,\n std.numeric,\n std.variant,\n std.typecons,\n std.algorithm,\n std.typetuple,\n std.exception;\n\nvoid main() {\n\n\tchar[] s = readln.strip.dup;\n\tint k = readln.strip.to!int;\n\n\tif (s.length < k || s.length % k != 0) {\n\t\twriteln(\"NO\");\n\t\treturn;\n\t}\n\n\tint ans, i, it = s.length / k, idx = s.length / k;\n\twhile (it <= s.length) {\n\t\tdebug writeln(\"s = \", s[i .. it]);\n\t\tif (s[i .. it] == s[i .. it].retro.text) {\n\t\t\t++ans;\n\t\t}\n\t\telse {\n\t\t\tbreak;\n\t\t}\n\t\ti = it;\n\t\tit += idx;\n\t\tdebug writefln(\"i = %s, it = %s, s.len = %s\", i, it, s.length);\n\t}\n\n\twriteln(ans == k ? \"YES\" : \"NO\");\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.range;\nimport std.array;\nimport std.conv;\nimport std.complex;\nimport std.math;\nimport std.ascii;\nimport std.bigint;\nimport std.container;\nimport std.typecons;\n\nauto readInt() {\n\treturn readInts()[0];\n}\nauto readInts() {\n\treturn array(map!(to!int)(readln().strip().split()));\n}\nauto readLong() { \n\treturn readLongs()[0];\n}\nauto readLongs() {\n\treturn array(map!(to!long)(readln().strip().split()));\n}\n\nbool isPalindrome(string s) {\n\tforeach(i; 0..s.length) {\n\t\tif(s[i] != s[$-i-1]){\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\nvoid main() {\n\tauto s = readln().strip();\n\tauto k = readInt();\n\tif(s.length%k != 0) {\n\t\twriteln(\"NO\");\n\t\treturn;\n\t}\n\tforeach(i; 0..k) {\n\t\tauto t = s[s.length/k*i..s.length/k*(i+1)];\n\t\tif(!isPalindrome(t)){\n\t\t\twriteln(\"NO\");\n\t\t\treturn;\n\t\t}\n\t}\n\twriteln(\"YES\");\n}\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "import 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.string,\n std.numeric,\n std.variant,\n std.typecons,\n std.algorithm,\n std.typetuple,\n std.exception;\n\nvoid main() {\n\n\tchar[] s = readln.strip.dup;\n\tint k = readln.strip.to!int;\n\n\tif (s.length < k) {\n\t\twriteln(\"NO\");\n\t\treturn;\n\t}\n\n\tint ans, i, it = s.length / k, idx = s.length / k;\n\twhile (it <= s.length) {\n\t\tdebug writeln(\"s = \", s[i .. it]);\n\t\tif (s[i .. it] == s[i .. it].retro.text) {\n\t\t\t++ans;\n\t\t}\n\t\telse {\n\t\t\tbreak;\n\t\t}\n\t\ti = it;\n\t\tit += idx;\n\t\tdebug writefln(\"i = %s, it = %s, s.len = %s\", i, it, s.length);\n\t}\n\n\twriteln(ans == k ? \"YES\" : \"NO\");\n}"}, {"source_code": "import 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.string,\n std.numeric,\n std.variant,\n std.typecons,\n std.algorithm,\n std.typetuple,\n std.exception;\n\nvoid main() {\n\n\tchar[] s = readln.strip.dup;\n\tint k = readln.strip.to!int;\n\n\tint ans, i, it = s.length / k;\n\twhile (it <= s.length) {\n\t\tdebug writeln(\"s = \", s[i .. it]);\n\t\tif (s[i .. it] == s[i .. it].retro.to!string) {\n\t\t\t++ans;\n\t\t}\n\t\ti = it;\n\t\tit += k;\n\t\tdebug writefln(\"i = %s, it = %s, s.len = %s\", i, it, s.length);\n\t}\n\n\twriteln(ans == k ? \"YES\" : \"NO\");\n}"}], "src_uid": "43bb8fec6b0636d88ce30f23b61be39f"} {"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\nconst int[] P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31];\n\nvoid solve() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto B = new int[](N);\n\n foreach (i, a; A) foreach (j, p; P) {\n if (a % p == 0) {\n B[i.to!int] = j.to!int + 1;\n break;\n }\n }\n\n auto X = B.dup.sort().uniq.array;\n int[int] Y;\n foreach (i; 0..X.length.to!int) Y[X[i]] = i + 1;\n foreach (i; 0..N) B[i] = Y[B[i]];\n X.length.writeln;\n B.map!(to!string).join(\" \").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\tauto m = 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\tans[ti].length = n;\n\t\tbool[int] set;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tfor (int j = 2; j*j <= a[i]; ++j)\n\t\t\t{\n\t\t\t\tif (a[i] % j == 0)\n\t\t\t\t{\n\t\t\t\t\tset[j] = true;\n\t\t\t\t\tans[ti][i] = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tauto keys = set.keys;\n\t\tm[ti] = cast(int)keys.length;\n\t\tint[int] keyToNum;\n\t\tforeach (i, key; keys)\n\t\t{\n\t\t\tkeyToNum[key] = cast(int)(i+1);\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tans[ti][i] = keyToNum[ans[ti][i]];\n\t\t}\n\t}\n\n\tforeach (ti, e; ans)\n\t{\n\t\twriteln(m[ti]);\n\t\te.map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"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\nconst int[] P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31];\n\nvoid solve() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n auto B = new int[](N);\n\n foreach (i, a; A) foreach (j, p; P) {\n if (a % p == 0) {\n B[i.to!int] = j.to!int + 1;\n break;\n }\n }\n\n B.map!(to!string).join(\" \").writeln;\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) {\n solve();\n }\n}\n"}], "src_uid": "c3cd949c99e96c9da186a34d49bd6197"} {"source_code": "module main;\n\nimport 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, min;\n\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int x = io.readInt;\n int y = io.readInt;\n writeln(min(max(x + y - n + 1, 1), n), \" \", min(x + 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 = 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;\n\t\tauto x = RD;\n\t\tauto y = RD;\n\n\t\tif (x + y < n + 1)\n\t\t{\n\t\t\tans[ti][0] = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[ti][0] = min((x+y) - (n+1) + 2, n);\n\t\t}\n\t\tans[ti][1] = min(x+y-1, n);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0], \" \", e[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 t = readln.chomp.to!int; \n while (t--) {\n auto v = readln.chomp.split.map!(to!int);\n auto n = v[0], x = v[1], y = v[2];\n \n int mn = n - min(n-1, max(0, \n max(0, n-x-1) + max(0, n-y-1) + (max(x, y) < n ? 1 : 0)));\n int mx = min(n, x-1 + y-1 + 1);\n \n writeln(mn, ' ', mx);\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 t = readln.chomp.to!int; \n while (t--) {\n auto v = readln.chomp.split.map!(to!int);\n auto n = v[0], x = v[1], y = v[2];\n \n int mn = n - min(n-1, n-x-1 + n-y-1 + (max(x, y) < n ? 1 : 0));\n int mx = min(n, x-1 + y-1 + 1);\n \n writeln(mn, ' ', mx);\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 auto t = readln.chomp.to!int; \n while (t--) {\n auto v = readln.chomp.split.map!(to!int);\n auto n = v[0], x = v[1], y = v[2];\n \n int mn = n - min(n-1, max(0, n-x-1 + n-y-1 + (max(x, y) < n ? 1 : 0)));\n int mx = min(n, x-1 + y-1 + 1);\n \n writeln(mn, ' ', mx);\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;\n\t\tauto x = RD;\n\t\tauto y = RD;\n\n\t\tif (x + y < n + 1)\n\t\t{\n\t\t\tans[ti][0] = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[ti][0] = min((x+y) - (n+1) + 2, n);\n\t\t}\n\t\tans[ti][1] = x+y-1;\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\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;\n\t\tauto x = RD;\n\t\tauto y = RD;\n\n\t\tif (x + y < n + 1)\n\t\t{\n\t\t\tans[ti][0] = 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[ti][0] = (x+y) - (n+1) + 2;\n\t\t}\n\t\tans[ti][1] = x+y-1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0], \" \", e[1]);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "58c887568002d947706c448e6faa0f77"} {"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\nint N;\nlong H;\nlong[] A;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n H = readLong();\n A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n int lo = 0, hi = N + 1;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n auto a = A[0 .. mid].dup;\n a.sort;\n long sum;\n for (int i = mid - 1; i >= 0; i -= 2) {\n sum += a[i];\n }\n (sum <= H) ? (lo = mid) : (hi = mid);\n }\n writeln(lo);\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, h;\n\twhile (readf (\" %s %s\", &n, &h) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint res = 0;\n\t\twhile (res <= n)\n\t\t{\n\t\t\tauto b = a[0..res];\n\t\t\tsort (b);\n\t\t\tlong need = 0;\n\t\t\tfor (int i = res - 1; i >= 0; i -= 2)\n\t\t\t{\n\t\t\t\tneed += b[i];\n\t\t\t}\n\t\t\tdebug {writeln (res, \": \", b, \", \", need);}\n\t\t\tif (need > h)\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 - 1);\n\t}\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, h;\n rd(n, h);\n auto a = readln.split.to!(int[]);\n\n a ~= (h + 1);\n int[] b;\n foreach (k, el; a) {\n b ~= el;\n b.sort;\n b.reverse;\n int cur_h = 0;\n bool ok = true;\n foreach (i; 0 .. b.length) {\n if (cur_h + b[i] > h) {\n ok = false;\n break;\n }\n if (i & 1) {\n cur_h += max(b[i - 1], b[i]);\n }\n }\n if (!ok) {\n writeln(k);\n break;\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"}], "negative_code": [], "src_uid": "2ff0919ee7dfdfb916b23c26fb2caf20"} {"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint count=0;\n\tint[] m = new int[a];\n\tfor (int i=0; i 0; --total){\n\t\tint code;\n\t\treadf(\" %s\", &code);\n\t\tif(code != prevCode){\n\t\t\t++countIclends;\n\t\t\tprevCode = code;\n\t\t}\n\t}\n\twriteln(countIclends);\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\nint main(string[] argv)\n{\n\tint n;\n\tint pm;\n\tscanf(\"%d %d\", &n, &pm);\n\tint ng = 1;\n\tforeach (int i; 1..n)\n\t{\n\t\tint cm;\n\t\tscanf(\"%d\", &cm);\n\t\tif (pm != cm) ng++;\n\t\tpm = cm;\n\t}\n\tprintf(\"%d\", ng);\n\treturn 0;\n}\n\n"}, {"source_code": "module main;\n\nimport std.stdio;\nimport std.numeric;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main(string[] args)\n{\n\treadln;\n\tstring former = \"\";\n\tint answer = 0;\n\tforeach(string line; stdin.lines) {\n\t\tif (line != former)\n\t\t\tanswer++;\n\t\tformer = line;\n\t}\n\n\tanswer.writeln;\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 = readln.chomp.to!int;\n\n auto p = readln.chomp;\n\n int ans = 1;\n\n foreach(i ; 0 .. n - 1){\n auto magnet = readln.chomp;\n\n if (magnet != p) {\n ans++;\n }\n\n p = magnet;\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 writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n int n; readf(\"%d\", &n);\n string prev = \"\";\n int c = 0;\n for (int i = 0; i < n; i++) {\n string line; readf(\"%s\\n\", &line);\n if (line != prev) {\n //writef(line ~ \" \" ~ prev ~ \"\\n\");\n c++;\n prev = line;\n }\n }\n writef(\"%d\\n\", c);\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 = readln.chomp.to!int;\n\n auto p = readln.chomp;\n\n int ans = 1, value = 1;\n\n foreach(i ; 0 .. n - 1){\n auto magnet = readln.chomp;\n\n if (magnet == p) {\n value++;\n ans = max(ans, value);\n }\n else {\n value = 1;\n }\n\n p = magnet;\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 writeln(line);\n throw new Exception(\"args num < input num\");\n }\n}"}], "src_uid": "6c52df7ea24671102e4c0eee19dc6bba"} {"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\tlong x = a[$-1];\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint l = -1;\r\n\t\t\tforeach_reverse (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (a[i] != x)\r\n\t\t\t\t{\r\n\t\t\t\t\tl = i;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (l == -1) break;\r\n\t\t\tint len = n - l - 1;\r\n\t\t\tforeach (i; 0..len)\r\n\t\t\t{\r\n\t\t\t\tif (l - i < 0) break;\r\n\t\t\t\ta[l-i] = x;\r\n\t\t\t}\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": "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 int[] a = readln.strip.split(\" \").to!(int[]);\r\n int res = 0;\r\n while (a.uniq.array.length != 1)\r\n {\r\n // writeln(a);\r\n // writeln(\"len = \", a.uniq.array.length);\r\n int left_pad;\r\n int indx;\r\n for(int i = n - 1; i >= 0; i--)\r\n {\r\n if (a[i] == a[n-1])\r\n left_pad++;\r\n else\r\n {\r\n indx = i;\r\n break;\r\n }\r\n }\r\n if (indx - left_pad + 1 > 0)\r\n {\r\n // writeln(\"changing from\", indx - left_pad + 1, \" to \", indx + 1);\r\n a[indx - left_pad + 1 .. indx + 1] = a[n - 1];\r\n }\r\n else\r\n {\r\n a[0 .. indx + 1] = a[n - 1];\r\n }\r\n res++;\r\n }\r\n writeln(res);\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "dc10b869293df2b7a557262c805635ba"} {"source_code": "import std.stdio,std.string,std.algorithm;\n\nlong evalIt(ref string s,string sub){\n\tif(s.ptr==sub.ptr){\n\t\tauto l=sub.length;\n\t\tauto r=evalPlus(sub,null);\n\t\ts=s[l..$];\n\t\treturn r;\n\t}\n\tlong r=s[0]-'0';\n\ts=s[1..$];\n\treturn r;\n}\n\nlong evalMult(ref string s,string sub){\n\tlong cur=evalIt(s,sub);\n\twhile(s.length&&s[0]=='*'){\n\t\ts=s[1..$];\n\t\tcur*=evalIt(s,sub);\n\t}\n\treturn cur;\n}\n\nlong evalPlus(ref string s,string sub){\n\tlong cur=evalMult(s,sub);\n\twhile(s.length){\n\t\tassert(s[0]=='+');\n\t\ts=s[1..$];\n\t\tcur+=evalMult(s,sub);\n\t}\n\treturn cur;\n}\n\nvoid main(){\n\tstring it=readln.strip;\n\tstring ott=it;\n\tlong cand=evalPlus(ott,null);\n\tforeach(i;0..it.length){\n\t\tif(it[i]=='*'){\n\t\t\tforeach(j;i+2..it.length+1){\n\t\t\t\tif(j==it.length||it[j]=='+'||it[j]=='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[i+1..j]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach(j;0..i){\n\t\t\t\tif(it[j]!='+'&&it[j]!='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[j..i]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(cand);\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.ascii;\n\nlong factor(string s, ref int p) {\n if (s[p] == '(') {\n p++;\n long r = expr(s, p);\n assert(s[p] == ')');\n p++;\n return r;\n } else if ('0' <= s[p] && s[p] <= '9') {\n long r = s[p] - '0';\n p++;\n return r;\n } else {\n assert(false);\n }\n}\n\nlong term(string s, ref int p) {\n long r = factor(s, p);\n while (s[p] == '*') {\n p++;\n r *= factor(s, p);\n }\n return r;\n}\n\nlong expr(string s, ref int p) {\n long r = term(s, p);\n while (s[p] == '+') {\n p++;\n r += term(s, p);\n }\n return r;\n}\n\nvoid main() {\n string s = readln().strip();\n s = \"1*\" ~ s ~ \"*1$\";\n int n = cast(int)s.length;\n long ans = 0;\n foreach (i; 0..n) {\n if (s[i] == '*') {\n foreach (j; i+1..n) {\n if (s[j] == '*') {\n int p = 0;\n p = 0;\n ans = max(ans, expr(s[0..i+1] ~ \"(\" ~ s[i+1..j] ~ \")\" ~ s[j..$], p));\n }\n }\n }\n }\n writeln(ans);\n}\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.ascii;\n\nlong factor(string s, ref int p) {\n if (s[p] == '(') {\n p++;\n long r = expr(s, p);\n assert(s[p++] == ')');\n return r;\n } else if (s[p].isDigit()) {\n return s[p++] - '0';\n } else {\n assert(false);\n }\n}\n\nlong term(string s, ref int p) {\n long r = factor(s, p);\n while (s[p] == '*') {\n p++;\n r *= factor(s, p);\n }\n return r;\n}\n\nlong expr(string s, ref int p) {\n long r = term(s, p);\n while (s[p] == '+') {\n p++;\n r += term(s, p);\n }\n return r;\n}\n\nvoid main() {\n string s = readln().strip();\n s = \"1*\" ~ s ~ \"*1$\";\n int n = cast(int)s.length;\n long ans = 0;\n foreach (i; 0..n) {\n if (s[i] == '*') {\n foreach (j; i+1..n) {\n if (s[j] == '*') {\n int p = 0;\n ans = max(ans, expr(s[0..i+1] ~ \"(\" ~ s[i+1..j] ~ \")\" ~ s[j..$], p));\n }\n }\n }\n }\n writeln(ans);\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.ascii;\n\nlong factor(string s, ref int p) {\n if (s[p] == '(') {\n p++;\n long r = expr(s, p);\n assert(s[p++] == ')');\n return r;\n } else if ('0' <= s[p] && s[p] <= '9') {\n return s[p++] - '0';\n } else {\n assert(false);\n }\n}\n\nlong term(string s, ref int p) {\n long r = factor(s, p);\n while (s[p] == '*') {\n p++;\n r *= factor(s, p);\n }\n return r;\n}\n\nlong expr(string s, ref int p) {\n long r = term(s, p);\n while (s[p] == '+') {\n p++;\n r += term(s, p);\n }\n return r;\n}\n\nvoid main() {\n string s = readln().strip();\n s = \"1*\" ~ s ~ \"*1$\";\n int n = cast(int)s.length;\n long ans = 0;\n foreach (i; 0..n) {\n if (s[i] == '*') {\n foreach (j; i+1..n) {\n if (s[j] == '*') {\n int p = 0;\n ans = max(ans, expr(s[0..i+1] ~ \"(\" ~ s[i+1..j] ~ \")\" ~ s[j..$], p));\n }\n }\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio,std.string,std.algorithm;\n\nlong evalIt(ref string s,string sub){\n\tif(s.ptr==sub.ptr){\n\t\tauto l=sub.length;\n\t\tauto r=evalPlus(sub,null);\n\t\ts=s[l..$];\n\t\treturn r;\n\t}\n\tlong r=s[0]-'0';\n\ts=s[1..$];\n\treturn r;\n}\n\nlong evalMult(ref string s,string sub){\n\tlong cur=evalIt(s,sub);\n\twhile(s.length&&s[0]=='*'){\n\t\ts=s[1..$];\n\t\tcur*=evalIt(s,sub);\n\t}\n\treturn cur;\n}\n\nlong evalPlus(ref string s,string sub){\n\tlong cur=evalMult(s,sub);\n\twhile(s.length){\n\t\tassert(s[0]=='+');\n\t\ts=s[1..$];\n\t\tif(s.ptr==sub.ptr) cur+=evalIt(s,sub);\n\t\telse cur+=evalMult(s,sub);\n\t}\n\treturn cur;\n}\n\nvoid main(){\n\tstring it=readln.strip;\n\tstring ott=it;\n\tlong cand=evalPlus(ott,null);\n\tforeach(i;0..it.length){\n\t\tif(it[i]=='*'){\n\t\t\tforeach(j;i+1..it.length){\n\t\t\t\tif(it[j]=='+'||it[j]=='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[i+1..j]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach(j;0..i-1){\n\t\t\t\tif(it[j]!='+'&&it[j]!='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[j..i]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(cand);\n}\n"}, {"source_code": "import std.stdio,std.string,std.algorithm;\n\nlong evalIt(ref string s,string sub){\n\tif(s.ptr==sub.ptr){\n\t\tauto l=sub.length;\n\t\tauto r=evalPlus(sub,null);\n\t\ts=s[l..$];\n\t\treturn r;\n\t}\n\tlong r=s[0]-'0';\n\ts=s[1..$];\n\treturn r;\n}\n\nlong evalMult(ref string s,string sub){\n\tlong cur=evalIt(s,sub);\n\twhile(s.length&&s[0]=='*'){\n\t\ts=s[1..$];\n\t\tcur*=evalIt(s,sub);\n\t}\n\treturn cur;\n}\n\nlong evalPlus(ref string s,string sub){\n\tlong cur=evalMult(s,sub);\n\twhile(s.length){\n\t\tassert(s[0]=='+');\n\t\ts=s[1..$];\n\t\tif(s.ptr==sub.ptr) cur+=evalIt(s,sub);\n\t\telse cur+=evalMult(s,sub);\n\t}\n\treturn cur;\n}\n\nvoid main(){\n\tstring it=readln.strip;\n\tstring ott=it;\n\tlong cand=evalPlus(ott,null);\n\tforeach(i;0..it.length){\n\t\tif(it[i]=='*'){\n\t\t\tforeach(j;i+2..it.length){\n\t\t\t\tif(it[j]=='+'||it[j]=='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[i+1..j]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach(j;0..i-1){\n\t\t\t\tif(it[j]!='+'&&it[j]!='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[j..i]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(cand);\n}\n"}, {"source_code": "import std.stdio,std.string,std.algorithm;\n\nlong evalIt(ref string s,string sub){\n\tif(s.ptr==sub.ptr){\n\t\tauto l=sub.length;\n\t\tauto r=evalPlus(sub,null);\n\t\ts=s[l..$];\n\t\treturn r;\n\t}\n\tlong r=s[0]-'0';\n\ts=s[1..$];\n\treturn r;\n}\n\nlong evalMult(ref string s,string sub){\n\tlong cur=evalIt(s,sub);\n\twhile(s.length&&s[0]=='*'){\n\t\ts=s[1..$];\n\t\tcur*=evalIt(s,sub);\n\t}\n\treturn cur;\n}\n\nlong evalPlus(ref string s,string sub){\n\tlong cur=evalMult(s,sub);\n\twhile(s.length){\n\t\tassert(s[0]=='+');\n\t\ts=s[1..$];\n\t\tif(s.ptr==sub.ptr) cur+=evalIt(s,sub);\n\t\telse cur+=evalMult(s,sub);\n\t}\n\treturn cur;\n}\n\nvoid main(){\n\tstring it=readln.strip;\n\tstring ott=it;\n\tlong cand=evalPlus(ott,null);\n\tforeach(i;0..it.length){\n\t\tif(it[i]=='*'){\n\t\t\tforeach(j;i+2..it.length+1){\n\t\t\t\tif(j==it.length||it[j]=='+'||it[j]=='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[i+1..j]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach(j;0..i-1){\n\t\t\t\tif(it[j]!='+'&&it[j]!='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[j..i]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(cand);\n}\n"}, {"source_code": "import std.stdio,std.string,std.algorithm;\n\nlong evalIt(ref string s,string sub){\n\tif(s.ptr==sub.ptr){\n\t\tauto l=sub.length;\n\t\tauto r=evalPlus(sub,null);\n\t\ts=s[l..$];\n\t\treturn r;\n\t}\n\tlong r=s[0]-'0';\n\ts=s[1..$];\n\treturn r;\n}\n\nlong evalMult(ref string s,string sub){\n\tlong cur=evalIt(s,sub);\n\twhile(s.length&&s[0]=='*'){\n\t\ts=s[1..$];\n\t\tcur*=evalIt(s,sub);\n\t}\n\treturn cur;\n}\n\nlong evalPlus(ref string s,string sub){\n\tlong cur=evalMult(s,sub);\n\twhile(s.length){\n\t\tassert(s[0]=='+');\n\t\ts=s[1..$];\n\t\tif(s.ptr==sub.ptr) cur+=evalIt(s,sub);\n\t\telse cur+=evalMult(s,sub);\n\t}\n\treturn cur;\n}\n\nvoid main(){\n\tstring it=readln.strip;\n\tstring ott=it;\n\tlong cand=evalPlus(ott,null);\n\tforeach(i;0..it.length){\n\t\tif(it[i]=='*'){\n\t\t\tforeach(j;i+2..it.length+1){\n\t\t\t\tif(j==it.length||it[j]=='+'||it[j]=='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[i+1..j]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach(j;0..i){\n\t\t\t\tif(it[j]!='+'&&it[j]!='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[j..i]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(cand);\n}\n"}, {"source_code": "import std.stdio,std.string,std.algorithm;\n\nlong evalIt(ref string s,string sub){\n\tif(s.ptr==sub.ptr){\n\t\tauto l=sub.length;\n\t\tauto r=evalPlus(sub,null);\n\t\ts=s[l..$];\n\t\treturn r;\n\t}\n\tlong r=s[0]-'0';\n\ts=s[1..$];\n\treturn r;\n}\n\nlong evalMult(ref string s,string sub){\n\tlong cur=evalIt(s,sub);\n\twhile(s.length&&s[0]=='*'){\n\t\ts=s[1..$];\n\t\tcur*=evalIt(s,sub);\n\t}\n\treturn cur;\n}\n\nlong evalPlus(ref string s,string sub){\n\tlong cur=evalMult(s,sub);\n\twhile(s.length){\n\t\tassert(s[0]=='+');\n\t\ts=s[1..$];\n\t\tcur+=evalMult(s,sub);\n\t}\n\treturn cur;\n}\n\nvoid main(){\n\tstring it=readln.strip;\n\tstring ott=it;\n\tlong cand=evalPlus(ott,null);\n\tforeach(i;0..it.length){\n\t\tif(it[i]=='*'){\n\t\t\tforeach(j;i+1..it.length){\n\t\t\t\tif(it[j]=='+'||it[j]=='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[i+1..j]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach(j;0..i-1){\n\t\t\t\tif(it[j]!='+'&&it[j]!='*'){\n\t\t\t\t\tstring ot=it;\n\t\t\t\t\tcand=max(cand,evalPlus(ot,it[j..i]));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln(cand);\n}\n"}], "src_uid": "39dbd405be19c5a56c2b97b28e0edf06"} {"source_code": "import std.stdio;\nimport std.math;\n\nvoid main()\n{\n\tint n, t;\n\n\tscanf(\"%d%d\", &n, &t);\n\tprintf(\"%.10f\\n\", n * pow(1.000000011, t));\n}", "positive_code": [{"source_code": "import std.math;\nimport std.stdio;\n\nvoid main ()\n{\n\treal n, t;\n\twhile (readf (\" %s %s\", &n, &t) > 0)\n\t{\n\t\twritefln (\"%.20f\", n * 1.000000011L ^^ t);\n\t}\n}\n"}], "negative_code": [], "src_uid": "36ad784f23bd1e8e579052642a6e9244"} {"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 hh, mm;\n hh = cin.read_int;\n mm = cin.read_int;\n writeln((24 - hh - 1) * 60 + (60 - mm));\n } \n}", "positive_code": [{"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 writeln(60*(24-e[0]-1)+60-e[1]);\n }\n}\n\n//辞書順順列はiota(1,N),nextPermituionを使う\n\nenum INF = long.max/3;\nenum MOD = 10L^^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//最小を返す\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)mod(a-(1L< 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分解\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のn個上の親を返す\n //バグあるかも\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=0&&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=1&&b<=size);\n\n T vl=UNIT,vr=UNIT;\n for(long l=a+n,r=b+n;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\n{\n return v>=INF/2;\n}\n\nlong mod(long n, long mod) pure @nogc\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}\nlong powmod(long a, long n, long mod) {\n long 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 long value;\n\n this(ModInt!Mod v)\n {\n value = v.value;\n }\n this(long v)\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 opBinaryRight(string op, T)(inout T v) const\n if((op==\"^^\")&&isIntegral!T)\n {\n return typeof(this)(powmod(v, value, Mod));\n }\n ModInt!Mod opBinary(string op, T)(inout T v) const\n if((op==\"^^\")&&(is(T==ModInt!Mod)||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 assert(MInt(54) ^^ MInt(9) == 5);\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=0 &&\n y= 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//素因数分解\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//約数をすべて列挙\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までの素数のリスト\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 b.value\";\n auto st = tables.sort!\"a.size < b.size\";\n \n Table dummytab = Table(0, 0, false);\n foreach (g; groups) {\n dummytab.size = g.size;\n auto idx = st.lowerBound(dummytab).length;\n foreach (i; idx .. tables.length) {\n if (tables[i].taken == false) {\n tables[i].taken = true;\n m += 1;\n s += g.value;\n reqnum ~= g.index;\n tabnum ~= tables[i].index;\n break;\n }\n }\n }\n writeln(m, \" \", s);\n foreach (i; 0 .. reqnum.length) {\n writeln(reqnum[i], \" \", tabnum[i]);\n }\n\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.sorting;\nimport std.container.rbtree;\n\nstruct Group {\n int index;\n int size;\n int value;\n}\n\nstruct Table {\n int index;\n int size;\n bool taken;\n}\n\nint main(string[] args) {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n;\n readf(\" %s\\n\", &n);\n Group[] groups = new Group[n];\n foreach (i; 0 .. n) {\n readf(\" %s %s\\n\", &groups[i].size, &groups[i].value);\n groups[i].index = i + 1;\n }\n int k;\n readf(\" %s\\n\", &k);\n auto tableTree = new RedBlackTree!(Table, \"a.size < b.size\", true); \n //Table[] tables = new Table[k];\n foreach (i; 0 .. k) {\n Table t;\n readf(\" %s\", &t.size);\n t.index = i + 1;\n tableTree.insert(t);\n }\n\n int m = 0, s = 0;\n int[] reqnum;\n int[] tabnum;\n\n groups.sort!\"a.value > b.value\";\n \n Table t = Table(0, 0, false);\n foreach (g; groups) {\n t.size = g.size;\n t.taken = false;\n auto er = tableTree.equalRange(t);\n if (!er.empty) {\n t = er.front;\n t.taken = true;\n }\n else {\n auto ur = tableTree.upperBound(t);\n if(!ur.empty) {\n t = ur.front;\n t.taken = true;\n }\n }\n if (t.taken) {\n tableTree.removeKey(t);\n m += 1;\n s += g.value;\n reqnum ~= g.index;\n tabnum ~= t.index;\n }\n }\n\n writeln(m, \" \", s);\n foreach (i; 0 .. reqnum.length) {\n writeln(reqnum[i], \" \", tabnum[i]);\n }\n\n return 0;\n}\n"}], "negative_code": [], "src_uid": "ac4e4aca1146d7ad706c4ea12c90caf6"} {"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;\nstring[][] A;\nint[] P;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = new string[][](N, 2);\n\t\tforeach (i; 0 .. N) foreach (j; 0 .. 2) {\n\t\t\tA[i][j] = readToken;\n\t\t}\n\t\tP = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tP[i] = readInt - 1;\n\t\t}\n\t\t\n\t\tbool[][] dp = new bool[][](N + 1, 2);\n\t\tdp[1][] = true;\n\t\tforeach (i; 1 .. N) {\n\t\t\tforeach (j; 0 .. 2) if (dp[i][j]) {\n\t\t\t\tforeach (k; 0 .. 2) {\n\t\t\t\t\tif (A[P[i - 1]][j] <= A[P[i]][k]) {\n\t\t\t\t\t\tdp[i + 1][k] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln((dp[N][0] || dp[N][1]) ? \"YES\" : \"NO\");\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;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tstring [2] [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto s = readln ().split ();\n\t\t\tstring u = s.front.dup;\n\t\t\ts.popFront ();\n\t\t\tstring v = s.front.dup;\n\t\t\ta ~= [u, v];\n\t\t}\n\t\tdebug {writeln (a);}\n\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\tauto f = new bool [2] [n];\n\t\tf[0][0] = f[0][1] = true;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tf[i][0] = (f[i - 1][0] && a[p[i - 1]][0] < a[p[i]][0]) ||\n\t\t\t (f[i - 1][1] && a[p[i - 1]][1] < a[p[i]][0]);\n\t\t\tf[i][1] = (f[i - 1][0] && a[p[i - 1]][0] < a[p[i]][1]) ||\n\t\t\t (f[i - 1][1] && a[p[i - 1]][1] < a[p[i]][1]);\n\t\t}\n\t\twriteln ((f[n - 1][0] || f[n - 1][1]) ? \"YES\" : \"NO\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "a48ef749bf54d673772e09025ae806de"} {"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\nuint xrand() {\n static uint x = 314159265, y = 358979323, z = 846264338, w = 327950288;\n uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;\n}\n\nclass Tree {\n Tree l, r;\n int size;\n int val, ad;\n this(int val) {\n l = r = null;\n size = 1;\n this.val = val;\n this.ad = 0;\n }\n void propagate() {\n if (l) l.ad += ad;\n if (r) r.ad += ad;\n val += ad;\n ad = 0;\n }\n Tree change(Tree l, Tree r) {\n this.l = l;\n this.r = r;\n size = (l ? l.size : 0) + 1 + (r ? r.size : 0);\n return this;\n }\n}\nTree merge(Tree a, Tree b) {\n if (!a) return b;\n if (!b) return a;\n a.propagate();\n b.propagate();\n if (xrand() % (a.size + b.size) < a.size) {\n return a.change(a.l, merge(a.r, b));\n } else {\n return b.change(merge(a, b.l), b.r);\n }\n}\nTuple!(Tree, Tree) splitGE(Tree a, int key) {\n if (!a) return tuple!(Tree, Tree)(null, null);\n a.propagate();\n if (key <= a.val) {\n auto l = splitGE(a.l, key);\n return tuple(l[0], a.change(l[1], a.r));\n } else {\n auto r = splitGE(a.r, key);\n return tuple(a.change(a.l, r[0]), r[1]);\n }\n}\nTuple!(Tree, Tree) splitHead(Tree a) {\n assert(a);\n a.propagate();\n if (a.l) {\n auto l = splitHead(a.l);\n return tuple(l[0], a.change(l[1], a.r));\n } else {\n return tuple(a, a.r);\n }\n}\nstring toStr(Tree a) {\n if (!a) return \"\";\n return format(\"<%s (%s+%s) %s>\", toStr(a.l), a.val, a.ad, toStr(a.r));\n}\nint[] toSeq(Tree a, int ad = 0) {\n if (!a) return [];\n ad += a.ad;\n return toSeq(a.l, ad) ~ (a.val + ad) ~ toSeq(a.r, ad);\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = 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 \n debug {\n // O~(\\sum_i (R[i] - L[i] + 1))\n int[] lis;\n foreach (i; 0 .. N) {\n foreach_reverse (x; L[i] .. R[i] + 1) {\n const pos = lis.lowerBound(x);\n if (pos == lis.length) {\n lis ~= x;\n } else {\n lis[pos] = x;\n }\n }\n writeln(L[i], \" \", R[i], \" \", lis);\n }\n writeln(\"brute: \", lis.length);\n }\n \n Tree t = null;\n foreach (i; 0 .. N) {\n auto sp0 = t.splitGE(L[i]);\n auto sp1 = sp0[1].splitGE(R[i]);\n if (sp1[1]) {\n sp1[1] = sp1[1].splitHead[1];\n }\n if (sp1[0]) {\n sp1[0].ad += 1;\n }\n debug {\n writeln(\" \", sp0[0].toSeq, \" \", sp1[0].toSeq, \" \", sp1[1].toSeq);\n }\n t = sp0[0].merge(new Tree(L[i])).merge(sp1[0]).merge(sp1[1]);\n debug {\n writeln(L[i], \" \", R[i], \" \", t.toSeq, \" \", t.toStr);\n }\n }\n writeln(t.size);\n }\n } catch (EOFException e) {\n }\n}\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=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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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--------------------------\nMt19937 gen;\nclass item\n{\n\tint prior,key,add,cnt;\n\titem l,r;\n\tthis()\n\t{\n\t\tl=r=null;\n\t\tprior=uniform!int();\n\t\tcnt=1;\n\t}\n};\nvoid push(item t)\n{\n\tt.key+=t.add;\n\tif(t.l)t.l.add+=t.add;\n\tif(t.r)t.r.add+=t.add;\n\tt.add=0;\n}\nint cnt(item t){return t?t.cnt:0;}\nvoid upd(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\tdebug writeln(l !is null);\n\tdebug writeln(r is null);\n\tdebug stdout.flush;\n\tif(!l || !r){t=l?l:r;return;}\n\t//assert(false);\n\tif(l.prior>r.prior)\n\t{\n\t\tpush(l);\n\t\tmerge(l.r,l.r,r);\n\t\tt=l;\n\t}\n\telse\n\t{\n\t\tpush(r);\n\t\tmerge(r.l,l,r.l);\n\t\tt=r;\n\t}\n\tupd(t);\n}\nvoid split(item t,int val,ref item l,ref item r)\n{\n\tif(!t){l=r=null;return;}\n\tpush(t);\n\tif(t.key1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t//Random gen;\n\tclass item\n\t{\n\t\tint key,add,cnt;\n\t\tuint prior;\n\t\titem l,r;\n\t\tthis()\n\t\t{\n\t\t\tl=r=null;\n\t\t\tprior=uniform!uint;\n\t\t\tcnt=1;\n\t\t}\n\t};\n\tvoid push(item t)\n\t{\n\t\tt.key+=t.add;\n\t\tif(t.l)t.l.add+=t.add;\n\t\tif(t.r)t.r.add+=t.add;\n\t\tt.add=0;\n\t}\n\tint cnt(item t){return t?t.cnt:0;}\n\tvoid upd(item t)\n\t{\n\t\tt.cnt=cnt(t.l)+cnt(t.r)+1;\n\t}\n\tvoid merge(ref item t,item l,item r)\n\t{\n\t\tdebug writeln(l !is null);\n\t\tdebug writeln(r is null);\n\t\tdebug stdout.flush;\n\t\tif(!l || !r){t=l?l:r;return;}\n\t\t//assert(false);\n\t\tif(l.prior>r.prior)\n\t\t{\n\t\t\tpush(l);\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\tpush(r);\n\t\t\tmerge(r.l,l,r.l);\n\t\t\tt=r;\n\t\t}\n\t\tupd(t);\n\t}\n\tvoid split(item t,int val,ref item l,ref item r)\n\t{\n\t\tif(!t){l=r=null;return;}\n\t\tpush(t);\n\t\tif(t.key f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] 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\nint[][][] G;\n\nint[] vis;\nbool[][] viss;\n\nbool dfsTop(int u) {\n vis[u] = 1;\n foreach (i; G[0][u]) {\n const v = A[i] ^ B[i] ^ u;\n if (vis[v] == 0) {\n if (!dfsTop(v)) {\n return false;\n }\n } else if (vis[v] == 1) {\n return false;\n }\n }\n vis[u] = 2;\n return true;\n}\n\nvoid dfs(int s, int u) {\n viss[s][u] = true;\n foreach (i; G[s][u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!viss[s][v]) {\n dfs(s, v);\n }\n }\n}\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 G = new int[][][](2, N);\n foreach (i; 0 .. M) {\n G[0][A[i]] ~= i;\n G[1][B[i]] ~= i;\n }\n \n vis = new int[N];\n bool ok = true;\n foreach (u; 0 .. N) {\n if (vis[u] == 0) {\n if (!dfsTop(u)) {\n ok = false;\n }\n }\n }\n if (ok) {\n viss = new bool[][](2, N);\n int ansCnt;\n auto ans = new char[N];\n ans[] = 'E';\n foreach (u; 0 .. N) {\n if (!viss[0][u] && !viss[1][u]) {\n ++ansCnt;\n ans[u] = 'A';\n }\n foreach (s; 0 .. 2) {\n if (!viss[s][u]) {\n dfs(s, u);\n }\n }\n }\n writeln(ansCnt);\n writeln(ans);\n } else {\n writeln(-1);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.stdio;\nvoid main () {\n\tint n, m;\n\treadf !(\" %s %s\") (n, m);\n\tauto adj = new int [] [2] [n];\n\tforeach (j; 0..m) {\n\t\tint u, v;\n\t\treadf !(\" %s %s\") (u, v);\n\t\tu -= 1;\n\t\tv -= 1;\n\t\tadj[u][0] ~= v;\n\t\tadj[v][1] ~= u;\n\t}\n\n\tauto vis = new byte [2] [n], ok = true, res = \"\";\n\tvoid recur (int k, int v) {\n\t\tif (vis[v][k]) {\n\t\t\tok &= vis[v][k] > 1;\n\t\t\treturn;\n\t\t}\n\t\tvis[v][k] = 1;\n\t\tforeach (u; adj[v][k]) recur (k, u);\n\t\tvis[v][k] = 2;\n\t}\n\tforeach (i; 0..n) {\n\t\tres ~= \"AE\"[vis[i][].any];\n\t\trecur (0, i);\n\t\trecur (1, i);\n\t}\n\n\tif (ok) {\n\t\twriteln (res.count ('A'));\n\t\twriteln (res);\n\t}\n\telse writeln (-1);\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, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tauto fwd = new int [] [n];\n\t\tauto rev = 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\tfwd[u] ~= v;\n\t\t\trev[v] ~= u;\n\t\t}\n\n\t\tauto fwdVis = new byte [n];\n\t\tauto revVis = new byte [n];\n\t\tbool ok = true;\n\n\t\tvoid recur (ref int [] [] adj, ref byte [] vis, int v)\n\t\t{\n\t\t\tif (vis[v] > 0)\n\t\t\t{\n\t\t\t\tif (vis[v] == 1)\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvis[v] = 1;\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\trecur (adj, vis, u);\n\t\t\t}\n\t\t\tvis[v] = 2;\n\t\t}\n\n\t\tstring answer;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (!fwdVis[i] && !revVis[i])\n\t\t\t{\n\t\t\t\tanswer ~= 'A';\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tanswer ~= 'E';\n\t\t\t}\n\t\t\trecur (fwd, fwdVis, i);\n\t\t\trecur (rev, revVis, i);\n\t\t}\n\n\t\tif (ok)\n\t\t{\n\t\t\twriteln (answer.count ('A'));\n\t\t\twriteln (answer);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\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\nvoid main ()\n{\n\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tauto fwd = new int [] [n];\n\t\tauto rev = 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\tfwd[u] ~= v;\n\t\t\trev[v] ~= u;\n\t\t}\n\n\t\tauto fwdVis = new byte [n];\n\t\tauto revVis = new byte [n];\n\t\tbool ok = true;\n\n\t\tvoid recur (ref int [] [] adj, ref byte [] vis, int v)\n\t\t{\n\t\t\tif (vis[v] > 0)\n\t\t\t{\n\t\t\t\tif (vis[v] == 1)\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tvis[v] = 1;\n\t\t\tforeach (u; adj[v])\n\t\t\t{\n\t\t\t\trecur (adj, vis, u);\n\t\t\t}\n\t\t\tvis[v] = 2;\n\t\t}\n\n\t\tstring answer;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (!fwdVis[i] && !revVis[i])\n\t\t\t{\n\t\t\t\tanswer ~= 'A';\n\t\t\t\trecur (fwd, fwdVis, i);\n\t\t\t\trecur (rev, revVis, i);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tanswer ~= 'E';\n\t\t\t}\n\t\t}\n\n\t\tif (ok)\n\t\t{\n\t\t\twriteln (answer.count ('A'));\n\t\t\twriteln (answer);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\nvoid main () {\n\tint n, m;\n\treadf !(\" %s %s\") (n, m);\n\tauto adj = new int [] [] [] (2, n);\n\tforeach (j; 0..m) {\n\t\tint u, v;\n\t\treadf !(\" %s %s\") (u, v);\n\t\tu -= 1;\n\t\tv -= 1;\n\t\tadj[0][u] ~= v;\n\t\tadj[1][v] ~= u;\n\t}\n\n\tauto vis = new byte [] [] (2, n), ok = true, res = \"\";\n\tvoid recur (int k, int v) {\n\t\tif (vis[k][v]) {\n\t\t\tok &= vis[k][v] > 1;\n\t\t\treturn;\n\t\t}\n\t\tvis[k][v] = 1;\n\t\tforeach (u; adj[k][v]) recur (k, u);\n\t\tvis[k][v] = 2;\n\t}\n\tforeach (i; 0..n) {\n\t\tres ~= \"AE\"[vis[i].any];\n\t\trecur (0, i);\n\t\trecur (1, i);\n\t}\n\n\tif (ok) {\n\t\twriteln (res.count ('A'));\n\t\twriteln (res);\n\t}\n\telse writeln (-1);\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\nint[][][] G;\n\nint[] vis;\nbool[][] viss;\n\nbool dfsTop(int u) {\n vis[u] = 1;\n foreach (i; G[0][u]) {\n const v = A[i] ^ B[i] ^ u;\n if (vis[v] == 0) {\n if (!dfsTop(v)) {\n return false;\n }\n } else if (vis[v] == 1) {\n return false;\n }\n }\n vis[u] = 2;\n return true;\n}\n\nvoid dfs(int s, int u) {\n viss[s][u] = true;\n foreach (i; G[s][u]) {\n const v = A[i] ^ B[i] ^ u;\n if (!viss[s][v]) {\n dfs(s, v);\n }\n }\n}\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 G = new int[][][](2, N);\n foreach (i; 0 .. M) {\n G[0][A[i]] ~= i;\n G[1][B[i]] ~= i;\n }\n \n vis = new int[N];\n bool ok = true;\n foreach (u; 0 .. N) {\n if (vis[u] == 0) {\n if (!dfsTop(u)) {\n ok = false;\n }\n }\n }\n if (ok) {\n viss = new bool[][](2, N);\n auto ans = new char[N];\n ans[] = 'E';\n foreach (u; 0 .. N) {\n if (!viss[0][u] && !viss[1][u]) {\n ans[u] = 'A';\n }\n foreach (s; 0 .. 2) {\n if (!viss[s][u]) {\n dfs(s, u);\n }\n }\n }\n writeln(ans);\n } else {\n writeln(-1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "94e58f3f7aa4d860b95d34c7c9f89058"} {"source_code": "import core.stdc.stdio;\nimport std.algorithm;\nchar[505] s;\nint[505] c,q;\nint[505][505] dp;\nint n,m,k;\nint main()\n{\n\tscanf(\"%d%d%d\",&n,&m,&k);\n\tfor (int i=1;i<=n;i++)\n\t{\n\t\tscanf(\"%s\",&s);\n\t\tint len=0;\n\t\tfor (int j=0;j=0;l--) dp[i][j]=min(dp[i][j],dp[i-1][j-l]+q[len-l]);\n\t}\n\tprintf(\"%d\\n\",dp[n][k]);\n\treturn 0;\n}", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n \n int n, m, k; rd(n, m, k);\n auto a=new char[][](n, m);\n foreach(i; 0..n) a[i]=readln.chomp.to!(char[]);\n\n\n const int inf=1e9.to!(int);\n auto best=new int[][](n, k+1);\n foreach(i; 0..n){\n fill(best[i], inf);\n auto pos=new int[0];\n foreach(int j; 0..m)if(a[i][j]=='1') pos~=j;\n auto t=pos.length;\n if(t==0){fill(best[i], 0); continue;}\n foreach(l; 0..t)foreach(r; l..t)if(t-(r-l+1)<=k)\n chmin(best[i][t-(r-l+1)], pos[r]-pos[l]+1); \n if(t<=k) best[i][t]=0;\n }\n auto dp=new int[](k+1);\n fill(dp, inf);\n dp[k]=0;\n foreach(i; 0..n){\n auto nex=new int[](k+1);\n fill(nex, inf);\n for(int j=0; j<=k; j++)for(int l=0; l<=j; l++)\n chmin(nex[j-l], dp[j]+best[i][l]);\n dp.swap(nex);\n }\n writeln(reduce!(min)(dp));\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){\n e=l[i].to!(typeof(e));\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array;\n\nenum inf = 2*10^^9;\n\nvoid main() {\n int n, m, k;\n scan(n, m, k);\n\n auto dd = new int[][](n, 0);\n foreach (i ; 0 .. n) {\n auto s = readln.chomp;\n foreach (j, ch; s) {\n if (ch == '1') {\n dd[i] ~= j;\n }\n }\n }\n\n debug {\n writeln(dd);\n }\n\n auto ks = new int[][](n, k + 1);\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. k + 1) {\n if (j >= dd[i].length) {\n ks[i][j] = 0;\n }\n else {\n ks[i][j] = inf;\n\n int sp = dd[i].length.to!int - j;\n\n foreach (l ; 0 .. j + 1) {\n ks[i][j] = min(ks[i][j], dd[i][l + sp - 1] - dd[i][l] + 1);\n }\n }\n }\n }\n\n debug {\n writeln(ks);\n }\n\n auto dp = new int[][](n + 1, k + 1);\n fillAll(dp, inf);\n dp[0][0] = 0;\n\n foreach (i ; 1 .. n + 1) {\n foreach (j ; 0 .. k + 1) {\n foreach (l ; 0 .. j + 1) {\n dp[i][j] = min(dp[i][j], dp[i-1][l] + ks[i-1][j-l]);\n }\n }\n }\n\n int ans = dp[n][k];\n writeln(ans);\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;\n\nenum inf = 10000;\n\nvoid main() {\n int n, m, k;\n scan(n, m, k);\n\n auto dd = new int[][](n, 0);\n foreach (i ; 0 .. n) {\n auto s = readln.chomp;\n foreach (j, ch; s) {\n if (ch == '1') {\n dd[i] ~= j;\n }\n }\n }\n\n debug {\n writeln(dd);\n }\n\n auto ks = new int[][](n, k + 1);\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. k + 1) {\n if (j >= dd[i].length) {\n ks[i][j] = 0;\n }\n else {\n ks[i][j] = inf;\n\n int sp = dd[i].length.to!int - j;\n\n foreach (l ; 0 .. j + 1) {\n ks[i][j] = min(ks[i][j], dd[i][l + sp - 1] - dd[i][l] + 1);\n }\n }\n }\n }\n\n debug {\n writeln(ks);\n }\n\n auto dp = new int[][](n + 1, k + 1);\n fillAll(dp, inf);\n dp[0][0] = 0;\n\n foreach (i ; 1 .. n + 1) {\n foreach (j ; 0 .. k + 1) {\n foreach (l ; 0 .. j + 1) {\n dp[i][j] = min(dp[i][j], dp[i-1][l] + ks[i-1][j-l]);\n }\n }\n }\n\n int ans = dp[n][k];\n writeln(ans);\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"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n \n int n, m, k; rd(n, m, k);\n auto a=new char[][](n, m);\n foreach(i; 0..n) a[i]=readln.chomp.to!(char[]);\n\n\n const int inf=1e9.to!(int);\n auto best=new int[][](n, k+1);\n foreach(i; 0..n){\n fill(best[i], inf);\n auto pos=new int[0];\n foreach(int j; 0..m)if(a[i][j]=='1') pos~=j;\n auto t=pos.length;\n foreach(l; 0..t)foreach(r; l..t)if(t-(r-l+1)<=k)\n chmin(best[i][t-(r-l+1)], pos[r]-pos[l]+1); \n }\n auto dp=new int[](k+1);\n fill(dp, inf);\n dp[k]=0;\n foreach(i; 0..n){\n auto nex=new int[](k+1);\n fill(nex, inf);\n for(int j=0; j<=k; j++)for(int l=0; l<=j; l++)\n chmin(nex[j-l], dp[j]+best[i][l]);\n dp.swap(nex);\n }\n writeln(reduce!(min)(dp));\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){\n e=l[i].to!(typeof(e));\n }\n}\n"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n \n int n, m, k; rd(n, m, k);\n auto a=new char[][](n, m);\n foreach(i; 0..n) a[i]=readln.chomp.to!(char[]);\n\n\n const int inf=1e9.to!(int);\n auto best=new int[][](n, k+1);\n foreach(i; 0..n){\n fill(best[i], inf);\n auto pos=new int[0];\n foreach(int j; 0..m)if(a[i][j]=='1') pos~=j;\n auto t=pos.length;\n if(t==0){fill(best[i], 0); continue;}\n foreach(l; 0..t)foreach(r; l..t)if(t-(r-l+1)<=k)\n chmin(best[i][t-(r-l+1)], pos[r]-pos[l]+1); \n }\n auto dp=new int[](k+1);\n fill(dp, inf);\n dp[k]=0;\n foreach(i; 0..n){\n auto nex=new int[](k+1);\n fill(nex, inf);\n for(int j=0; j<=k; j++)for(int l=0; l<=j; l++)\n chmin(nex[j-l], dp[j]+best[i][l]);\n dp.swap(nex);\n }\n writeln(reduce!(min)(dp));\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){\n e=l[i].to!(typeof(e));\n }\n}\n"}], "src_uid": "cf5650c13ce0404d2df10fa3196d7923"} {"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 M = readInt();\n const N = readInt();\n const K = readInt();\n auto yoko = new int[][](M, N - 1);\n foreach (x; 0 .. M) foreach (y; 0 .. N - 1) {\n yoko[x][y] = readInt();\n }\n auto tate = new int[][](M - 1, N);\n foreach (x; 0 .. M - 1) foreach (y; 0 .. N) {\n tate[x][y] = readInt();\n }\n \n auto ans = new int[][](M, N);\n if (K % 2 == 0) {\n auto dp = new int[][][](K / 2 + 1, M, N);\n foreach (k; 1 .. K / 2 + 1) {\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n dp[k][x][y] = INF;\n }\n }\n foreach (k; 0 .. K / 2) {\n foreach (x; 0 .. M) foreach (y; 0 .. N - 1) {\n chmin(dp[k + 1][x][y + 1], dp[k][x][y] + yoko[x][y]);\n chmin(dp[k + 1][x][y], dp[k][x][y + 1] + yoko[x][y]);\n }\n foreach (x; 0 .. M - 1) foreach (y; 0 .. N) {\n chmin(dp[k + 1][x + 1][y], dp[k][x][y] + tate[x][y]);\n chmin(dp[k + 1][x][y], dp[k][x + 1][y] + tate[x][y]);\n }\n }\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n ans[x][y] = 2 * dp[K / 2][x][y];\n }\n } else {\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n ans[x][y] = -1;\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;\r\nimport std.conv;\r\nimport std.math;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nimmutable int infinity = int.max / 45;\r\n\r\nvoid main ()\r\n{\r\n\tint n, m, k;\r\n\twhile (readf !(\" %s %s %s\") (n, m, k) > 0)\r\n\t{\r\n\t\tauto a = new int [] [] (n * 2 - 1, m * 2 - 1);\r\n\t\tforeach (ref line; a)\r\n\t\t{\r\n\t\t\tline[] = infinity;\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..m - 1)\r\n\t\t\t{\r\n\t\t\t\treadf !(\" %s\") (a[i * 2][j * 2 + 1]);\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\treadf !(\" %s\") (a[i * 2 + 1][j * 2]);\r\n\t\t\t}\r\n\t\t}\r\n\t\tauto answer = new int [] [] [] (2, n, m);\r\n\t\tint z = 0;\r\n\r\n\t\tif (!(k & 1))\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..m)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[z][i][j] = 0;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tauto d = k / 2;\r\n\t\t\tfor (int step = 0; step < d; step++)\r\n\t\t\t{\r\n\t\t\t\tz ^= 1;\r\n\t\t\t\tforeach (i; 0..n)\r\n\t\t\t\t{\r\n\t\t\t\t\tforeach (j; 0..m)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tanswer[z][i][j] = infinity;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tforeach (i; 0..n)\r\n\t\t\t\t{\r\n\t\t\t\t\tforeach (j; 0..m)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (i - 1 >= 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tanswer[z][i][j] = min\r\n\t\t\t\t\t\t\t (answer[z][i][j],\r\n\t\t\t\t\t\t\t answer[!z][i - 1][j] +\r\n\t\t\t\t\t\t\t a[i * 2 - 1][j * 2]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (i + 1 < n)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tanswer[z][i][j] = min\r\n\t\t\t\t\t\t\t (answer[z][i][j],\r\n\t\t\t\t\t\t\t answer[!z][i + 1][j] +\r\n\t\t\t\t\t\t\t a[i * 2 + 1][j * 2]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (j - 1 >= 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tanswer[z][i][j] = min\r\n\t\t\t\t\t\t\t (answer[z][i][j],\r\n\t\t\t\t\t\t\t answer[!z][i][j - 1] +\r\n\t\t\t\t\t\t\t a[i * 2][j * 2 - 1]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (j + 1 < m)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tanswer[z][i][j] = min\r\n\t\t\t\t\t\t\t (answer[z][i][j],\r\n\t\t\t\t\t\t\t answer[!z][i][j + 1] +\r\n\t\t\t\t\t\t\t a[i * 2][j * 2 + 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\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[z][i][j] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[z][i][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\tanswer[z][i][j] *= 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%(%s %)\\n%)\") (answer[z]);\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 infinity = int.max / 2;\r\n\r\nvoid main ()\r\n{\r\n\tint n, m, k;\r\n\twhile (readf !(\" %s %s %s\") (n, m, k) > 0)\r\n\t{\r\n\t\tauto a = new int [] [] (n * 2 - 1, m * 2 - 1);\r\n\t\tforeach (ref line; a)\r\n\t\t{\r\n\t\t\tline[] = infinity;\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..m - 1)\r\n\t\t\t{\r\n\t\t\t\treadf !(\" %s\") (a[i * 2][j * 2 + 1]);\r\n\t\t\t\ta[i * 2][j * 2] = min (a[i * 2][j * 2],\r\n\t\t\t\t a[i * 2][j * 2 + 1]);\r\n\t\t\t\ta[i * 2][j * 2 + 2] = min (a[i * 2][j * 2 + 2],\r\n\t\t\t\t a[i * 2][j * 2 + 1]);\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\treadf !(\" %s\") (a[i * 2 + 1][j * 2]);\r\n\t\t\t\ta[i * 2][j * 2] = min (a[i * 2][j * 2],\r\n\t\t\t\t a[i * 2 + 1][j * 2]);\r\n\t\t\t\ta[i * 2 + 2][j * 2] = min (a[i * 2 + 2][j * 2],\r\n\t\t\t\t a[i * 2 + 1][j * 2]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto cur = new int [] [] (n, m);\r\n\t\tauto answer = new int [] [] (n, m);\r\n\t\tauto d = k / 2;\r\n\t\tif (!(k & 1))\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..m)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[i][j] = a[i * 2][j * 2] * d * 2;\r\n\t\t\t\t\tcur[i][j] = 0;\r\n\t\t\t\t\tforeach (e; 1..d + 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (i - e >= 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcur[i - e][j] =\r\n\t\t\t\t\t\t\t cur[i - e + 1][j] +\r\n\t\t\t\t\t\t\t a[(i - e) * 2 + 1][j * 2];\r\n\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t cur[i - e][j] +\r\n\t\t\t\t\t\t\t a[(i - e) * 2][j * 2] * (d - e));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (i + e < n)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcur[i + e][j] =\r\n\t\t\t\t\t\t\t cur[i + e - 1][j] +\r\n\t\t\t\t\t\t\t a[(i + e) * 2 - 1][j * 2];\r\n\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t cur[i + e][j] +\r\n\t\t\t\t\t\t\t a[(i + e) * 2][j * 2] * (d - e));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (j - e >= 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcur[i][j - e] =\r\n\t\t\t\t\t\t\t cur[i][j - e + 1] +\r\n\t\t\t\t\t\t\t a[i * 2][(j - e) * 2 + 1];\r\n\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t cur[i][j - e] +\r\n\t\t\t\t\t\t\t a[i * 2][(j - e) * 2] * (d - e));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (j + e < m)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcur[i][j + e] =\r\n\t\t\t\t\t\t\t cur[i][j + e - 1] +\r\n\t\t\t\t\t\t\t a[i * 2][(j + e) * 2 - 1];\r\n\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t cur[i][j + e] +\r\n\t\t\t\t\t\t\t a[i * 2][(j + e) * 2] * (d - e));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tforeach (f; 1..e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint g = e - f;\r\n\t\t\t\t\t\t\tif (i - f >= 0 && j - g >= 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcur[i - f][j - g] = min\r\n\t\t\t\t\t\t\t\t (cur[i - f + 1][j - g] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2 + 1][(j - g) * 2],\r\n\t\t\t\t\t\t\t\t cur[i - f][j - g + 1] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2][(j - g) * 2 + 1]);\r\n\t\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t\t cur[i - f][j - g] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2][(j - g) * 2] * (d - e));\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tif (i - f >= 0 && j + g < m)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcur[i - f][j + g] = min\r\n\t\t\t\t\t\t\t\t (cur[i - f + 1][j + g] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2 + 1][(j + g) * 2],\r\n\t\t\t\t\t\t\t\t cur[i - f][j + g - 1] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2][(j + g) * 2 - 1]);\r\n\t\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t\t cur[i - f][j + g] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2][(j + g) * 2] * (d - e));\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tif (i + f < n && j - g >= 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcur[i + f][j - g] = min\r\n\t\t\t\t\t\t\t\t (cur[i + f - 1][j - g] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2 - 1][(j - g) * 2],\r\n\t\t\t\t\t\t\t\t cur[i + f][j - g + 1] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2][(j - g) * 2 + 1]);\r\n\t\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t\t cur[i + f][j - g] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2][(j - g) * 2] * (d - e));\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tif (i + f < n && j + g < m)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcur[i + f][j + g] = min\r\n\t\t\t\t\t\t\t\t (cur[i + f - 1][j + g] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2 - 1][(j + g) * 2],\r\n\t\t\t\t\t\t\t\t cur[i + f][j + g - 1] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2][(j + g) * 2 - 1]);\r\n\t\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t\t cur[i + f][j + g] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2][(j + g) * 2] * (d - e));\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}\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\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] = -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\tanswer[i][j] *= 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%(%s %)\\n%)\") (answer);\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\nimmutable int infinity = int.max / 2;\r\n\r\nvoid main ()\r\n{\r\n\tint n, m, k;\r\n\twhile (readf !(\" %s %s %s\") (n, m, k) > 0)\r\n\t{\r\n\t\tauto a = new int [] [] (n * 2 - 1, m * 2 - 1);\r\n\t\tforeach (ref line; a)\r\n\t\t{\r\n\t\t\tline[] = infinity;\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..m - 1)\r\n\t\t\t{\r\n\t\t\t\treadf !(\" %s\") (a[i * 2][j * 2 + 1]);\r\n\t\t\t\ta[i * 2][j * 2] = min (a[i * 2][j * 2],\r\n\t\t\t\t a[i * 2][j * 2 + 1]);\r\n\t\t\t\ta[i * 2][j * 2 + 2] = min (a[i * 2][j * 2 + 2],\r\n\t\t\t\t a[i * 2][j * 2 + 1]);\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\treadf !(\" %s\") (a[i * 2 + 1][j * 2]);\r\n\t\t\t\ta[i * 2][j * 2] = min (a[i * 2][j * 2],\r\n\t\t\t\t a[i * 2 + 1][j * 2]);\r\n\t\t\t\ta[i * 2 + 2][j * 2] = min (a[i * 2 + 2][j * 2],\r\n\t\t\t\t a[i * 2 + 1][j * 2]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto cur = new int [] [] (n, m);\r\n\t\tauto answer = new int [] [] (n, m);\r\n\t\tauto d = k / 2;\r\n\t\tif (!(k & 1))\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..m)\r\n\t\t\t\t{\r\n\t\t\t\t\tanswer[i][j] = a[i * 2][j * 2] * d * 2;\r\n\t\t\t\t\tcur[i][j] = 0;\r\n\t\t\t\t\tforeach (e; 1..d + 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (i - e >= 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcur[i - e][j] =\r\n\t\t\t\t\t\t\t cur[i - e + 1][j] +\r\n\t\t\t\t\t\t\t a[(i - e) * 2 + 1][j * 2];\r\n\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t cur[i - e][j] +\r\n\t\t\t\t\t\t\t a[(i - e) * 2][j * 2] * (d - e));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (i + e < n)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcur[i + e][j] =\r\n\t\t\t\t\t\t\t cur[i + e - 1][j] +\r\n\t\t\t\t\t\t\t a[(i + e) * 2 - 1][j * 2];\r\n\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t cur[i + e][j] +\r\n\t\t\t\t\t\t\t a[(i + e) * 2][j * 2] * (d - e));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (j - e >= 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcur[i][j - e] =\r\n\t\t\t\t\t\t\t cur[i][j - e + 1] +\r\n\t\t\t\t\t\t\t a[i * 2][(j - e) * 2 + 1];\r\n\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t cur[i][j - e] +\r\n\t\t\t\t\t\t\t a[i * 2][(j - e) * 2] * (d - e));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (j + e < n)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tcur[i][j + e] =\r\n\t\t\t\t\t\t\t cur[i][j + e - 1] +\r\n\t\t\t\t\t\t\t a[i * 2][(j + e) * 2 - 1];\r\n\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t cur[i][j + e] +\r\n\t\t\t\t\t\t\t a[i * 2][(j + e) * 2] * (d - e));\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tforeach (f; 1..e)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tint g = e - f;\r\n\t\t\t\t\t\t\tif (i - f >= 0 && j - g >= 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcur[i - f][j - g] = min\r\n\t\t\t\t\t\t\t\t (cur[i - f + 1][j - g] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2 + 1][(j - g) * 2],\r\n\t\t\t\t\t\t\t\t cur[i - f][j - g + 1] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2][(j - g) * 2 + 1]);\r\n\t\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t\t cur[i - f][j - g] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2][(j - g) * 2] * (d - e));\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tif (i - f >= 0 && j + g < m)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcur[i - f][j + g] = min\r\n\t\t\t\t\t\t\t\t (cur[i - f + 1][j + g] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2 + 1][(j + g) * 2],\r\n\t\t\t\t\t\t\t\t cur[i - f][j + g - 1] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2][(j + g) * 2 - 1]);\r\n\t\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t\t cur[i - f][j + g] +\r\n\t\t\t\t\t\t\t\t a[(i - f) * 2][(j + g) * 2] * (d - e));\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tif (i + f < n && j - g >= 0)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcur[i + f][j - g] = min\r\n\t\t\t\t\t\t\t\t (cur[i + f - 1][j - g] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2 - 1][(j - g) * 2],\r\n\t\t\t\t\t\t\t\t cur[i + f][j - g + 1] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2][(j - g) * 2 + 1]);\r\n\t\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t\t cur[i + f][j - g] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2][(j - g) * 2] * (d - e));\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tif (i + f < n && j + g < m)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tcur[i + f][j + g] = min\r\n\t\t\t\t\t\t\t\t (cur[i + f - 1][j + g] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2 - 1][(j + g) * 2],\r\n\t\t\t\t\t\t\t\t cur[i + f][j + g - 1] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2][(j + g) * 2 - 1]);\r\n\t\t\t\t\t\t\t\tanswer[i][j] = min (answer[i][j],\r\n\t\t\t\t\t\t\t\t cur[i + f][j + g] +\r\n\t\t\t\t\t\t\t\t a[(i + f) * 2][(j + g) * 2] * (d - e));\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}\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\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] = -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\tanswer[i][j] *= 2;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\twritefln !(\"%(%(%s %)\\n%)\") (answer);\r\n\t}\r\n}\r\n"}], "src_uid": "7b13ee633c81abdcf912542ba1779a45"} {"source_code": "import std.algorithm, std.container, std.range, std.array, std.ascii, std.bigint, std.conv, std.format, std.math, std.random, std.stdio, std.string, std.typecons;\n\nvoid main() {\n int t;\n scanf(\"%d\", &t);\n \n while (t--) {\n int n;\n scanf(\"%d\", &n);\n \n auto arr = new long[][](n, 2);\n \n foreach (ref e; arr) scanf(\"%ld\", &e[0]);\n foreach (ref e; arr) scanf(\"%ld\", &e[1]);\n \n long low = 0, high = arr.fold!((r, x) => r + x[1])(0L);\n while (low < high) {\n auto m = (high + low) / 2;\n if (arr.filter!(a => a[0] > m).map!`a[1]`.sum <= m) {\n high = m;\n } else {\n low = m + 1;\n }\n }\n high.writeln;\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 long[](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\t\n\t\tauto index = a.MAKE_IDX();\n\t\tlong at, bt = b.sum;\n\t\tans[ti] = bt;\n\t\tforeach (i; index)\n\t\t{\n\t\t\tbt -= b[i];\n\t\t\tat.chmax(a[i]);\n\t\t\tans[ti].chmin(max(at, bt));\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.algorithm, std.container, std.range, std.array, std.ascii, std.bigint, std.conv, std.format, std.math, std.random, std.stdio, std.string, std.typecons;\n\nvoid main() {\n int t;\n scanf(\"%d\", &t);\n \n while (t--) {\n int n;\n scanf(\"%d\", &n);\n \n auto arr = new int[][](n, 2);\n \n foreach (ref e; arr) scanf(\"%d\", &e[0]);\n foreach (ref e; arr) scanf(\"%d\", &e[1]);\n \n long low = 0, high = arr.fold!((r, x) => r + x[1])(0L);\n while (low < high) {\n auto m = (high + low) / 2;\n if (arr.filter!(a => a[0] > m).map!`a[1]`.sum <= m) {\n high = m;\n } else {\n low = m + 1;\n }\n }\n high.writeln;\n }\n}\n"}], "src_uid": "254cb444b9bdfa5e177adad23b7e814a"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 x = RD;\n\t\tauto a = RDA;\n\t\ta.sort!\"a > b\"();\n\t\tlong s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts += a[i];\n\t\t\tif (s < x*(i+1)) break;\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}", "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\nint solve() {\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 A.sort!\"a > b\";\n\n long sm = 0;\n\n foreach (i; 0..N) {\n sm += A[i];\n if (sm < (i + 1) * M) return i;\n }\n\n return N;\n}\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) writeln(solve);\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, x;\n\t\treadf !(\" %s %s\") (n, x);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tlong cur = 0;\n\t\tint res = 0;\n\t\tforeach_reverse (i, c; a)\n\t\t{\n\t\t\tcur += c;\n\t\t\tif (cur >= (n - i) * 1L * x)\n\t\t\t{\n\t\t\t\tres = n - i;\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\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 long x = r.next!uint;\n auto a = r.nextA!uint(n);\n sort (a);\n int res;\n long s;\n debug stderr.writeln (a);\n foreach_reverse (z; a) {\n s += z;\n debug stderr.writefln (\"s = %d, res = %d, x = %d\", s, res, x);\n if (s < x * (res+1)) break;\n ++res;\n }\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\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 x = RD!int;\n\t\tauto a = RDA;\n\t\ta.sort!\"a > b\"();\n\t\tlong s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts += a[i];\n\t\t\tif (s < x*(i+1)) break;\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}"}], "src_uid": "51f922bb2c51f50b5c3b55725dd7766e"} {"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 Tuple!(long, long)[200_000] pointsBucket;\n long[200_000] pointCountBucket;\n auto nt = next!int;\n foreach(tc; 0 .. nt)\n {\n auto n = next!long;\n auto k = next!long;\n auto points = pointsBucket[0 .. cast(size_t) n];\n foreach(i; 0 .. cast(size_t)n)\n points[i][0] = next!long;\n foreach(i; 0 .. cast(size_t)n)\n points[i][1] = next!long;\n auto spoints = sort(points);\n long countInRange(long lx, long hx)\n {\n return spoints.upperBound(tuple(lx, long.min)).lowerBound(tuple(hx, long.max)).length;\n }\n auto pointCount = pointCountBucket[0 .. cast(size_t)n];\n foreach(i; 0 .. cast(size_t)n)\n pointCount[i] = countInRange(points[i][0] - k, points[i][0]);\n int lowindex = 0;\n int maxbelow = 0;\n int curr = 0;\n int best = 0;\n while(curr < n)\n {\n int localbest = cast(int) pointCount[curr];\n while(lowindex < n && points[lowindex][0] < points[curr][0] - k)\n {\n maxbelow = cast(int) max(maxbelow, pointCount[lowindex]);\n lowindex++;\n }\n localbest += maxbelow;\n best = max(localbest, best);\n curr++;\n }\n writeln(best);\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\n\n/* Things which don't work on D: \n 1. import std gives TLE so it has to be expanded to std.algorithm, std.stdio...\n 2. Array Indicing ONLY typecasts integers (UNLESS 64 bit system in which case long) so EITHER cast to INT or SIZE_T\n*/\n\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid printer(T)(T range) { for(int i = 0; i < range.length; ++i){ write(' ', range[i]); } writeln(); }\nalias ll = long;\nsize_t sz(long t){ return to!size_t(t); }\n\nvoid play(){\n int n; ll k;\n readf(\" %s %s \", &n, &k);\n auto xc = new ll [] (n);\n foreach(i; 0 .. n){\n readf(\"%s \", xc[i]);\n }\n readln;\n auto xcr = sort(xc);\n /* xc = assumeSorted(xc); */\n ll[] cover, tills;\n foreach(i; 0 .. n){\n auto till = n - xcr.upperBound(xc[i]+k).length;\n tills ~= till;\n cover ~= till - i;\n }\n ll[] maxleft;\n // Deep Copy (HOW TO MAKE IT WORK!)\n maxleft ~= cover;\n for(int j = n - 2; j >= 0; --j){\n maxleft[j] = max(maxleft[j+1], cover[j]);\n }\n for(auto i = 0; i < n; ++i){\n if(tills[i] < n){\n cover[i] += maxleft[sz(tills[i])];\n }\n }\n writeln(cover.maxElement());\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"}], "negative_code": [], "src_uid": "ae4378fbdb863ed6c30aae5d22851531"} {"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 foreach (u; 0 .. N) {\n A[u] = readInt() - 1;\n }\n \n auto indeg = new int[N];\n foreach (u; 0 .. N) {\n ++indeg[A[u]];\n }\n \n auto cyc = new bool[N];\n auto vis = new int[N];\n vis[] = -1;\n foreach (u; 0 .. N) {\n if (!~vis[u]) {\n int v;\n for (v = u; !~vis[v]; v = A[v]) {\n vis[v] = u;\n }\n if (vis[v] == u) {\n for (int w = v; ; ) {\n cyc[w] = true;\n w = A[w];\n if (w == v) {\n break;\n }\n }\n }\n }\n }\n debug {\n writeln(\"cyc = \", cyc);\n }\n \n auto to = A.dup;\n foreach (u; 0 .. N) {\n if (cyc[u]) {\n if (indeg[A[u]] > 1) {\n --indeg[A[u]];\n to[u] = -1;\n }\n }\n }\n foreach (u; 0 .. N) {\n if (!cyc[u]) {\n if (indeg[A[u]] > 1) {\n --indeg[A[u]];\n to[u] = -1;\n }\n }\n }\n \n int[] us;\n foreach (u; 0 .. N) {\n if (indeg[u] == 0) {\n for (int v = u; ~v; v = to[v]) {\n us ~= v;\n }\n }\n }\n const usLen = cast(int)(us.length);\n foreach (j; 0 .. usLen) {\n to[us[j]] = us[(j + 1) % usLen];\n }\n \n int ans;\n foreach (u; 0 .. N) {\n if (A[u] == to[u]) {\n ++ans;\n }\n }\n writeln(ans);\n foreach (u; 0 .. N) {\n if (u > 0) write(\" \");\n write(to[u] + 1);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\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, 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 rndGen.seed(19260817);\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;\r\n a[] -= 1;\r\n auto w = new bool[n];\r\n foreach(c; a) w[c] = true;\r\n auto b = new int[n];\r\n b[] -= 1;\r\n auto vis = new bool[n];\r\n foreach(v; 0 .. 2) {\r\n foreach(i, c; a){\r\n if (w[i] == v) {\r\n if (!vis[c]) {\r\n b[i] = c;\r\n vis[c] = true;\r\n }\r\n }\r\n }\r\n }\r\n auto c = n.iota.filter!(i => b[i] == -1).array;\r\n auto d = n.iota.filter!(i => !vis[i]).array;\r\n int k = c.length.to!(int);\r\n while (true) {\r\n d.randomShuffle;\r\n if (k.iota.all!(j => c[j] != d[j])) break;\r\n }\r\n foreach(j; 0 .. k) {\r\n b[c[j]] = d[j];\r\n }\r\n n.iota.map!(i => a[i] == b[i]).sum.writeln;\r\n writefln!\"%(%s %)\"(b.map!(q{a + 1}));\r\n }\r\n\r\n} // main\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\trndGen.seed (125626);\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\r\n\t\tauto wanted = new bool [n];\r\n\t\tforeach (ref cur; a)\r\n\t\t{\r\n\t\t\twanted[cur] = true;\r\n\t\t}\r\n\r\n\t\tauto b = new int [n];\r\n\t\tb[] = -1;\r\n\t\tauto vis = new bool [n];\r\n\t\tforeach (value; 0..2)\r\n\t\t{\r\n\t\t\tforeach (i, ref cur; a)\r\n\t\t\t{\r\n\t\t\t\tif (wanted[i] == value)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (!vis[cur])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tb[i] = cur;\r\n\t\t\t\t\t\tvis[cur] = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto c = n.iota.filter !(i => b[i] == -1).array;\r\n\t\tauto d = n.iota.filter !(i => !vis[i]).array;\r\n\t\tauto k = c.length.to !(int);\r\n\t\tif (k == 1 && c.front == d.front)\r\n\t\t{\r\n\t\t\tassert (false);\r\n\t\t}\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\trandomShuffle (d);\r\n\t\t\tif (k.iota.all !(j => c[j] != d[j]))\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\tforeach (j; 0..k)\r\n\t\t{\r\n\t\t\tb[c[j]] = d[j];\r\n\t\t}\r\n\r\n\t\twriteln (n.iota.map !(i => a[i] == b[i]).sum);\r\n\t\twritefln !(\"%(%s %)\") (b.map !(q{a + 1}));\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\nint[] inv(int[] a)\n{\n auto b = new int[](a.length);\n foreach (i, x ; a) {\n b[x] = cast(int)i;\n }\n return b;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(x => x.to!int - 1).array;\n int[][int] freq;\n bool[int] used;\n foreach (i, x ; a) {\n if (!(x in freq))\n freq[x] = new int[](0);\n freq[x] ~= cast(int)i;\n }\n int[] result = new int[](n);\n result[] = -1;\n foreach (i, gifters ; freq) {\n foreach(gifter ; gifters) {\n if (gifter in used)\n continue;\n if (!(gifter in freq)) {\n result[i] = gifter;\n used[gifter] = true;\n break;\n }\n }\n if (result[i] == -1) {\n foreach(gifter ; gifters) {\n if (gifter in used)\n continue;\n result[i] = gifter;\n used[gifter] = true;\n break;\n }\n }\n }\n int[] avail;\n foreach (i ; 0 .. n) {\n if (!(i in used))\n avail ~= i;\n }\n int[] slots;\n foreach (i, x ; result) {\n if (x == -1)\n slots ~= cast(int)i;\n }\n\n if (slots.length == 1 && slots[0] == avail[0]) {\n foreach (i, x ; result) {\n if (x != -1) {\n avail ~= result[i];\n result[i] = -1;\n slots ~= cast(int)i;\n break;\n }\n }\n }\n\n assert(avail.length == slots.length);\n\n while (true) {\n bool good = true;\n foreach (i ; 0 .. avail.length) {\n if (avail[i] == slots[i]) {\n good = false;\n break;\n }\n }\n if (good)\n break;\n avail.randomShuffle;\n }\n\n foreach (i ; 0 .. avail.length) {\n result[slots[i]] = avail[i];\n }\n\n writeln(n - cast(int)slots.length);\n writeln(inv(result).map!(x => x + 1).map!text.joiner(\" \"));\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;\n\twhile (t--) solve;\n}\n\nvoid solve()\n{\n\tint n = readInt!int;\n\tauto a = new int[](n);\n\tauto b = new int[](n);\n\tb[] = -1;\n\tauto inds = new int[][](n);\n\tforeach(i, ref ai; a)\n\t{\n\t\tai = readInt!int - 1;\n\t\tinds[ai] ~= cast(int)i;\n\t}\n\tint[] toGive;\n\tint good = 0;\n\tforeach(i, ind; inds) \n\t{\n\t\tif (ind.length > 0) \n\t\t{\n\t\t\tb[ind[0]] = a[ind[0]];\n\t\t\tassert(a[ind[0]] == cast(int)i);\n\t\t\tgood++;\n\t\t}\n\t\telse toGive ~= cast(int)i;\n\t}\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (b[i] == -1) { b[i] = toGive[0]; toGive = toGive[1 .. $]; }\n\t}\n\tint[] inc;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (b[i] == i) inc ~= cast(int) i;\n\t}\n\tgood.writeln;\n\tif (inc.length == 0)\n\t{\n\t\tb[] += 1;\n\t\tb.each!(bi => bi.write(\" \")); writeln;\n\t}\n\telse if (inc.length == 1)\n\t{\n\t\tauto i = inc[0];\n\t\tint o = -1;\n\t\tforeach(j; 0 .. n) if (j != i && a[j] == a[i] && b[j] == a[j])\n\t\t{\n\t\t\tswap(b[i], b[j]);\n\t\t\tbreak;\n\t\t}\n\t\tb[] += 1;\n\t\tb.each!(bi => bi.write(\" \")); writeln;\n\t}\n\telse\n\t{\n\t\tint toput = 1;\n\t\tforeach(i; 0 .. n)\n\t\t{\n\t\t\tif (b[i] == i)\n\t\t\t{\n\t\t\t\tb[i] = inc[toput];\n\t\t\t\ttoput++;\n\t\t\t\tif (toput == inc.length) toput = 0;\n\t\t\t}\n\t\t}\n\t\tb[] += 1;\n\t\tb.each!(bi => bi.write(\" \")); 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.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\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 \r\n auto arr = list!int;\r\n \r\n auto received = new bool[n];\r\n auto answer = new int[n];\r\n int[int] who;\r\n \r\n int k = 0;\r\n \r\n foreach (int i, e; arr) {\r\n if (!received[e - 1]) {\r\n received[e - 1] = true;\r\n answer[i] = e;\r\n who[e] = i;\r\n k++;\r\n }\r\n }\r\n \r\n writeln(k);\r\n \r\n auto rem = new DList!int;\r\n foreach (int i; 0 .. n) {\r\n if (!received[i]) {\r\n rem.insertBack(i);\r\n }\r\n }\r\n \r\n foreach (int i, e; arr) {\r\n if (answer[i] != 0) continue;\r\n \r\n if (rem.front == i) {\r\n rem.insertBack(rem.front);\r\n rem.removeFront();\r\n \r\n if (rem.front == i) {\r\n rem.removeFront();\r\n rem.insertBack(arr[i] - 1);\r\n answer[who[arr[i]]] = i + 1;\r\n }\r\n }\r\n \r\n answer[i] = rem.front + 1;\r\n who[rem.front + 1] = i;\r\n rem.removeFront();\r\n }\r\n \r\n writefln!\"%(%d %)\"(answer);\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\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\tauto cnt = 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(-1);\r\n\r\n\t\tauto b = new bool[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tb[a[i]] = true;\r\n\t\t}\r\n\t\tans[ti].length = n;\r\n\r\n\t\tint[] arr;\r\n\t\tauto used = new bool[](n);\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (b[i])\r\n\t\t\t\t++cnt[ti];\r\n\t\t\telse\r\n\t\t\t\tarr ~= i;\r\n\t\t}\r\n\t\tvoid f(int i)\r\n\t\t{\r\n\t\t\tint x;\r\n\t\t\tif (used[a[i]])\r\n\t\t\t{\r\n\t\t\t\tif (arr[0] != i)\r\n\t\t\t\t{\r\n\t\t\t\t\tx = arr[0];\r\n\t\t\t\t\tarr.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\tx = arr[1];\r\n\t\t\t\t\tarr ~= arr.front;\r\n\t\t\t\t\tarr = arr[2..$];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tx = a[i];\r\n\t\t\tans[ti][i] = x+1;\r\n\t\t\tused[x] = true;\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!b[i])\r\n\t\t\t\tf(i);\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (b[i])\r\n\t\t\t\tf(i);\r\n\t\t}\r\n\t}\r\n\r\n\tforeach (ti, e; ans)\r\n\t{\r\n\t\twriteln(cnt[ti]);\r\n\t\tans[ti].map!(to!string).join(\" \").writeln;\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\nint[] inv(int[] a)\n{\n auto b = new int[](a.length);\n foreach (i, x ; a) {\n b[x] = cast(int)i;\n }\n return b;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(x => x.to!int - 1).array;\n int[][int] freq;\n bool[int] used;\n foreach (i, x ; a)\n freq[x] = freq.get(x, new int[](0)) ~ [cast(int)i];\n int[] result = new int[](n);\n result[] = -1;\n foreach (i, gifters ; freq) {\n foreach(gifter ; gifters) {\n if (gifter in used)\n continue;\n if (!(gifter in freq)) {\n result[i] = gifter;\n used[gifter] = true;\n break;\n }\n }\n if (result[i] == -1) {\n foreach(gifter ; gifters) {\n if (gifter in used)\n continue;\n result[i] = gifter;\n used[gifter] = true;\n break;\n }\n }\n }\n bool[int] avail;\n foreach (i ; 0 .. n) {\n if (!(i in used))\n avail[i] = true;\n }\n int[] slots;\n foreach (i, x ; result) {\n if (x == -1)\n slots ~= cast(int)i;\n }\n\n if (slots.length == 1 && slots[0] in avail) {\n foreach (i, x ; result) {\n if (x != -1) {\n avail[result[i]] = true;\n result[i] = -1;\n slots ~= cast(int)i;\n break;\n }\n }\n }\n\n foreach (slot ; slots) {\n foreach (k, v ; avail) {\n if (k != slot) {\n result[slot] = k;\n avail.remove(k);\n break;\n }\n }\n }\n writeln(n - cast(int)slots.length);\n writeln(inv(result).map!(x => x + 1).map!text.joiner(\" \"));\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;\n\twhile (t--) solve;\n}\n\nvoid solve()\n{\n\tint n = readInt!int;\n\tauto a = new int[](n);\n\tauto b = new int[](n);\n\tb[] = -1;\n\tauto inds = new int[][](n);\n\tforeach(i, ref ai; a)\n\t{\n\t\tai = readInt!int - 1;\n\t\tinds[ai] ~= cast(int)i;\n\t}\n\tint[] toGive;\n\tint good = 0;\n\tforeach(i, ind; inds) \n\t{\n\t\tif (ind.length > 0) \n\t\t{\n\t\t\tb[ind[0]] = a[ind[0]];\n\t\t\tassert(a[ind[0]] == cast(int)i);\n\t\t\tgood++;\n\t\t}\n\t\telse toGive ~= cast(int)i;\n\t}\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (b[i] == -1) { b[i] = toGive[0]; toGive = toGive[1 .. $]; }\n\t}\n\tint[] inc;\n\tforeach(i; 0 .. n)\n\t{\n\t\tif (b[i] == i) inc ~= cast(int) i;\n\t}\n\tgood.writeln;\n\tif (inc.length == 0)\n\t{\n\t\tb[] += 1;\n\t\tb.each!(bi => bi.write(\" \")); writeln;\n\t}\n\telse if (inc.length == 1)\n\t{\n\t\tauto i = inc[0];\n\t\tint o = -1;\n\t\tforeach(j; 0 .. n) if (j != i && a[j] == a[i] && b[j] == a[j])\n\t\t{\n\t\t\tswap(b[i], b[j]);\n\t\t\tbreak;\n\t\t}\n\t\tb[] += 1;\n\t\tb.each!(bi => bi.write(\" \")); writeln;\n\t}\n\telse\n\t{\n\t\tforeach(i; 0 .. n)\n\t\t{\n\t\t\tif (b[i] == i)\n\t\t\t{\n\t\t\t\tb[i] = inc[(i + 1)%(cast(int)inc.length)];\n\t\t\t}\n\t\t}\n\t\tb[] += 1;\n\t\tb.each!(bi => bi.write(\" \")); 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.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\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 \r\n auto arr = list!int;\r\n \r\n auto received = new bool[n];\r\n auto answer = new int[n];\r\n int[int] who;\r\n \r\n foreach (int i, e; arr) {\r\n if (!received[e - 1]) {\r\n received[e - 1] = true;\r\n answer[i] = e;\r\n who[e] = i;\r\n }\r\n }\r\n \r\n auto rem = new DList!int;\r\n foreach (int i; 0 .. n) {\r\n if (!received[i]) {\r\n rem.insertBack(i);\r\n }\r\n }\r\n \r\n foreach (int i, e; arr) {\r\n if (answer[i] != 0) continue;\r\n \r\n if (rem.front == i) {\r\n rem.insertBack(rem.front);\r\n rem.removeFront();\r\n \r\n if (rem.front == i) {\r\n rem.removeFront();\r\n rem.insertBack(arr[i] - 1);\r\n answer[who[arr[i]]] = i + 1;\r\n }\r\n }\r\n \r\n answer[i] = rem.front + 1;\r\n who[rem.front + 1] = i;\r\n rem.removeFront();\r\n }\r\n \r\n writefln!\"%(%d %)\"(answer);\r\n }\r\n}\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 foreach (u; 0 .. N) {\n A[u] = readInt() - 1;\n }\n \n auto indeg = new int[N];\n foreach (u; 0 .. N) {\n ++indeg[A[u]];\n }\n \n auto cyc = new bool[N];\n auto vis = new int[N];\n vis[] = -1;\n foreach (u; 0 .. N) {\n if (!~vis[u]) {\n int v;\n for (v = u; !~vis[v]; v = A[v]) {\n vis[v] = u;\n }\n if (vis[v] == u) {\n for (int w = v; ; ) {\n cyc[w] = true;\n w = A[w];\n if (w == v) {\n break;\n }\n }\n }\n }\n }\n debug {\n writeln(\"cyc = \", cyc);\n }\n \n auto to = A.dup;\n foreach (u; 0 .. N) {\n if (cyc[u]) {\n if (indeg[A[u]] > 1) {\n --indeg[A[u]];\n to[u] = -1;\n }\n }\n }\n foreach (u; 0 .. N) {\n if (indeg[A[u]] > 1) {\n --indeg[A[u]];\n to[u] = -1;\n }\n }\n \n int[] us;\n foreach (u; 0 .. N) {\n if (indeg[u] == 0) {\n for (int v = u; ~v; v = to[v]) {\n us ~= v;\n }\n }\n }\n const usLen = cast(int)(us.length);\n foreach (j; 0 .. usLen) {\n to[us[j]] = us[(j + 1) % usLen];\n }\n \n int ans;\n foreach (u; 0 .. N) {\n if (A[u] == to[u]) {\n ++ans;\n }\n }\n writeln(ans);\n foreach (u; 0 .. N) {\n if (u > 0) write(\" \");\n write(to[u] + 1);\n }\n writeln;\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "89687dcbf37fc776b508252ddac8e8d4"} {"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 q;\n readf(\"%s\", &q);\n readln;\n \n while (q--) {\n int b, w;\n readf(\"%s %s\", &b, &w);\n readln;\n \n Tuple!(int, int)[] ans;\n if (b == w) {\n foreach (i; 0 .. b) {\n ans ~= tuple(1, 2*i + 1);\n ans ~= tuple(1, 2*i + 2);\n }\n } else {\n \n int start = 2;\n if (b > w) {\n swap(b, w);\n start = 3;\n }\n \n ans ~= tuple(2, start);\n w -= 1;\n \n int reach = 0;\n int cur = start+1;\n while (b > 0) {\n b -= 1;\n ans ~= tuple(2, cur);\n cur += 1;\n\n w -= 1;\n ans ~= tuple(2, cur);\n cur += 1;\n\n reach += 2;\n }\n \n if (reach < w) {\n writeln(\"NO\");\n continue;\n }\n \n foreach (pos; cur.iota.drop(1 + start).stride(2)) {\n foreach (rw; [1, 3]) {\n if (w == 0) { break; }\n \n ans ~= tuple(rw, pos);\n w -= 1;\n }\n }\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n }\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nint[2][200005] ans;\n\nvoid solve() {\n int b, w;\n readf(\" %s %s\", b, w);\n int x = min(b, w);\n int y = max(b, w);\n int maxY = x * 4 - (x - 1);\n if (y > maxY) {\n writeln(\"NO\");\n return;\n }\n int k = 0;\n foreach(i; 0..(x*2-1)) {\n ans[k][0] = 2;\n ans[k][1] = 2 + i;\n k++;\n }\n foreach(j; [1, 3]) {\n for (int i = 0; i < x && k < (b+w); i++) {\n ans[k][0] = j;\n ans[k][1] = 2 + (i*2);\n k++;\n }\n }\n if (k < b + w) {\n ans[k][0] = 2;\n ans[k][1] = 1;\n k++;\n }\n if (k < b + w) {\n ans[k][0] = 2;\n ans[k][1] = 2 + ((x - 1) * 2) + 1;\n k++;\n }\n\n writeln(\"YES\");\n int shift = (x == w) ? 0 : 1;\n foreach(a; ans[0..k]) {\n writeln(a[0]+shift, \" \", a[1]);\n }\n}\n\nvoid main() {\n int q;\n readf(\" %s\", q);\n foreach(_; 0..q) {\n solve();\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 q = RD!int;\n\tauto ans = new long[2][][](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto b = RD;\n\t\tauto w = RD;\n\t\tif (max(b, w)-1 > min(b, w)*3)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\tlong x, y;\n\t\tif (b > w)\n\t\t{\n\t\t\tx = 2;\n\t\t\ty = 3;\n\t\t\tans[i] ~= [[x, y], [x+1, y]];\n\t\t\t--b;\n\t\t\t--w;\n\t\t\t++x;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tx = y = 2;\n\t\t\tans[i] ~= [[x, y], [x+1, y]];\n\t\t\t--w;\n\t\t\t--b;\n\t\t\t++x;\n\t\t}\n\n\t\tauto dir = [[1, 0], [0, 1], [0, -1]];\n\t\twhile (b != 0 || w != 0)\n\t\t{\n\t\t\tif ((x+y)%2 == 0)\n\t\t\t{\n\t\t\t\tauto m = cast(int)min(3, max(1, b-w));\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\tauto dx = dir[j][0];\n\t\t\t\t\tauto dy = dir[j][1];\n\t\t\t\t\tans[i] ~= [x+dx, y+dy];\n\t\t\t\t\t--b;\n\t\t\t\t}\n\t\t\t\t++x;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tauto m = cast(int)min(3, max(1, w-b));\n\t\t\t\tforeach (j; 0..m)\n\t\t\t\t{\n\t\t\t\t\tauto dx = dir[j][0];\n\t\t\t\t\tauto dy = dir[j][1];\n\t\t\t\t\tans[i] ~= [x+dx, y+dy];\n\t\t\t\t\t--w;\n\t\t\t\t}\n\t\t\t\t++x;\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\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], \" \", ee[1]);\n\t\t\t}\n\t\t}\n\t}\n\tstdout.flush();\n\tdebug readln();\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 q;\n readf(\"%s\", &q);\n readln;\n \n while (q--) {\n int b, w;\n readf(\"%s %s\", &b, &w);\n readln;\n \n Tuple!(int, int)[] ans;\n if (b == w) {\n foreach (i; 0 .. b) {\n ans ~= tuple(1, 2*i + 1);\n ans ~= tuple(1, 2*i + 2);\n }\n } else {\n \n int start = 2;\n if (b > w) {\n swap(b, w);\n start = 3;\n }\n \n ans ~= tuple(2, start);\n w -= 1;\n \n int reach = 0;\n int cur = start+1;\n while (b > 0) {\n b -= 1;\n ans ~= tuple(2, cur);\n cur += 1;\n\n w -= 1;\n ans ~= tuple(2, cur);\n\n reach += 2;\n }\n \n if (reach < w) {\n writeln(\"NO\");\n continue;\n }\n \n foreach (pos; cur.iota.drop(1 + start).stride(2)) {\n foreach (rw; [1, 3]) {\n if (w == 0) { break; }\n \n ans ~= tuple(rw, pos);\n w -= 1;\n }\n }\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\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 q;\n readf(\"%s\", &q);\n readln;\n \n foreach (strw; (q*2 + 2).iota.drop(2).stride(2)) {\n int b, w;\n readf(\"%s %s\", &b, &w);\n readln;\n \n Tuple!(int, int)[] ans;\n if (b == w) {\n foreach (i; 0 .. b) {\n ans ~= tuple(strw, 2*i + 1);\n ans ~= tuple(strw, 2*i + 2);\n }\n } else {\n \n int start = 2;\n if (b > w) {\n swap(b, w);\n start = 3;\n }\n \n ans ~= tuple(strw, start);\n w -= 1;\n \n int reach = 0;\n int cur = start+1;\n while (b > 0) {\n b -= 1;\n ans ~= tuple(strw, cur);\n cur += 1;\n\n w -= 1;\n ans ~= tuple(strw, cur);\n\n reach += 2;\n }\n \n if (reach < w) {\n writeln(\"NO\");\n continue;\n }\n \n foreach (pos; cur.iota.drop(1 + start).stride(2)) {\n foreach (rw; [strw-1, strw+1]) {\n if (w == 0) { break; }\n \n ans ~= tuple(rw, pos);\n w -= 1;\n }\n }\n }\n \n writeln(\"YES\");\n ans.each!(t => writeln(t[0], ' ', t[1]));\n }\n}"}], "src_uid": "92dff52c8f02d500de9fef6f2095b0bd"} {"source_code": "import std.stdio, std.range, std.string, std.conv, std.algorithm;\nimport std.math;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[string] db;\n\n foreach (i; 0..n) {\n string name = readln.chomp;\n if (name in db) {\n writeln(name, db[name]);\n db[name]++;\n } else {\n db[name] = true;\n writeln(\"OK\");\n db[name] = 1;\n }\n }\n}", "positive_code": [{"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nstring readline()\n{\n\tstring result = readln();\n\tif (result[$-1] == '\\n') result.length--;\n\treturn result;\n}\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\\n\", &n);\n\tint[string] db;\n\tforeach (int i; 0..n)\n\t{\n\t\tstring name = readline();\n\t\tif (name in db)\n\t\t{\n\t\t\tdb[name]++; write(name, db[name], '\\n');\n\t\t} else {\n\t\t\twrite(\"OK\\n\");\n\t\t\tdb[name] = 0;\n\t\t}\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main()\n{\n auto n = stdin.readln.strip.to!int;\n int [string] names;\n for(int i=0; i (c - 'a' + 1).to!long).array;\r\n const a = S.length % 2 == 0 ? pts.sum : pts.sum - min(pts[0], pts[$ - 1]);\r\n const b = pts.sum - a;\r\n\r\n const winner = a > b ? \"Alice\" : \"Bob\";\r\n return \"%s %s\".format(winner, abs(a - b));\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>>\".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 foreach(_; 0..t)\r\n {\r\n string s = readln.strip;\r\n if (s.length == 1)\r\n writeln(\"Bob \", cast(int) s[0] - cast(int) 'a' + 1);\r\n else\r\n {\r\n if (s.length % 2 == 0)\r\n writeln(\"Alice \", s.map!(x => cast(int) x - cast(int) 'a' + 1).sum);\r\n else\r\n {\r\n if (cast(int) s[0] >= cast(int) s[$ - 1])\r\n writeln(\"Alice \", s[0 .. $ -1].map!(x => cast(int) x - cast(int) 'a' + 1).sum - cast(int) s[$ - 1] - 1 + cast(int) 'a');\r\n else\r\n writeln(\"Alice \", s[1 .. $].map!(x => cast(int) x - cast(int) 'a' + 1).sum - cast(int) s[0] - 1 + cast(int) 'a');\r\n }\r\n }\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 S = scan;\r\n\r\n auto pts = S.map!(c => (c - 'a' + 1).to!long).array.sort;\r\n const a = S.length % 2 == 0 ? pts.sum : pts[1..$].sum;\r\n const b = S.length % 2 == 0 ? 0 : pts[0..1].sum;\r\n\r\n const winner = a > b ? \"Alice\" : \"Bob\";\r\n return \"%s %s\".format(winner, abs(a - b));\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>>\".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": "8f02891aa9d2fcd1963df3a4028aa5c0"} {"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 mod = 10^^9 + 7;\n\nvoid main() {\n int n;\n scan(n);\n\n auto dp = new int[][](n + 1, n + 2);\n dp[0][0] = 1;\n\n foreach (i ; 1 .. n + 1) {\n char c;\n scan(c);\n\n foreach_reverse (j ; 0 .. n + 1) {\n if (c == 'f') {\n if (j-1 >= 0) dp[i][j] = dp[i-1][j-1];\n }\n else {\n dp[i][j] = (dp[i-1][j] + dp[i][j+1]) % mod;\n }\n }\n }\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", dp);\n }\n\n int ans;\n\n foreach (j ; 0 .. n + 1) {\n (ans += dp[n-1][j]) %= mod;\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": "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 int n;\n readf(\"%s\", &n);\n readln;\n \n char[] arr;\n foreach (_; 0 .. n) {\n arr ~= readln.chomp.front;\n }\n \n debug { arr.writeln; }\n \n auto dp = new int[][] (n+1, n+1);\n dp[1][0] = 1;\n foreach (i; 2 .. n+1) {\n int sm = 0;\n foreach_reverse (j; 0 .. n+1) {\n sm = (sm + dp[i-1][j]) % MD;\n if (arr[i-2] == 'f') {\n if (j > 0) { dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MD; }\n } else {\n dp[i][j] = (dp[i][j] + sm) % MD;\n }\n }\n }\n \n debug { dp.writeln; }\n \n auto ans = dp[n].fold!((r, v) => (r + v) % MD)(0);\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 mod = 10^^9 + 7;\n\nvoid main() {\n int n;\n scan(n);\n\n auto dp = new int[][](n + 1, n + 1);\n dp[0][0] = 1;\n\n auto s = new int[](n + 1);\n s[0] = 1;\n\n foreach (i ; 1 .. n + 1) {\n char c;\n scan(c);\n\n if (c == 's') {\n foreach (j ; 0 .. n + 1) {\n dp[i][j] += s[j];\n }\n }\n else {\n foreach (j ; 0 .. n + 1) {\n if (j-1 >= 0) (dp[i][j] += dp[i-1][j-1]) %= mod;\n }\n }\n\n s[] = dp[i].dup;\n foreach_reverse (j ; 0 .. n) {\n (s[j] += s[j+1]) %= mod;\n }\n }\n\n int ans;\n\n foreach (j ; 0 .. n + 1) {\n (ans += dp[n-1][j]) %= mod;\n }\n\n debug {\n iota(n+1).each!(i => writeln(dp[i][0 .. 10]));\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 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 mod = 10^^9 + 7;\n\nint n;\nchar[5000] prog;\nint[5001][ ] dp;\n\nint dyn(int pos, int level, bool canDedent) {\n if (pos == n)\n return 1;\n if (~dp[pos][level])\n return dp[pos][level];\n const isLoop = prog[pos] == 'f';\n int result = dyn(pos + 1, level + isLoop, !isLoop);\n if (level && canDedent)\n result = (result + dyn(pos, level - 1, canDedent)) % mod;\n return (dp[pos][level] = result);\n}\n\nvoid main() {\n dp = uninitializedArray!(int[5001][ ])(5000);\n while (read(n)) {\n prog[0 .. n].each!read();\n memSet(dp, 0xFF);\n writeln(dyn(0, 0, false));\n }\n\n stdout.flush();\n _Exit(0);\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 mod = 10^^9 + 7;\n\nint n;\nchar[5000] prog;\nint[5001][ ] dp;\n\nint dyn(int first, int last) {\n if (first == last)\n return 1;\n if (~dp[first][last])\n return dp[first][last];\n int result = 0;\n if (prog[first] == 's')\n result = dyn(first + 1, last);\n else\n foreach (end; first + 1 .. last)\n if (prog[end] == 's')\n result = (result + dyn(first + 1, end + 1) * dyn(end + 1, last)) % mod;\n return (dp[first][last] = result);\n}\n\nvoid main() {\n dp = uninitializedArray!(int[5001][ ])(5000);\n while (read(n)) {\n prog[0 .. n].each!read();\n memSet(dp, 0xFF);\n writeln(dyn(0, n));\n }\n\n stdout.flush();\n _Exit(0);\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 MD = 10 ^^ 9 + 7;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n char[] arr;\n foreach (_; 0 .. n) {\n arr ~= readln.chomp.front;\n }\n \n debug { arr.writeln; }\n \n auto dp = new int[][] (n+1, n+1);\n dp[1][0] = 1;\n foreach (i; 2 .. n+1) {\n foreach (j; 0 .. n+1) {\n if (arr[i-2] == 'f') {\n if (j > 0) { dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MD; }\n } else {\n dp[i][j] = (dp[i][j] + dp[i-1][j]) % MD;\n if (j > 0) { dp[i][j-1] = (dp[i][j-1] + dp[i-1][j]) % MD; }\n }\n }\n }\n \n debug { dp.writeln; }\n \n auto ans = dp[n].fold!((r, v) => (r + v) % MD)(0);\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 mod = 10^^9 + 7;\n\nvoid main() {\n int n;\n scan(n);\n\n auto dp = new int[][](n + 1, 5000 + 1);\n dp[0][0] = 1;\n\n foreach (i ; 0 .. n) {\n char c;\n scan(c);\n\n if (c == 's') {\n foreach (j ; 0 .. 5000 + 1) {\n if (j-1 >= 0) (dp[i+1][j-1] += dp[i][j]) %= mod;\n (dp[i+1][j] += dp[i][j]) %= mod;\n }\n }\n else {\n foreach (j ; 0 .. 5000 + 1) {\n if (j+1 <= 5000) (dp[i+1][j+1] += dp[i][j]) %= mod;\n }\n }\n }\n\n int ans;\n\n foreach (j ; 0 .. 5000 + 1) {\n (ans += dp[n-1][j]) %= mod;\n }\n\n debug {\n iota(n+1).each!(i => writeln(dp[i][0 .. 10]));\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}"}], "src_uid": "c4033b57cd52b4c8567e946e136cb5dc"} {"source_code": "module _;\nvoid main() {\n\timport std.stdio, std.conv, std.string;\n\tint n =readln.strip.to!int;\n\tint[char] cnt;\n\tforeach(i; 0..n) {\n\t\tcnt[readln[0]]++;\n\t}\n\tint ans = 0;\n\tforeach(k; cnt.byKey) {\n\t\tans += cnt[k]*(cnt[k]-1)/2;\n\t\tint half = cnt[k]/2;\n\t\tans -= half * (cnt[k]-half);\n\t}\n\twriteln(ans);\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\tint [char] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto t = readln.strip;\n\t\t\ts[t[0]] += 1;\n\t\t}\n\t\tint res = 0;\n\t\tforeach (k, v; s)\n\t\t{\n\t\t\tint a = v / 2;\n\t\t\tint b = v - a;\n\t\t\tres += a * (a - 1) / 2;\n\t\t\tres += b * (b - 1) / 2;\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\nint f (int x) {\n return (x * (x - 1) ) / 2;\n}\n\nvoid main() {\n int n = readln.strip.to!int;\n int[26] c;\n foreach (i; 0 .. n) {\n auto s = readln;\n ++c[s[0].to!int - 97];\n }\n int res;\n foreach (i; 0 .. 26) {\n int m = c[i] >> 1;\n res += f (m) + f (c[i] - m);\n }\n writeln (res);\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 std.math: abs ;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!long;\n\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\\n\", n);\n int[26] counter;\n counter[] = 0;\n foreach(i; 0..n) {\n string s = readln().strip;\n counter[ s[0] - 'a' ] ++;\n }\n\n int total = 0;\n foreach(i; 0..26) {\n int c = counter[i];\n int c1 = c/2;\n int c2= c - c1;\n total += c1 * (c1-1)/2 + c2*(c2-1)/2;\n }\n\n writeln(total);\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\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 N = RD!int;\n\tauto cnt = new long[](30);\n\tforeach (i; 0..N)\n\t{\n\t\tauto s = RD!string;\n\t\t++cnt[s[0]-'a'];\n\t}\n\t\n\tlong ans;\n\tforeach (e; cnt)\n\t{\n\t\tauto x = (e+1) / 2;\n\t\tauto y = e / 2;\n\t\tans += x * (x-1) / 2;\n\t\tans += y * (y-1) / 2;\n\t}\n\n\twriteln(ans);\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\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 N = RD!int;\n\tauto cnt = new long[](30);\n\tforeach (i; 0..N)\n\t{\n\t\tauto s = RD!string;\n\t\t++cnt[s[0]-'a'];\n\t}\n\tcnt.sort!\"a > b\"();\n\tauto x = (cnt[0]+1) / 2;\n\tauto y = cnt[0] / 2;\n\tlong ans;\n\tans += x * (x-1) / 2;\n\tans += y * (y-1) / 2;\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "22a3561ff70b802f080feaabc4a71298"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\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 !(long)).array;\n\t\tlong [] s;\n\t\ts ~= 0;\n\t\tforeach (c; a)\n\t\t{\n\t\t\ts ~= s.back + c;\n\t\t}\n\t\tauto r = s.assumeSorted ();\n\n\t\tauto b = readln.splitter.map !(to !(long)).array;\n\t\tforeach (x; b)\n\t\t{\n\t\t\tauto p = r.lowerBound (x);\n\t\t\tauto pos = p.length;\n\t\t\twriteln (pos, \" \", x - p.back);\n\t\t}\n\t}\n}\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 as=readln.split.to!(long[]);\n auto bs=readln.split.to!(long[]);\n\n auto dub=new long[](n+1);\n foreach(i; 0..n) dub[i+1]=dub[i]+as[i];\n dub~=1_000_000_000_000_000_000;\n int x=0;\n foreach(b; bs){\n while(dub[x+1]= 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\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\tif ((x+y) % 2)\r\n\t\t\tans[ti] = [-1, -1];\r\n\t\telse\r\n\t\t{\r\n\t\t\tauto a = min(x, (x+y)/2);\r\n\t\t\tans[ti] = [a, (x+y)/2 - a];\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}", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto x = readInt!int;\n\tauto y = readInt!int;\n\tint dist(int x0, int y0, int x1, int y1)\n\t{\n\t\treturn abs(x1 - x0) + abs(y1 - y0);\n\t}\n\tauto hs = (x + y) / 2;\n\tif (hs*2 != x + y) return writeln(-1, \" \", -1);\n\t// ox + oy = hs\n\t// oy = hs - ox\n\tforeach(ox; 0 .. x + 1)\n\t{\n\t\tauto oy = hs - ox;\n\t\tif (dist(x, y, ox, oy) == hs) return writeln(ox, \" \", oy);\n\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"}], "negative_code": [], "src_uid": "f1d3032f1cb07ad6187a37c84376510d"} {"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 X = scan!long;\r\n auto A = scan!long(N);\r\n\r\n int[long] numCounts;\r\n foreach(a; A.sort.reverse) {\r\n if((a * X) in numCounts) { \r\n numCounts[a * X]--;\r\n if (numCounts[a * X] == 0) numCounts.remove(a * X);\r\n }\r\n else numCounts[a]++;\r\n }\r\n\r\n return numCounts.values.sum;\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>>\".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 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 a = RDA;\r\n\r\n\t\tlong[long] cnt;\r\n\t\tforeach (i; 0..n)\r\n\t\t\t++cnt[a[i]];\r\n\r\n\t\tforeach (key; cnt.keys.sort)\r\n\t\t{\r\n\t\t\tauto y = key * x;\r\n\t\t\tauto z = min(cnt.get(y, 0), cnt[key]);\r\n\t\t\tcnt[key] -= z;\r\n\t\t\tcnt[y] -= z;\r\n\t\t\tans[ti] += cnt[key];\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, 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\tsort (a);\r\n\t\tint j = 0;\r\n\t\tint res = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] == 0)\r\n\t\t\t{\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\twhile (j < n && a[j] < a[i] * 1L * x)\r\n\t\t\t{\r\n\t\t\t\tj += 1;\r\n\t\t\t}\r\n\t\t\tif (j < n && a[j] == a[i] * 1L * x)\r\n\t\t\t{\r\n\t\t\t\ta[j] = 0;\r\n\t\t\t}\r\n\t\t\telse\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"}], "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!long;\r\n auto X = scan!long;\r\n auto A = scan!long(N);\r\n\r\n int[long] numCounts;\r\n foreach(a; A) {\r\n if (a % X == 0 && ((a / X) in numCounts)) {\r\n numCounts[a / X]--;\r\n if (numCounts[a / X] == 0) numCounts.remove(a / X);\r\n }\r\n else if((a * X) in numCounts) { \r\n numCounts[a * X]--;\r\n if (numCounts[a * X] == 0) numCounts.remove(a * X);\r\n }\r\n else numCounts[a]++;\r\n }\r\n\r\n return numCounts.values.sum;\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>>\".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": "c19500d867fd0108fdeed2cbd00bc970"} {"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 B = readarray!int;\r\n\r\n int k_lb = 0, k_ub = N + 1;\r\n for (int x = 1; x <= N; x++) {\r\n int i = x - 1;\r\n int b = B[i];\r\n if (x < b) {\r\n k_lb = max(k_lb, x);\r\n k_ub = min(k_ub, b - 1);\r\n } else if (x > b) {\r\n k_lb = max(k_lb, b);\r\n k_ub = min(k_ub, x - 1);\r\n } else {\r\n assert(false);\r\n }\r\n }\r\n\r\n int k = k_lb;\r\n Array!int L, U;\r\n auto G = new int[][N+2];\r\n for (int x = 1; x <= N; x++) {\r\n int i = x - 1;\r\n int b = B[i];\r\n if (x <= k) {\r\n G[b] ~= x;\r\n } else {\r\n G[b] ~= x;\r\n }\r\n }\r\n\r\n foreach (c; 0 .. N + 2) {\r\n G[c].sort!((i, j) => G[i].length < G[j].length);\r\n }\r\n\r\n int[] as;\r\n DList!int Q;\r\n if (! G[0].empty) { Q.insert(0); }\r\n else if (! G[N+1].empty) { Q.insert(N+1); }\r\n else assert(false);\r\n while (! Q.empty) {\r\n auto c = Q.front; Q.removeFront;\r\n as ~= c;\r\n foreach (v; G[c]) {\r\n Q.insert(v);\r\n }\r\n }\r\n\r\n writeln(k);\r\n writefln(\"%(%s %)\", as[1..$]);\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\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 b = readln.splitter.map !(to !(int)).array;\r\n\t\tauto s = new int [] [n + 2];\r\n\t\tforeach (int i, ref c; b)\r\n\t\t{\r\n\t\t\ts[c] ~= i + 1;\r\n\t\t}\r\n\r\n\t\tint [] a;\r\n\t\tint cur = 0;\r\n\t\tbool up = false;\r\n\t\tint k = 0;\r\n\t\tif (s[cur].empty)\r\n\t\t{\r\n\t\t\tcur = n + 1;\r\n\t\t\tup = true;\r\n\t\t}\r\n\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\tint next = NA;\r\n\t\t\tforeach (v; s[cur])\r\n\t\t\t{\r\n\t\t\t\tif (up)\r\n\t\t\t\t{\r\n\t\t\t\t\tk = max (k, v);\r\n\t\t\t\t}\r\n\t\t\t\tif (!s[v].empty)\r\n\t\t\t\t{\r\n\t\t\t\t\tnext = v;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tforeach (v; s[cur])\r\n\t\t\t{\r\n\t\t\t\tif (v != next)\r\n\t\t\t\t{\r\n\t\t\t\t\ta ~= v;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\ts[cur] = null;\r\n\t\t\tif (next == NA)\r\n\t\t\t{\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\ta ~= next;\r\n\r\n\t\t\tup ^= true;\r\n\t\t\tcur = next;\r\n\t\t}\r\n\r\n\t\twriteln (k);\r\n\t\twritefln !(\"%(%s %)\") (a.map !(q{a}));\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[] B;\r\nint K;\r\nint[] A;\r\n\r\nvoid solve() {\r\n auto minL = new int[N + 1];\r\n auto maxR = new int[N + 1];\r\n minL[0] = N + 2;\r\n foreach (i; 0 .. N) {\r\n minL[i + 1] = min(minL[i], B[i]);\r\n }\r\n maxR[N] = -1;\r\n foreach_reverse (i; 0 .. N) {\r\n maxR[i] = max(B[i], maxR[i + 1]);\r\n }\r\n {\r\n int[] ks;\r\n foreach (k; 0 .. N + 1) {\r\n if (minL[k] > k && k >= maxR[k]) {\r\n ks ~= k;\r\n }\r\n }\r\n debug {\r\n writeln(\"ks = \", ks);\r\n }\r\n assert(ks.length == 1);\r\n K = ks[0];\r\n }\r\n \r\n auto graph = new int[][N + 2];\r\n foreach (i; 0 .. N) {\r\n graph[B[i]] ~= i + 1;\r\n }\r\n auto us = [0, N + 1];\r\n for (int j = 0; j < us.length; ++j) {\r\n graph[us[j]].sort!((v, w) => (graph[v].length < graph[w].length));\r\n foreach (v; graph[us[j]]) {\r\n us ~= v;\r\n }\r\n }\r\n assert(us.length == N + 2);\r\n A = us[2 .. $];\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 B = new int[N];\r\n foreach (i; 0 .. N) {\r\n B[i] = readInt;\r\n }\r\n \r\n solve;\r\n \r\n writeln(K);\r\n foreach (i; 0 .. N) {\r\n if (i) write(\" \");\r\n write(A[i]);\r\n }\r\n writeln;\r\n }\r\n }\r\n } catch (EOFException e) {\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 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 B = readarray!int;\r\n\r\n int k_lb = 0, k_ub = N + 1;\r\n for (int x = 1; x <= N; x++) {\r\n int i = x - 1;\r\n int b = B[i];\r\n if (x < b) {\r\n k_lb = max(k_lb, x);\r\n k_ub = min(k_ub, b - 1);\r\n } else if (x > b) {\r\n k_lb = max(k_lb, b);\r\n k_ub = min(k_ub, x - 1);\r\n } else {\r\n assert(false);\r\n }\r\n }\r\n\r\n int k = k_lb;\r\n Array!int L, U;\r\n auto G = new int[][N+2];\r\n for (int x = 1; x <= N; x++) {\r\n int i = x - 1;\r\n int b = B[i];\r\n if (x <= k) {\r\n G[b] ~= x;\r\n } else {\r\n G[b] ~= x;\r\n }\r\n }\r\n\r\n foreach (c; 0 .. N + 1) {\r\n G[c].sort!((i, j) => G[i].length < G[j].length);\r\n }\r\n\r\n int[] as;\r\n DList!int Q;\r\n if (! G[0].empty) { Q.insert(0); }\r\n else if (! G[N+1].empty) { Q.insert(N+1); }\r\n else assert(false);\r\n while (! Q.empty) {\r\n auto c = Q.front; Q.removeFront;\r\n as ~= c;\r\n foreach (v; G[c]) {\r\n Q.insert(v);\r\n }\r\n }\r\n\r\n writeln(k);\r\n writefln(\"%(%s %)\", as[1..$]);\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\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 B = readarray!int;\r\n\r\n int k_lb = 0, k_ub = N + 1;\r\n for (int x = 1; x <= N; x++) {\r\n int i = x - 1;\r\n int b = B[i];\r\n if (x < b) {\r\n k_lb = max(k_lb, x);\r\n k_ub = min(k_ub, b - 1);\r\n } else if (x > b) {\r\n k_lb = max(k_lb, b);\r\n k_ub = min(k_ub, x - 1);\r\n } else {\r\n assert(false);\r\n }\r\n }\r\n\r\n int k = k_lb;\r\n Array!int L, U;\r\n auto G = new int[][N+2];\r\n for (int x = 1; x <= N; x++) {\r\n int i = x - 1;\r\n int b = B[i];\r\n if (x <= k) {\r\n G[b] ~= x;\r\n } else {\r\n G[b] ~= x;\r\n }\r\n }\r\n\r\n int[] as;\r\n DList!int Q;\r\n if (! G[0].empty) { Q.insert(0); }\r\n else if (! G[N+1].empty) { Q.insert(N+1); }\r\n else assert(false);\r\n while (! Q.empty) {\r\n auto c = Q.front; Q.removeFront;\r\n as ~= c;\r\n foreach (v; G[c]) {\r\n Q.insert(v);\r\n }\r\n }\r\n\r\n writeln(k);\r\n writefln(\"%(%s %)\", as[1..$]);\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\nint N;\r\nint[] B;\r\nint K;\r\nint[] A;\r\n\r\nvoid solve() {\r\n auto minL = new int[N + 1];\r\n auto maxR = new int[N + 1];\r\n minL[0] = N + 2;\r\n foreach (i; 0 .. N) {\r\n minL[i + 1] = min(minL[i], B[i]);\r\n }\r\n maxR[N] = -1;\r\n foreach_reverse (i; 0 .. N) {\r\n maxR[i] = max(B[i], maxR[i + 1]);\r\n }\r\n {\r\n int[] ks;\r\n foreach (k; 0 .. N + 1) {\r\n if (minL[k] > k && k >= maxR[k]) {\r\n ks ~= k;\r\n }\r\n }\r\n debug {\r\n writeln(\"ks = \", ks);\r\n }\r\n assert(ks.length == 1);\r\n K = ks[0];\r\n }\r\n \r\n auto graph = new int[][N + 2];\r\n foreach (i; 0 .. N) {\r\n graph[B[i]] ~= i + 1;\r\n }\r\n auto us = [0, N + 1];\r\n for (int j = 0; j < us.length; ++j) {\r\n foreach (v; graph[us[j]]) {\r\n us ~= v;\r\n }\r\n }\r\n assert(us.length == N + 2);\r\n A = us[2 .. $];\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 B = new int[N];\r\n foreach (i; 0 .. N) {\r\n B[i] = readInt;\r\n }\r\n \r\n solve;\r\n \r\n writeln(K);\r\n foreach (i; 0 .. N) {\r\n if (i) write(\" \");\r\n write(A[i]);\r\n }\r\n writeln;\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "src_uid": "152aba87aaf14d1841f6622dc66051af"} {"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(int[] a, bool tie)\n{\n int even_cnt = cast(int)a.count(0);\n int odd_cnt = cast(int)a.length - even_cnt;\n\n if (abs(even_cnt - odd_cnt) > 1)\n return -1;\n\n int odd_i, even_i;\n int[] arr;\n if (odd_cnt == even_cnt) {\n if (tie)\n odd_i = 1;\n else\n even_i = 1;\n } else if (odd_cnt < even_cnt) {\n odd_i = 1;\n } else {\n even_i = 1;\n }\n\n foreach (x ; a) {\n if (x) {\n arr ~= odd_i;\n odd_i += 2;\n } else {\n arr ~= even_i;\n even_i += 2;\n }\n }\n long ans = 0;\n foreach (i ; 0 .. cast(int)a.length) {\n ans += abs(arr[i] - i);\n }\n assert(ans % 2 == 0);\n return ans / 2;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int n;\n readln.formattedRead!\" %d \"(n);\n auto a = readln.strip.split.map!(x => x.to!int % 2).array;\n writeln(min(solve(a, true), solve(a, false)));\n }\n}\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tint n = readInt!int;\n\tauto a = ma(n, readInt!int%2);\n\tauto m1 = n/2;\n\tauto m2 = n - m1;\n\tint fe = void;\n\tint[2] c; \n\tc[0] = cast(int)a.count!(ai => ai == 0);\n\tc[1] = n - c[0];\n\tif (c[0] != m2 && c[1] != m2) return writeln(-1);\n\tlong allOps = long.max; \n\tvoid tryFe(int fe)\n\t{\n\t if (c[fe] != m2) return;\n\t\tint[] lfe = null;\n\t\tforeach(i, ai; a)\n\t\t{\n\t\t\tif (ai == fe)\n\t\t\t{\n\t\t\t\tlfe ~= cast(int)i;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"lfe \", lfe);\n\t\tlong ops = 0;\n\t\tforeach(i; 0 .. n)\n\t\t{\n\t\t\tif (i%2 == 0)\n\t\t\t{\n\t\t\t\tassert(lfe.length > 0);\n\t\t\t\tops += abs(lfe[0] - i);\n\t\t\t\tlfe = lfe[1 .. $];\n\t\t\t}\n\t\t}\n\t\tallOps = min(allOps, ops);\n\t}\n\ttryFe(0); tryFe(1);\n\tallOps.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"}, {"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\nlong solve (int [] a, int pos)\r\n{\r\n\tauto n = a.length.to !(int);\r\n\tauto half = (n + 1 - pos) / 2;\r\n\tauto total = a.sum;\r\n\tif (total != half)\r\n\t{\r\n\t\treturn long.max;\r\n\t}\r\n\tlong res = 0;\r\n\tforeach (int i, ref c; a)\r\n\t{\r\n\t\tif (c & 1)\r\n\t\t{\r\n\t\t\tres += abs (i - pos);\r\n\t\t\tpos += 2;\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\tauto n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta[] %= 2;\r\n\t\tauto res = long.max;\r\n\t\tres = min (res, solve (a, 0));\r\n\t\tres = min (res, solve (a, 1));\r\n\t\tif (res == long.max)\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": "be51a3e4038bd9a3f6d4993b75a20d1c"} {"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\nint[10^^4] p;\n\nvoid main() {\n int n, m;\n while (read(n, m)) {\n foreach (ref x; p[0 .. n])\n read(x);\n while (m--) {\n int left, right, pos;\n read(left, right, pos);\n left--;\n const x = p[pos - 1];\n const lte = p[left .. right].filter!(y => y <= x).walkLength();\n writeln(pos == left + lte ? \"Yes\" : \"No\");\n }\n debug writeln();\n }\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\nvoid main(){\n int N, M, l, r, x;\n\n readVars(N, M);\n auto p = readln.split.to!(int[]);\n\n int cnt;\n\n foreach(i ; 0 .. M){\n readVars(l, r, x);\n l--;\n x--;\n\n cnt = 0;\n\n foreach(j ; l .. r){\n cnt += (p[j] < p[x]);\n }\n\n if (cnt == x - l) {\n writeln(\"Yes\");\n } else {\n writeln(\"No\");\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 throw new Exception(\"args num < input num\");\n }\n}"}], "negative_code": [], "src_uid": "44162a97e574594ac0e598368e8e4e14"} {"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 Tuple!(long, long)[] a;\n foreach (i ; 0 .. n) {\n long ai, bi;\n readf!\" %d %d \"(ai, bi);\n a ~= tuple(min(ai, bi), max(ai, bi));\n }\n a.sort!((x, y) => x[1] < y[1]);\n long ans = a[0][0] * 2 + a[0][1];\n foreach (i ; 1 .. a.length) {\n ans += a[i][0] * 2 + (a[i][1] - a[i - 1][1]);\n }\n ans += a.back[1];\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\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\n\r\nvoid solve() {\r\n int n = read!int;\r\n long a, b, maxV, res;\r\n foreach(i; 0 .. n) {\r\n scanf(\"%lld %lld\\n\", &a, &b);\r\n res += min(a,b);\r\n if (max(a,b) > maxV)\r\n maxV = max(a,b);\r\n }\r\n res <<= 1;\r\n maxV <<= 1;\r\n writeln(res + maxV);\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\tlong res = 0;\r\n\t\tlong hi = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tlong a, b;\r\n\t\t\treadf !(\" %s %s\") (a, b);\r\n\t\t\tif (a > b)\r\n\t\t\t{\r\n\t\t\t\tswap (a, b);\r\n\t\t\t}\r\n\t\t\tres += a * 2;\r\n\t\t\thi = max (hi, b);\r\n\t\t}\r\n\t\treadln;\r\n\t\twriteln (res + hi * 2);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "7100fa11adfa0c1f5d33f9e3a1c3f352"} {"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 auto s = readln.strip;\n long ans = 0;\n char last = 0;\n foreach (ch ; s) {\n if (last != ch) {\n ans += (ch == '0');\n }\n last = ch;\n }\n writeln(min(2, ans));\n }\n}\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int)\n{\n\tauto s = readString;\n\tint i = 0;\n\tint[2] cnt;\n\twhile (i < s.length)\n\t{\n\t\tchar ch = s[i];\n\t\twhile (i+1 < s.length && s[i+1] == ch) i++;\n\t\tcnt[ch-'0']++;\n\t\ti++;\n\t}\n\tif (cnt[0] == 0)\n\t{\n\t\treturn writeln(0);\n\t}\n\tif (cnt[1] == 0)\n\t{\n\t\treturn writeln(1);\n\t}\n\tif (cnt[0] == 1)\n\t{\n\t\treturn writeln(1);\n\t}\n\treturn writeln(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"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.array;\r\n\r\nvoid main()\r\n{\r\n int t;\r\n scanf(\"%d\", &t);\r\n getchar();\r\n foreach(i; 0..t){\r\n\tauto str = readln.strip();\r\n\tstring result;\r\n\twhile (str.length > 0)\r\n\t{\r\n\t\tresult ~= str[0];\r\n\t\tstr = str.stripLeft(str[0]);\r\n\t}\r\n\tif (result.length > 3)\r\n\t\twriteln(2);\r\n\telse if (result == \"0\")\r\n\t\twriteln(1);\r\n\telse if (result == \"1\")\r\n\t\twriteln(0);\r\n\telse if (result == \"01\" || result == \"10\")\r\n\t\twriteln(1);\r\n\telse if (result == \"101\")\r\n\t\twriteln(1);\r\n\telse\r\n\t\twriteln(2);\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 s = RD!string;\r\n\r\n\t\tlong cnt = s[0] == '0' ? 1 : 0;\r\n\t\tforeach (i; 0..s.length-1)\r\n\t\t{\r\n\t\t\tif (s[i] == '1' && s[i+1] == '0')\r\n\t\t\t\t++cnt;\r\n\t\t}\r\n\t\tans[ti] = min(cnt, 2);\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;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nint solve (string s)\r\n{\r\n\ts = s.strip ('1');\r\n\tif (s.empty)\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\tif (s.all !(q{a == '0'}))\r\n\t{\r\n\t\treturn 1;\r\n\t}\r\n\treturn 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\treadln.strip.solve.writeln;\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "2e6ddb2b11f8ac857e81d4b9b0c7d783"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int NA = -1;\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 c = readln.split.map !(to !(int)).array;\n\t\tint [] p;\n\t\tint [] q;\n\t\tint [] r;\n\t\tfor (int d = 2; d <= k; d++)\n\t\t{\n\t\t\tif (k % d == 0)\n\t\t\t{\n\t\t\t\tp ~= d;\n\t\t\t\tq ~= 0;\n\t\t\t\tr ~= 0;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tq[$ - 1]++;\n\t\t\t\t\tk /= d;\n\t\t\t\t}\n\t\t\t\twhile (k % d == 0);\n\t\t\t}\n\t\t}\n\t\tforeach (cur; c)\n\t\t{\n\t\t\tforeach (i; 0..p.length)\n\t\t\t{\n\t\t\t\tint s = 0;\n\t\t\t\twhile (cur % p[i] == 0)\n\t\t\t\t{\n\t\t\t\t\tcur /= p[i];\n\t\t\t\t\ts++;\n\t\t\t\t}\n\t\t\t\tr[i] = max (r[i], s);\n\t\t\t}\n\t\t}\n\t\twriteln (p.length.iota.all\n\t\t !(x => q[x] <= r[x]) ? \"Yes\" : \"No\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\n\nimmutable int MAXN = cast(int)1e6;\n\nint[MAXN + 5] Pr, nx, cnt;\n\nvoid sieve() {\n\tPr[0] = Pr[1] = 0;\n\tforeach(i; 2..MAXN) Pr[i] = 1;\n\tforeach(i; 2..MAXN) if (Pr[i]) {\n\t\tfor(int j = i; j <= MAXN; j += i) nx[j] = i, Pr[j] = 0;\n\t}\n}\n\nint N, K;\n\nvoid add(int x, void function(ref int a, in int b) f) {\n\twhile (x > 1) {\n\t\tint c = 0, t = nx[x];\n\t\twhile (x % t == 0) {\n\t\t\t++c; x /= t;\n\t\t}\n\t\tf(cnt[t], c);\n\t}\n}\n\nvoid main() {\n\tsieve();\n\treadf(\"%d %d\", &N, &K);\n\tforeach(i; 1..N+1) {\n\t\tint inp; readf(\" %d\", &inp);\n\t\tadd(inp, function(ref int a, in int b) { a = max(a, b); });\n\t}\n\tadd(K, function(ref int a, in int b) { a -= b; });\n\tforeach (i; cnt) if (i < 0) {\n\t\twritef(\"No\\n\"); return;\n\t}\n\twritef(\"Yes\\n\"); \n}"}], "negative_code": [], "src_uid": "e72fa6f8a31c34fd3ca0ce3a3873ff50"} {"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 if (n % 2 == 0) {\n writeln(-1);\n return;\n }\n \n foreach (_; 0 .. 2) {\n n.iota.writefln!(\"%(%s %)\");\n }\n auto lst = (2*n).iota.stride(2).map!(x => x % n);\n lst.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.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\tif (n % 2 == 0)\t\t\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto a = array (iota (n));\n\t\t\tauto c = a.dup;\n\t\t\tc[] *= 2;\n\t\t\tc[] %= n;\n\t\t\twritefln (\"%(%s %)\", a);\n\t\t\twritefln (\"%(%s %)\", a);\n\t\t\twritefln (\"%(%s %)\", c);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "2f0942c531fd5758b220104c3338b702"} {"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 arr = readln.splitter.map!(to!int).array;\n auto pos = arr.count!(x => x > 0);\n auto neg = arr.count!(x => x < 0);\n auto z = arr.length - pos - neg;\n if (pos >= 3 || neg >= 3)\n {\n writeln(\"NO\");\n return;\n }\n if (z)\n {\n arr = [0] ~ arr.filter!(x => x != 0).array;\n }\n foreach (i; 0 .. arr.length)\n foreach (j; i + 1 .. arr.length)\n foreach (k; j + 1 .. arr.length)\n {\n auto sum = arr[i] + arr[j] + arr[k];\n if (!arr.canFind(sum))\n {\n writeln(\"NO\");\n return;\n }\n }\n writeln(\"YES\");\n}\n\nvoid main()\n{\n size_t TC = 1;\n TC = readln.strip.to!int;\n foreach (_; 0 .. TC)\n 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\nbool solve (int n, int [] a)\r\n{\r\n\tsort (a);\r\n\tauto g = a.group;\r\n\r\n\ta = [];\r\n\tforeach (ref x; g)\r\n\t{\r\n\t\tforeach (i; 0..min (3, x[1]))\r\n\t\t{\r\n\t\t\ta ~= x[0];\r\n\t\t}\r\n\t}\r\n\tif (a.length > 10)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\r\n\tbool [long] b;\r\n\tforeach (ref c; a)\r\n\t{\r\n\t\tb[c] = true;\r\n\t}\r\n\r\n\tforeach (i; 0..a.length)\r\n\t{\r\n\t\tforeach (j; i + 1..a.length)\r\n\t\t{\r\n\t\t\tforeach (k; j + 1..a.length)\r\n\t\t\t{\r\n\t\t\t\tif (0L + a[i] + a[j] + a[k] !in b)\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}\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 (n, a) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "70028bbb9b7bce1f0d2753275b3e752f"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.stdio;\nimport std.typecons;\nimmutable int N = 2 ^^ 16 + 8;\nint[N] deg, s;\nint n;\nint[] d1;\nTuple!(int, int)[] edges;\nvoid main() {\n\tscanf(\"%d\", &n);\n\tforeach (i; 0..n) {\n\t\tscanf(\"%d%d\", °[i], &s[i]);\n\t\tif (deg[i] == 1) d1 ~= i;\n\t}\n\twhile (!d1.empty()) {\n\t\tint i = d1.back(); // this and next are UFCS for std.array\n\t\td1.popBack();\n\t\tif (deg[i] == 0) continue;\n\t\tassert(deg[i] == 1);\n\t\tdeg[i] = 0;\n\t\tint j = s[i];\n\t\tdeg[j] -= 1;\n\t\tif (deg[j] == 1) d1 ~= j;\n\t\ts[j] ^= i;\n\t\tedges ~= tuple(i, j);\n\t}\n\twritefln(\"%d\", edges.length);\n\tforeach (t; edges) {\n\t\twritefln(\"%d %d\", t[0], t[1]);\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\tauto d = new int [n];\n\t\tauto s = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &d[i], &s[i]);\n\t\t}\n\n\t\tint [] q;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (d[i] == 1)\n\t\t\t{\n\t\t\t\tq ~= i;\n\t\t\t}\n\t\t}\n\n\t\tint [] [] e;\n\t\twhile (!q.empty)\n\t\t{\n\t\t\tint i = q.front;\n\t\t\tq.popFront ();\n\t\t\tif (d[i] != 1)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\te ~= [i, s[i]];\n\t\t\td[i]--;\n\t\t\td[s[i]]--;\n\t\t\tif (d[s[i]] == 1)\n\t\t\t{\n\t\t\t\tq ~= s[i];\n\t\t\t}\n\t\t\ts[s[i]] ^= i;\n\t\t\ts[i] ^= s[i];\n\t\t}\n\n\t\twriteln (e.length);\n\t\tforeach (c; e)\n\t\t{\n\t\t\twriteln (c[0], ' ', c[1]);\n\t\t}\n\t}\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\nstruct P {\n int v;\n int d, s;\n}\nstruct E {\n int from, to;\n}\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n BinaryHeap!(Array!P, \"a.d > b.d\") PQ;\n auto ps = new P[N];\n foreach (i; 0 .. N) {\n int d, s; scanf(\"%d %d\\n\", &d, &s);\n int v = i;\n ps[i] = P(v, d, s);\n PQ.insert(P(v, d, s));\n }\n auto done = new bool[N];\n E[] ans;\n while (!PQ.empty) {\n auto p = PQ.front; PQ.removeFront;\n if (done[p.v]) continue;\n done[p.v] = true;\n if (p.d == 0) continue;\n assert(p.d == 1);\n ans ~= E(p.v, p.s);\n ps[ p.s ].d--;\n ps[ p.s ].s = ps[ p.s ].s ^ p.v;\n PQ.insert(ps[ p.s ]);\n done[p.v] = true;\n }\n writeln(ans.length);\n foreach (a; ans) {\n writefln(\"%d %d\", a.from, a.to);\n }\n}\n"}, {"source_code": "// 1. start with a full forest\n// 2. take any vertex with the current degree of 1 = V\n// 3. its \"s\" value is the adjacent vertex number = S\n// 4. add an edge (V, S)\n// 5. remove V from the forest, decrease S degree, XOR s value of S with V\n// 6. if vertices with non-zero degree have remained, then goto 2\n\nimport std.stdio;\nimport std.algorithm;\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 int[2][0x10000] desc;\n int[0x10000] queue; // vertices with \"current\" degree of 1\n int queue_n = 0;\n foreach (i; 0..n)\n {\n auto d = read!int;\n auto s = read!int;\n\n if (d == 1)\n queue[queue_n++] = i;\n\n desc[i][0] = d;\n desc[i][1] = s;\n }\n\n int m = 0;\n int[2][0x10000] ans;\n foreach (i; 0..n)\n {\n debug writeln(\"queue = \", queue[0..queue_n]);\n\n if (queue_n == 0)\n break;\n\n auto p = queue[--queue_n];\n\n if (desc[p][0] == 0)\n continue;\n\n auto j = desc[p][1];\n\n ans[m][0] = p;\n ans[m][1] = j;\n m++;\n desc[j][0]--;\n desc[j][1] ^= p;\n\n if (desc[j][0] == 1)\n queue[queue_n++] = j;\n }\n\n writeln(m);\n foreach (i; 0..m)\n {\n writefln(\"%s %s\", ans[i][0], ans[i][1]);\n }\n\n return 0;\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 d = new int [n];\n\t\tauto s = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s\", &d[i], &s[i]);\n\t\t}\n\n\t\tint [] q;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (d[i] == 1)\n\t\t\t{\n\t\t\t\tq ~= i;\n\t\t\t}\n\t\t}\n\n\t\tint [] [] e;\n\t\twhile (!q.empty)\n\t\t{\n\t\t\tint i = q.front;\n\t\t\tq.popFront ();\n\t\t\tif (d[i] != 1)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\te ~= [i, s[i]];\n\t\t\td[i]--;\n\t\t\td[s[i]]--;\n\t\t\ts[s[i]] ^= i;\n\t\t\ts[i] ^= s[i];\n\t\t}\n\n\t\twriteln (e.length);\n\t\tforeach (c; e)\n\t\t{\n\t\t\twriteln (c[0], ' ', c[1]);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.stdio;\nimport std.typecons;\nimmutable int N = 2 ^^ 16 + 8;\nint[N] deg, s;\nint n;\nint[] d1;\nTuple!(int, int)[] edges;\nvoid main() {\n\tscanf(\"%d\", &n);\n\tforeach (i; 0..n) {\n\t\tscanf(\"%d%d\", °[i], &s[i]);\n\t\tif (deg[i] == 1) d1 ~= i;\n\t}\n\twhile (!d1.empty()) {\n\t\tint i = d1.back(); // this and next are UFCS for std.array\n\t\td1.popBack();\n\t\tif (deg[i] == 0) continue;\n\t\tassert(deg[i] == 1);\n\t\tdeg[i] = 0;\n\t\tint j = s[i];\n\t\tdeg[j] -= 1;\n\t\ts[j] ^= i;\n\t\tedges ~= tuple(i, j);\n\t}\n\twritefln(\"%d\", edges.length);\n\tforeach (t; edges) {\n\t\twritefln(\"%d %d\", t[0], t[1]);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\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 int[3][0x10000] desc;\n foreach (i; 0..n)\n {\n desc[i][0] = read!int;\n desc[i][1] = read!int;\n desc[i][2] = i;\n }\n\n auto sorted = sort!\"a[0] < b[0]\"(desc[0..n].dup);\n debug writeln(\"sorted = \", sorted);\n\n int m = 0;\n Tuple!(int, int)[0x10000] ans;\n foreach (i; 0..n)\n {\n auto p = sorted[i][2];\n\n if (desc[p][0] == 0)\n continue;\n\n debug writeln(\"i = \", i);\n debug write(\"desc = \", desc[0..n], \" -> \");\n assert(sorted[i][0] == 1);\n\n auto j = desc[p][1];\n ans[m][0] = p;\n ans[m][1] = j;\n m++;\n desc[j][0]--;\n desc[j][1] ^= p;\n\n debug writeln(desc[0..n]);\n }\n\n writeln(m);\n foreach (i; 0..m)\n {\n writefln(\"%s %s\", ans[i][0], ans[i][1]);\n }\n\n return 0;\n}\n"}], "src_uid": "14ad30e33bf8cad492e665b0a486008e"} {"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 t = r.nextA!uint (nt);\n foreach (n; t) {\n int x = n;\n if (x & 1) {\n write ('7');\n x -= 3;\n }\n while (x > 0) {\n write ('1');\n x -= 2;\n }\n 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\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 n = RD!int;\n\t\tauto digit = n / 2;\n\t\t//if (digit <= 9)\n\t\t{\n\t\t\tstring str;\n\t\t\tif (n % 2 == 0)\n\t\t\t\tstr ~= \"1\";\n\t\t\telse\n\t\t\t\tstr ~= \"7\";\n\t\t\t\n\t\t\tforeach (i; 1..digit)\n\t\t\t\tstr ~= \"1\";\n\t\t\tans[ti] = str;\n\t\t}\n\t\t/*else\n\t\t{\n\t\t\tauto arr = [9, 9, 8, 2, 4, 4, 3, 5, 3];\n\t\t\tauto cnt = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6];\n\t\t\tauto remain = n - 18;\n\t\t\tbool isLimit = true;\n\t\t\tforeach (i; 0..9)\n\t\t\t{\n\t\t\t\tauto lim = isLimit ? arr[i] : 9;\n\t\t\t\tlong num;\n\t\t\t\tforeach_reverse (j; 0..lim+1)\n\t\t\t\t{\n\t\t\t\t\tif (remain >= cnt[j] - 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tnum = j;\n\t\t\t\t\t\tremain -= cnt[j] - 2;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (num < lim)\n\t\t\t\t\tisLimit = false;\n\t\t\t\tans[ti] += num * 10^^(8-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}\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 T = readln.chomp.to!int;\n\n while (T--) {\n auto N = readln.chomp.to!int;\n if (N % 2) write(7), N -= 3;\n foreach (i; 0..N/2) write(1);\n 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, core.stdc.stdio;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n\n while (T--) {\n auto N = readln.chomp.to!int;\n for (int i = N; N > 3; N -= 2) write(1);\n if (N == 2) write(1);\n else write(7);\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 = 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\tif (n >= 47)\n\t\t{\n\t\t\tans[ti] = 998244353;\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto digit = n / 2;\n\t\tif (digit <= 9)\n\t\t{\n\t\t\tstring str;\n\t\t\tif (n % 2 == 0)\n\t\t\t\tstr ~= \"1\";\n\t\t\telse\n\t\t\t\tstr ~= \"7\";\n\t\t\t\n\t\t\tforeach (i; 1..digit)\n\t\t\t\tstr ~= \"1\";\n\t\t\tans[ti] = str.to!long;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto arr = [9, 9, 8, 2, 4, 4, 3, 5, 3];\n\t\t\tauto cnt = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6];\n\t\t\tauto remain = n - 18;\n\t\t\tbool isLimit = true;\n\t\t\tforeach (i; 0..9)\n\t\t\t{\n\t\t\t\tauto lim = isLimit ? arr[i] : 9;\n\t\t\t\tlong num;\n\t\t\t\tforeach_reverse (j; 0..lim+1)\n\t\t\t\t{\n\t\t\t\t\tif (remain >= cnt[j] - 2)\n\t\t\t\t\t{\n\t\t\t\t\t\tnum = j;\n\t\t\t\t\t\tremain -= cnt[j] - 2;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (num < lim)\n\t\t\t\t\tisLimit = false;\n\t\t\t\tans[ti] += num * 10^^(8-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}\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\tif (n >= 47)\n\t\t{\n\t\t\tans[ti] = 998244353;\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto digit = n / 2;\n\t\tif (digit <= 9)\n\t\t{\n\t\t\tstring str;\n\t\t\tif (n % 2 == 0)\n\t\t\t\tstr ~= \"1\";\n\t\t\telse\n\t\t\t\tstr ~= \"7\";\n\t\t\t\n\t\t\tforeach (i; 1..digit)\n\t\t\t\tstr ~= \"1\";\n\t\t\tans[ti] = str.to!long;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto remain = n - 18;\n\t\t\tstring str;\n\t\t\tforeach (i; 0..9)\n\t\t\t{\n\t\t\t\tif (remain >= 4)\n\t\t\t\t{\n\t\t\t\t\tstr ~= \"9\";\n\t\t\t\t\tremain -= 4;\n\t\t\t\t}\n\t\t\t\telse if (remain >= 1)\n\t\t\t\t{\n\t\t\t\t\tstr ~= \"7\";\n\t\t\t\t\tremain -= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tstr ~= \"1\";\n\t\t\t}\n\t\t\tans[ti] = str.to!long;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "07db573b0db736d798b6c18c06c32f3d"} {"source_code": "// cheese-cracker [2022-01-31]\n\nvoid solve(){\n long n = scan;\n long ten = (n/10) % 10;\n long d = n % 7;\n long u = 7 - d;\n long down = n - d;\n long up = n + u;\n long tend = (down / 10) % 10;\n long tenu = (up / 10) % 10;\n if(tend == ten){\n writeln(down);\n }else{\n writeln(up);\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;\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 auto d = n % 7;\r\n if (d == 0)\r\n writeln(n);\r\n else {\r\n int m = n % 10;\r\n if (m >= d)\r\n writeln(n - d);\r\n else {\r\n writeln(n + 7 - (n+7) % 7);\r\n }\r\n }\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "128372d890f632494e59e81287abd85a"} {"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 int n, l, r;\n readf!\" %d %d %d \"(n, l, r);\n auto a = readln.strip.split.map!(to!int).array.sort;\n long result = 0;\n for (int i = 0; i < a.length; i++) {\n int x = a[i];\n int min_x = l - x;\n int max_x = r - x;\n auto chop_l = a.assumeSorted.lowerBound(min_x).length;\n auto chop_r = a.assumeSorted.upperBound(max_x).length;\n if (a.length > chop_l + chop_r) {\n auto count = a.length - chop_l - chop_r;\n if (x >= min_x && x <= max_x)\n count--;\n result += count;\n }\n }\n writeln(result / 2);\n }\n}\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(_; 0 .. to!int(readln.strip)) {\r\n int n, l, r; readf(\"%d %d %d\\n\", n, l, r);\r\n auto ar = readln.strip.split.map!(to!int).array.sort;\r\n long ans = 0;\r\n foreach(e; ar) {\r\n int up = ar.upperBound(l-e-1).length;\r\n int dw = ar.upperBound(r-e).length;\r\n ans += up - dw;\r\n if(l <= 2*e && 2*e <= r) ans--;\r\n }\r\n writeln(ans/2);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.container, std.conv, std.stdio, std.string;\r\n\r\nvoid main() {\r\n foreach(_; 0 .. to!int(readln.strip)) {\r\n int n, l, r; readf(\"%d %d %d\\n\", n, l, r);\r\n auto ar = readln.strip.split.map!(to!int).array.sort;\r\n int ans = 0;\r\n foreach(e; ar) {\r\n int up = ar.upperBound(l-e-1).length;\r\n int dw = ar.upperBound(r-e).length;\r\n ans += up - dw;\r\n if(l <= 2*e && 2*e <= r) ans--;\r\n }\r\n writeln(ans/2);\r\n }\r\n}\r\n"}], "src_uid": "2f12b2bb23497119bb70ca0839991d68"} {"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\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 opUnary (string op : \"++\")() pure nothrow @nogc {\n if (++v >= q) {\n v -= q;\n }\n return this;\n }\n ref IntM opUnary (string op : \"--\")() pure nothrow @nogc {\n if (--v < 0) {\n v += q;\n }\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 -= 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 long rhs) const pure nothrow @nogc {\n IntM a = 1, b = this;\n long 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 int opCast(T : int)() const pure nothrow @nogc { return v; }\n int opCmp (const IntM rhs) const pure nothrow @nogc {\n if (v < rhs.v) {\n return -1;\n }\n if (v > rhs.v) {\n return 1;\n }\n return 0;\n }\n bool opEquals (const IntM rhs) const pure nothrow @nogc { return v == rhs.v; }\n string toString() const pure nothrow { return ((v < 0) ? v + q : v).text; }\n //a ^ x = this (mod q)\n int discreteLogarithm (in IntM a) const {\n enum int n = ceil (sqrt (q.to!double)).to!int;\n IntM an = a ^^ n;\n int[int] h;\n IntM cur = an;\n foreach (p; 1 .. n + 1) {\n auto ptr = cur.v !in h;\n if (cur.v !in h) {\n h[cur.v] = p;\n }\n cur *= an;\n }\n cur = this;\n int res = int.max;\n foreach (q; 0 .. n + 1) {\n auto ptr = cur.v in h;\n if (ptr) {\n res = min (res, *ptr * n - q); \n }\n cur *= a;\n }\n return res != int.max ? res : -1;\n }\n}\n\nstruct IntM2 {\n enum q = 1_000_000_006;\n int v;\n this (int m) pure nothrow @nogc {\n v = m % q;\n if (v < 0) {\n v += q;\n }\n }\n IntM2 opAssign (int m) pure nothrow @nogc {\n v = m % q;\n if (v < 0) {\n v += q;\n }\n return this;\n }\n IntM2 opUnary (string op : \"-\")() const pure nothrow @nogc {\n return IntM2 ((q - v) % q);\n }\n ref IntM2 opUnary (string op : \"++\")() pure nothrow @nogc {\n if (++v >= q) {\n v -= q;\n }\n return this;\n }\n ref IntM2 opUnary (string op : \"--\")() pure nothrow @nogc {\n if (--v < 0) {\n v += q;\n }\n return this;\n }\n ref IntM2 opOpAssign (string op : \"+\")(in IntM2 rhs) pure nothrow @nogc {\n v += rhs.v;\n v %= q;\n return this;\n }\n ref IntM2 opOpAssign (string op : \"-\")(in IntM2 rhs) pure nothrow @nogc {\n v -= rhs.v;\n v %= q;\n return this;\n }\n ref IntM2 opOpAssign (string op : \"*\")(in IntM2 rhs) pure nothrow @nogc {\n v = ((v.to!(long)) * rhs.v.to!(long)) % q;\n return this;\n }\n IntM2 opBinary (string op : \"+\")(in IntM2 rhs) const pure nothrow @nogc {\n return IntM2 ( (v + rhs.v) % q);\n }\n IntM2 opBinary (string op : \"-\")(in IntM2 rhs) const pure nothrow @nogc {\n return IntM2 ( (v - rhs.v) % q);\n }\n IntM2 opBinary (string op : \"*\")(in IntM2 rhs) const pure nothrow @nogc {\n return IntM2 (((v.to!(long)) * rhs.v.to!(long)) % q);\n }\n IntM2 opBinary (string op : \"^^\")(in long rhs) const pure nothrow @nogc {\n IntM2 a = 1, b = this;\n long 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 IntM2 opBinary (string op)(in int v) const pure nothrow @nogc if (op == \"+\" || op == \"-\" || op == \"*\") {\n mixin (\"return this \" ~ op ~ \" IntM2(v);\");\n }\n int opCast(T : int)() const pure nothrow @nogc { return v; }\n int opCmp (const IntM2 rhs) const pure nothrow @nogc {\n if (v < rhs.v) {\n return -1;\n }\n if (v > rhs.v) {\n return 1;\n }\n return 0;\n }\n bool opEquals (const IntM2 rhs) const pure nothrow @nogc { return v == rhs.v; }\n string toString() const pure nothrow { return ((v < 0) ? v + q : v).text; }\n}\n\nalias Matrix = IntM2[3][3];\nMatrix mul (in Matrix a, in Matrix b) {\n Matrix c;\n foreach (i; 0 .. 3) foreach (j; 0 .. 3) foreach (k; 0 .. 3) {\n c[i][j] += a[i][k] * b[k][j];\n }\n return c;\n}\n\nMatrix power (Matrix x, long rhs) {\n Matrix a;\n foreach (i; 0 .. 3) foreach (j; 0 .. 3) a[i][j] = IntM2 (i == j ? 1 : 0);\n Matrix b;\n foreach (i; 0 .. 3) b[i] = x[i].dup;\n long p = rhs;\n while (p > 0) {\n //a * (b ^ p) == x ^ rhs\n if (p & 1) {\n a = mul (a, b);\n }\n b = mul (b, b);\n p >>>= 1;\n }\n return a;\n}\n\nvoid main() {\n long n;\n int[4] f;\n int[4] h;\n int c;\n readf! \" %d %d %d %d %d\" (n, f[1], f[2], f[3], c);\n IntM[4] g;\n foreach (i; 1 .. 4) {\n g[i] = IntM (f[i]);\n foreach (j; 0 .. i) {\n g[i] *= IntM (c);\n }\n h[i] = g[i].to!int; \n }\n foreach (p; [2, 3, 5, 7, 11, 13, 17, 23, 27, 31]) {\n bool ok = true;\n foreach (i; 1 .. 4) {\n f[i] = IntM(h[i]).discreteLogarithm (IntM(p));\n if (f[i] < 0) {\n ok = false;\n break;\n }\n }\n if (ok) {\n debug stderr.writeln (\"p = \", p);\n Matrix q;\n foreach (i; 0 .. 3) foreach (j; 0 .. 3) q[i][j] = IntM2 (0);\n q[0][0] = q[0][1] = q[0][2] = q[1][0] = q[2][1] = IntM2 (1);\n Matrix w = power (q, n - 3);\n debug stderr.writeln (w);\n IntM2 res2 = 0;\n foreach (i; 0 .. 3) {\n res2 += IntM2 (f[3 - i]) * w[0][i];\n }\n debug stderr.writeln (res2);\n IntM res = IntM (p) ^^ res2.v;\n res *= (IntM (c) ^^ n) ^^ (IntM.q - 2);\n writeln (res);\n return;\n }\n }\n}\n\nunittest {\n enum DL_TESTS = 10;\n foreach (p; [2, 3, 5, 7, 11, 17]) {\n stderr.writeln (p);\n IntM a = p;\n IntM x = 1;\n foreach (j; 0 .. DL_TESTS) {\n assert (x.discreteLogarithm (a) == j);\n x *= a; \n }\n foreach (j; iota (100, 10007 * DL_TESTS, 10007)) {\n IntM y = IntM (p) ^^ j;\n assert (y.discreteLogarithm (a) == j);\n }\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\nT gcdext(T) (T a, T b, ref T x, ref T y) pure nothrow @nogc {\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n T res = gcdext (b, a % b, y, x);\n y -= x * (a / b);\n return res;\n}\n\nstruct IntM(int q = 1_000_000_007) {\n alias N = IntM!q;\n int v;\n private void fromInt (int m) pure nothrow @nogc {\n v = m % q;\n if (v < 0) {\n v += q;\n }\n }\n this (int m) pure nothrow @nogc {\n fromInt (m);\n }\n N opAssign (int m) pure nothrow @nogc {\n fromInt (m);\n return this;\n }\n N opUnary (string op : \"-\")() const pure nothrow @nogc {\n return N ((q - v) % q);\n }\n ref N opUnary (string op : \"++\")() pure nothrow @nogc {\n if (++v >= q) {\n v -= q;\n }\n return this;\n }\n ref N opUnary (string op : \"--\")() pure nothrow @nogc {\n if (--v < 0) {\n v += q;\n }\n return this;\n }\n ref N opOpAssign (string op : \"+\")(in N rhs) pure nothrow @nogc {\n v += rhs.v;\n v %= q;\n return this;\n }\n ref N opOpAssign (string op : \"-\")(in N rhs) pure nothrow @nogc {\n v -= rhs.v;\n v %= q;\n return this;\n }\n ref N opOpAssign (string op : \"*\")(in N rhs) pure nothrow @nogc {\n v = ((v.to!(long)) * rhs.v.to!(long)) % q;\n return this;\n }\n N opBinary (string op : \"+\")(in N rhs) const pure nothrow @nogc {\n return N ( (v + rhs.v) % q);\n }\n N opBinary (string op : \"-\")(in N rhs) const pure nothrow @nogc {\n return N ( (v - rhs.v) % q);\n }\n N opBinary (string op : \"*\")(in N rhs) const pure nothrow @nogc {\n return N (((v.to!(long)) * rhs.v.to!(long)) % q);\n }\n N opBinary (string op : \"/\")(in N rhs) const pure nothrow @nogc {\n return this * N.inversion ();\n }\n N inversion () const pure @nogc {\n int x, y;\n immutable g = gcdext!int (v, q, x, y);\n assert (g == 1);\n return N (x);\n }\n N opBinary (string op : \"^^\")(in long rhs) const pure nothrow @nogc {\n N a = 1, b = this;\n long 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 N opBinary (string op)(in int v) const pure nothrow @nogc if (op == \"+\" || op == \"-\" || op == \"*\") {\n mixin (\"return this \" ~ op ~ \" N(v);\");\n }\n int opCast(T : int)() const pure nothrow @nogc { return v; }\n int opCmp (const N rhs) const pure nothrow @nogc {\n if (v < rhs.v) {\n return -1;\n }\n if (v > rhs.v) {\n return 1;\n }\n return 0;\n }\n bool opEquals (const N rhs) const pure nothrow @nogc { return v == rhs.v; }\n string toString() const pure nothrow { return ((v < 0) ? v + q : v).text; }\n //a ^ x = this (mod q)\n int discreteLogarithm (in N a) const {\n enum int n = ceil (sqrt (q.to!double)).to!int;\n N an = a ^^ n;\n int[int] h;\n N cur = an;\n foreach (p; 1 .. n + 1) {\n auto ptr = cur.v !in h;\n if (cur.v !in h) {\n h[cur.v] = p;\n }\n cur *= an;\n }\n cur = this;\n int res = int.max;\n foreach (q; 0 .. n + 1) {\n auto ptr = cur.v in h;\n if (ptr) {\n res = min (res, *ptr * n - q); \n }\n cur *= a;\n }\n return res != int.max ? res : -1;\n }\n}\n\nalias Matrix = IntM2[3][3];\nMatrix mul (in Matrix a, in Matrix b) {\n Matrix c;\n foreach (i; 0 .. 3) foreach (j; 0 .. 3) foreach (k; 0 .. 3) {\n c[i][j] += a[i][k] * b[k][j];\n }\n return c;\n}\n\nMatrix power (Matrix x, long rhs) {\n Matrix a;\n foreach (i; 0 .. 3) foreach (j; 0 .. 3) a[i][j] = IntM2 (i == j ? 1 : 0);\n Matrix b;\n foreach (i; 0 .. 3) b[i] = x[i].dup;\n long p = rhs;\n while (p > 0) {\n //a * (b ^ p) == x ^ rhs\n if (p & 1) {\n a = mul (a, b);\n }\n b = mul (b, b);\n p >>>= 1;\n }\n return a;\n}\n\nalias IntM1 = IntM!();\nalias IntM2 = IntM!(1_000_000_006);\n\nvoid main() {\n long n;\n int[4] f;\n int[4] h;\n int c;\n readf! \" %d %d %d %d %d\" (n, f[1], f[2], f[3], c);\n IntM1[4] g;\n foreach (i; 1 .. 4) {\n g[i] = IntM1 (f[i]);\n foreach (j; 0 .. i) {\n g[i] *= IntM1 (c);\n }\n h[i] = g[i].to!int; \n }\n foreach (p; [2, 3, 5, 7, 11, 13, 17, 23, 27, 31]) {\n bool ok = true;\n foreach (i; 1 .. 4) {\n f[i] = IntM1(h[i]).discreteLogarithm (IntM1(p));\n if (f[i] < 0) {\n ok = false;\n break;\n }\n }\n if (ok) {\n debug stderr.writeln (\"p = \", p);\n Matrix q;\n foreach (i; 0 .. 3) foreach (j; 0 .. 3) q[i][j] = IntM2 (0);\n q[0][0] = q[0][1] = q[0][2] = q[1][0] = q[2][1] = IntM2 (1);\n Matrix w = power (q, n - 3);\n debug stderr.writeln (w);\n IntM2 res2 = 0;\n foreach (i; 0 .. 3) {\n res2 += IntM2 (f[3 - i]) * w[0][i];\n }\n debug stderr.writeln (res2);\n IntM1 res = IntM1 (p) ^^ res2.v;\n res *= (IntM1 (c) ^^ n).inversion ();\n writeln (res);\n return;\n }\n }\n}\n"}], "negative_code": [], "src_uid": "6fcd8713af5a108d590bc99da314cded"} {"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 read_string() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int read_int() { \n return read_string.to!int; \n }\n double read_double() { \n return read_string.to!double; \n }\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 for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (arr.canFind(arr[i] + arr[j])) {\n write(arr.length - arr.find(arr[i] + arr[j]).length + 1, \" \");\n writeln(i + 1, \" \", j + 1);\n return;\n }\n }\n }\n writeln(-1);\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 read_string() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int read_int() { \n return read_string.to!int; \n }\n double read_double() { \n return read_string.to!double; \n }\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 for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (arr.canFind(arr[i] + arr[j])) {\n write(countUntil(arr, arr.find(arr[i] + arr[j])) + 1, \" \");\n writeln(i + 1, \" \", j + 1);\n return;\n }\n }\n }\n writeln(-1);\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 read_string() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int read_int() { \n return read_string.to!int; \n }\n double read_double() { \n return read_string.to!double; \n }\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 for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (arr.canFind(arr[i] + arr[j])) {\n writeln(arr[i] + arr[j], \" \", arr[i], \" \", arr[j]);\n return;\n }\n }\n }\n writeln(-1);\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 read_string() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int read_int() { \n return read_string.to!int; \n }\n double read_double() { \n return read_string.to!double; \n }\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 for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (arr.canFind(arr[i] + arr[j])) {\n writeln(arr[i], \" \", arr[j], \" \", arr[i] + arr[j]);\n return;\n }\n }\n }\n writeln(-1);\n } \n}"}], "src_uid": "94a38067fc8dd8619fa6e5873ca60220"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto a = ma(n, readInt!int - 1);\n auto sa = a.dup; sort(sa);\n auto sPosS = new int[][](n);\n foreach(i, ai; sa) sPosS[ai] ~= cast(int)i;\n bool excedent = false;\n foreach(i; 0 .. n) if (sPosS[i].length > 1) excedent = true;\n debug writeln(\"sPosS \", sPosS);\n auto adj = new int[](n);\n foreach(i; 0 .. n)\n {\n assert(sPosS[a[i]].length > 0);\n adj[i] = sPosS[a[i]].front;\n sPosS[a[i]].popFront;\n }\n debug writeln(\"adj \", adj);\n auto visited = new bool[](n);\n int getPar(int i)\n {\n assert(!visited[i]);\n visited[i] = true;\n int ans = 1;\n if (!visited[adj[i]]) ans ^= getPar(adj[i]);\n return ans;\n }\n auto par = int(0);\n foreach(i; 0 .. n) if (!visited[i]) par ^= 1^getPar(i);\n if (excedent) return writeln(\"YES\");\n if (par) 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;\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 = read!int;\r\n auto A = readarray!int;\r\n\r\n bool f() {\r\n if (N == 1) return true;\r\n if (N == 2) return (A[0] <= A[1]);\r\n\r\n auto B = A.dup; B.sort;\r\n for (int i = 0; i+1 < N; i++) {\r\n if (B[i] == B[i+1]) return true;\r\n }\r\n\r\n long c = count_inversion(A);\r\n return c % 2 == 0;\r\n }\r\n writeln(f() ? \"YES\" : \"NO\");\r\n}\r\n\r\nlong count_inversion(T)(in T[] xs_) {\r\n long inversion = 0;\r\n auto xs = xs_.dup;\r\n auto buf = new T[xs.length];\r\n void f(int s, int t) {\r\n if (s + 1 == t) return;\r\n int mid = (s + t) / 2;\r\n int i = s;\r\n f(s, mid);\r\n f(mid, t);\r\n int li = s, ri = mid;\r\n while (li < mid || ri < t) {\r\n if (li == mid) { buf[i++] = xs[ri++]; continue; }\r\n if (ri == t) { buf[i++] = xs[li++]; continue; }\r\n if (xs[li] < xs[ri]) {\r\n buf[i++] = xs[li++];\r\n } else if (xs[li] > xs[ri]) {\r\n buf[i++] = xs[ri++];\r\n inversion += mid - li;\r\n } else {\r\n writefln(\"s = %d, t = %d\", s, t);\r\n writefln(\"li = %d, ri = %d, i = %d\", li, ri, i);\r\n assert(false);\r\n }\r\n }\r\n for (int j = s; j < t; j++) xs[j] = buf[j];\r\n assert(i == t);\r\n }\r\n f(0, xs.length);\r\n return inversion;\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 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 f() {\r\n if (N == 1) return true;\r\n if (N == 2) return (A[0] <= A[1]);\r\n long c = count_inversion(A);\r\n return c % 2 == 0;\r\n }\r\n writeln(f() ? \"YES\" : \"NO\");\r\n}\r\n\r\nlong count_inversion(T)(in T[] xs_) {\r\n long inversion = 0;\r\n auto xs = xs_.dup;\r\n auto buf = new T[xs.length];\r\n void f(int s, int t) {\r\n if (s + 1 == t) return;\r\n int mid = (s + t) / 2;\r\n int i = s;\r\n f(s, mid);\r\n f(mid, t);\r\n int li = s, ri = mid;\r\n while (li < mid || ri < t) {\r\n if (li == mid) { buf[i++] = xs[ri++]; continue; }\r\n if (ri == t) { buf[i++] = xs[li++]; continue; }\r\n if (xs[li] <= xs[ri]) {\r\n buf[i++] = xs[li++];\r\n } else if (xs[li] > xs[ri]) {\r\n buf[i++] = xs[ri++];\r\n inversion += mid - li;\r\n } else {\r\n writefln(\"s = %d, t = %d\", s, t);\r\n writefln(\"li = %d, ri = %d, i = %d\", li, ri, i);\r\n assert(false);\r\n }\r\n }\r\n for (int j = s; j < t; j++) xs[j] = buf[j];\r\n assert(i == t);\r\n }\r\n f(0, xs.length);\r\n return inversion;\r\n}\r\n"}, {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto a = ma(n, readInt!int - 1);\n auto sa = a.dup; sort(sa);\n auto sPosS = new int[][](n);\n foreach(i, ai; sa) sPosS[ai] ~= cast(int)i;\n debug writeln(\"sPosS \", sPosS);\n auto adj = new int[](n);\n foreach(i; 0 .. n)\n {\n assert(sPosS[a[i]].length > 0);\n adj[i] = sPosS[a[i]].front;\n sPosS[a[i]].popFront;\n }\n auto visited = new bool[](n);\n int getPar(int i)\n {\n assert(!visited[i]);\n visited[i] = true;\n int ans = 1;\n if (!visited[adj[i]]) ans ^= getPar(adj[i]);\n return ans;\n }\n auto par = int(0);\n foreach(i; 0 .. n) if (!visited[i]) par ^= 1^getPar(i);\n if (par) 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"}], "src_uid": "58bf218b0472e22e54cd39a7ce6bb612"} {"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\nint id(char c) {\n return cast(int)(c - 'a');\n}\n\nint diff(int mod, char c, in int[][] hist) {\n int ret = 0;\n auto N = hist.length;\n foreach (j; 0 .. 26) {\n if (j == c.id) continue;\n ret += hist[mod][j].abs;\n }\n return ret;\n}\n\nvoid main() {\n long N, M; scanf(\"%lld %lld\\n\", &N, &M);\n auto x = readln.chomp,\n y = readln.chomp;\n int X = cast(int)x.length,\n Y = cast(int)y.length;\n int gcd = gcd(X, Y);\n long lcm = cast(long)(X) / gcd * Y;\n auto histogram = new int[][](gcd, 26);\n foreach (int i, c; y) {\n histogram[i % gcd][c.id]++;\n }\n long ans = 0;\n foreach (int i, c; x) {\n ans += diff(i % gcd, c, histogram);\n }\n writeln(ans * (N * X / lcm));\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.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!long;\n auto m = next!long;\n auto x = next!string;\n auto y = next!string;\n auto g = gcd(cast(long)x.length, cast(long)y.length);\n auto lx = x.length / g;\n auto ly = y.length / g;\n debug writeln(g, \" \", ly);\n long matches = 0;\n foreach(cl; 0 .. g)\n {\n long[char] chrCnt;\n foreach(inst; 0 .. ly)\n\tchrCnt.require(y[cast(int)(inst * g + cl)], 0)++;\n foreach(inst; 0 .. lx)\n\tmatches += chrCnt.require(x[cast(int)(inst * g + cl)], 0);\n }\n assert(n * x.length == m * y.length);\n auto l = lx * y.length;\n auto lres = l - matches;\n auto res = (n * x.length) / l * lres;\n res.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;\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.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n auto n = next!long;\n auto m = next!long;\n auto x = next!string;\n auto y = next!string;\n auto g = gcd(x.length, y.length);\n auto lx = x.length / g;\n auto ly = y.length / g;\n debug writeln(g, \" \", ly);\n long matches = 0;\n foreach(cl; 0 .. g)\n {\n long[char] chrCnt;\n foreach(inst; 0 .. ly)\n\tchrCnt.require(y[inst * g + cl], 0)++;\n foreach(inst; 0 .. lx)\n\tmatches += chrCnt.require(x[inst * g + cl], 0);\n }\n assert(n * x.length == m * y.length);\n auto l = lx * y.length;\n auto lres = l - matches;\n auto res = (n * x.length) / l * lres;\n res.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.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\nint id(char c) {\n return cast(int)(c - 'a');\n}\n\nint diff(int mod, char c, in int[][] hist) {\n int ret = 0;\n auto N = hist.length;\n foreach (j; 0 .. 26) {\n if (j == c.id) continue;\n ret += hist[mod][j].abs;\n }\n return ret;\n}\n\nvoid main() {\n long N, M; scanf(\"%lld %lld\\n\", &N, &M);\n auto x = readln.chomp,\n y = readln.chomp;\n int X = cast(int)x.length,\n Y = cast(int)y.length;\n int gcd = gcd(X, Y);\n long lcm = X / gcd * Y;\n auto histogram = new int[][](gcd, 26);\n foreach (int i, c; y) {\n histogram[i % gcd][c.id]++;\n }\n long ans = 0;\n foreach (int i, c; x) {\n ans += diff(i % gcd, c, histogram);\n }\n writeln(ans * (N * X / lcm));\n}\n"}], "src_uid": "cd921b5fc4140f1cd19e73c42b3bc2fe"} {"source_code": "// Codeforces My Practice\n// author: Leonardone @ NEETSDKASU\nimport std.stdio, std.string, std.array, std.algorithm, std.conv, std.range;\n\n// no my think\n\nvoid main() {\n auto nk = to!(int[])(split(chomp(readln())));\n int n = nk[0], k = nk[1];\n auto xs = to!(long[])(split(chomp(readln())));\n int[5300][201] tb;\n for (int i = 0; i <= k; i++) {\n for (int j = 0; j < 5300; j++) {\n tb[i][j] = -1;\n }\n }\n tb[0][0] = 0;\n foreach (x ; xs) {\n int c2, c5;\n while (x % 2 == 0) {\n x /= 2;\n c2++;\n }\n while (x % 5 == 0) {\n x /= 5;\n c5++;\n }\n for (int i = k - 1; i > 0; i--) {\n for (int j = 5299; j >= 0; j--) {\n if (tb[i][j] < 0) { continue; }\n tb[i+1][j+c5] = max(tb[i+1][j+c5], tb[i][j]+c2);\n }\n }\n tb[1][c5] = max(tb[1][c5], c2);\n }\n int ans = 0;\n for (int i = 1; i < 5300; i++) {\n if (tb[k][i] < 0) { continue; }\n ans = max(ans, min(tb[k][i], i));\n }\n writeln(ans);\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, k;\nlong[] a;\n\nvoid main() {\n scan(n, k);\n a = readln.split.to!(long[]);\n\n auto two = new int[](n);\n auto five = new int[](n);\n\n foreach (i ; 0 .. n) {\n while (a[i] % 2 == 0) {\n a[i] /= 2;\n two[i]++;\n }\n\n while (a[i] % 5 == 0) {\n a[i] /= 5;\n five[i]++;\n }\n }\n\n int lim = n * 25;\n\n auto dp = new int[][][](2, k + 1, lim + 1);\n fillAll(dp, -1);\n dp[0][0][0] = 0;\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. k + 1) {\n foreach (f ; 0 .. lim + 1) {\n if (dp[i & 1][j][f] == -1) continue;\n dp[(i & 1) ^ 1][j][f] = max(dp[(i & 1) ^ 1][j][f], dp[i & 1][j][f]);\n\n if (j + 1 <= k) {\n dp[(i & 1) ^ 1][j + 1][f + five[i]] = max(dp[(i & 1) ^ 1][j + 1][f + five[i]], dp[i & 1][j][f] + two[i]);\n }\n }\n }\n }\n\n int ans;\n\n foreach (f ; 0 .. lim + 1) {\n ans = max(ans, min(f, dp[n & 1][k][f]));\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}"}, {"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 auto two = new int[](N);\n auto five = new int[](N);\n foreach (i, a; A) {\n while (a % 2 == 0) a /= 2, two[i] += 1;\n while (a % 5 == 0) a /= 5, five[i] += 1;\n }\n\n auto dp = new int[][][](2, M+1, 25*N+1);\n auto ok = new bool[][][](2, M+1, 25*N+1);\n ok[0][0][0] = true;\n int cur = 0, tar = 1;\n\n foreach (i; 0..N) {\n foreach (j; 0..M+1) {\n dp[tar][j][] = 0;\n ok[tar][j][] = 0;\n }\n foreach (j; 0..M+1) foreach (k; 0..25*i+1) if (ok[cur][j][k]) {\n dp[tar][j][k] = max(dp[tar][j][k], dp[cur][j][k]);\n ok[tar][j][k] = true;\n if (j < M) {\n dp[tar][j+1][k+five[i]] = max(dp[tar][j+1][k+five[i]], dp[cur][j][k] + two[i]);\n ok[tar][j+1][k+five[i]] = true;\n }\n }\n swap(cur, tar);\n }\n\n int ans = 0;\n foreach (j; 0..M+1) foreach (k; 0..25*N+1) {\n ans = max(ans, min(k, dp[cur][j][k]));\n }\n ans.writeln;\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, k;\nlong[] a;\n\nvoid main() {\n scan(n, k);\n a = readln.split.to!(long[]);\n\n auto two = new int[](n);\n auto five = new int[](n);\n\n foreach (i ; 0 .. n) {\n while (a[i] % 2 == 0) {\n a[i] /= 2;\n two[i]++;\n }\n\n while (a[i] % 5 == 0) {\n a[i] /= 5;\n five[i]++;\n }\n }\n\n int lim = n * 25;\n\n auto dp = new int[][][](2, k + 1, lim + 1);\n fillAll(dp, -1);\n dp[0][0][0] = 0;\n\n foreach (i ; 0 .. n) {\n foreach (j ; 0 .. k + 1) {\n foreach (f ; 0 .. lim + 1) {\n if (dp[i & 1][j][f] == -1) continue;\n dp[(i & 1) ^ 1][j][f] = max(dp[(i & 1) ^ 1][j][f], dp[i & 1][j][f]);\n\n if (j + 1 <= k) {\n dp[(i & 1) ^ 1][j + 1][f + five[i]] = max(dp[(i & 1) ^ 1][j + 1][f + five[i]], dp[i & 1][j][f] + two[i]);\n }\n }\n }\n }\n\n int ans;\n\n foreach (f ; 0 .. lim + 1) {\n ans = max(ans, min(f, dp[n & 1][k][f]));\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": [{"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 A = readln.split.map!(to!long).array;\n auto TF = new Tuple!(int, int)[](N);\n\n foreach (i; 0..N) {\n while (A[i] % 5 == 0) {\n TF[i][1] += 1;\n A[i] /= 5;\n }\n while (A[i] % 2 == 0) {\n TF[i][0] += 1;\n A[i] /= 2;\n }\n }\n\n auto dp = new int[][](N + 1, 4000);\n auto dp2 = new bool[][](N + 1, 4000);\n dp2[0][0] = true;\n \n foreach (i; 0..N) {\n for (int j = i + 1; j >= 1; j--) {\n foreach (k; 0..3800) {\n if (k - TF[i][1] >= 0 && dp2[j - 1][k - TF[i][1]]) {\n dp[j][k] = max(dp[j][k], dp[j - 1][k - TF[i][1]] + TF[i][0]);\n dp2[j][k] = true;\n }\n }\n }\n dp[1][TF[i][1]] = max(dp[1][TF[i][1]], TF[i][0]);\n dp2[1][TF[i][1]] = true;\n }\n\n \n int ans = 0;\n foreach (i; 0..3800) {\n if (dp2[K][i]) ans = max(ans, min(i, dp[K][i]));\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;\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 TF = new Tuple!(int, int)[](N);\n\n foreach (i; 0..N) {\n while (A[i] % 5 == 0) {\n TF[i][1] += 1;\n A[i] /= 5;\n }\n while (A[i] % 2 == 0) {\n TF[i][0] += 1;\n A[i] /= 2;\n }\n }\n\n auto dp = new int[][](N + 1, 4000);\n auto dp2 = new bool[][](N + 1, 4000);\n dp2[0][0] = true;\n \n foreach (i; 0..N) {\n for (int j = i + 1; j >= 1; j--) {\n foreach (k; 0..3800) {\n if (k - TF[i][1] >= 0 && dp2[j - 1][k - TF[i][1]]) {\n dp[j][k] = max(dp[j][k], dp[j - 1][k - TF[i][1]] + TF[i][0]);\n dp2[j][k] = true;\n }\n }\n }\n dp[1][TF[i][1]] = max(dp[1][TF[i][1]], TF[i][0]);\n dp2[1][TF[i][1]] = true;\n }\n\n \n int ans = 0;\n foreach (i; 0..3800) {\n if (dp2[K][i]) ans = max(ans, min(i, dp[K][i]));\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;\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 TF = new Tuple!(int, int)[](N);\n\n foreach (i; 0..N) {\n while (A[i] % 5 == 0) {\n TF[i][1] += 1;\n A[i] /= 5;\n }\n while (A[i] % 2 == 0) {\n TF[i][0] += 1;\n A[i] /= 2;\n }\n }\n\n auto dp = new int[][](N + 1, 2000);\n auto dp2 = new bool[][](N + 1, 2000);\n dp2[0][0] = true;\n \n foreach (i; 0..N) {\n for (int j = i + 1; j >= 1; j--) {\n foreach (k; 0..1900) {\n if (k - TF[i][1] >= 0 && dp2[j - 1][k - TF[i][1]]) {\n dp[j][k] = max(dp[j][k], dp[j - 1][k - TF[i][1]] + TF[i][0]);\n dp2[j][k] = true;\n }\n }\n }\n dp[1][TF[i][1]] = max(dp[1][TF[i][1]], TF[i][0]);\n dp2[1][TF[i][1]] = true;\n }\n\n int ans = 0;\n foreach (i; 0..1900) {\n if (dp2[K][i]) ans = max(ans, min(i, dp[K][i]));\n }\n ans.writeln;\n}\n"}], "src_uid": "ea0de6955a0ddf56980cb1ac7216e8b7"} {"source_code": "import std.numeric;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m))\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\ta[i]--;\n\t\t}\n\n\t\tint d;\n\t\tforeach (i; 0..n)\n\t\t\td = gcd (d, a[i]);\n\t\twhile (d % 2 == 0)\n\t\t\td /= 2;\n\n\t\tlong res;\n\n\t\tvoid add (int x)\n\t\t{\n\t\t\twhile (x < m)\n\t\t\t\tres += m - x,\n\t\t\t\tx *= 2;\n\t\t}\n\n\t\tfor (int w = 1; w * w <= d; w += 2)\n\t\t\tif (d % w == 0)\n\t\t\t{\n\t\t\t\tadd (w);\n\t\t\t\tif (w * w < d)\n\t\t\t\t\tadd (d / w);\n\t\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.numeric;\nimport std.stdio;\n\nint main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m))\n\t{\n\t\tm--;\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\ta[i]--;\n\t\t}\n\n\t\tint d = 0;\n\t\tforeach (i; 0..n)\n\t\t\td = gcd (d, a[i]);\n\t\twhile (d % 2 == 0)\n\t\t\td /= 2;\n\n\t\tlong res = 0;\n\n\t\tvoid add (int x)\n\t\t{\n\t\t\twhile (x <= m)\n\t\t\t{\n\t\t\t\tres += m - x + 1;\n\t\t\t\tx *= 2;\n\t\t\t}\n\t\t}\n\n\t\tfor (int w = 1; w * w <= d; w += 2)\n\t\t\tif (d % w == 0)\n\t\t\t{\n\t\t\t\tadd (w);\n\t\t\t\tif (w * w < d)\n\t\t\t\t\tadd (d / w);\n\t\t\t}\n\t\twritefln (\"%s\", res);\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.math;\nimport std.numeric;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint main ()\n{\n\tint n;\n\tlong m;\n\twhile ((readf (\" %s %s\", &n, &m) >= 0) && !stdin.eof ())\n\t{\n\t\tm--;\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\ta[i]--;\n\t\t}\n\n\t\tint d = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\td = gcd (d, a[i]);\n\t\t}\n\t\twhile (d % 2 == 0)\n\t\t{\n\t\t\td /= 2;\n\t\t}\n\n\t\tlong res = 0;\n\n\t\tvoid add (int x)\n\t\t{\n\t\t\twhile (x <= m)\n\t\t\t{\n\t\t\t\tres += m - x + 1;\n\t\t\t\tx *= 2;\n\t\t\t}\n\t\t}\n\n\t\tfor (int w = 1; w * w <= d; w += 2)\n\t\t{\n\t\t\tif (d % w == 0)\n\t\t\t{\n\t\t\t\tadd (w);\n\t\t\t\tif (w * w < d)\n\t\t\t\t{\n\t\t\t\t\tadd (d / w);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twritefln (\"%s\", res);\n\t}\n\treturn 0;\n}\n"}], "negative_code": [], "src_uid": "189a8a9a6e99ed52bda9a5773bf2621b"} {"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\tforeach (a; [7 * 2, 5 * 3])\n\t\t{\n\t\t\tauto p = [2 * 3, 2 * 5, a];\n\t\t\tp ~= n - p.sum;\n\t\t\tsort (p);\n\t\t\tif (p[0] > 0 && isStrictlyMonotonic (p))\n\t\t\t{\n\t\t\t\twriteln (\"YES\");\n\t\t\t\twritefln !(\"%(%s %)\") (p);\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": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tif (n <= 30) continue;\n\t\tif (n-30 == 6 || n-30 == 10 || n-30 == 14)\n\t\t\tans[ti] = [6, 10, 15, n-31];\n\t\telse\n\t\t\tans[ti] = [6, 10, 14, n-30];\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}"}], "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\tif (n <= 30) continue;\n\t\tans[ti] = [6, 10, 14, n-30];\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}"}], "src_uid": "8a6c3436f73286ca54f51fb90017a299"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int a, b, c, d;\n a = rd!int;\n b = rd!int;\n c = rd!int;\n d = rd!int;\n writeln(max(a+b, c+d));\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.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, c, d;\n\t\treadf !(\" %s %s %s %s\") (a, b, c, d);\n\t\twriteln (max (a + b, c + d));\n\t}\n}\n"}], "negative_code": [], "src_uid": "a60321dd9ada279c007415f28775099b"} {"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 char[] s, t; get(s); get(t);\r\n char[] r;\r\n if (s.length > t.length) swap(s, t);\r\n foreach (l; 1..s.length + 1) if (s.length % l == 0 && t.length % l == 0) {\r\n auto x = s[0..l];\r\n auto n = (s.length / l) * (t.length / l) / gcd(s.length / l, t.length / l);\r\n foreach (i; 0..s.length / l) if (s[i * l..i * l + l] != x) goto next;\r\n foreach (i; 0..t.length / l) if (t[i * l..i * l + l] != x) goto next;\r\n if (r.empty || r.length > l * n) {\r\n r = [];\r\n foreach (_; 0..n) r ~= x;\r\n }\r\n next:\r\n }\r\n if (r.empty) {\r\n writeln(-1);\r\n } else {\r\n writeln(r);\r\n }\r\n }\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.numeric;\r\nvoid main()\r\n{\r\n int q;\r\n readf!\"%d\\n\"(q);\r\n foreach (_; 0 .. q)\r\n {\r\n string s = readln.strip, t = readln.strip;\r\n auto n = s.length, m = t.length, g = gcd(n, m);\r\n string res = s[0 .. g];\r\n while (res.length % n || res.length % m)\r\n res ~= s[0 .. g];\r\n writeln(res[0 .. n] == s && res[0 .. m] == t ? res : \"-1\");\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 s1 = RD!string;\r\n\t\tauto s2 = RD!string;\r\n\r\n\t\tauto len = lcm(s1.length, s2.length);\r\n\t\twhile (ans[ti].length < len)\r\n\t\t{\r\n\t\t\tans[ti] ~= s1;\r\n\t\t}\r\n\t\tstring s3;\r\n\t\twhile (s3.length < len)\r\n\t\t{\r\n\t\t\ts3 ~= s2;\r\n\t\t}\r\n\t\tforeach (i; 0..s3.length)\r\n\t\t{\r\n\t\t\tif (ans[ti][i] != s3[i])\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}\r\n\t}\r\n\r\n\tforeach (e; ans)\r\n\t{\r\n\t\twriteln(e.empty ? \"-1\" : 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.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 s = readln.strip;\r\n\t\tauto t = readln.strip;\r\n\t\tauto m = s.length;\r\n\t\tauto n = t.length;\r\n\t\tauto g = gcd (m, n);\r\n\t\tauto x = s[0..g];\r\n\t\tauto r = x;\r\n\t\twhile (r.length % m != 0 || r.length % n != 0)\r\n\t\t{\r\n\t\t\tr ~= x;\r\n\t\t}\r\n\t\twriteln ((r[0..m] == s && r[0..n] == t) ? r : \"-1\");\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "710c7211d23cf8c01fae0b476a889276"} {"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, x;\n readf!\" %d %d %d \"(n, k, x);\n auto s = readln.strip;\n x--;\n string[] ans;\n foreach_reverse (chunk ; s.split('a')) {\n auto cnt = x % (chunk.length * k + 1);\n x /= (chunk.length * k + 1);\n ans ~= replicate(\"b\", cast(size_t)cnt);\n }\n writeln(ans.retro.join('a'));\n }\n}\n", "positive_code": [{"source_code": "immutable multi = true;\n\nuint n, k;\nulong x;\nbyte[] s;\n\nvoid readInput()\n{\n n = readInt!uint;\n k = readInt!uint;\n x = readInt!ulong;\n s = cast(byte[]) readString;\n debug writeln(\"read string \", s);\n}\n\nvoid genInput()\n{\n import std.random;\n foreach(i; 0 .. 100) s ~= \"*a\"[0];\n n = cast(uint) s.length;\n k = 0;\n x = 1;\n debug writeln(\"generated \", cast(string)s);\n}\nalias input = readInput;\n\nvoid solve(int tc)\n{\n debug writeln(\"called solve with \", tc, \" \", s);\n uint[] groups;\n bool open = false;\n foreach(si; s)\n {\n debug writeln(\"in char \", si);\n final switch(si)\n\t{\n\tcase '*':\n\t if (open)\n\t {\n\t groups[$-1]++;\n\t }\n\t else\n\t {\n\t groups ~= 1;\n\t }\n\t open = true;\n\t break;\n\tcase 'a':\n\t open = false;\n\t break;\n\t}\n }\n debug writeln(\"groups \", groups);\n foreach(ref gi; groups)\n {\n gi = k * gi + 1;\n }\n import std.experimental.checkedint;\n auto order = new ulong[](groups.length);\n Checked!(ulong, Saturate) prevOrder = ulong(1);\n foreach_reverse(i; 0 .. order.length)\n {\n order[i] = (prevOrder * groups[i]).get;\n prevOrder = order[i];\n }\n auto digits = new long[](groups.length);\n void fillDigits(uint i, ulong xth)\n {\n if (i+1 == digits.length)\n {\n\tdigits[i] = xth;\n\treturn;\n }\n digits[i] = xth / order[i + 1];\n xth = xth % order[i + 1];\n fillDigits(i + 1, xth);\n }\n if (digits) fillDigits(0, x - 1);\n int currentGroup = 0;\n byte[] ans;\n open = false;\n foreach(si; s)\n {\n final switch(si)\n\t{\n\tcase '*':\n\t if (!open)\n\t {\n\t foreach(i; 0 .. digits[currentGroup])\n\t\tans ~= 'b';\n\t open = true;\n\t currentGroup++;\n\t }\n\t break;\n\tcase 'a':\n\t open = false;\n\t ans ~= 'a';\n\t break;\n\t}\n }\n writeln(cast(string)ans);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t)\n\t {\n\t input();\n\t solve(tc);\n\t }\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;\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<<60;\r\n\r\nvoid solve() {\r\n int N, K; long X; scanf(\"%d %d %lld\\n\", &N, &K, &X);\r\n X--;\r\n auto S = readln.strip;\r\n\r\n long[] M; {\r\n bool prev = false;\r\n for (int i = 0; i < N; i++) {\r\n if (S[i] == '*') {\r\n if (prev) { M.back += K; }\r\n else {\r\n M ~= K + 1;\r\n }\r\n prev = true;\r\n } else {\r\n prev = false;\r\n }\r\n }\r\n }\r\n\r\n int m = cast(int)(M.length);\r\n auto Y = new long[m];\r\n for (int i = m - 1; i >= 0; i--) {\r\n Y[i] = X % M[i];\r\n X /= M[i];\r\n }\r\n\r\n char[] ans; {\r\n int j = 0;\r\n bool prev = false;\r\n for (int i = 0; i < N; i++) {\r\n if (S[i] == '*') {\r\n if (prev) {\r\n // do nothing\r\n } else {\r\n foreach (_; 0 .. Y[j]) {\r\n ans ~= 'b';\r\n }\r\n j++;\r\n }\r\n prev = true;\r\n } else {\r\n ans ~= 'a';\r\n prev = false;\r\n }\r\n }\r\n assert(j == m);\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;\n\nint[]\ngenStars (in string s) {\n int[] ret = [0];\n\n foreach (c; s)\n if (c == '*')\n ++ ret[$ - 1];\n else if (c == 'a' && ret[$ - 1] != 0)\n ret ~= 0;\n\n if (ret[$ - 1] == 0)\n ret = ret[0 .. $ - 1];\n\n return ret;\n}\n\nvoid\nsolve () {\n int n, k;\n ulong x;\n string s;\n\n readf(\"%s %s %s\\n\", n, k, x);\n s = readln()[0 .. $ - 1];\n -- x;\n\n int[] stars = genStars(s);\n if (stars.length == 0) {\n writeln(s);\n return;\n }\n\n stars[] = stars[] * k + 1;\n\n size_t index = stars.length;\n real product = 1;\n\n while (product <= x) {\n -- index;\n product *= stars[index];\n }\n\n uint[] ans = new uint[stars.length];\n\n while (x != 0) {\n ulong prefix = cast(ulong)(product / stars[index]);\n ans[index] = cast(uint)(x / prefix);\n x %= prefix;\n product = prefix;\n ++ index;\n }\n\n index = 0;\n for (size_t i = 0; i != s.length; ++ i) {\n if (s[i] == 'a')\n write('a');\n else {\n while (i != s.length && s[i] == '*')\n ++ i;\n -- i;\n write('b'.repeat(ans[index]));\n ++ index;\n }\n }\n writeln();\n}\n\nvoid main () {\n int t;\n readf(\"%s\\n\", t);\n\n foreach (__sth; 0 .. t) {\n solve();\n }\n}\n\n\n// \"\"\n"}], "negative_code": [{"source_code": "import std;\n\nint[]\ngenStars (in string s) {\n int[] ret = [0];\n\n foreach (c; s)\n if (c == '*')\n ++ ret[$ - 1];\n else if (c == 'a' && ret[$ - 1] != 0)\n ret ~= 0;\n\n if (ret.length > 1 && ret[$ - 1] == 0)\n ret = ret[0 .. $ - 1];\n\n return ret;\n}\n\nvoid\nsolve () {\n int n, k;\n ulong x;\n string s;\n\n readf(\"%s %s %s\\n\", n, k, x);\n s = readln()[0 .. $ - 1];\n -- x;\n\n int[] stars = genStars(s);\n stars[] = stars[] * k + 1;\n\n size_t index = stars.length - 1;\n ulong product = stars[index];\n\n while (product < x) {\n -- index;\n product *= stars[index];\n }\n\n //writeln(stars);\n\n int[] ans = new int[stars.length];\n\n while (x != 0) {\n ulong prefix = product / stars[index];\n ans[index] = cast(int)(x / prefix);\n x %= prefix;\n product = prefix;\n ++ index;\n }\n\n index = 0;\n for (size_t i = 0; i != s.length; ++ i) {\n if (s[i] == 'a')\n write('a');\n else {\n while (i != s.length && s[i] == '*')\n ++ i;\n -- i;\n write('b'.repeat(ans[index]));\n ++ index;\n }\n }\n writeln();\n}\n\nvoid main () {\n int t;\n readf(\"%s\\n\", t);\n\n foreach (__sth; 0 .. t) {\n solve();\n }\n}\n\n\n// \"\"\n"}, {"source_code": "import std;\n\nint[]\ngenStars (in string s) {\n int[] ret = [0];\n\n foreach (c; s)\n if (c == '*')\n ++ ret[$ - 1];\n else if (c == 'a' && ret[$ - 1] != 0)\n ret ~= 0;\n\n return ret;\n}\n\nvoid\nsolve () {\n int n, k;\n ulong x;\n string s;\n\n readf(\"%s %s %s\\n\", n, k, x);\n s = readln()[0 .. $ - 1];\n -- x;\n\n int[] stars = genStars(s);\n stars[] = stars[] * k + 1;\n\n size_t index = stars.length - 1;\n ulong product = stars[index];\n\n while (product < x) {\n -- index;\n product *= stars[index];\n }\n\n int[] ans = new int[stars.length];\n\n while (x != 0) {\n ulong prefix = product / stars[index];\n ans[index] = cast(int)(x / prefix);\n x %= prefix;\n product = prefix;\n ++ index;\n }\n\n index = 0;\n for (size_t i = 0; i != s.length; ++ i) {\n if (s[i] == 'a')\n write('a');\n else {\n while (i != s.length && s[i] == '*')\n ++ i;\n -- i;\n write('b'.repeat(ans[index]));\n ++ index;\n }\n }\n writeln();\n}\n\nvoid main () {\n int t;\n readf(\"%s\\n\", t);\n\n foreach (__sth; 0 .. t) {\n solve();\n }\n}\n\n\n// \"\"\n"}, {"source_code": "immutable multi = true;\n\nuint n, k;\nulong x;\nbyte[] s;\n\nvoid readInput()\n{\n auto n = readInt!uint;\n auto k = readInt!uint;\n auto x = readInt!ulong;\n auto s = cast(byte[]) readString;\n}\n\nvoid genInput()\n{\n import std.random;\n foreach(i; 0 .. 100) s ~= \"*a\"[0];\n n = cast(uint) s.length;\n k = 0;\n x = 1;\n debug writeln(\"generated \", cast(string)s);\n}\nalias input = readInput;\n\nvoid solve(int tc)\n{\n uint[] groups;\n bool open = false;\n foreach(si; s)\n {\n final switch(si)\n\t{\n\tcase '*':\n\t if (open)\n\t {\n\t groups[$-1]++;\n\t }\n\t else\n\t {\n\t groups ~= 1;\n\t }\n\t open = true;\n\t break;\n\tcase 'a':\n\t open = false;\n\t break;\n\t}\n }\n foreach(ref gi; groups)\n {\n gi = k * gi + 1;\n }\n import std.experimental.checkedint;\n auto order = new ulong[](groups.length);\n Checked!(ulong, Saturate) prevOrder = ulong(1);\n foreach_reverse(i; 0 .. order.length)\n {\n order[i] = (prevOrder * groups[i]).get;\n prevOrder = order[i];\n }\n auto digits = new long[](groups.length);\n void fillDigits(uint i, ulong xth)\n {\n if (i+1 == digits.length)\n {\n\tdigits[i] = xth;\n\treturn;\n }\n digits[i] = xth / order[i + 1];\n xth = xth % order[i + 1];\n fillDigits(i + 1, xth);\n }\n if (digits) fillDigits(0, x - 1);\n int currentGroup = 0;\n byte[] ans;\n open = false;\n foreach(si; s)\n {\n final switch(si)\n\t{\n\tcase '*':\n\t if (!open)\n\t {\n\t foreach(i; 0 .. digits[currentGroup])\n\t\tans ~= 'b';\n\t open = true;\n\t currentGroup++;\n\t }\n\t break;\n\tcase 'a':\n\t open = false;\n\t ans ~= 'a';\n\t break;\n\t}\n }\n writeln(cast(string)ans);\n}\n\n// main {{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1; \n\tforeach(tc; 0 .. t)\n\t {\n\t input();\n\t solve(tc);\n\t }\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": "32ed4995e557cfdcbef375e2b9edb1a6"} {"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\tstring s = rstring;\n\t\tbool[] ls = s.map!(c => c == '<').array;\n\n\t\tint[] us;\n\t\t{\n\t\t\tint u = 1;\n\t\t\tforeach(l; ls){\n\t\t\t\tif(l){\n\t\t\t\t\tu += 1;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tus ~= u;\n\t\t\t\t\tu = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tus ~= u;\n\t\t}\n\t\tlog(\"us:\", us);\n\t\tint sum = 0;\n\t\tint[] ans;\n\t\tforeach(u; us){\n\t\t\tforeach(i; n - sum - u + 1 .. n - sum + 1) ans ~= i;\n\t\t\tsum += u;\n\t\t}\n\t\tans.map!(to!string).array.join(\" \").writeln;\n\n\t\tint[] vs;\n\t\t{\n\t\t\tint v = 1;\n\t\t\tforeach(l; ls){\n\t\t\t\tif(l){\n\t\t\t\t\tvs ~= v;\n\t\t\t\t\tv = 1;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tv += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tvs ~= v;\n\t\t}\n\t\tlog(\"vs:\", vs);\n\t\tint sum2 = 0;\n\t\tint[] ans2;\n\t\tforeach(int j, v; vs){\n\t\t\tforeach_reverse(i; n - sum2 - (v - 1) + 1 .. n - sum2 + 1) ans2 ~= i;\n\t\t\tans2 ~= j + 1;\n\t\t\tsum2 += v - 1;\n\t\t}\n\t\tans2.map!(to!string).array.join(\" \").writeln;\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 int[][](t*2);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\t\t{\n\t\t\tauto ai = ti * 2;\n\t\t\tint x = n;\n\t\t\tint i;\n\t\t\twhile (i < n-1)\n\t\t\t{\n\t\t\t\tif (s[i] == '>')\n\t\t\t\t{\n\t\t\t\t\tans[ai] ~= x;\n\t\t\t\t\t--x;\n\t\t\t\t\t++i;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint cnt;\n\t\t\t\t\tforeach (j; i..n-1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (s[j] == '>') break;\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t}\n\t\t\t\t\tforeach (j; 0..cnt+1)\n\t\t\t\t\t{\n\t\t\t\t\t\tans[ai] ~= x - cnt + j;\n\t\t\t\t\t}\n\t\t\t\t\tx -= cnt + 1;\n\t\t\t\t\ti += cnt + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x >= 1)\n\t\t\t\tans[ai] ~= x;\n\t\t}\n\t\t{\n\t\t\tauto ai = ti * 2 + 1;\n\t\t\tint x = 1;\n\t\t\tint i;\n\t\t\twhile (i < n-1)\n\t\t\t{\n\t\t\t\tif (s[i] == '<')\n\t\t\t\t{\n\t\t\t\t\tans[ai] ~= x;\n\t\t\t\t\t++x;\n\t\t\t\t\t++i;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tint cnt;\n\t\t\t\t\tforeach (j; i..n-1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (s[j] == '<') break;\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t}\n\t\t\t\t\tforeach (j; 0..cnt+1)\n\t\t\t\t\t{\n\t\t\t\t\t\tans[ai] ~= x + cnt - j;\n\t\t\t\t\t}\n\t\t\t\t\tx += cnt + 1;\n\t\t\t\t\ti += cnt + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (x <= n)\n\t\t\t\tans[ai] ~= x;\n\t\t}\n\t}\n\tforeach (e; ans)\n\t\te.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "fd0e9b90f36611c28fa8aca5b4e59ae9"} {"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\nint solve(string s, string t)\r\n{\r\n auto n = to!int(s.length), m = to!int(t.length);\r\n auto next = new int[][](n, 26);\r\n fill(next[n - 1], n);\r\n next[n - 1][s[n - 1] - 'a'] = n - 1;\r\n foreach_reverse (i; 0 .. n - 1)\r\n {\r\n next[i + 1].copy(next[i]);\r\n next[i][s[i] - 'a'] = i;\r\n }\r\n auto prev = new int[][](n, 26);\r\n fill(prev[0], -1);\r\n prev[0][s[0] - 'a'] = 0;\r\n foreach (i; 1 .. n)\r\n {\r\n prev[i - 1].copy(prev[i]);\r\n prev[i][s[i] - 'a'] = i;\r\n }\r\n auto fp = new int[m];\r\n fp[0] = next[0][t[0] - 'a'];\r\n foreach (i; 1 .. m) fp[i] = next[fp[i - 1] + 1][t[i] - 'a'];\r\n auto bp = new int[m];\r\n bp[m - 1] = prev[n - 1][t[m - 1] - 'a'];\r\n foreach_reverse (i; 0 .. m - 1) bp[i] = prev[bp[i + 1] - 1][t[i] - 'a'];\r\n int res;\r\n foreach (i; 0 .. m - 1) res = max(res, bp[i + 1] - fp[i]);\r\n return res;\r\n}\r\n \r\nint main(string[] args)\r\n{\r\n readln;\r\n auto s = readln.strip;\r\n auto t = readln.strip;\r\n auto ret = solve(s, t);\r\n writeln(ret);\r\n return 0;\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 N, M; get(N, M);\r\n char[] S, T; get(S); get(T);\r\n\r\n auto ii = new int[]['z' + 1];\r\n auto jj = new int[]['z' + 1];\r\n foreach (i, c; S) {\r\n ii[c] ~= i.to!int;\r\n jj[c] ~= i.to!int;\r\n }\r\n auto ls = new int[](M);\r\n auto rs = new int[](M);\r\n int l = -1, r = N;\r\n foreach (i, c; T) {\r\n while (ii[c].front <= l) ii[c].popFront();\r\n ls[i] = l = ii[c].front;\r\n }\r\n foreach_reverse (i, c; T) {\r\n while (jj[c][$ - 1] >= r) jj[c] = jj[c][0..$ - 1];\r\n rs[i] = r = jj[c][$ - 1];\r\n }\r\n\r\n writeln(0.iota(M - 1).map!(i => rs[i + 1] - ls[i]).maxElement());\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 n = RD!int;\r\n\tauto m = RD!int;\r\n\tauto s1 = RD!(char[]);\r\n\tauto s2 = RD!(char[]);\r\n\r\n\tint[] f(in char[] ss, in char[] tt)\r\n\t{\r\n\t\tauto p = new int[](m);\r\n\t\tint l;\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tforeach (i; l..n)\r\n\t\t\t{\r\n\t\t\t\tif (ss[i] == tt[j])\r\n\t\t\t\t{\r\n\t\t\t\t\tp[j] = i;\r\n\t\t\t\t\tl = i+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\treturn p;\r\n\t}\r\n\tauto p1 = f(s1, s2);\r\n\ts1.reverse;\r\n\ts2.reverse;\r\n\tauto p2 = f(s1, s2);\r\n\tp2.reverse;\r\n\r\n\tint ans;\r\n\tforeach (i; 1..m)\r\n\t{\r\n\t\tauto w = (n - 1 - p2[i]) - p1[i-1];\r\n\t\tans.chmax(w);\r\n\t}\r\n\r\n\twriteln(ans);\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, M; get(N, M);\r\n char[] S, T; get(S); get(T);\r\n\r\n auto ii = new int[]['z' + 1];\r\n auto jj = new int[]['z' + 1];\r\n foreach (i, c; S) {\r\n ii[c] ~= i.to!int;\r\n jj[c] ~= i.to!int;\r\n }\r\n auto ls = new int[](M);\r\n int l;\r\n foreach (i, c; T) {\r\n while (ii[c].front < l) ii[c].popFront();\r\n ls[i] = ii[c].front;\r\n l = ii[c].front;\r\n }\r\n auto rs = new int[](M);\r\n int r = N;\r\n foreach_reverse (i, c; T) {\r\n while (jj[c][$ - 1] > r) jj[c] = jj[c][0..$ - 1];\r\n rs[i] = jj[c][$ - 1];\r\n r = jj[c][$ - 1];\r\n }\r\n\r\n writeln(0.iota(M - 1).map!(i => rs[i + 1] - ls[i]).maxElement());\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 n = RD!int;\r\n\tauto m = RD!int;\r\n\tauto s1 = RD!(char[]);\r\n\tauto s2 = RD!(char[]);\r\n\r\n\tint f(in char[] ss, in char[] tt)\r\n\t{\r\n\t\tint p;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (ss[i] == tt[0])\r\n\t\t\t{\r\n\t\t\t\tp = i;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint res;\r\n\t\tforeach (j; 1..m-1)\r\n\t\t{\r\n\t\t\tforeach (i; p+1..n)\r\n\t\t\t{\r\n\t\t\t\tif (ss[i] == tt[j])\r\n\t\t\t\t{\r\n\t\t\t\t\tres.chmax(i-p);\r\n\t\t\t\t\tp = i;\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\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tif (ss[i] == tt[m-1])\r\n\t\t\t{\r\n\t\t\t\tres.chmax(i-p);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n\tint ans = f(s1, s2);\r\n\ts1.reverse;\r\n\ts2.reverse;\r\n\tans.chmax(f(s1, s2));\r\n\r\n\twriteln(ans);\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "src_uid": "17fff01f943ad467ceca5dce5b962169"} {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\n int n;\n scanf(\"%d\", &n);\n int ch = 0, ne = 0;\n int x;\n for (int i = 0; i < n; i++){\n scanf(\"%d\", &x);\n if (x % 2 == 0){\n ch++;\n } else {\n ne++;\n }\n }\n if (ne < ch){\n printf(\"%d\", ne);\n } else {\n printf(\"%d\", ch + (ne - ch) / 3);\n }\n\n\treturn 0;\n}", "positive_code": [{"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm.comparison;\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= odd) {\n\t\tprintf(\"%d\", odd);\n\t\treturn 0;\n\t}\n\tint ans = even;\n\todd -= even;\n\tint t = odd / 3;\n\tans = ans + t;\n\tprintf(\"%d\", max(ans, 0));\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.conv;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint[] arr = new int[n];\n\tint even = 0;\n\tint odd = 0;\n\t\n\tfor(int i = 0; i= 0 ) {\n\t\tans = max(ans, min(odd, even));\n\t\todd -= 2;\n\t\teven += 1;\n\t}\n\tprintf(\"%d\", ans );\n\t\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\n\nint main()\n{\n int n;\n\tscanf(\"%d\", &n);\n\tint x = 0, y = 0;\n\tfor (int z, i = 0; i < n; i++) {\n\t\tscanf(\"%d\", &z);\n\t\tif (z % 2 == 1) x = x + 1;\n\t\t\telse y = y + 1;\n\t}\n\tint ans;\n\tif (x < y) ans = x;\n\telse {\n\t\tans = y;\n\t\tx = x - y;\n\t\tans = ans + x / 3;\n\t}\n writeln(ans);\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n, a, o = 0, e = 0, z = 0;\n\tscanf(\"%d\", &n);\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tscanf(\"%d\", &a);\n\t\tif (a%2 == 0)\n\t\t\te = e+1;\n\t\telse\n\t\t\to = o+1;\n\t\t\t\n\t}\n\t\n\tfor (int i = 0; i <= o; i += 3)\n\t{\n\t\tif (e < o-i)\n\t\t{\n\t\t\tif (i/3+e > z)\n\t\t\t\tz = i/3+e;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (i/3+o-i > z)\n\t\t\t\tz = i/3+o-i;\n\t\t}\n\t}\n\tprintf(\"%d\", z);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv) {\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 }\n int odd = 0, even = 0;\n for (int i = 0; i < n; i++) {\n if (a[i] % 2 == 0) {\n even++;\n }\n else {\n odd++;\n }\n }\n int k = 0;\n int tmp = (even < odd) ? even : odd;\n k += tmp;\n even -= tmp;\n odd -= tmp;\n k += odd / 3;\n printf(\"%d\\n\", k);\n return 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k,ch=0,nch=0;\n\tscanf(\"%d\", &n);\n for(int i = 0; i= nch) {\n printf(\"%d\", nch);\n } else {\n printf(\"%d\", ch + (nch - ch) / 3);\n }\n\treturn 0;\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 a = 0;\n\tint b = 0;\n\tfor(int i = 0; i < n; i++) {\n\t\tint x;\n\t\tscanf(\"%d\", &x);\n\t\tif (x % 2 == 0) {\n\t\t\ta++;\n\t\t} else {\n\t\t\tb++;\n\t\t}\n\t}\n\tif (b <= a) {\n\t\tprintf(\"%d\\n\", b);\n\t} else {\n\t\tprintf(\"%d\\n\", (b + 2 * a) / 3);\n\t}\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm.comparison;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint t;\n\tint c1 = 0, c2 = 0;\n\tfor(int i = 0; i 0 && beta > 0){\n\t ans++;alpha--;beta--;\n\t}\n\tans = ans + (beta / 3);\n\tprintf(\"%d\", ans);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nvoid main(string[] args)\n{\n int n,ans1=0,ans2=0,ans=0;\n scanf(\"%d\",&n);\n for (int i=1;i<=n;++i){\n int x;\n scanf(\"%d\",&x);\n if (x&1) ++ans1;\n else ++ans2;\n }\n if (ans1=0) ans+=ans1/3;\n writeln(ans);\n}\n\n\n\n"}, {"source_code": "module main;\n\nimport std.c.stdio;\nint min(int a,int b)\n{\n if(a>b)return b;\n else return a;\n}\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n+1];\n\tint odd=0;\n\tint even=0;\n\tfor(int i=0; i even ? even : odd;\n\todd -= even;\n\tprintf(\"%d\", even + odd / 3);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n \nvoid main() {\n\tint n;\n\tscanf(\"%d\", &n);\n\tint a, cnt1, cnt0;\n\tfor (int i = 0; i < n; ++i) {\n\t\tscanf(\"%d\", &a);\n\t\tif (a & 1) ++cnt1;\n\t\telse ++cnt0;\n\t}\n\tint ans = min(cnt0, cnt1);\n\tcnt1 -= ans;\n\tans += cnt1 / 3;\n\tprintf(\"%d\", ans);\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n\tint n = 0;\n\treadf(\"%d \", &n);\n\tint ch = 0;\n\tint nech = 0;\n foreach (_; 0 .. n)\n {\n int a;\n readf(\"%d \", &a);\n if (a % 2 == 0)\n \tch = ch + 1;\n else\n \tnech = nech + 1;\n }\n if (nech <= ch) {\n \twriteln(nech);\n } else {\n \tauto x = nech - ch;\n \twriteln(ch + x / 3);\n }\n\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n \nvoid main() {\n\tint n;\n\tscanf(\"%d\", &n);\n\tint a, cnt1, cnt0;\n\tfor (int i = 0; i < n; ++i) {\n\t\tscanf(\"%d\", &a);\n\t\tif (a & 1) ++cnt1;\n\t\telse ++cnt0;\n\t}\n\tint ans = min(cnt0, cnt1);\n\tcnt1 -= ans;\n\tans += cnt1 / 3;\n\tprintf(\"%d\", ans);\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n//import std.c.cstdlib;\n//import std.c.cmath;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i numNech) {\n\t\n\t ans = numNech;\n\t } else {\n\t ans = numChet;\n\t }\n\tnumChet -= ans;\n\tnumNech -= ans;\n\tans += numNech / 3;\n\tprintf(\"%d\", ans);\n\treturn 0;\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 [] arr = new int[n+10];\n\tfor(int i = 0; ictodd){\n writeln(ctodd);\n }\n else {\n ctodd-=ctev;\n ctodd/=3;\n int ans=ctev+ctodd;\n writeln(ans);\n }\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 [] arr = new int[n];\n\tfor(int i = 0; i b) mn = b;\n\telse\n\t mn = a;\n\t \n int ans = 0;\n if (mn == a){ \n ans = ans + a;\n a = 0;\n }\n else{\n ans = ans + b;\n a = a - b;\n ans = ans + a / 3;\n\t}\n\t\n\tprintf(\"%d\", ans);\n\t\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\nvoid main(string[ ] args)\n{\n int n;\n scanf(\"%d\", &n);\n int n_0 = 0;\n int n_1 = 0;\n for (int i = 0; i < n; ++i) {\n int a;\n scanf(\"%d\", &a);\n if (a % 2 == 0) {\n ++n_0;\n } else {\n ++n_1;\n }\n }\n //writeln(n_0);\n //writeln(n_1);\n int ans;\n if (n_0 >= n_1) {\n writeln(n_1);\n } else {\n writeln(n_0 + (n_1 - n_0) / 3);\n }\n}\n"}, {"source_code": "import std.stdio; \nvoid main() { \n int ans=0;\n int c_odd=0,c_even=0;\n int n,x;\n readf(\" %d\", &n);\n for ( int i = 0; i < n; i++ ) {\n readf(\" %d\",&x);\n if(x%2==0)\n\tc_even++;\n else\n\tc_odd++;\n }\n if(c_eveneven) ans=even;\n\tans+=(odd-ans)/3;\n\t\n\tprintf(\"%d\",ans);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int n,o=0,e=0,x;\n readf(\"%d \",&n);\n for(int i=1;i<=n;i++){\n readf(\"%d \",&x);\n if(x%2==1)\n o++;\n else\n e++;\n }\n int mi=e;\n if(o<=e)\n mi=o;\n int ans=mi+((o-mi)/3);\n writeln(ans);\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 c0 = 0;\n\tint c1 = 0;\n\tfor(int i = 0; i c1) {\n\t\tans = c1;\n\t\tc0 = 0;\n\t\tc1 = 0;\n\t}\n\tans += c1 / 3;\n\tprintf(\"%d\", ans);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint min(int a, int b){\n if(a > b)\n return b;\n return a;\n}\nint max(int a, int b){\n if(a < b)\n return b;\n return a;\n}\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= 0; i--){\n ans = max(ans, i + (a - i)/3) ;\n }\n printf(\"%d\", ans);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\n\nint n, x, cnt0, cnt1, ans;\n\nvoid main()\n{\n scanf(\"%d\", &n);\n \n for(int i = 1; i <= n ;i++)\n {\n scanf(\"%d\", &x);\n \n if(x%2 == 1)\n {\n cnt1 = cnt1 + 1;\n }else\n {\n cnt0 = cnt0 + 1;\n }\n }\n \n if(cnt0 >= cnt1)\n {\n writefln(\"%d\", cnt1);\n }else\n {\n ans = cnt0 + (cnt1 - cnt0)/3;\n \n writefln(\"%d\", ans);\n }\n}"}, {"source_code": "module main;\nimport std.c.stdio;\nint n, cnt_1, cnt_2, cnt, Min;\nint []A = new int [100001];\nint main ()\n{\n scanf(\"%d\",&n);\n for(int i = 0; i < n; i++) {\n scanf(\"%d\",&A[i]);\n if(A[i] & 1)\n cnt_1++;\n else\n cnt_2++;\n }\n Min = cnt_1 > cnt_2 ? cnt_2 : cnt_1;\n cnt += Min;\n cnt_1 -= Min;\n cnt_2 -= Min;\n\tcnt += (cnt_1 / 3);\n\tprintf(\"%d\", cnt);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k,unu = 0, doi = 0;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i c1) {\n\t\tres = c1;\n\t\tc0 = 0;\n\t\tc1 = 0;\n\t}\n\tres += c1 / 3;\n\twriteln(res);\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\tfor(int i = 0; i= odd) {\n\t\tprintf(\"%d\", odd);\n\t\treturn 0;\n\t}\n\tint ans = even;\n\todd -= even;\n\tint t = odd / 3;\n\tans = ans + t - (odd - t * 3);\n\tprintf(\"%d\", max(ans, 0));\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm.comparison;\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= odd) {\n\t\tprintf(\"%d\", odd);\n\t\treturn 0;\n\t}\n\tint ans = even;\n\todd -= even;\n\tint t = odd / 3;\n\tans = ans + t - (odd % 3 == 1 ? 1 : 0);\n\tprintf(\"%d\", max(ans, 0));\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.conv;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint[] arr = new int[n];\n\tint even = 0;\n\tint odd = 0;\n\t\n\tfor(int i = 0; i= arr[k-1] && arr[i] >0)\n\t\t\tq++;\n\tprintf(\"%d\", q);*/\n\treturn 0;\n}\n"}, {"source_code": "module main;\n\nimport std.c.stdio;\nimport std.algorithm.comparison;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint t;\n\tint c1 = 0, c2 = 0;\n\tfor(int i = 0; ians2) ans1=ans2;\n writeln(ans1);\n}\n\n\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.array;\n \nvoid main() {\n\tint n;\n\tscanf(\"%d\", &n);\n\tint a, cnt1, cnt0;\n\tfor (int i = 0; i < n; ++i) {\n\t\tscanf(\"%d\", &a);\n\t\tif (a & 1) ++cnt1;\n\t\telse ++cnt0;\n\t}\n\tprintf(\"%d\", min(cnt0, cnt1));\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n//import std.c.cstdlib;\n//import std.c.cmath;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i numNech) {\n\t\n\t ans = numNech;\n\t } else {\n\t ans = numChet;\n\t }\n\tnumChet -= ans;\n\tnumNech -= ans;\n\tans += numNech / 3;\n\tprintf(\"%d\", ans);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n//import std.c.cstdlib;\n//import std.c.cmath;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i numNech) {\n\t\n\t ans = numNech;\n\t } else {\n\t ans = numChet;\n\t }\n\t//numChet -= ans;\n\t//numNech -= ans;\n\tprintf(\"%d\", ans);\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\nint min(int a,int b)\n{\n if(a>b)return b;\n else return a;\n}\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n+1];\n\tint odd=0;\n\tint even=0;\n\tfor(int i=0; ib)return b;\n else return a;\n}\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n+1];\n\tint odd=0;\n\tint even=0;\n\tfor(int i=0; ib)return b;\n else return a;\n}\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d\", &n);\n\tint [] arr = new int[n+1];\n\tint odd=0;\n\tint even=0;\n\tfor(int i=0; i even ? even : odd);\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 [] arr = new int[n+10];\n\tfor(int i = 0; i= starttm) { cyclesSizes ~= tm[v] - tm[u] + 1; }\n }\n \n foreach (i; 1 .. n+1) {\n if (tm[i] != 0) { continue; }\n \n debug { tm.writeln; }\n \n dfs(i, t);\n }\n \n immutable int MD = 10 ^^ 9 + 7;\n \n auto pws = recurrence!((a, n) => a[n-1] * 2 % MD)(1).take(n+1).array;\n \n int cycleOpts(int sz) {\n return (pws[sz] - 2 + MD) % MD; \n }\n \n debug { cyclesSizes.writeln; }\n \n int ans = cyclesSizes.fold!((ans, nxt) => (ans.to!long * cycleOpts(nxt) % MD).to!int)(1);\n \n auto rest = n - cyclesSizes.sum;\n \n ans = ans.to!long * pws[rest] % MD; \n \n ans.writeln;\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\nenum prime = 1_000_000_000 + 7;\nlong pmod(long a)\n{\n pragma(inline, true);\n return (a%prime + prime)%prime;\n}\nlong pow(long base, long exp)\n{\n pragma(inline, true);\n base %= prime;\n auto acc = long(1);\n while(exp)\n {\n if (exp & 1) acc = (acc * base) % prime;\n exp = exp >> 1;\n base = (base * base) % prime;\n }\n return acc;\n}\n\nvoid main(string[] args)\n{\n debug stdin = File(args[1]);\n auto n = next!int;\n auto a = new int[](n);\n a[] = next!int(n)[] - 1;\n auto depth = new int[](n);\n auto neis = new int[][](n);\n auto visited = new bool[](n);\n int[int[2]] edgecount;\n foreach(i, ai; a)\n {\n neis[i] ~= ai;\n neis[ai] ~= cast(int) i;\n edgecount.require([min(cast(int)i, ai), max(cast(int)i, ai)], 0)++;\n }\n auto cyclelen = int(0);\n auto count = int(0);\n bool foundCycle = false;\n void dfs(int node, int depthtoput, int parent)\n {\n debug writeln(\"visiting \", node, \" \", parent);\n count++;\n depth[node] = depthtoput;\n visited[node] = true;\n foreach(nei; neis[node])\n if (edgecount[[min(node, nei), max(node, nei)]] > 0)\n {\n edgecount[[min(node, nei), max(node, nei)]]--;\n debug writeln(node, \" -> \", nei);\n if (visited[nei])\n {\n if (!foundCycle)\n {\n assert(depth[nei] < depth[node], text(\"found cycle with \", nei, \" \", node));\n cyclelen = depth[node] - depth[nei] + 1;\n foundCycle = true;\n }\n continue;\n }\n dfs(nei, depthtoput + 1, node);\n }\n }\n long ans = 1;\n foreach(i; 0 .. n)\n {\n if (!visited[i])\n {\n cyclelen = 0;\n count = 0;\n foundCycle = false;\n dfs(i, 0, -1);\n assert(count >= cyclelen);\n auto notincycle = count - cyclelen;\n auto rc = pow(2, cyclelen) - 2;\n auto rn = pow(2, notincycle);\n auto r = pmod(rc * rn);\n ans = pmod(ans * r);\n }\n }\n ans.writeln;\n}\n\n\n// INPUT\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 * 1024 * 8;\n const wordSize = 4096;\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;\n\nenum prime = 1_000_000_000 + 7;\nlong pmod(long a)\n{\n pragma(inline, true);\n return (a%prime + prime)%prime;\n}\nlong pow(long base, long exp)\n{\n pragma(inline, true);\n base %= prime;\n auto acc = long(1);\n while(exp)\n {\n if (exp & 1) acc = (acc * base) % prime;\n exp = exp >> 1;\n base = (base * base) % prime;\n }\n return acc;\n}\n\nvoid main(string[] args)\n{\n debug stdin = File(args[1]);\n auto n = next!int;\n auto a = new int[](n);\n a[] = next!int(n)[] - 1;\n auto depth = new int[](n);\n auto neis = new int[][](n);\n auto visited = new bool[](n);\n int[int[2]] edgecount;\n foreach(i, ai; a)\n {\n neis[i] ~= ai;\n neis[ai] ~= cast(int) i;\n edgecount.require([min(cast(int)i, ai), max(cast(int)i, ai)], 0)++;\n }\n auto cyclelen = int(0);\n auto count = int(0);\n bool foundCycle = false;\n void dfs(int node, int depthtoput, int parent)\n {\n debug writeln(\"visiting \", node, \" \", parent);\n count++;\n depth[node] = depthtoput;\n visited[node] = true;\n foreach(nei; neis[node])\n if (edgecount[[min(node, nei), max(node, nei)]] > 0)\n {\n edgecount[[min(node, nei), max(node, nei)]]--;\n debug writeln(node, \" -> \", nei);\n if (visited[nei])\n {\n if (!foundCycle)\n {\n assert(depth[nei] < depth[node], text(\"found cycle with \", nei, \" \", node));\n cyclelen = depth[node] - depth[nei] + 1;\n foundCycle = true;\n }\n continue;\n }\n dfs(nei, depthtoput + 1, node);\n }\n }\n long ans = 1;\n foreach(i; 0 .. n)\n {\n if (!visited[i])\n {\n cyclelen = 0;\n count = 0;\n foundCycle = false;\n dfs(i, 0, -1);\n assert(count >= cyclelen);\n auto notincycle = count - cyclelen;\n auto rc = pow(2, cyclelen) - 2;\n auto rn = pow(2, notincycle);\n auto r = pmod(rc * rn);\n ans = pmod(ans * r);\n }\n }\n ans.writeln;\n}\n\n\n// INPUT\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 * 1024 * 8;\n const wordSize = 4096;\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 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 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\nenum prime = 1_000_000_000 + 7;\nlong pmod(long a)\n{\n pragma(inline, true);\n return (a%prime + prime)%prime;\n}\nlong pow(long base, long exp)\n{\n if (exp == 0)\n return 1;\n base %= prime;\n if (exp % 2 == 0)\n {\n auto pres = pow(base, exp / 2);\n return (pres * pres) % prime;\n }\n return (pow(base, exp - 1) * base) % prime;\n}\n\nvoid main(string[] args)\n{\n debug stdin = File(args[1]);\n auto n = next!int;\n auto a = new int[](n);\n a[] = next!int(n)[] - 1;\n auto depth = new int[](n);\n auto neis = new int[][](n);\n auto visited = new bool[](n);\n int[int[2]] edgecount;\n foreach(i, ai; a)\n {\n neis[i] ~= ai;\n neis[ai] ~= cast(int) i;\n edgecount.require([min(cast(int)i, ai), max(cast(int)i, ai)], 0)++;\n }\n auto cyclelen = int(0);\n auto count = int(0);\n bool foundCycle = false;\n void dfs(int node, int depthtoput, int parent)\n {\n debug writeln(\"visiting \", node, \" \", parent);\n count++;\n depth[node] = depthtoput;\n visited[node] = true;\n foreach(nei; neis[node])\n if (edgecount[[min(node, nei), max(node, nei)]] > 0)\n {\n edgecount[[min(node, nei), max(node, nei)]]--;\n debug writeln(node, \" -> \", nei);\n if (visited[nei])\n {\n if (!foundCycle)\n {\n assert(depth[nei] < depth[node], text(\"found cycle with \", nei, \" \", node));\n cyclelen = depth[node] - depth[nei] + 1;\n foundCycle = true;\n }\n continue;\n }\n dfs(nei, depthtoput + 1, node);\n }\n }\n long ans = 1;\n foreach(i; 0 .. n)\n {\n if (!visited[i])\n {\n cyclelen = 0;\n count = 0;\n foundCycle = false;\n dfs(i, 0, -1);\n assert(count >= cyclelen);\n auto notincycle = count - cyclelen;\n auto rc = pow(2, cyclelen) - 2;\n auto rn = pow(2, notincycle);\n auto r = pmod(rc * rn);\n ans = pmod(ans * r);\n }\n }\n ans.writeln;\n}\n\n\n// INPUT\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 * 1024 * 8;\n const wordSize = 4096;\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 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 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\nenum prime = 1_000_000_000 + 7;\nlong pmod(long a)\n{\n return (a%prime + prime)%prime;\n}\nlong pow(long base, long exp)\n{\n if (exp == 0)\n return 1;\n base %= prime;\n if (exp % 2 == 0)\n {\n auto pres = pow(base, exp / 2);\n return (pres * pres) % prime;\n }\n return (pow(base, exp - 1) * base) % prime;\n}\n\nvoid main(string[] args)\n{\n debug stdin = File(args[1]);\n auto n = next!int;\n auto a = next!int(n);\n a[] -= 1;\n auto depth = new int[](n);\n auto neis = new int[][](n);\n auto visited = new bool[](n);\n int[int[2]] edgecount;\n foreach(i, ai; a)\n {\n neis[i] ~= ai;\n neis[ai] ~= cast(int) i;\n edgecount.require([min(cast(int)i, ai), max(cast(int)i, ai)], 0)++;\n }\n auto cyclelen = int(0);\n auto count = int(0);\n bool foundCycle = false;\n void dfs(int node, int depthtoput, int parent)\n {\n debug writeln(\"visiting \", node, \" \", parent);\n count++;\n depth[node] = depthtoput;\n visited[node] = true;\n foreach(nei; neis[node])\n if (edgecount[[min(node, nei), max(node, nei)]] > 0)\n {\n edgecount[[min(node, nei), max(node, nei)]]--;\n debug writeln(node, \" -> \", nei);\n if (visited[nei])\n {\n if (!foundCycle)\n {\n assert(depth[nei] < depth[node], text(\"found cycle with \", nei, \" \", node));\n cyclelen = depth[node] - depth[nei] + 1;\n foundCycle = true;\n }\n continue;\n }\n dfs(nei, depthtoput + 1, node);\n }\n }\n long ans = 1;\n foreach(i; 0 .. n)\n {\n if (!visited[i])\n {\n cyclelen = 0;\n count = 0;\n foundCycle = false;\n dfs(i, 0, -1);\n assert(count >= cyclelen);\n auto notincycle = count - cyclelen;\n auto rc = pow(2, cyclelen) - 2;\n auto rn = pow(2, notincycle);\n auto r = pmod(rc * rn);\n ans = pmod(ans * r);\n }\n }\n ans.writeln;\n}\n\n\n// INPUT\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 * 1024 * 8;\n const wordSize = 4096;\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 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 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 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 auto arr = [0] ~ readln.chomp.split.map!(to!int).array;\n \n int[] cycleSzs;\n \n auto g = new int[][] (n+1);\n foreach (i, e; arr.dropOne.enumerate(1)) {\n if (arr[e] == i) {\n if (i < e) { cycleSzs ~= 2; }\n } else {\n g[i] ~= e;\n g[e] ~= i;\n }\n }\n \n debug { g.writeln; }\n \n int t = 1;\n auto tm = new int[] (n+1);\n auto isOut = new bool[] (n+1);\n \n void dfs(int v, int fr) {\n tm[v] = t++;\n foreach (u; g[v]) {\n if (u == fr) { continue; }\n \n if (tm[u] != 0 && isOut[u]) { continue; }\n \n if (tm[u] != 0 && !isOut[u]) {\n isOut[v] = true;\n cycleSzs ~= tm[v] - tm[u] + 1;\n return;\n }\n \n dfs(u, v);\n }\n \n isOut[v] = true;\n }\n \n foreach (i; 1 .. n+1) {\n if (tm[i] != 0) { continue; }\n \n dfs(i, -1);\n }\n \n immutable int MD = 10 ^^ 9 + 7;\n \n auto pws = recurrence!((a, n) => a[n-1] * 2 % MD)(1).take(n+1).array;\n \n int cycleOpts(int sz) {\n return (pws[sz] - 2 + MD) % MD; \n }\n \n debug { cycleSzs.writeln; }\n \n int ans = cycleSzs.fold!((ans, nxt) => (ans.to!long * cycleOpts(nxt) % MD).to!int)(1);\n \n auto rest = n - cycleSzs.sum;\n \n ans = ans.to!long * pws[rest] % MD; \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;\n readf(\"%s\", &n);\n readln;\n \n auto arr = [0] ~ readln.chomp.split.map!(to!int).array;\n \n int[] cycleSzs;\n \n auto g = new int[][] (n+1);\n foreach (i, e; arr.dropOne.enumerate(1)) {\n if (arr[e] == i) {\n if (i < e) { cycleSzs ~= 2; }\n } else {\n g[i] ~= e;\n g[e] ~= i;\n }\n }\n \n debug { g.writeln; }\n \n int t = 1;\n auto tm = new int[] (n+1);\n auto isOut = new bool[] (n+1);\n \n void dfs(int v, int fr) {\n tm[v] = t++;\n foreach (u; g[v]) {\n if (u == fr) { continue; }\n \n if (tm[u] != 0 && isOut[u]) { continue; }\n \n if (tm[u] != 0 && !isOut[u]) {\n isOut[v] = true;\n cycleSzs ~= tm[v] - tm[u] + 1;\n return;\n }\n \n dfs(u, v);\n }\n \n isOut[v] = true;\n }\n \n foreach (i; 1 .. n+1) {\n if (tm[i] != 0) { continue; }\n \n dfs(i, -1);\n }\n \n immutable int MD = 10 ^^ 9 + 7;\n \n auto pws = recurrence!((a, n) => a[n-1] * 2 % MD)(1).take(n+1).array;\n \n int cycleOpts(int sz) {\n return (pws[sz] - 2 + MD) % MD; \n }\n \n debug { cycleSzs.writeln; }\n \n int ans = cycleSzs.fold!((ans, nxt) => ans * cycleOpts(nxt) % MD)(1);\n \n auto rest = n - cycleSzs.sum;\n \n ans = ans.to!long * pws[rest] % MD; \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;\n\nenum prime = 1_000_000 + 7;\nlong pmod(long a)\n{\n return (a%prime + prime)%prime;\n}\nlong pow(long base, long exp)\n{\n if (exp == 0)\n return 1;\n base %= prime;\n if (exp % 2 == 0)\n {\n auto pres = pow(base, exp / 2);\n return (pres * pres) % prime;\n }\n return (pow(base, exp - 1) * base) % prime;\n}\n\nvoid main(string[] args)\n{\n debug stdin = File(args[1]);\n auto n = next!int;\n auto a = next!int(n);\n a[] -= 1;\n auto depth = new int[](n);\n auto neis = new int[][](n);\n auto visited = new bool[](n);\n int[int[2]] edgecount;\n foreach(i, ai; a)\n {\n neis[i] ~= ai;\n neis[ai] ~= cast(int) i;\n edgecount.require([min(cast(int)i, ai), max(cast(int)i, ai)], 0)++;\n }\n auto cyclelen = int(0);\n auto count = int(0);\n bool foundCycle = false;\n void dfs(int node, int depthtoput, int parent)\n {\n debug writeln(\"visiting \", node, \" \", parent);\n count++;\n depth[node] = depthtoput;\n visited[node] = true;\n foreach(nei; neis[node])\n if (edgecount[[min(node, nei), max(node, nei)]] > 0)\n {\n edgecount[[min(node, nei), max(node, nei)]]--;\n debug writeln(node, \" -> \", nei);\n if (visited[nei])\n {\n if (!foundCycle)\n {\n assert(depth[nei] < depth[node], text(\"found cycle with \", nei, \" \", node));\n cyclelen = depth[node] - depth[nei] + 1;\n foundCycle = true;\n }\n continue;\n }\n dfs(nei, depthtoput + 1, node);\n }\n }\n long ans = 1;\n foreach(i; 0 .. n)\n {\n if (!visited[i])\n {\n cyclelen = 0;\n count = 0;\n foundCycle = false;\n dfs(i, 0, -1);\n assert(count >= cyclelen);\n auto notincycle = count - cyclelen;\n auto rc = pow(2, cyclelen) - 2;\n auto rn = pow(2, notincycle);\n auto r = pmod(rc * rn);\n ans = pmod(ans * r);\n }\n }\n ans.writeln;\n}\n\n\n// INPUT\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 * 1024 * 8;\n const wordSize = 4096;\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 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 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\nenum prime = 1_000_000_000 + 7;\nlong pmod(long a)\n{\n pragma(inline, true);\n return (a%prime + prime)%prime;\n}\nlong pow(long base, long exp)\n{\n pragma(inline, true);\n base %= prime;\n auto p = base;\n auto acc = long(1);\n while(exp)\n {\n if (exp & 1) acc *= p;\n exp = exp >> 1;\n p = (p * p) % prime;\n }\n return acc;\n}\n\nvoid main(string[] args)\n{\n debug stdin = File(args[1]);\n auto n = next!int;\n auto a = new int[](n);\n a[] = next!int(n)[] - 1;\n auto depth = new int[](n);\n auto neis = new int[][](n);\n auto visited = new bool[](n);\n int[int[2]] edgecount;\n foreach(i, ai; a)\n {\n neis[i] ~= ai;\n neis[ai] ~= cast(int) i;\n edgecount.require([min(cast(int)i, ai), max(cast(int)i, ai)], 0)++;\n }\n auto cyclelen = int(0);\n auto count = int(0);\n bool foundCycle = false;\n void dfs(int node, int depthtoput, int parent)\n {\n debug writeln(\"visiting \", node, \" \", parent);\n count++;\n depth[node] = depthtoput;\n visited[node] = true;\n foreach(nei; neis[node])\n if (edgecount[[min(node, nei), max(node, nei)]] > 0)\n {\n edgecount[[min(node, nei), max(node, nei)]]--;\n debug writeln(node, \" -> \", nei);\n if (visited[nei])\n {\n if (!foundCycle)\n {\n assert(depth[nei] < depth[node], text(\"found cycle with \", nei, \" \", node));\n cyclelen = depth[node] - depth[nei] + 1;\n foundCycle = true;\n }\n continue;\n }\n dfs(nei, depthtoput + 1, node);\n }\n }\n long ans = 1;\n foreach(i; 0 .. n)\n {\n if (!visited[i])\n {\n cyclelen = 0;\n count = 0;\n foundCycle = false;\n dfs(i, 0, -1);\n assert(count >= cyclelen);\n auto notincycle = count - cyclelen;\n auto rc = pow(2, cyclelen) - 2;\n auto rn = pow(2, notincycle);\n auto r = pmod(rc * rn);\n ans = pmod(ans * r);\n }\n }\n ans.writeln;\n}\n\n\n// INPUT\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 * 1024 * 8;\n const wordSize = 4096;\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 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 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": "869f94e76703cde502bd908b476d970e"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 p = RD!int;\n\tauto a = RDA!int;\n\tmod = p;\n\t\n\tint[] ans;\n\ta.sort();\n\tforeach (i; 1..a.back+1)\n\t{\n\t\tauto cnt = new int[](n);\n\t\tbool ok = true;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tauto d = max(a[j] - i, 0);\n\t\t\tif (d >= n)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t++cnt[d];\n\t\t}\n\t\tif (!ok) continue;\n\n\t\tlong pat = 1;\n\t\tlong s;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\ts += cnt[j];\n\t\t\tif (s - j <= 0)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tpat.modm(s-j);\n\t\t}\n\t\tif (!ok) continue;\n\t\tif (pat != 0)\n\t\t{\n\t\t\tans ~= i;\n\t\t}\n\t}\n\n\twriteln(ans.length);\n\tans.map!(to!string).join(\" \").writeln;\n\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\tint n, p;\n\twhile (readf !(\" %s %s\") (n, p) > 0) {\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tint [] answer;\n\t\tforeach (x; 1..4001) {\n\t\t\tbool ok = true;\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..n) {\n\t\t\t\twhile (cur < n && x + i >= a[cur]) {\n\t\t\t\t\tcur += 1;\n\t\t\t\t}\n\t\t\t\tok &= !!((cur - i) % p);\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tanswer ~= x;\n\t\t\t}\n\t\t}\n\t\twriteln (answer.length);\n\t\twritefln !(\"%(%s %)\") (answer);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\tint n, p;\n\twhile (readf !(\" %s %s\") (n, p) > 0) {\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\t\tint [] answer;\n\t\tforeach (x; 1..n + 1) {\n\t\t\tbool ok = true;\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..n) {\n\t\t\t\twhile (cur < n && x + i >= a[cur]) {\n\t\t\t\t\tcur += 1;\n\t\t\t\t}\n\t\t\t\tok &= !!((cur - i) % x);\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tanswer ~= x;\n\t\t\t}\n\t\t}\n\t\twriteln (answer.length);\n\t\twritefln !(\"%(%s %)\") (answer);\n\t}\n}\n"}], "src_uid": "f046fc902b22fdbc3b1ec9cb4f411179"} {"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 string str;\n\n void solve(long tc = -1)\n {\n auto fromab = str.find(\"AB\");\n if (fromab.empty)\n return writeln(\"NO\");\n if (fromab[2 .. $].canFind(\"BA\"))\n return writeln(\"YES\");\n auto fromba = str.find(\"BA\");\n if (fromba.empty)\n return writeln(\"NO\");\n if (fromba[2 .. $].canFind(\"AB\"))\n return writeln(\"YES\");\n return 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", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\n\n\nbool find(const(char)[] s,\n immutable(char)[] pat1,\n immutable(char)[] pat2) {\n uint p1 = cast(uint)s.indexOf(pat1);\n if (p1 == -1) {\n return false;\n }\n auto t = s[p1+pat1.length..$];\n uint p2 = cast(uint)t.indexOf(pat2);\n if (p2 == -1) {\n return false;\n }\n return true;\n}\n\nvoid main() {\n string s = readln();\n writeln(find(s, \"AB\", \"BA\") || find(s, \"BA\", \"AB\") ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\n\n\nbool find(const(char)[] s,\n immutable(char)[] pat1,\n immutable(char)[] pat2) {\n auto p1 = s.indexOf(pat1);\n if (p1 == -1) {\n return false;\n }\n auto t = s[p1+pat1.length..$];\n auto p2 = t.indexOf(pat2);\n if (p2 == -1) {\n return false;\n }\n return true;\n}\n\nvoid main() {\n string s = readln();\n writeln(find(s, \"AB\", \"BA\") || find(s, \"BA\", \"AB\") ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "version (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\tstring s = readln;\n\n\tint idx = s.indexOf(\"AB\");\n\tif (idx != -1) {\n\t\tif (s[idx + 2 .. $].indexOf(\"BA\") != -1) {\n\t\t\twriteln(\"YES\");\n\t\t\treturn;\n\t\t}\n\t}\n\n\tint jdx = s.indexOf(\"BA\");\n\tif (jdx != -1) {\n\t\tif (s[jdx + 2 .. $].indexOf(\"AB\") != -1) {\n\t\t\twriteln(\"YES\");\n\t\t\treturn;\n\t\t}\n\t}\n\n\twriteln(\"NO\");\n}"}, {"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main() {\n string s = readln.chomp;\n\n bool ab = false;\n bool ba = false;\n bool optional = false;\n\n char last = s[0];\n foreach (char i; s) {\n if (last == 'A' && i == 'B' && !ab) {\n ab = true;\n last = 'x';\n } else if (last == 'B' && i == 'A' && !ba) {\n ba = true;\n last = 'y';\n } else {\n if (last == 'x' && i == 'A') {\n optional = true;\n ab = false;\n } else if (last == 'y' && i == 'B') {\n optional = true;\n ba = false;\n } else\n last = i;\n }\n if ((ab || ba) && optional || ba && ab) {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main() {\n string s = readln.chomp;\n\n bool ab = false;\n bool ba = false;\n bool optional = false;\n\n char last = s[0];\n foreach (char i; s[1 .. $]) {\n if (last == 'A' && i == 'B' && !ab) {\n ab = true;\n last = 'x';\n } else if (last == 'B' && i == 'A' && !ba) {\n ba = true;\n last = 'y';\n } else {\n if (last == 'x' && i == 'A') {\n optional = true;\n ab = false;\n } else if (last == 'y' && i == 'B') {\n optional = true;\n ba = false;\n } else\n last = i;\n }\n if ((ab || ba) && optional || ba && ab) {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\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 string s=readln.strip;\n if(s.length<4){\n writeln(\"NO\");\n return;\n }\n long i=s.indexOf(\"AB\");\n long j=s[cast(uint)i+2..$].indexOf(\"BA\");\n if(i>=0 && j>=0){\n writeln(\"YES\");\n return;\n }\n i=s.indexOf(\"BA\");\n j=s[cast(uint)i+2..$].indexOf(\"AB\");\n if(i>=0 && j>=0)\n writeln(\"YES\");\n else 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;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n string str;\n\n void solve(long tc = -1)\n {\n if (str.canFind(\"AB\") && str.canFind(\"BA\")\n && (str.find(\"AB\")[2 .. $].canFind(\"BA\")\n || str.find(\"BA\")[2 .. $].canFind(\"AB\")))\n return writeln(\"YES\");\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"}], "negative_code": [{"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main() {\n string s = readln.chomp;\n\n bool first = true;\n\n char last = s[0];\n foreach (char i; s[1 .. $]) {\n if ((last == 'A' && i == 'B') || (last == 'B' && i == 'A')) {\n if (first) {\n first = false;\n last = 'x';\n } else {\n writeln(\"YES\");\n return;\n }\n } else\n last = i;\n }\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main() {\n string s = readln.chomp;\n\n bool first = true;\n\n char last = s[0];\n foreach (char i; s[1 .. $]) {\n if ((last == 'A' && i == 'B') || (last == 'B' && i == 'A')) {\n if (first) {\n first = false;\n last = 'x';\n } else {\n writeln(\"YES\");\n return;\n }\n }\n }\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main() {\n string s = readln.chomp;\n\n bool ab = false;\n bool ba = false;\n bool optional = false;\n\n char last = s[0];\n foreach (char i; s[1 .. $]) {\n if (last == 'A' && i == 'B' && !ab) {\n ab = true;\n last = 'x';\n } else if (last == 'B' && i == 'A' && !ba) {\n ba = true;\n last = 'y';\n } else {\n if (last == 'x' && i == 'A') {\n optional = true;\n ab = false;\n } else if (last == 'y' && i == 'B') {\n optional = true;\n ba = false;\n }\n last = i;\n }\n if ((ab || ba) && optional) {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main() {\n string s = readln.chomp;\n\n bool ab = false;\n bool ba = false;\n\n char last = s[0];\n foreach (char i; s[1 .. $]) {\n if (last == 'A' && i == 'B' && !ab) {\n ab = true;\n last = 'x';\n } else if (last == 'B' && i == 'A' && !ba) {\n ba = true;\n last = 'x';\n } else {\n last = i;\n }\n if (ab && ba) {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main() {\n string s = readln.chomp;\n\n bool ab = false;\n bool ba = false;\n bool optional = false;\n\n char last = s[0];\n foreach (char i; s[1 .. $]) {\n if (last == 'A' && i == 'B' && !ab) {\n ab = true;\n last = 'x';\n } else if (last == 'B' && i == 'A' && !ba) {\n ba = true;\n last = 'y';\n } else {\n if (last == 'x' && i == 'A') {\n optional = true;\n ab = false;\n } else if (last == 'y' && i == 'B') {\n optional = true;\n ba = false;\n } else\n last = i;\n }\n if ((ab || ba) && optional) {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main() {\n string s = readln.chomp;\n\n bool ab = false;\n bool ba = false;\n bool optional_ab = false;\n bool optional_ba = false;\n\n char last = s[0];\n foreach (char i; s[1 .. $]) {\n if (last == 'A' && i == 'B' && !ab) {\n ab = true;\n last = 'x';\n } else if (last == 'B' && i == 'A' && !ba) {\n ba = true;\n last = 'y';\n } else {\n if (last == 'x' && i == 'A')\n optional_ba = true;\n else if (last == 'y' && i == 'B')\n optional_ab = true;\n last = i;\n }\n if ((ab || optional_ab) && (ba || optional_ba)) {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio : writeln, readln;\nimport std.string : chomp;\n\nvoid main()\n{\n string s = readln.chomp;\n\n bool ab = false;\n bool ba = false;\n\n char last = s[0];\n foreach (char i; s[1 .. $])\n {\n if (last == 'A' && i == 'B')\n {\n ab = true;\n last = 'x';\n }\n else if (last == 'B' && i == 'A')\n {\n ba = true;\n last = 'x';\n }\n else\n {\n last = i;\n }\n if (ab && ba)\n {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\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 string s=readln.strip;\n long i=s.indexOf(\"AB\"),j=s.indexOf(\"BA\");\n if(i>=0 && j>=0 && abs(i-j)>=2)\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;\nimport std.math;\nimport std.typecons;\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n string str;\n\n void solve(long tc = -1)\n {\n bool hasleft, hasright;\n foreach(i; 0 .. str.length)\n {\n if (str[i] == 'B')\n {\n if (i >= 1 && str[i - 1] == 'A')\n {\n if (hasright)\n {\n writeln(\"YES\");\n return;\n }\n }\n if (i + 1 < str.length && str[i + 1] == 'A')\n {\n if (hasleft)\n {\n writeln(\"YES\");\n return;\n }\n }\n if (i >= 1 && str[i - 1] == 'A')\n hasleft = true;\n if (i + 1 < str.length && str[i + 1] == 'A')\n hasright = true;\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.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 string str;\n\n void solve(long tc = -1)\n {\n auto cntaba = str.count(\"ABA\");\n auto cntab = str.count(\"AB\");\n cntab -= cntaba;\n auto cntba = str.count(\"BA\");\n cntba -= cntaba;\n if (cntaba >= 2)\n {\n writeln(\"YES\");\n return;\n }\n if (cntaba == 0)\n {\n if (cntba > 0 && cntab > 0)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\n else\n {\n if (cntba > 0 || cntab > 0)\n writeln(\"YES\");\n else\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"}, {"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 string str;\n\n void solve(long tc = -1)\n {\n bool hasleft, hasright;\n bool answer = false;\n loop1:foreach(i; 0 .. str.length)\n {\n if (str[i] == 'B')\n {\n if (i >= 1 && str[i - 1] == 'A')\n {\n if (hasright)\n {\n answer = true;\n break loop1;\n }\n }\n if (i + 1 < str.length && str[i + 1] == 'A')\n {\n if (hasleft)\n {\n answer = true;\n break loop1;\n }\n }\n if (i >= 1 && str[i - 1] == 'A')\n hasleft = true;\n if (i + 1 < str.length && str[i + 1] == 'A')\n hasright = true;\n }\n }\n hasleft = false; hasright = false;\n bool answer2;\n loop2:foreach(i; 0 .. str.length)\n {\n if (str[i] == 'A')\n {\n if (i >= 1 && str[i - 1] == 'B')\n {\n if (hasright)\n {\n answer2 = true;\n break loop2;\n }\n }\n if (i + 1 < str.length && str[i + 1] == 'B')\n {\n if (hasleft)\n {\n answer2 = true;\n break loop2;\n }\n }\n if (i >= 1 && str[i - 1] == 'B')\n hasleft = true;\n if (i + 1 < str.length && str[i + 1] == 'B')\n hasright = true;\n }\n }\n if (answer && answer2)\n writeln(\"YES\");\n else\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"}], "src_uid": "33f7c85e47bd6c83ab694a834fa728a2"} {"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 NA = -1;\n\nint [] [] a;\nbool [] b;\nint [] f;\nint [] g;\n\nvoid recur (int v, int p)\n{\n\tif (b[v])\n\t{\n\t\tf[v] = max (f[v], 0);\n\t}\n\n\tforeach (u; a[v])\n\t{\n\t\tif (u == p)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\trecur (u, v);\n\t\tf[v] = max (f[v], f[u] + 1);\n\t}\n}\n\nvoid recur2 (int v, int p, int z)\n{\n\tint max1 = int.min;\n\tint max2 = int.min;\n\n\tforeach (u; a[v])\n\t{\n\t\tif (u == p)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tif (max1 < f[u])\n\t\t{\n\t\t\tmax2 = max1;\n\t\t\tmax1 = f[u];\n\t\t}\n\t\telse if (max2 < f[u])\n\t\t{\n\t\t\tmax2 = f[u];\n\t\t}\n\t}\n\n\tforeach (u; a[v])\n\t{\n\t\tif (u == p)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tint cur;\n\t\tif (max1 == f[u])\n\t\t{\n\t\t\tcur = max2 + 2;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcur = max1 + 2;\n\t\t}\n\t\tcur = max (cur, z + 1);\n\t\tf[u] = max (f[u], cur);\n\t\trecur2 (u, v, cur);\n\t}\n}\n\nvoid recur3 (int v, int p)\n{\n\tif (b[v])\n\t{\n\t\tg[v] = max (g[v], 0);\n\t}\n\n\tforeach (u; a[v])\n\t{\n\t\tif (u == p)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tg[u] = max (g[u], g[v] + 1);\n\t\trecur3 (u, v);\n\t}\n}\n\nvoid main ()\n{\n\tint n, m, d;\n\twhile (readf (\" %s %s %s\", &n, &m, &d) > 0)\n\t{\n\t\tb = new bool [n];\n\t\tforeach (i; 0..m)\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\ta = 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--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tf = new int [n];\n\t\tf[] = int.min;\n\t\trecur (0, NA);\n\t\tdebug {writeln (f);}\n\t\trecur2 (0, NA, int.min);\n\t\tdebug {writeln (f);}\n\t\tg = new int [n];\n\t\tg[] = int.min;\n\t\trecur3 (0, NA);\n\t\tdebug {writeln (g);}\n\t\tint res = 0;\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\tres += (f[v] <= d && g[v] <= d);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;\nimport std.algorithm, std.container, std.datetime;\n\nint n, m, d;\nbool[] isE;\nint[][] g;\nint md, mv;\nint[] dps;\nvoid dfs(int v, int b, int dp) {\n\tif (isE[v] && md < dp) {\n\t\tmd = dp;\n\t\tmv = v;\n\t}\n\tdps[v] = dp;\n\tforeach (u; g[v]) {\n\t\tif (u == b) continue;\n\t\tdfs(u, v, dp+1);\n\t}\n}\n\nvoid dfs2(int v, int b, int dp) {\n\n}\nint solve() {\n\treadf(\"%d %d %d\\n\", &n, &m, &d);\n\tauto p = readln().split().map!(s => to!int(s)-1).array;\n\tisE.length = n;\n\tforeach (u; p) {\n\t\tisE[u] = true;\n\t}\n\tg.length = n;\n\tforeach (i; 0..n-1) {\n\t\tint a, b;\n\t\treadf(\"%d %d\\n\", &a, &b); a--; b--;\n\t\tg[a] ~= b;\n\t\tg[b] ~= a;\n\t}\n\tdps.length = n;\n\tmd = mv = -1;\n\tdfs(p[0], -1, 0);\n\tauto v = mv;\n\tmd = mv = -1;\n\tdfs(v, -1, 0);\n\tauto dp1 = dps.dup;\n\tdfs(mv, -1, 0);\n\tauto dp2 = dps.dup;\n\tint res = 0;\n\tforeach (i; 0..n) {\n\t\tif (dp1[i] <= d && dp2[i] <= d) {\n\t\t\tres++;\n\t\t}\n\t}\n//\tif (md > d*2) return 0;\n\treturn res;\n}\n\nint main() {\n\twriteln(solve());\n return 0;\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\nint [] [] a;\nbool [] b;\nint [] f;\nint [] g;\n\nvoid recur (int v, int p)\n{\n\tif (b[v])\n\t{\n\t\tf[v] = max (f[v], 0);\n\t}\n\n\tforeach (u; a[v])\n\t{\n\t\tif (u == p)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\trecur (u, v);\n\t\tf[v] = max (f[v], f[u] + 1);\n\t}\n}\n\nvoid recur2 (int v, int p)\n{\n\tint max1 = int.min;\n\tint max2 = int.min;\n\n\tforeach (u; a[v])\n\t{\n\t\tif (u == p)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tif (max1 < f[u])\n\t\t{\n\t\t\tmax2 = max1;\n\t\t\tmax1 = f[u];\n\t\t}\n\t\telse if (max2 < f[u])\n\t\t{\n\t\t\tmax2 = f[u];\n\t\t}\n\t}\n\n\tforeach (u; a[v])\n\t{\n\t\tif (u == p)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tif (max1 == f[u])\n\t\t{\n\t\t\tf[u] = max (f[u], max2 + 2);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tf[u] = max (f[u], max1 + 2);\n\t\t}\n\t\trecur2 (u, v);\n\t}\n}\n\nvoid recur3 (int v, int p)\n{\n\tif (b[v])\n\t{\n\t\tg[v] = max (g[v], 0);\n\t}\n\n\tforeach (u; a[v])\n\t{\n\t\tif (u == p)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tg[u] = max (g[u], g[v] + 1);\n\t\trecur3 (u, v);\n\t}\n}\n\nvoid main ()\n{\n\tint n, m, d;\n\twhile (readf (\" %s %s %s\", &n, &m, &d) > 0)\n\t{\n\t\tb = new bool [n];\n\t\tforeach (i; 0..m)\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\ta = 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--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\n\t\tf = new int [n];\n\t\tf[] = -MAX_C;\n\t\trecur (0, NA);\n\t\tdebug {writeln (f);}\n\t\trecur2 (0, NA);\n\t\tdebug {writeln (f);}\n\t\tg = new int [n];\n\t\tg[] = -MAX_C;\n\t\trecur3 (0, NA);\n\t\tdebug {writeln (g);}\n\t\tint res = 0;\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\tres += (f[v] <= d && g[v] <= d);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "52863d45ad223687e6975344ab9d3124"} {"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 char[] s; get(s);\r\n foreach (i; 0..s.length) {\r\n if (i%2 == 0) {\r\n if (s[i] == 'a') {\r\n s[i] = 'b';\r\n } else {\r\n s[i] = 'a';\r\n }\r\n } else {\r\n if (s[i] == 'z') {\r\n s[i] = 'y';\r\n } else {\r\n s[i] = 'z';\r\n }\r\n }\r\n }\r\n writeln(s);\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 string[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto s = RD!string;\r\n\r\n\t\tforeach (i; 0..s.length)\r\n\t\t{\r\n\t\t\tif (i % 2 == 0)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] == 'a')\r\n\t\t\t\t\tans[ti] ~= 'b';\r\n\t\t\t\telse\r\n\t\t\t\t\tans[ti] ~= 'a';\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (s[i] == 'z')\r\n\t\t\t\t\tans[ti] ~= 'y';\r\n\t\t\t\telse\r\n\t\t\t\t\tans[ti] ~= '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}"}], "negative_code": [], "src_uid": "c02357c4d959e300f970f66f9b3107eb"} {"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)\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 main()\n{\n auto t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto a = makeSlice(n, next!int);\n auto res = a.count(0);\n logSym!(a, res);\n a = a.map!(ai => ai == 0? 1 : ai).array;\n logSym!(a, res);\n if (a.sum == 0)\n res++;\n logSym!(a, res);\n writeln(res);\n }\n}\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 long readLong() {\n import std.conv : to;\n\n return readToken.to!long;\n }\n\n string[] tokens;\n}\n\nvoid main() {\n import std.algorithm : max, min;\n\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int[] a = new int[n];\n int result = 0, sum = 0;\n for (int i = 0; i < n; ++i) {\n a[i] = io.readInt;\n if (!a[i]) {\n a[i]++, result++;\n }\n sum += a[i];\n }\n if (!sum) {\n result++;\n }\n writeln(result);\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= 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 n = RD!int;\n\t\tauto a = RDA;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0)\n\t\t\t{\n\t\t\t\t++a[i];\n\t\t\t\t++ans[ti];\n\t\t\t}\n\t\t}\n\n\t\tauto s = a.sum;\n\t\tif (s == 0)\n\t\t\t++ans[ti];\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "1ffb08fe61cdf90099c82162b8353b1f"} {"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\tauto hw = readln.chomp.split.map!(to!int);\n\tauto field = new string[](hw[0]);\n\tforeach (i; 0..hw[0]) {\n\t\tfield[i] = readln.chomp;\n\t}\n\tint cnt;\n\tforeach (y; 0..hw[0]-1) {\n\t\tforeach (x; 0..hw[1]-1) {\n\t\t\tbool f, a, c, e;\n\t\t\tforeach (i; 0..2) {\n\t\t\t\tforeach (j;0..2) {\n\t\t\t\t\tif (field[y+i][x+j] == 'f') f = 1;\n\t\t\t\t\tif (field[y+i][x+j] == 'a') a = 1;\n\t\t\t\t\tif (field[y+i][x+j] == 'c') c = 1;\n\t\t\t\t\tif (field[y+i][x+j] == 'e') e = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (f + a + c + e == 4) cnt++;\n\t\t}\n\t}\n\tcnt.writeln;\n}", "positive_code": [{"source_code": "import std.algorithm;\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\tstring [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= readln.strip;\n\t\t}\n\n\t\tlong res = 0;\n\t\tauto f = ['f': true, 'a': true, 'c': true, 'e': true];\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tforeach (j; 0..m - 1)\n\t\t\t{\n\t\t\t\tbool [char] b;\n\t\t\t\tforeach (p; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (q; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tb[s[i + p][j + q]] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tres += b == f;\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}, {"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\nint n, m;\nstring data[100];\n\nbool check(int x, int y, char c) {\n\treturn data[x][y] == c || data[x + 1][y] == c || data[x][y + 1] == c || data[x + 1][y + 1] == c;\n}\n\nvoid main() {\n\treadf(\"%s %s\", &n, &m);\n\treadln();\n\tfor (int i = 0; i < n; ++i)\n\t\tdata[i] = readln();\n\tint result = 0;\n\tfor (int i = 0; i < n - 1; ++i)\n\t\tfor (int j = 0; j < m - 1; ++j)\n\t\t{\n\t\t\tif (!check(i, j, 'f')) continue;\n\t\t\tif (!check(i, j, 'a')) continue;\n\t\t\tif (!check(i, j, 'c')) continue;\n\t\t\tif (!check(i, j, 'e')) continue;\n\t\t\t++result;\n\t\t}\n\twriteln(result);\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}\nint n, m;\nint countFaces(ref char[][] mat, int i, int j) {\n int[4] count;\n for (int dy = 0; dy < 2; dy++) {\n for (int dx = 0; dx < 2; dx++) {\n if (mat[i + dy][j + dx] == 'f') count[0]++;\n if (mat[i + dy][j + dx] == 'a') count[1]++;\n if (mat[i + dy][j + dx] == 'c') count[2]++;\n if (mat[i + dy][j + dx] == 'e') count[3]++;\n }\n }\n return (count[0] == 1 && count[1] == 1 && count[2] == 1 && count[3] == 1);\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 char[][] mat = new char[][](n, m); \n for (int i = 0; i < n; i++) {\n mat[i] = cin.readString.dup;\n }\n if (n < 2 || m < 2) {\n writeln(0);\n return;\n }\n int count = 0;\n for (int i = 0; i <= n - 2; i++) {\n for (int j = 0; j <= m - 2; j++) {\n if (countFaces(mat, i, j)) count++;\n }\n }\n writeln(count);\n } \n}"}], "negative_code": [], "src_uid": "742e4e6ca047da5f5ebe5d854d6a2024"} {"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 auto s = readln.chomp;\n s = \"2\" ~ s;\n auto p = new int[] (s.length + 1);\n p[0] = 0;\n foreach (i; 1 .. s.length) {\n p[i] = s[i] == '0' ? p[i-1] + 1 : 0;\n }\n \n int ans = 0;\n foreach (i; 1 .. s.length) {\n foreach (len; 1 .. 19) {\n if (i.to!int - len + 1 < 1) { break; }\n if (s[i-len+1] != '1') { continue; }\n \n auto x = to!int(s[i-len+1 .. i+1], 2);\n \n debug { writeln(i, ' ', len, ' ', x); }\n \n if (p[i-len] + len >= x) { ++ans; }\n }\n }\n \n ans.writeln;\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\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid solve(){\n\tint t = rint;\n\tforeach(_; 0 .. t){\n\t\tbool[ ] bs = read.to!(char[]).map!(c => c == '1').array;\n\t\tint n = bs.length.to!int;\n\t\t\n\t\tlong ans;\n\t\tint j;\n\t\tforeach(i; 0 .. n){\n\t\t\tif(bs[i]){\n\t\t\t\tint m = 0;\n\t\t\t\tforeach(k; i .. n){\n\t\t\t\t\tint len = k - j + 1;\n\t\t\t\t\tm *= 2, m += (bs[k]? 1: 0);\n\t\t\t\t\tlog(\"[\", bs[i .. k + 1].map!(b => b ? \"1\": \"0\").array.join(), \"]\", \"j:\", j, \"i:\", i, \"k:\", k, \"len:\", len, \"m:\", m);\n\t\t\t\t\tif(len >= m) ans += 1;\n\t\t\t\t\telse if(len < m) break;\n\t\t\t\t\tlog(\"ans:\", ans);\n\t\t\t\t}\n\t\t\t\tj = i + 1;\n\t\t\t}\n\t\t}\n\t\tans.writeln;\n\t}\n}\n/*\n1\n011\n00101\n000110\n0000111\n000001001\n0000001010\n00000001011\n000000001100\n\nAfter 0's in a row, check if there is \n\n*/\n"}], "negative_code": [], "src_uid": "3c93a76f986b1ef653bf5834716ac72a"} {"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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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!lint;\n\t\tlint xx=0;\n\t\tforeach(i;a)xx=gcd(xx,i);\n\t\tif(xx!=1)\n\t\t{\n\t\t\twriteln(\"YES\\n0\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint ans=0;\n\t\t\tforeach(i;0..n-1)\n\t\t\t{\n\t\t\t\twhile(a[i]&1)\n\t\t\t\t{\n\t\t\t\t\tlong x=a[i]+a[i+1],y=a[i]-a[i+1];\n\t\t\t\t\ta[i]=x;\n\t\t\t\t\ta[i+1]=y;\n\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile((a[n-1]&1) || (a[n-2]&1))\n\t\t\t{\n\t\t\t\tlong x=a[n-2]+a[n-1],y=a[n-2]-a[n-1];\n\t\t\t\ta[n-2]=x;\n\t\t\t\ta[n-1]=y;\n\t\t\t\tans++;\n\t\t\t}\n\t\t\twriteln(\"YES\\n\",ans);\n\t\t}\n\t}\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 N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n writeln(\"YES\");\n\n if (A.reduce!gcd > 1) {\n writeln(0);\n return;\n }\n\n int ans = 0;\n foreach (i; 0..N) {\n if (A[i] % 2 == 0) continue;\n else if (i == N-1) ans += 2;\n else if (A[i+1] % 2 == 0) ans += 2;\n else {\n ans += 1;\n A[i+1] = 2;\n }\n }\n\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "da38d1a63152e0a354b04936e9511969"} {"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\nimport std.container;\r\n\r\nalias Tuple!(int, \"to\", long, \"cost\") Edge;\r\nalias Tuple!(int, \"v\", long, \"cost\") State;\r\n\r\nvoid main() {\r\n int N, M; scanf(\"%d %d\\n\", &N, &M);\r\n auto G = new Edge[][2*N];\r\n foreach (i; 0 .. N) {\r\n G[i] ~= Edge(N + i, 0);\r\n }\r\n foreach (i; 0 .. M) {\r\n int U, V, W; scanf(\"%d %d %d\\n\", &U, &V, &W);\r\n U--; V--;\r\n G[U] ~= Edge(V, W);\r\n G[N + V] ~= Edge(N + U, W);\r\n }\r\n auto PQ = heapify!\"a.cost > b.cost\"(new State[0], 0);\r\n auto D = new long[](2*N);\r\n D[] = long.max;\r\n PQ.insert(State(0, 0));\r\n D[0] = 0;\r\n while (! PQ.empty) {\r\n State cur = PQ.front; PQ.popFront;\r\n if (D[cur.v] != cur.cost) continue;\r\n foreach (e; G[cur.v]) {\r\n auto nextv = e.to;\r\n auto nexts = State(nextv, cur.cost + e.cost);\r\n if (D[nexts.v] > nexts.cost) {\r\n D[nexts.v] = nexts.cost;\r\n PQ.insert(nexts);\r\n }\r\n }\r\n }\r\n long[] buf;\r\n for (int p = 1; p < N; p++) {\r\n long ans = long.max;\r\n for (int b = 0; b < 2; b++) {\r\n ans = min(ans, D[p + N * b]);\r\n }\r\n buf ~= (ans == long.max ? -1 : ans);\r\n }\r\n writefln(\"%(%s %)\", buf);\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\nimport std.container;\r\n\r\nalias Tuple!(int, \"to\", long, \"cost\") Edge;\r\nalias Tuple!(int, \"v\", long, \"cost\") State;\r\n\r\nlong[] dijkstra(in Edge[][] G, int N, int s) {\r\n auto PQ = heapify!\"a.cost > b.cost\"(new State[0], 0);\r\n auto D = new long[](N);\r\n D[] = long.max;\r\n PQ.insert(State(s, 0));\r\n D[s] = 0;\r\n while (! PQ.empty) {\r\n State cur = PQ.front; PQ.popFront;\r\n if (D[cur.v] != cur.cost) continue;\r\n foreach (e; G[cur.v]) {\r\n auto nextv = e.to;\r\n auto nexts = State(nextv, cur.cost + e.cost);\r\n if (D[nexts.v] > nexts.cost) {\r\n D[nexts.v] = nexts.cost;\r\n PQ.insert(nexts);\r\n }\r\n }\r\n }\r\n return D;\r\n}\r\n\r\nvoid main() {\r\n int N, M; scanf(\"%d %d\\n\", &N, &M);\r\n auto G = new Edge[][2*N];\r\n foreach (i; 0 .. N) {\r\n G[i] ~= Edge(N + i, 0);\r\n }\r\n foreach (i; 0 .. M) {\r\n int U, V, W; scanf(\"%d %d %d\\n\", &U, &V, &W);\r\n U--; V--;\r\n G[U] ~= Edge(V, W);\r\n G[N + V] ~= Edge(N + U, W);\r\n }\r\n auto D = dijkstra(G, 2*N, 0);\r\n long[] buf;\r\n for (int p = 1; p < N; p++) {\r\n long ans = long.max;\r\n for (int b = 0; b < 2; b++) {\r\n ans = min(ans, D[p + N * b]);\r\n }\r\n buf ~= (ans == long.max ? -1 : ans);\r\n }\r\n writefln(\"%(%s %)\", buf);\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\nimport std.container;\r\n\r\nalias Tuple!(int, \"to\", long, \"cost\") Edge;\r\nalias Tuple!(int, \"v\", long, \"cost\") State;\r\n\r\nlong[] dijkstra(in Edge[][] G, int N, int s) {\r\n auto PQ = heapify!\"a.cost > b.cost\"(new State[0], 0);\r\n auto D = new long[](N);\r\n D[] = long.max;\r\n PQ.insert(State(0, 0));\r\n D[0] = 0;\r\n while (! PQ.empty) {\r\n State cur = PQ.front; PQ.popFront;\r\n if (D[cur.v] != cur.cost) continue;\r\n foreach (e; G[cur.v]) {\r\n auto nextv = e.to;\r\n auto nexts = State(nextv, cur.cost + e.cost);\r\n if (D[nexts.v] > nexts.cost) {\r\n D[nexts.v] = nexts.cost;\r\n PQ.insert(nexts);\r\n }\r\n }\r\n }\r\n return D;\r\n}\r\n\r\nvoid main() {\r\n int N, M; scanf(\"%d %d\\n\", &N, &M);\r\n auto G = new Edge[][2*N];\r\n foreach (i; 0 .. N) {\r\n G[i] ~= Edge(N + i, 0);\r\n }\r\n foreach (i; 0 .. M) {\r\n int U, V, W; scanf(\"%d %d %d\\n\", &U, &V, &W);\r\n U--; V--;\r\n G[U] ~= Edge(V, W);\r\n G[N + V] ~= Edge(N + U, W);\r\n }\r\n auto D = dijkstra(G, 2*N, 0);\r\n long[] buf;\r\n for (int p = 1; p < N; p++) {\r\n long ans = long.max;\r\n for (int b = 0; b < 2; b++) {\r\n ans = min(ans, D[p + N * b]);\r\n }\r\n buf ~= (ans == long.max ? -1 : ans);\r\n }\r\n writefln(\"%(%s %)\", buf);\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\nimport std.container;\r\n\r\nalias Tuple!(int, \"from\", int, \"to\", long, \"cost\") Edge;\r\nalias Tuple!(int, \"v\", int, \"b\") ExtV;\r\nalias Tuple!(ExtV, \"v\", long, \"cost\") State;\r\n\r\nvoid main() {\r\n int N, M; readf(\"%d %d\\n\", &N, &M);\r\n auto G = new Edge[][N],\r\n rG = new Edge[][N];\r\n foreach (i; 0 .. M) {\r\n int U, V, W; readf(\"%d %d %d\\n\", &U, &V, &W);\r\n U--; V--;\r\n G[U] ~= Edge(U, V, W);\r\n rG[V] ~= Edge(V, U, W);\r\n }\r\n auto PQ = heapify!\"a.cost > b.cost\"(new State[0]);\r\n long[ExtV] D;\r\n PQ.insert(State(ExtV(0, 0), 0));\r\n while (! PQ.empty) {\r\n State cur = PQ.front; PQ.popFront;\r\n if (cur.v.b == 0) {\r\n // can use original and reversed\r\n foreach (e; G[cur.v.v]) {\r\n auto nextv = e.to;\r\n auto nexts = State(ExtV(nextv, 0), cur.cost + e.cost);\r\n if (nexts.v !in D || D[nexts.v] > nexts.cost) {\r\n D[nexts.v] = nexts.cost;\r\n PQ.insert(nexts);\r\n }\r\n }\r\n }\r\n // can use reversed\r\n foreach (e; rG[cur.v.v]) {\r\n auto nextv = e.to;\r\n auto nexts = State(ExtV(nextv, 1), cur.cost + e.cost);\r\n if (nexts.v !in D || D[nexts.v] > nexts.cost) {\r\n D[nexts.v] = nexts.cost;\r\n PQ.insert(nexts);\r\n }\r\n }\r\n }\r\n long[] buf;\r\n for (int p = 1; p < N; p++) {\r\n long ans = int.max;\r\n for (int b = 0; b < 2; b++) {\r\n auto k = ExtV(p, b);\r\n if (k !in D) continue;\r\n ans = min(ans, D[k]);\r\n }\r\n buf ~= (ans == int.max ? -1 : ans);\r\n }\r\n writefln(\"%(%s %)\", buf);\r\n}\r\n"}], "src_uid": "b08f925e09a9c2e7ccc6a8c5c143fc5f"} {"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\nvoid main()\n{\n int t;\n read(t);\n foreach(tc; 0 .. t)\n {\n int n = next!int;\n string s = next!string;\n auto res = s.filter!(c => to!int(c) % 2 != 0).array.take(2);\n if (res.length == 2)\n {\n foreach(r; res)\n write(r);\n writeln;\n }\n else\n {\n writeln(-1);\n }\n }\n}\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 long readLong() {\n import std.conv : to;\n\n return readToken.to!long;\n }\n\n string[] tokens;\n}\n\nvoid main() {\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n string s = io.readToken;\n int i = 0;\n while (i < n && (s[i] - '0') % 2 == 0) {\n i++;\n }\n if (i == n) {\n writeln(-1);\n }\n else {\n int j = n - 1;\n while (j >= 0 && (s[j] - '0') % 2 == 0) {\n j--;\n }\n if (i == j) {\n writeln(-1);\n }\n else {\n writeln(s[i], s[j]);\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); }\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\t\tlong cnt;\n\t\tstring tmp;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tauto num = [c].to!int;\n\t\t\tif (num % 2 == 1)\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\ttmp ~= c;\n\t\t\t\tif (cnt == 2) break;\n\t\t\t}\n\t\t}\n\t\tif (cnt != 2)\n\t\t\tans[ti] = -1;\n\t\telse\n\t\t\tans[ti] = tmp.to!long;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "8f00837e04627e445dfb8b6cd0216640"} {"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 Q = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto mn = new int[Q + 1];\n auto mx = new int[Q + 1];\n mn[] = N;\n mx[] = -1;\n foreach (i; 0 .. N) {\n chmin(mn[A[i]], i);\n chmax(mx[A[i]], i);\n }\n \n bool ans = false;\n auto as = A.dup;\n \n int inner;\n foreach (i; 0 .. N) {\n if (A[i] != 0) {\n inner = A[i];\n break;\n }\n }\n if (inner == 0) {\n inner = Q;\n }\n DList!int stack;\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = inner;\n } else {\n if (mn[A[i]] == i) {\n if (!stack.empty && stack.back >= A[i]) {\n debug {\n writeln(\"incorrect order\");\n }\n goto failed;\n }\n stack ~= A[i];\n inner = stack.back;\n }\n if (stack.empty || stack.back != A[i]) {\n debug {\n writeln(\"not top\");\n }\n goto failed;\n }\n if (mx[A[i]] == i) {\n stack.removeBack;\n if (!stack.empty) {\n inner = stack.back;\n }\n }\n }\n }\n if (as.count(Q) == 0) {\n if (A.count(0) == 0) {\n debug {\n writeln(\"place for Q not found\");\n }\n goto failed;\n } else {\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = Q;\n break;\n }\n }\n }\n }\n ans = true;\n failed:\n \n if (ans) {\n writeln(\"YES\");\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(as[i]);\n }\n writeln();\n } else {\n writeln(\"NO\");\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, 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 Q = s[1];\n auto A = readln.split.map!(to!int).array;\n auto B = A.dup;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"YES\");\n fill(B, Q);\n B.map!(to!string).join(\" \").writeln;\n return;\n }\n\n\n auto next = iota(1, N+1).array;\n auto prev = iota(-1, N-1).array;\n\n auto LR = new int[][](Q+1, 2);\n foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;\n\n foreach (i; 0..N) {\n LR[A[i]][0] = min(LR[A[i]][0], i);\n LR[A[i]][1] = max(LR[A[i]][1], i);\n }\n\n foreach_reverse (i; 1..Q+1) {\n if (LR[i][0] == INF) continue;\n for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {\n if (A[j] != 0 && A[j] < i) {\n writeln(\"NO\");\n return;\n } else if (B[j] == 0) {\n B[j] = i;\n }\n }\n\n if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];\n if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];\n }\n\n foreach (i; 0..N) if (B[i] == 0) B[i] = 1;\n\n if (LR[Q][0] == INF) {\n bool ok = false;\n foreach (i; 0..N) {\n if (A[i] == 0) {\n B[i] = Q;\n ok = true;\n break;\n }\n }\n if (!ok) {\n writeln(\"NO\");\n return;\n }\n }\n\n writeln(\"YES\");\n B.map!(to!string).join(\" \").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, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int fstzro = arr.canFind(0) ? n - arr.find(0).length.to!int : -1;\n foreach (i; 0 .. n) {\n if (arr[i] == 0 && i > 0 && arr[i-1] != 0) {\n arr[i] = arr[i-1];\n }\n }\n foreach_reverse (i; 0 .. n) {\n if (arr[i] == 0 && i < n-1 && arr[i+1] != 0) arr[i] = arr[i+1];\n }\n foreach (i; 0 .. n) {\n if (arr[i] == 0) arr[i] = q;\n }\n \n debug { arr.writeln; }\n \n if (!arr.canFind(q)) {\n if (fstzro != -1) {\n arr[fstzro] = q;\n } else {\n writeln(\"NO\");\n return;\n }\n }\n \n immutable int MAX_IDX = q;\n int[] fw = new int[] (MAX_IDX+1);\n void add(int idx, int v) {\n while (idx <= MAX_IDX) {\n fw[idx] = v;\n idx += (idx & -idx);\n }\n }\n \n int get(int idx) {\n int mx = -1;\n while (idx > 0) {\n mx = max(mx, fw[idx]);\n idx -= (idx & -idx);\n }\n return mx;\n }\n \n int[] lst = new int[] (MAX_IDX+1);\n lst[] = -1;\n foreach (i, e; arr) {\n if (lst[e] != -1 && lst[e] < get(e-1)) {\n writeln(\"NO\");\n return;\n }\n lst[e] = cast(int) i;\n add(e, cast(int) i);\n }\n \n writeln(\"YES\");\n arr.writefln!(\"%(%s %)\");\n}"}, {"source_code": "// same submission to check against added tests\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int logHalf = 18;\nimmutable int half = 1 << logHalf;\nimmutable int limit = half << 1;\n\nvoid main ()\n{\n\tint n, q;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &q) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tauto lo = new int [q + 1];\n\t\tlo[] = int.max;\n\t\tauto hi = new int [q + 1];\n\t\thi[] = int.min;\n\t\tint pos0 = -1;\n\t\tforeach (i, c; a)\n\t\t{\n\t\t\tif (c != 0)\n\t\t\t{\n\t\t\t\tlo[c] = min (lo[c], i);\n\t\t\t\thi[c] = max (hi[c], i);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpos0 = i;\n\t\t\t}\n\t\t}\n\t\tif (lo[q] == int.max)\n\t\t{\n\t\t\tif (pos0 == -1)\n\t\t\t{\n\t\t\t\twriteln (\"NO\");\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo[q] = pos0;\n\t\t\t\thi[q] = pos0;\n\t\t\t}\n\t\t}\n\n\t\tforeach (j; 1..q)\n\t\t{\n\t\t\tif (lo[j] == int.max)\n\t\t\t{\n\t\t\t\tlo[j] = lo[q];\n\t\t\t\thi[j] = hi[q];\n\t\t\t}\n\t\t}\n\t\tlo[1] = 0;\n\t\thi[1] = n - 1;\n\n\t\tauto t = new int [limit];\n\n\t\tvoid tFill (int u, int v, int w)\n\t\t{\n\t\t\tfor (u += half, v += half; u < v; u >>= 1, v >>= 1)\n\t\t\t{\n\t\t\t\tif (u & 1)\n\t\t\t\t{\n\t\t\t\t\tt[u] = w;\n\t\t\t\t\tu += 1;\n\t\t\t\t}\n\t\t\t\tif (v & 1)\n\t\t\t\t{\n\t\t\t\t\tv -= 1;\n\t\t\t\t\tt[v] = w;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint tGet (int u)\n\t\t{\n\t\t\tint res = 0;\n\t\t\tfor (u += half; u > 0; u >>= 1)\n\t\t\t{\n\t\t\t\tres = max (res, t[u]);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tforeach (j; 1..q + 1)\n\t\t{\n\t\t\ttFill (lo[j], hi[j] + 1, j);\n\t\t}\n\n\t\tauto b = n.iota.map !(i => tGet (i)).array;\n\t\tdebug {writeln (b);}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] != 0 && a[i] != 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\twritefln (\"%(%s %)\", b);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int logHalf = 18;\nimmutable int half = 1 << logHalf;\nimmutable int limit = half << 1;\n\nvoid main ()\n{\n\tint n, q;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &q) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tauto lo = new int [q + 1];\n\t\tlo[] = int.max;\n\t\tauto hi = new int [q + 1];\n\t\thi[] = int.min;\n\t\tint pos0 = -1;\n\t\tforeach (i, c; a)\n\t\t{\n\t\t\tif (c != 0)\n\t\t\t{\n\t\t\t\tlo[c] = min (lo[c], i);\n\t\t\t\thi[c] = max (hi[c], i);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpos0 = i;\n\t\t\t}\n\t\t}\n\t\tif (lo[q] == int.max)\n\t\t{\n\t\t\tif (pos0 == -1)\n\t\t\t{\n\t\t\t\twriteln (\"NO\");\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlo[q] = pos0;\n\t\t\t\thi[q] = pos0;\n\t\t\t}\n\t\t}\n\n\t\tforeach (j; 1..q)\n\t\t{\n\t\t\tif (lo[j] == int.max)\n\t\t\t{\n\t\t\t\tlo[j] = lo[q];\n\t\t\t\thi[j] = hi[q];\n\t\t\t}\n\t\t}\n\t\tlo[1] = 0;\n\t\thi[1] = n - 1;\n\n\t\tauto t = new int [limit];\n\n\t\tvoid tFill (int u, int v, int w)\n\t\t{\n\t\t\tfor (u += half, v += half; u < v; u >>= 1, v >>= 1)\n\t\t\t{\n\t\t\t\tif (u & 1)\n\t\t\t\t{\n\t\t\t\t\tt[u] = w;\n\t\t\t\t\tu += 1;\n\t\t\t\t}\n\t\t\t\tif (v & 1)\n\t\t\t\t{\n\t\t\t\t\tv -= 1;\n\t\t\t\t\tt[v] = w;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint tGet (int u)\n\t\t{\n\t\t\tint res = 0;\n\t\t\tfor (u += half; u > 0; u >>= 1)\n\t\t\t{\n\t\t\t\tres = max (res, t[u]);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tforeach (j; 1..q + 1)\n\t\t{\n\t\t\ttFill (lo[j], hi[j] + 1, j);\n\t\t}\n\n\t\tauto b = n.iota.map !(i => tGet (i)).array;\n\t\tdebug {writeln (b);}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] != 0 && a[i] != 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\twritefln (\"%(%s %)\", b);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nstruct seg\n{\n int l = int.max;\n int r;\n}\n\nint[] t;\nvoid build(int[] a, int v)\n{\n if (a.length == 1) {\n t[v] = a[0];\n if (!t[v])\n t[v] = int.max;\n }\n else {\n int mid = cast(int)a.length >> 1;\n build(a[0 .. mid], v * 2 + 1);\n build(a[mid .. $], v * 2 + 2);\n t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);\n }\n}\n\nint get(int v, int ql, int qr, int l, int r)\n{\n if (l == ql && r == qr)\n return t[v];\n int mid = (l + r) / 2;\n if (qr <= mid)\n return get(v * 2 + 1, ql, qr, l, mid);\n if (ql >= mid)\n return get(v * 2 + 2, ql, qr, mid, r);\n int t1 = get(v * 2 + 1, ql, mid, l, mid);\n int t2 = get(v * 2 + 2, mid, qr, mid, r);\n return min(t1, t2);\n}\n\nvoid main()\n{\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n auto a = readln.splitter.map!(to!int).array;\n t = new int[n * 4];\n build(a, 0);\n auto b = new seg[m];\n foreach (int i, val; a) {\n if (!val) \n continue;\n --val;\n b[val].l = min(b[val].l, i);\n b[val].r = max(b[val].r, i);\n }\n if (!a.count(m)) {\n bool ok = false;\n foreach (ref val; a) {\n if (!val) {\n val = m;\n ok = true;\n break;\n }\n }\n if (!ok) {\n writeln(\"NO\");\n return;\n }\n }\n foreach (i, ref sg; b) {\n if (sg.l != int.max\n && get(0, sg.l, sg.r + 1, 0, n) <= i) {\n writeln(\"NO\");\n return;\n }\n }\n if (a.count(0) == a.length)\n a[] = m;\n else {\n int i;\n while (!a[i])\n ++i;\n a[0 .. i] = a[i];\n while (i < a.length) {\n if (a[i]) {\n ++i;\n continue;\n }\n int c = i;\n while (i < a.length && !a[i])\n ++i;\n a[c .. i] = a[c - 1];\n }\n }\n writefln(\"YES\\n%(%d %)\", a);\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\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto Q = s[1];\n auto A = readln.split.map!(to!int).array;\n auto B = A.dup;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"YES\");\n fill(B, Q);\n B.map!(to!string).join(\" \").writeln;\n return;\n }\n\n\n auto next = iota(1, N+1).array;\n auto prev = iota(-1, N-1).array;\n\n auto LR = new int[][](Q+1, 2);\n foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;\n\n foreach (i; 0..N) {\n LR[A[i]][0] = min(LR[A[i]][0], i);\n LR[A[i]][1] = max(LR[A[i]][1], i);\n }\n\n foreach_reverse (i; 1..Q+1) {\n if (LR[i][0] == INF) continue;\n for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {\n if (A[j] != 0 && A[j] < i) {\n writeln(\"NO\");\n return;\n } else if (A[j] == 0) {\n B[j] = i;\n }\n }\n for (int j = prev[LR[i][0]]; j >= 0 && B[j] == 0; j = prev[j]) {\n B[j] = i;\n LR[i][0] = j;\n }\n for (int j = next[LR[i][1]]; j < N && B[j] == 0; j = next[j]) {\n B[j] = i;\n LR[i][1] = j;\n }\n\n if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];\n if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];\n }\n\n if (LR[Q][0] == INF) {\n bool ok = false;\n foreach (i; 0..N) {\n if (A[i] == 0) {\n B[i] = Q;\n ok = true;\n break;\n }\n }\n if (!ok) {\n writeln(\"NO\");\n return;\n }\n }\n\n writeln(\"YES\");\n B.map!(to!string).join(\" \").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 int INF = 1 << 29;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto Q = s[1];\n auto A = readln.split.map!(to!int).array;\n auto B = A.dup;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"YES\");\n fill(B, Q);\n B.map!(to!string).join(\" \").writeln;\n return;\n }\n\n\n auto next = iota(1, N+1).array;\n auto prev = iota(-1, N-1).array;\n\n auto LR = new int[][](Q+1, 2);\n foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;\n\n foreach (i; 0..N) {\n LR[A[i]][0] = min(LR[A[i]][0], i);\n LR[A[i]][1] = max(LR[A[i]][1], i);\n }\n\n foreach_reverse (i; 1..Q+1) {\n if (LR[i][0] == INF) continue;\n for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {\n if (A[j] != 0 && A[j] < i) {\n writeln(\"NO\");\n return;\n } else if (A[j] == 0) {\n B[j] = i;\n }\n }\n\n if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];\n if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];\n }\n\n foreach (i; 0..N) if (B[i] == 0) B[i] = 1;\n\n if (LR[Q][0] == INF) {\n bool ok = false;\n foreach (i; 0..N) {\n if (A[i] == 0) {\n B[i] = Q;\n ok = true;\n break;\n }\n }\n if (!ok) {\n writeln(\"NO\");\n return;\n }\n }\n\n writeln(\"YES\");\n B.map!(to!string).join(\" \").write;\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 int INF = 1 << 29;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto Q = s[1];\n auto A = readln.split.map!(to!int).array;\n auto B = A.dup;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"YES\");\n fill(B, Q);\n B.map!(to!string).join(\" \").writeln;\n return;\n }\n\n\n auto next = iota(1, N+1).array;\n auto prev = iota(-1, N-1).array;\n\n auto LR = new int[][](Q+1, 2);\n foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;\n\n foreach (i; 0..N) {\n LR[A[i]][0] = min(LR[A[i]][0], i);\n LR[A[i]][1] = max(LR[A[i]][1], i);\n }\n\n foreach_reverse (i; 1..Q+1) {\n if (LR[i][0] == INF) continue;\n for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {\n if (A[j] != 0 && A[j] < i) {\n writeln(\"NO\");\n return;\n } else if (A[j] == 0) {\n B[j] = i;\n }\n }\n\n if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];\n if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];\n }\n\n foreach (i; 0..N) if (B[i] == 0) B[i] = 1;\n\n if (LR[Q][0] == INF) {\n bool ok = false;\n foreach (i; 0..N) {\n if (A[i] == 0) {\n B[i] = Q;\n ok = true;\n break;\n }\n }\n if (!ok) {\n writeln(\"NO\");\n return;\n }\n }\n\n writeln(\"YES\");\n B.map!(to!string).join(\" \").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 int INF = 1 << 29;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto Q = s[1];\n auto A = readln.split.map!(to!int).array;\n auto B = A.dup;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"YES\");\n fill(B, Q);\n B.map!(to!string).join(\" \").writeln;\n return;\n }\n\n\n auto next = iota(1, N+1).array;\n auto prev = iota(-1, N-1).array;\n\n auto LR = new int[][](Q+1, 2);\n foreach (i; 0..Q+1) LR[i][0] = INF, LR[i][1] = -1;\n\n foreach (i; 0..N) {\n LR[A[i]][0] = min(LR[A[i]][0], i);\n LR[A[i]][1] = max(LR[A[i]][1], i);\n }\n\n foreach_reverse (i; 1..Q+1) {\n if (LR[i][0] == INF) continue;\n for (int j = LR[i][0]; j <= LR[i][1]; j = next[j]) {\n if (A[j] != 0 && A[j] < i) {\n writeln(\"NO\");\n return;\n } else if (A[j] == 0) {\n B[j] = i;\n }\n }\n for (int j = prev[LR[i][0]]; j >= 0 && B[j] == 0; j = prev[j]) {\n B[j] = i;\n }\n for (int j = next[LR[i][1]]; j < N && B[j] == 0; j = next[j]) {\n B[j] = i;\n }\n\n if (LR[i][0] > 0) next[LR[i][0]-1] = next[LR[i][1]];\n if (LR[i][1] < N-1) prev[LR[i][1]+1] = prev[LR[i][0]];\n }\n\n if (LR[Q][0] == INF) {\n bool ok = false;\n foreach (i; 0..N) {\n if (A[i] == 0) {\n B[i] = Q;\n ok = true;\n break;\n }\n }\n if (!ok) {\n writeln(\"NO\");\n return;\n }\n }\n\n writeln(\"YES\");\n B.map!(to!string).join(\" \").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, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n foreach (i; 0 .. n) {\n if (arr[i] == 0 && i > 0 && arr[i-1] != 0) arr[i] = arr[i-1];\n }\n foreach_reverse (i; 0 .. n) {\n if (arr[i] == 0 && i < n-1 && arr[i+1] != 0) arr[i] = arr[i+1];\n }\n foreach (i; 0 .. n) {\n if (arr[i] == 0) arr[i] = q;\n }\n \n debug { arr.writeln; }\n \n if (!arr.canFind(q)) {\n writeln(\"NO\");\n return;\n }\n \n immutable int MAX_IDX = q;\n int[] fw = new int[] (MAX_IDX+1);\n void add(int idx, int v) {\n while (idx <= MAX_IDX) {\n fw[idx] = v;\n idx += (idx & -idx);\n }\n }\n \n int get(int idx) {\n int mx = -1;\n while (idx > 0) {\n mx = max(mx, fw[idx]);\n idx -= (idx & -idx);\n }\n return mx;\n }\n \n int[] lst = new int[] (MAX_IDX+1);\n lst[] = -1;\n foreach (i, e; arr) {\n if (lst[e] != -1 && lst[e] < get(e-1)) {\n writeln(i, ' ', e, ' ', lst[e], ' ', get(e-1));\n writeln(\"NO\");\n return;\n }\n lst[e] = cast(int) i;\n add(e, cast(int) i);\n }\n \n writeln(\"YES\");\n 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, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n foreach (i; 0 .. n) {\n if (arr[i] == 0 && i > 0 && arr[i-1] != 0) arr[i] = arr[i-1];\n }\n foreach_reverse (i; 0 .. n) {\n if (arr[i] == 0 && i < n-1 && arr[i+1] != 0) arr[i] = arr[i+1];\n }\n foreach (i; 0 .. n) {\n if (arr[i] == 0) arr[i] = q;\n }\n \n debug { arr.writeln; }\n \n immutable int MAX_IDX = q;\n int[] fw = new int[] (MAX_IDX+1);\n void add(int idx, int v) {\n while (idx <= MAX_IDX) {\n fw[idx] = v;\n idx += (idx & -idx);\n }\n }\n \n int get(int idx) {\n int mx = -1;\n while (idx > 0) {\n mx = max(mx, fw[idx]);\n idx -= (idx & -idx);\n }\n return mx;\n }\n \n int[] lst = new int[] (MAX_IDX+1);\n lst[] = -1;\n foreach (i, e; arr) {\n if (lst[e] != -1 && lst[e] < get(e-1)) {\n writeln(i, ' ', e, ' ', lst[e], ' ', get(e-1));\n writeln(\"NO\");\n return;\n }\n lst[e] = cast(int) i;\n add(e, cast(int) i);\n }\n \n writeln(\"YES\");\n 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, q;\n readf(\"%s %s\", &n, &q);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n foreach (i; 0 .. n) {\n if (arr[i] == 0 && i > 0 && arr[i-1] != 0) arr[i] = arr[i-1];\n }\n foreach_reverse (i; 0 .. n) {\n if (arr[i] == 0 && i < n-1 && arr[i+1] != 0) arr[i] = arr[i+1];\n }\n foreach (i; 0 .. n) {\n if (arr[i] == 0) arr[i] = q;\n }\n \n debug { arr.writeln; }\n \n if (!arr.canFind(q)) {\n writeln(\"NO\");\n return;\n }\n \n immutable int MAX_IDX = q;\n int[] fw = new int[] (MAX_IDX+1);\n void add(int idx, int v) {\n while (idx <= MAX_IDX) {\n fw[idx] = v;\n idx += (idx & -idx);\n }\n }\n \n int get(int idx) {\n int mx = -1;\n while (idx > 0) {\n mx = max(mx, fw[idx]);\n idx -= (idx & -idx);\n }\n return mx;\n }\n \n int[] lst = new int[] (MAX_IDX+1);\n lst[] = -1;\n foreach (i, e; arr) {\n if (lst[e] != -1 && lst[e] < get(e-1)) {\n writeln(\"NO\");\n return;\n }\n lst[e] = cast(int) i;\n add(e, cast(int) i);\n }\n \n writeln(\"YES\");\n arr.writefln!(\"%(%s %)\");\n}"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nstruct seg\n{\n int l = int.max;\n int r;\n}\n\nint[] t;\nvoid build(int[] a, int v)\n{\n if (a.length == 1) {\n t[v] = a[0];\n }\n else {\n int mid = cast(int)a.length >> 1;\n build(a[0 .. mid], v * 2 + 1);\n build(a[mid .. $], v * 2 + 2);\n t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);\n }\n}\n\nint get(int v, int ql, int qr, int l, int r)\n{\n if (l == ql && r == qr)\n return t[v];\n int mid = (l + r) / 2;\n if (qr <= mid)\n return get(v * 2 + 1, ql, qr, l, mid);\n if (ql >= mid)\n return get(v * 2 + 2, ql, qr, mid, r);\n int t1 = get(v * 2 + 1, ql, mid, l, mid);\n int t2 = get(v * 2 + 2, mid, qr, mid, r);\n return min(t1, t2);\n}\n\nvoid main()\n{\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n auto a = readln.splitter.map!(to!int).array;\n t = new int[n * 4];\n build(a, 0);\n auto b = new seg[m];\n foreach (int i, val; a) {\n if (!val) \n continue;\n --val;\n b[val].l = min(b[val].l, i);\n b[val].r = max(b[val].r, i);\n }\n foreach (i, ref sg; b) {\n if (sg.l != int.max\n && get(0, sg.l, sg.r + 1, 0, n) <= i) {\n writeln(\"NO\");\n return;\n }\n }\n if (a.count(0) == a.length)\n a[] = m;\n else {\n int i;\n while (!a[i])\n ++i;\n a[0 .. i] = a[i];\n while (i < a.length) {\n if (a[i]) {\n ++i;\n continue;\n }\n writeln(i);\n int c = i;\n while (i < a.length && !a[i])\n ++i;\n writeln(i);\n a[c .. i] = a[c - 1];\n }\n }\n writefln(\"YES\\n%(%d %)\", a);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nstruct seg\n{\n int l = int.max;\n int r;\n}\n\nint[] t;\nvoid build(int[] a, int v)\n{\n if (a.length == 1) {\n t[v] = a[0];\n if (!t[v])\n t[v] = int.max;\n }\n else {\n int mid = cast(int)a.length >> 1;\n build(a[0 .. mid], v * 2 + 1);\n build(a[mid .. $], v * 2 + 2);\n t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);\n }\n}\n\nint get(int v, int ql, int qr, int l, int r)\n{\n if (l == ql && r == qr)\n return t[v];\n int mid = (l + r) / 2;\n if (qr <= mid)\n return get(v * 2 + 1, ql, qr, l, mid);\n if (ql >= mid)\n return get(v * 2 + 2, ql, qr, mid, r);\n int t1 = get(v * 2 + 1, ql, mid, l, mid);\n int t2 = get(v * 2 + 2, mid, qr, mid, r);\n return min(t1, t2);\n}\n\nvoid main()\n{\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n auto a = readln.splitter.map!(to!int).array;\n t = new int[n * 4];\n build(a, 0);\n auto b = new seg[m];\n foreach (int i, val; a) {\n if (!val) \n continue;\n --val;\n b[val].l = min(b[val].l, i);\n b[val].r = max(b[val].r, i);\n }\n if (!a.count(m)) {\n bool ok = false;\n foreach (ref val; a) {\n if (!val) {\n val = m;\n ok = true;\n }\n }\n if (!ok) {\n writeln(\"NO\");\n return;\n }\n }\n foreach (i, ref sg; b) {\n if (sg.l != int.max\n && get(0, sg.l, sg.r + 1, 0, n) <= i) {\n writeln(\"NO\");\n return;\n }\n }\n if (a.count(0) == a.length)\n a[] = m;\n else {\n int i;\n while (!a[i])\n ++i;\n a[0 .. i] = a[i];\n while (i < a.length) {\n if (a[i]) {\n ++i;\n continue;\n }\n int c = i;\n while (i < a.length && !a[i])\n ++i;\n a[c .. i] = a[c - 1];\n }\n }\n writefln(\"YES\\n%(%d %)\", a);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nstruct seg\n{\n int l = int.max;\n int r;\n}\n\nint[] t;\nvoid build(int[] a, int v)\n{\n if (a.length == 1) {\n t[v] = a[0];\n }\n else {\n int mid = cast(int)a.length >> 1;\n build(a[0 .. mid], v * 2 + 1);\n build(a[mid .. $], v * 2 + 2);\n t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);\n }\n}\n\nint get(int v, int ql, int qr, int l, int r)\n{\n if (l == ql && r == qr)\n return t[v];\n int mid = (l + r) / 2;\n if (qr <= mid)\n return get(v * 2 + 1, ql, qr, l, mid);\n if (ql >= mid)\n return get(v * 2 + 2, ql, qr, mid, r);\n int t1 = get(v * 2 + 1, ql, mid, l, mid);\n int t2 = get(v * 2 + 2, mid, qr, mid, r);\n return min(t1, t2);\n}\n\nvoid main()\n{\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n auto a = readln.splitter.map!(to!int).array;\n t = new int[n * 4];\n build(a, 0);\n auto b = new seg[m];\n foreach (int i, val; a) {\n if (!val) \n continue;\n --val;\n b[val].l = min(b[val].l, i);\n b[val].r = max(b[val].r, i);\n }\n foreach (i, ref sg; b) {\n if (sg.l != int.max\n && get(0, sg.l, sg.r + 1, 0, n) <= i) {\n writeln(\"NO\");\n return;\n }\n }\n if (a.count(0) == a.length)\n a[] = m;\n else {\n int i;\n while (!a[i])\n ++i;\n a[0 .. i] = a[i];\n while (i < a.length) {\n if (a[i]) {\n ++i;\n continue;\n }\n int c = i;\n while (i < a.length && !a[i])\n ++i;\n a[c .. i] = a[c - 1];\n }\n }\n writefln(\"YES\\n%(%d %)\", a);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nstruct seg\n{\n int l = int.max;\n int r;\n}\n\nint[] t;\nvoid build(int[] a, int v)\n{\n if (a.length == 1) {\n t[v] = a[0];\n if (!t[v])\n t[v] = int.max;\n }\n else {\n int mid = cast(int)a.length >> 1;\n build(a[0 .. mid], v * 2 + 1);\n build(a[mid .. $], v * 2 + 2);\n t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);\n }\n}\n\nint get(int v, int ql, int qr, int l, int r)\n{\n if (l == ql && r == qr)\n return t[v];\n int mid = (l + r) / 2;\n if (qr <= mid)\n return get(v * 2 + 1, ql, qr, l, mid);\n if (ql >= mid)\n return get(v * 2 + 2, ql, qr, mid, r);\n int t1 = get(v * 2 + 1, ql, mid, l, mid);\n int t2 = get(v * 2 + 2, mid, qr, mid, r);\n return min(t1, t2);\n}\n\nvoid main()\n{\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n auto a = readln.splitter.map!(to!int).array;\n t = new int[n * 4];\n build(a, 0);\n auto b = new seg[m];\n foreach (int i, val; a) {\n if (!val) \n continue;\n --val;\n b[val].l = min(b[val].l, i);\n b[val].r = max(b[val].r, i);\n }\n if (!a.count(0) && !a.count(m)) {\n writeln(\"NO\");\n return;\n }\n foreach (i, ref sg; b) {\n if (sg.l != int.max\n && get(0, sg.l, sg.r + 1, 0, n) <= i) {\n writeln(\"NO\");\n return;\n }\n }\n if (a.count(0) == a.length)\n a[] = m;\n else {\n int i;\n while (!a[i])\n ++i;\n a[0 .. i] = a[i];\n while (i < a.length) {\n if (a[i]) {\n ++i;\n continue;\n }\n int c = i;\n while (i < a.length && !a[i])\n ++i;\n a[c .. i] = a[c - 1];\n }\n }\n writefln(\"YES\\n%(%d %)\", a);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nstruct seg\n{\n int l = int.max;\n int r;\n}\n\nint[] t;\nvoid build(int[] a, int v)\n{\n if (a.length == 1) {\n t[v] = a[0];\n }\n else {\n int mid = cast(int)a.length >> 1;\n build(a[0 .. mid], v * 2 + 1);\n build(a[mid .. $], v * 2 + 2);\n t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);\n }\n}\n\nint get(int v, int ql, int qr, int l, int r)\n{\n if (l == ql && r == qr)\n return t[v];\n int mid = (l + r) / 2;\n if (qr <= mid)\n return get(v * 2 + 1, ql, qr, l, mid);\n if (ql >= mid)\n return get(v * 2 + 2, ql, qr, mid, r);\n int t1 = get(v * 2 + 1, ql, mid, l, mid);\n int t2 = get(v * 2 + 2, mid, qr, mid, r);\n return min(t1, t2);\n}\n\nvoid main()\n{\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n auto a = readln.splitter.map!(to!int).array;\n t = new int[n * 4];\n build(a, 0);\n auto b = new seg[m];\n foreach (int i, val; a) {\n if (!val) \n continue;\n --val;\n b[val].l = min(b[val].l, i);\n b[val].r = max(b[val].r, i);\n }\n foreach (i, ref sg; b) {\n if (sg.l != int.max\n && get(0, sg.l, sg.r + 1, 0, n) <= i) {\n writeln(\"NO\");\n return;\n }\n }\n if (a.count(0) == a.length)\n a[] = m;\n else {\n int i;\n while (!a[i])\n ++i;\n a[0 .. i] = a[i];\n while (i < a.length) {\n if (a[i]) {\n ++i;\n continue;\n }\n writeln(i);\n int c = i;\n while (i < a.length && !a[i])\n ++i;\n writeln(i);\n a[c .. i] = a[c - 1];\n }\n }\n writefln(\"%(%d %)\", a);\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 Q = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto mn = new int[Q + 1];\n auto mx = new int[Q + 1];\n mn[] = N;\n mx[] = -1;\n foreach (i; 0 .. N) {\n chmin(mn[A[i]], i);\n chmax(mx[A[i]], i);\n }\n \n auto diss = new int[][N];\n auto fins = new int[][N];\n foreach (j; 1 .. Q + 1) {\n if (mn[j] <= mx[j]) {\n diss[mn[j]] ~= j;\n fins[mx[j]] ~= j;\n }\n }\n foreach (i; 0 .. N) {\n diss[i].sort!((j0, j1) => (j0 < j1));\n fins[i].sort!((j0, j1) => (j0 > j1));\n }\n debug {\n writeln(\"diss = \", diss);\n writeln(\"fins = \", fins);\n }\n \n bool ans = false;\n auto as = A.dup;\n \n int outer;\n foreach (i; 0 .. N) {\n if (diss[i]) {\n outer = diss[i][0];\n break;\n }\n }\n if (outer == 0) {\n outer = Q;\n }\n DList!int stack;\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = outer;\n } else {\n foreach (j; diss[i]) {\n if (!stack.empty && stack.back >= j) {\n goto failed;\n }\n if (stack.empty) {\n outer = j;\n }\n stack ~= j;\n }\n if (stack.empty || stack.back != A[i]) {\n goto failed;\n }\n foreach (j; fins[i]) {\n if (stack.empty || stack.back != j) {\n goto failed;\n }\n stack.removeBack;\n }\n }\n }\n if (as.count(Q) == 0) {\n if (A.count(0) == 0) {\n goto failed;\n } else {\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = Q;\n break;\n }\n }\n }\n }\n ans = true;\n failed:\n if (ans) {\n writeln(\"YES\");\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(as[i]);\n }\n writeln();\n } else {\n writeln(\"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.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 A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto mn = new int[Q + 1];\n auto mx = new int[Q + 1];\n mn[] = N;\n mx[] = -1;\n foreach (i; 0 .. N) {\n chmin(mn[A[i]], i);\n chmax(mx[A[i]], i);\n }\n \n auto diss = new int[][N];\n auto fins = new int[][N];\n foreach (j; 1 .. Q + 1) {\n if (mn[j] <= mx[j]) {\n diss[mn[j]] ~= j;\n fins[mx[j]] ~= j;\n }\n }\n foreach (i; 0 .. N) {\n diss[i].sort!((j0, j1) => (j0 < j1));\n fins[i].sort!((j0, j1) => (j0 > j1));\n }\n debug {\n writeln(\"diss = \", diss);\n writeln(\"fins = \", fins);\n }\n \n bool ans = false;\n auto as = A.dup;\n \n int outer;\n foreach (i; 0 .. N) {\n if (diss[i]) {\n outer = diss[i][0];\n break;\n }\n }\n if (outer == 0) {\n outer = Q;\n }\n DList!int stack;\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = outer;\n } else {\n foreach (j; diss[i]) {\n if (!stack.empty && stack.back >= j) {\n goto failed;\n }\n if (stack.empty) {\n outer = j;\n }\n stack ~= j;\n }\n foreach (j; fins[i]) {\n if (stack.empty || stack.back != j) {\n goto failed;\n }\n stack.removeBack;\n }\n }\n }\n if (as.count(Q) == 0) {\n if (A.count(0) == 0) {\n goto failed;\n } else {\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = Q;\n break;\n }\n }\n }\n }\n ans = true;\n failed:\n if (ans) {\n writeln(\"YES\");\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(as[i]);\n }\n writeln();\n } else {\n writeln(\"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.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 A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto mn = new int[Q + 1];\n auto mx = new int[Q + 1];\n mn[] = N;\n mx[] = -1;\n foreach (i; 0 .. N) {\n chmin(mn[A[i]], i);\n chmax(mx[A[i]], i);\n }\n \n auto diss = new int[][N];\n auto fins = new int[][N];\n foreach (j; 1 .. Q + 1) {\n if (mn[j] <= mx[j]) {\n diss[mn[j]] ~= j;\n fins[mx[j]] ~= j;\n }\n }\n foreach (i; 0 .. N) {\n diss[i].sort!((j0, j1) => (j0 < j1));\n fins[i].sort!((j0, j1) => (j0 > j1));\n }\n debug {\n writeln(\"diss = \", diss);\n writeln(\"fins = \", fins);\n }\n \n int outer;\n foreach (i; 0 .. N) {\n if (diss[i]) {\n outer = diss[i][0];\n break;\n }\n }\n if (outer == 0) {\n outer = 1;\n }\n auto as = A.dup;\n DList!int stack;\n bool ans = false;\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = outer;\n } else {\n foreach (j; diss[i]) {\n if (!stack.empty && stack.back >= j) {\n goto failed;\n }\n if (stack.empty) {\n outer = j;\n }\n stack ~= j;\n }\n foreach (j; fins[i]) {\n if (stack.empty || stack.back != j) {\n goto failed;\n }\n stack.removeBack;\n }\n }\n }\n ans = true;\n failed:\n if (ans) {\n writeln(\"YES\");\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(as[i]);\n }\n writeln();\n } else {\n writeln(\"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.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 A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto mn = new int[Q + 1];\n auto mx = new int[Q + 1];\n mn[] = N;\n mx[] = -1;\n foreach (i; 0 .. N) {\n chmin(mn[A[i]], i);\n chmax(mx[A[i]], i);\n }\n \n bool ans = false;\n auto as = A.dup;\n \n int outer;\n foreach (i; 0 .. N) {\n if (A[i] != 0) {\n outer = A[i];\n break;\n }\n }\n if (outer == 0) {\n outer = Q;\n }\n DList!int stack;\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = outer;\n } else {\n if (mn[A[i]] == i) {\n if (!stack.empty && stack.back >= A[i]) {\n debug {\n writeln(\"incorrect order\");\n }\n goto failed;\n }\n if (stack.empty) {\n outer = A[i];\n }\n stack ~= A[i];\n }\n if (stack.empty || stack.back != A[i]) {\n debug {\n writeln(\"not top\");\n }\n goto failed;\n }\n if (mx[A[i]] == i) {\n stack.removeBack;\n }\n }\n }\n if (as.count(Q) == 0) {\n if (A.count(0) == 0) {\n debug {\n writeln(\"place for Q not found\");\n }\n goto failed;\n } else {\n foreach (i; 0 .. N) {\n if (A[i] == 0) {\n as[i] = Q;\n break;\n }\n }\n }\n }\n ans = true;\n failed:\n \n if (ans) {\n writeln(\"YES\");\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(as[i]);\n }\n writeln();\n } else {\n writeln(\"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "e0450f2644494c92ec0d9ea3ab9d0056"} {"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 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 k = cin.read_int;\n\n int[] arr = new int[n];\n if (k == n) writeln(-1);\n else {\n for (int i = n; i > n - k; i--) {\n arr[i - 1] = i;\n }\n for (int i = 1; i < n - k; i++) {\n arr[i - 1] = i + 1;\n }\n arr[n - k - 1] = 1;\n foreach (i; arr) write(i, \" \");\n }\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\nint N;\nint K;\n\nvoid main () {\n N = readInt();\n K = readInt();\n\n int i;\n\n if (N == K) {\n writeln(\"-1\");\n } else if (N == K + 1) {\n for (i = 1; i <= N; i++) {\n writef(\"%s \", i);\n }\n } else { \n writef(\"%s \", N);\n\n for (i = 2; i <= K + 1; i++) {\n writef(\"%s \", i);\n }\n \n writef(\"%s \", 1);\n\n for (i = K + 2; i <= N - 1; i++) {\n writef(\"%s \", i);\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 read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\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 k = cin.read_int;\n\n int[] arr = new int[n];\n for (int i = 1; i <= k; i++) {\n if (i * 2 > n) {\n writeln(-1);\n return;\n } else arr[i - 1] = i * 2;\n }\n\n for (int i = k + 1; i <= n; i++) {\n if (canFind(arr, i)) {\n for (int j = 1; j <= n; j++) {\n if(!canFind(arr, j)) arr[i - 1] = j;\n break;\n }\n } else arr[i - 1] = i;\n }\n \n foreach (i; arr) {\n write(i, \" \");\n }\n } \n}"}], "src_uid": "dc548fe1d8683b4b0ee4e0fa67638185"} {"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 if (x > 0 && A[x - 1][y] == '#') uf.connect((x - 1) * N + y, x * N + y);\n if (y > 0 && A[x][y - 1] == '#') uf.connect(x * N + (y - 1), x * N + y);\n }\n }\n int num;\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n if (A[x][y] == '#') {\n if (uf[x * N + y] < 0) {\n ++num;\n }\n }\n }\n \n bool ans = true;\n bool empRow, empCol;\n foreach (x; 0 .. M) {\n int mn = N, mx = -1;\n foreach (y; 0 .. N) {\n if (A[x][y] == '#') {\n chmin(mn, y);\n chmax(mx, y);\n }\n }\n if (mn <= mx) {\n foreach (y; mn .. mx + 1) {\n ans = ans && (A[x][y] == '#');\n }\n } else {\n empRow = true;\n }\n }\n foreach (y; 0 .. N) {\n int mn = M, mx = -1;\n foreach (x; 0 .. M) {\n if (A[x][y] == '#') {\n chmin(mn, x);\n chmax(mx, x);\n }\n }\n if (mn <= mx) {\n foreach (x; mn .. mx + 1) {\n ans = ans && (A[x][y] == '#');\n }\n } else {\n empCol = true;\n }\n }\n ans = ans && (empRow == empCol);\n \n writeln(ans ? num : -1);\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\nimmutable int NA = -1;\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 [] board;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tboard ~= readln.strip;\n\t\t}\n\n\t\tauto mark = new int [] [] (rows, cols);\n\t\tforeach (ref line; mark)\n\t\t{\n\t\t\tline[] = NA;\n\t\t}\n\t\tint num = 0;\n\n\t\tvoid doMark (int sRow, int sCol)\n\t\t{\n\t\t\talias Coord = Tuple !(int, q{row}, int, q{col});\n\t\t\tCoord [] q;\n\t\t\tq ~= Coord (sRow, sCol);\n\t\t\tmark[sRow][sCol] = num;\n\t\t\twhile (!q.empty)\n\t\t\t{\n\t\t\t\tauto row = q.front.row;\n\t\t\t\tauto col = q.front.col;\n\t\t\t\tq.popFront ();\n\t\t\t\tq.assumeSafeAppend ();\n\t\t\t\tforeach (dir; 0..dirs)\n\t\t\t\t{\n\t\t\t\t\tauto nRow = row + dRow[dir];\n\t\t\t\t\tauto nCol = col + dCol[dir];\n\t\t\t\t\tif (0 <= nRow && nRow < rows &&\n\t\t\t\t\t 0 <= nCol && nCol < cols &&\n\t\t\t\t\t board[nRow][nCol] == '#' &&\n\t\t\t\t\t mark[nRow][nCol] == NA)\n\t\t\t\t\t{\n\t\t\t\t\t\tmark[nRow][nCol] = num;\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\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tif (board[row][col] == '#' &&\n\t\t\t\t mark[row][col] == NA)\n\t\t\t\t{\n\t\t\t\t\tdoMark (row, col);\n\t\t\t\t\tnum += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tbool ok = true;\n\n\t\tauto countRow = new int [rows];\n\t\tauto countCol = new int [cols];\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint temp = 0;\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tif (board[row][col] == '#')\n\t\t\t\t{\n\t\t\t\t\tcountRow[row] += 1;\n\t\t\t\t\tcountCol[col] += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tok &= (countRow.canFind (0) == countCol.canFind (0));\n\n\t\tvoid checkSquare (ref int seen, int cur)\n\t\t{\n\t\t\tif (seen == NA)\n\t\t\t{\n\t\t\t\tseen = cur;\n\t\t\t}\n\t\t\telse if (seen < num)\n\t\t\t{\n\t\t\t\tif (cur == NA)\n\t\t\t\t{\n\t\t\t\t\tseen = num;\n\t\t\t\t}\n\t\t\t\telse if (cur != seen)\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (cur != NA)\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\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tint seen = NA;\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tauto cur = mark[row][col];\n\t\t\t\tcheckSquare (seen, cur);\n\t\t\t}\n\t\t}\n\t\tforeach (col; 0..cols)\n\t\t{\n\t\t\tint seen = NA;\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tauto cur = mark[row][col];\n\t\t\t\tcheckSquare (seen, cur);\n\t\t\t}\n\t\t}\n\n\t\twriteln (ok ? num : NA);\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 inputFile = stdin;\n auto n = next!int;\n auto m = next!int;\n auto imat = next!string(n);\n auto mat = new char[][](n, m);\n foreach(i; 0 .. n)\n mat[i][] = imat[i].dup;\n void impossible()\n {\n writeln(-1);\n }\n void ans(int a)\n {\n writeln(a);\n }\n int blankRows = 0;\n int blankCols = 0;\n foreach(i; 0 .. n)\n {\n int cnt = 0;\n int l = int.max;\n int h = int.min;\n foreach(j; 0 .. m)\n\tif (mat[i][j] == '#')\n\t {\n\t l = min(l, j);\n\t h = max(h, j);\n\t cnt++;\n\t }\n if (cnt == 0)\n\t{\n\t blankRows++;\n\t continue;\n\t}\n if (h - l + 1 != cnt)\n\treturn impossible;\n }\n foreach(i; 0 .. m)\n {\n int cnt = 0;\n int l = int.max;\n int h = int.min;\n foreach(j; 0 .. n)\n\tif (mat[j][i] == '#')\n\t {\n\t l = min(l, j);\n\t h = max(h, j);\n\t cnt++;\n\t }\n if (cnt == 0)\n\t{\n\t blankCols++;\n\t continue;\n\t}\n if (h - l + 1 != cnt)\n\treturn impossible;\n }\n if (blankRows != 0 && blankCols == 0\n || blankCols != 0 && blankRows == 0) return impossible;\n auto deltas = [[+1, 0], [-1, 0], [0, +1], [0, -1]];\n void dfs(int i, int j)\n {\n if (i < 0 || i >= n || j < 0 || j >= m || mat[i][j] != '#')\n return;\n assert(mat[i][j] == '#');\n mat[i][j] = '.';\n foreach(delta; deltas)\n dfs(i + delta[0], j + delta[1]);\n }\n int cmps = 0;\n foreach(i; 0 .. n)\n {\n foreach(j; 0 .. m)\n\t{\n\t if (mat[i][j] == '#')\n\t {\n\t dfs(i, j);\n\t cmps++;\n\t }\n\t}\n }\n return ans(cmps);\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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n\n auto MAP = new char[][](N.to!size_t, M.to!size_t);\n foreach (i; 0..N) foreach (j, c; readln.chomp) MAP[i][j] = c;\n\n bool rb, cb;\n foreach (i; 0..N) {\n bool rrb = true;\n foreach (j; 0..M) if (MAP[i][j] == '#') {\n rrb = false;\n break;\n }\n if (rrb) {\n rb = true;\n break;\n }\n }\n foreach (j; 0..M) {\n bool ccb = true;\n foreach (i; 0..N) if (MAP[i][j] == '#') {\n ccb = false;\n break;\n }\n if (ccb) {\n cb = true;\n break;\n }\n }\n if (rb != cb) {\n writeln(-1);\n return;\n }\n\n foreach (i; 0..N) {\n bool cd;\n if (MAP[i][0] == '#') cd = true;\n foreach (j; 1..M) {\n if (MAP[i][j-1] == '.' && MAP[i][j] == '#') {\n if (cd) {\n writeln(-1);\n return;\n } else {\n cd = true;\n }\n }\n }\n }\n foreach (j; 0..M) {\n bool cd;\n if (MAP[0][j] == '#') cd = true;\n foreach (i; 1..N) {\n if (MAP[i-1][j] == '.' && MAP[i][j] == '#') {\n if (cd) {\n writeln(-1);\n return;\n } else {\n cd = true;\n }\n }\n }\n }\n auto cs = new int[][](N.to!size_t, M.to!size_t);\n int c;\n foreach (i; 0..N) foreach (j; 0..M) if (MAP[i][j] == '#' && cs[i][j] == 0) {\n void paint(int i, int j) {\n foreach (d; [[1,0], [0,1], [-1,0], [0,-1]]) {\n auto ii = i+d[0];\n auto jj = j+d[1];\n if (ii < 0 || ii >= N || jj < 0 || jj >= M || MAP[ii][jj] == '.' || cs[ii][jj] != 0) continue;\n cs[ii][jj] = c;\n paint(ii, jj);\n }\n }\n ++c;\n cs[i][j] = c;\n paint(i, j);\n }\n writeln(c);\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\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 if (x > 0 && A[x - 1][y] == '#') uf.connect((x - 1) * N + y, x * N + y);\n if (y > 0 && A[x][y - 1] == '#') uf.connect(y * N + (y - 1), x * N + y);\n }\n }\n int num;\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n if (A[x][y] == '#') {\n if (uf[x * N + y] < 0) {\n ++num;\n }\n }\n }\n \n bool ans = true;\n bool empRow, empCol;\n foreach (x; 0 .. M) {\n int mn = N, mx = -1;\n foreach (y; 0 .. N) {\n if (A[x][y] == '#') {\n chmin(mn, y);\n chmax(mx, y);\n }\n }\n if (mn <= mx) {\n foreach (y; mn .. mx + 1) {\n ans = ans && (A[x][y] == '#');\n }\n } else {\n empRow = true;\n }\n }\n foreach (y; 0 .. N) {\n int mn = M, mx = -1;\n foreach (x; 0 .. M) {\n if (A[x][y] == '#') {\n chmin(mn, x);\n chmax(mx, x);\n }\n }\n if (mn <= mx) {\n foreach (x; mn .. mx + 1) {\n ans = ans && (A[x][y] == '#');\n }\n } else {\n empCol = true;\n }\n }\n ans = ans && (empRow == empCol);\n \n writeln(ans ? num : -1);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "7898b8258297a6cde8fecb1079172e10"} {"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 auto A = T.iota.map!(_ => readln.split.map!(to!long).array).array;\n\n foreach (i; 0..T) {\n auto a = A[i][0];\n auto b = A[i][1];\n auto e = A[i][2];\n if (a + e <= b) {\n writeln(0);\n continue;\n }\n long hi = e + 1;\n long lo = 0;\n while (hi - lo > 1) {\n auto mid = (hi + lo) / 2;\n if (a + e - mid > b + mid) {\n lo = mid;\n } else {\n hi = mid;\n }\n }\n writeln(lo + 1);\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\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\nvoid solve(){\n\tint t = rint;\n\tforeach(_; 0 .. t){\n\t\tlong a = rint;\n\t\tlong b = rint;\n\t\tlong c = rint;\n\t\t\n\t\tlong all = a + b + c;\n\t\t\n\t\tlong l = all / 2 + 1 - a;\n\t\tif(l < 0) l = 0;\n\t\t\n\t\tif(l > c) \"0\".writeln;\n\t\telse (c - l + 1).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 long[](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto s = RD;\n\t\tauto t = RD;\n\t\tauto e = RD;\n\t\t\n\t\tauto a = (s + t + e) / 2 + 1;\n\t\ta = max(a, s);\n\t\tans[i] = (s+e) < a ? 0 : s + e - a + 1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "0816295355375a2d3f1cd45852b86360"} {"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 = single;\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 string s;\n\n void solve(long tc = -1)\n {\n logSym!(this);\n long[][char] indices = null;\n long[char] singleaps = null;\n long[string] pairaps = null;\n foreach(i, c; s)\n {\n indices[c] ~= cast(long) i;\n singleaps[c]++;\n }\n foreach(i, c; s)\n {\n foreach(w; 'a' .. cast(char)('z' + 1))\n {\n if (w in indices)\n {\n auto pairs = assumeSorted(indices[w])\n .upperBound(i).length;\n if (pairs > 0)\n {\n char[] pair = [c, w];\n pairaps.require(cast(string) pair, 0) += cast(int) pairs;\n }\n }\n }\n }\n writeln(max(pairaps.byValue.fold!max(long.min),\n singleaps.byValue.fold!max(long.min)));\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": "//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 s = readln.stripRight;\n int[26] c;\n long[26][26] d;\n foreach (ch; s) {\n int i = ch.to!int - 97;\n foreach (j; 0 .. 26) {\n d[j][i] += c[j];\n }\n ++c[i];\n }\n long res;\n foreach (i; 0 .. 26) {\n res = max (res, c[i]);\n foreach (j; 0 .. 26) res = max (res, d[i][j]);\n }\n writeln (res);\n}\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\nvoid main() {\n import std.algorithm : max;\n\n IO io;\n string s = io.readToken;\n long[] cnt1 = new long[26];\n long[][] cnt2 = new long[][](26, 26);\n for (int i = 0; i < s.length; ++i) {\n int c = s[i] - 'a';\n for (int d = 0; d < 26; ++d) {\n cnt2[d][c] += cnt1[d];\n }\n cnt1[c]++;\n }\n long result = 0;\n for (int c = 0; c < 26; ++c) {\n result = max(result, cnt1[c]);\n for (int d = 0; d < 26; ++d) {\n result = max(result, cnt2[c][d]);\n }\n }\n writeln(result);\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 s = RD!string;\n\tauto cnt = new long[](26);\n\tauto ans = new long[][](26, 26);\n\tforeach (c; s)\n\t{\n\t\tauto i = c-'a';\n\t\tforeach (j; 0..26)\n\t\t{\n\t\t\tans[i][j] += cnt[j];\n\t\t}\n\t\t++cnt[i];\n\t}\n\t\n\tlong ans0 = cnt[cnt.MIN_POS!\"a > b\"];\n\tforeach (i; 0..26)\n\t{\n\t\tforeach (j; 0..26)\n\t\t{\n\t\t\tans0.chmax(ans[i][j]);\n\t\t}\n\t}\n\n\twriteln(ans0);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_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;\n\n IO io;\n string s = io.readToken;\n int[] cnt1 = new int[26];\n int[][] cnt2 = new int[][](26, 26);\n for (int i = 0; i < s.length; ++i) {\n int c = s[i] - 'a';\n for (int d = 0; d < 26; ++d) {\n cnt2[d][c] += cnt1[d];\n }\n cnt1[c]++;\n }\n int result = 0;\n for (int c = 0; c < 26; ++c) {\n result = max(result, cnt1[c]);\n for (int d = 0; d < 26; ++d) {\n result = max(result, cnt2[c][d]);\n }\n }\n writeln(result);\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 s = RD!string;\n\tauto cnt = new long[](26);\n\tforeach (c; s)\n\t{\n\t\t++cnt[c-'a'];\n\t}\n\tcnt.sort!\"a > b\"();\n\t\n\tlong ans = 1;\n\tans.chmax(cnt[0]);\n\tans.chmax(cnt[0] * cnt[1]);\n\tans.chmax(cnt[0]*(cnt[0]-1)/2);\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "69135ef7422b5811ae935a9d00796f88"} {"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 t = read.to!int;\n\tforeach(_; 0 .. t){\n\t\t\n\t\tstring s = readln.chomp;\n\t\tint[char] cnt;\n\t\tforeach(c; s){\n\t\t\tif(c !in cnt) cnt[c] = 0;\n\t\t\tcnt[c] += 1;\n\t\t}\n\t\t\n\t\tstring ans;\n\t\tchar[] ks;\n\t\tforeach(char c; 'a' .. 'z' + 1) if(c in cnt) ks ~= c;\n\t\tlog(\"cnt:\", cnt);\n\t\tlog(\"ks:\", ks);\n\t\t\n\t\tvoid f(char c){\n\t\t\tlog(\"c:\", c);\n\t\t\tforeach(j; 0 .. cnt[c]) ans ~= c;\n\t\t}\n\t\t\n\t\tif(ks.length >= 4){\n\t\t\tfor(int i = 1; i < ks.length; i += 2) f(ks[i]);\n\t\t\tfor(int i = 0; i < ks.length; i += 2) f(ks[i]);\n\t\t}\n\t\telse if(ks.length == 3){\n\t\t\tif(ks[1] - ks[0] > 1){\n\t\t\t\tf(ks[1]), f(ks[0]), f(ks[2]);\n\t\t\t}\n\t\t\telse if(ks[2] - ks[1] > 1){\n\t\t\t\tf(ks[1]), f(ks[2]), f(ks[0]);\n\t\t\t}\n\t\t\telse ans = \"No answer\".to!(char[]);\n\t\t}\n\t\telse if(ks.length == 2){\n\t\t\tif(ks[1] - ks[0] > 1){\n\t\t\t\tf(ks[1]), f(ks[0]);\n\t\t\t}\n\t\t\telse ans = \"No answer\".to!(char[]);\n\t\t}\n\t\telse if(ks.length == 1){\n\t\t\tf(ks[0]);\n\t\t}\n\t\t\n\t\tans.writeln;\n\t}\n\t\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 t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n auto s = readln.chomp;\n \n int[char] cnt;\n foreach (e; s) { ++cnt[e]; }\n \n debug { cnt.writeln; }\n \n auto diff = cnt.keys.length.to!int;\n auto sortedKeys = cnt.keys.dup.to!(dchar[]).sort.array;\n if ((diff == 2 && sortedKeys[0] + 1 == sortedKeys[1])\n || (diff == 3 && sortedKeys[0] + 1 == sortedKeys[1] && sortedKeys[1] + 1 == sortedKeys[2])) {\n writeln(\"No answer\");\n continue;\n }\n \n int[] ord;\n if (diff == 3) {\n if (sortedKeys[0] + 1 != sortedKeys[1]) { ord = [1, 0, 2]; }\n else { ord = [1, 2, 0]; }\n } else if (diff == 4) {\n ord = [2, 0, 3, 1];\n } else {\n auto ita = diff.iota;\n ord ~= ita.stride(2).array;\n ord ~= ita.dropOne.stride(2).array;\n }\n \n debug { ord.writeln; }\n \n dchar[] ans;\n foreach (e; ord) {\n auto c = sortedKeys[e];\n ans ~= c.repeat(cnt[c.to!char]).array;\n }\n \n ans.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 tests;\n\treadf (\" %s\", &tests);\n\treadln;\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip.dup;\n\t\tsort (s.representation);\n\t\tauto chars = group (s).array;\n\t\tchar [] res1;\n\t\tforeach_reverse (k; 0..2)\n\t\t{\n\t\t\tforeach (elem; chars.drop (k).stride (2))\n\t\t\t{\n\t\t\t\tres1 ~= elem[0].to !(char)\n\t\t\t\t .repeat (elem[1]).array;\n\t\t\t}\n\t\t}\n\t\tchar [] res2;\n\t\tforeach_reverse (k; 0..2)\n\t\t{\n\t\t\tforeach (elem; chars.retro.drop (k).stride (2))\n\t\t\t{\n\t\t\t\tres2 ~= elem[0].to !(char)\n\t\t\t\t .repeat (elem[1]).array;\n\t\t\t}\n\t\t}\n\t\tif (res1.findAdjacent\n\t\t !(q{abs (a.to !(int) - b.to !(int)) == 1}).empty)\n\t\t{\n\t\t\twriteln (res1);\n\t\t}\n\t\telse if (res2.findAdjacent\n\t\t !(q{abs (a.to !(int) - b.to !(int)) == 1}).empty)\n\t\t{\n\t\t\twriteln (res2);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"No answer\");\n\t\t}\n\t}\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 test () {\n auto s = readln.strip;\n int[26] c;\n foreach (i; s) {\n ++c[i.to!int - 97];\n }\n auto x = iota (0, 26, 2), y = iota (1, 26, 2);\n auto r1 = x.filter!(a => c[a] > 0);\n auto r2 = y.filter!(a => c[a] > 0);\n void p (int k) {\n write (replicate ([(97+ k).to!char], c[k]));\n }\n void o(T) (T r) {\n foreach (k; r) {\n p (k);\n }\n writeln;\n }\n if (r1.empty) {\n o (r2);\n return;\n }\n if (r2.empty) {\n o (r1);\n return;\n }\n foreach (i; r1) {\n foreach (j; r2) {\n if (abs (i - j) > 1) {\n foreach (k; r1) {\n if (k != i) p (k);\n }\n p (i);\n p (j);\n foreach (k; r2) {\n if (k != j) p (k);\n }\n writeln;\n return;\n }\n }\n }\n writeln (\"No answer\");\n}\n\nvoid main() {\n immutable nt = readln.strip.to!int;\n foreach (tid; 0 .. nt) {\n test ();\n }\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, filter, any;\nimport std.conv : to;\nimport std.range : iota, tee, zip;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport std.math : abs;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n uint T;\n readf(\" %s\\n\", T);\n\n foreach (l; 0 .. T) {\n string s = readln().strip;\n auto s1 = s.filter!(c => (c - 'a') % 2 == 0).array();\n auto s2 = s.filter!(c => (c - 'a') % 2 == 1).array();\n sort(s1);\n sort(s2);\n\n if (s1.length > 0 && s2.length > 0) {\n if (abs(to!int(s1[0]) - to!int(s2[$ - 1])) != 1)\n writeln(s2 ~ s1);\n else if (abs(to!int(s2[0]) - to!int(s1[$ - 1])) != 1)\n writeln(s1 ~ s2);\n else\n writeln(\"No answer\");\n }\n else\n writeln(s1 ~ s2);\n }\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, filter, any;\nimport std.conv : to;\nimport std.range : iota, tee, zip;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport std.math : abs;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n uint T;\n readf(\" %s\\n\", T);\n\n foreach (l; 0 .. T) {\n auto count = new int[100];\n string s = readln().strip;\n auto s1 = s.filter!(e => (e - 'a') % 2 == 0).array().dup;\n auto s2 = s.filter!(e => (e - 'a') % 2 == 1).array().dup;\n sort(s1);\n sort(s2);\n\n auto c1 = s1 ~ s2;\n auto r1 = zip(c1[0 .. $ - 1], c1[1 .. $]).any!(a => abs(to!int(a[0]) - to!int(a[1])) == 1);\n if (!r1) {\n writeln(c1);\n continue;\n }\n\n auto c2 = s2 ~ s1;\n auto r2 = zip(c2[0 .. $ - 1], c2[1 .. $]).any!(a => abs(to!int(a[0]) - to!int(a[1])) == 1);\n if (!r2) {\n writeln(c2);\n continue;\n }\n\n writeln(\"No answer\");\n }\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.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 t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n auto s = readln.chomp;\n \n int[char] cnt;\n foreach (e; s) { ++cnt[e]; }\n \n debug { cnt.writeln; }\n \n auto diff = cnt.keys.length.to!int;\n auto sortedKeys = cnt.keys.dup.to!(dchar[]).sort.array;\n if ((diff == 2 && sortedKeys[0] + 1 == sortedKeys[1])\n || (diff == 3 && sortedKeys[0] + 1 == sortedKeys[1] && sortedKeys[1] + 1 == sortedKeys[2])) {\n writeln(\"No answer\");\n continue;\n }\n \n int[] ord;\n if (diff == 4) {\n ord = [2, 0, 3, 1];\n } else {\n auto ita = diff.iota;\n ord ~= ita.stride(2).array;\n ord ~= ita.dropOne.stride(2).array;\n }\n \n debug { ord.writeln; }\n \n dchar[] ans;\n foreach (e; ord) {\n auto c = sortedKeys[e];\n ans ~= c.repeat(cnt[c.to!char]).array;\n }\n \n ans.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 tests;\n\treadf (\" %s\", &tests);\n\treadln;\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip.dup;\n\t\tsort (s.representation);\n\t\tauto chars = group (s);\n\t\tchar [] res;\n\t\tforeach_reverse (k; 0..2)\n\t\t{\n\t\t\tforeach (elem; chars.drop (k).stride (2))\n\t\t\t{\n\t\t\t\tres ~= elem[0].to !(char)\n\t\t\t\t .repeat (elem[1]).array;\n\t\t\t}\n\t\t}\n\t\tif (!res.findAdjacent !(q{abs (a - b) == 1}).empty)\n\t\t{\n\t\t\twriteln (\"No answer\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (res);\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 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 t = read.to!int;\n\tforeach(_; 0 .. t){\n\t\t\n\t\tstring s = readln.chomp;\n\t\tint[char] cnt;\n\t\tforeach(c; s){\n\t\t\tif(c !in cnt) cnt[c] = 0;\n\t\t\tcnt[c] += 1;\n\t\t}\n\t\t\n\t\tstring ans;\n\t\tchar[] ks;\n\t\tforeach(char c; 'a' .. 'z' + 1) if(c in cnt) ks ~= c;\n\t\tlog(\"cnt:\", cnt);\n\t\tlog(\"ks:\", ks);\n\t\t\n\t\tvoid f(char c){\n\t\t\tlog(\"c:\", c);\n\t\t\tforeach(j; 0 .. cnt[c]) ans ~= c;\n\t\t}\n\t\t\n\t\tif(ks.length >= 4){\n\t\t\tfor(int i = 1; i < ks.length; i += 2) f(ks[i]);\n\t\t\tfor(int i = ((ks.length - 1)/ 2) * 2; i >= 0; i -= 2) log(i), f(ks[i]);\n\t\t}\n\t\telse if(ks.length == 3){\n\t\t\tif(ks[1] - ks[0] > 1){\n\t\t\t\tf(ks[1]), f(ks[0]), f(ks[2]);\n\t\t\t}\n\t\t\telse if(ks[2] - ks[1] > 1){\n\t\t\t\tf(ks[1]), f(ks[2]), f(ks[0]);\n\t\t\t}\n\t\t\telse ans = \"No answer\".to!(char[]);\n\t\t}\n\t\telse if(ks.length == 2){\n\t\t\tif(ks[1] - ks[0] > 1){\n\t\t\t\tf(ks[1]), f(ks[0]);\n\t\t\t}\n\t\t\telse ans = \"No answer\".to!(char[]);\n\t\t}\n\t\telse if(ks.length == 1){\n\t\t\tf(ks[0]);\n\t\t}\n\t\t\n\t\tans.writeln;\n\t}\n\t\n\t\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;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport std.math : abs;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main()\n{\n GC.disable();\n\n uint T;\n readf(\" %s\\n\", T);\n\n foreach (l; 0 .. T)\n {\n auto count = new int[100];\n char[] s = readln().strip.dup;\n\n foreach (e; s)\n {\n count[e - 'a']++;\n }\n\n char[] ans;\n\n foreach_reverse (c; 0 .. 30)\n {\n if (c % 2 == 0)\n {\n foreach (ii; 0 .. count[c])\n ans ~= 'a' + c;\n }\n }\n\n foreach_reverse (c; 0 .. 30)\n {\n if (c % 2 == 1)\n {\n foreach (ii; 0 .. count[c])\n ans ~= 'a' + c;\n }\n }\n\n bool flag = false;\n foreach (i, c; ans)\n {\n if (i < to!int(ans.length) - 1 && abs(ans[i] - ans[i + 1]) == 1)\n {\n flag = true;\n break;\n }\n }\n\n if (flag)\n writeln(\"No answer\");\n else\n writeln(ans);\n\n }\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, filter, any;\nimport std.conv : to;\nimport std.range : iota, tee, zip;\nimport std.algorithm.comparison : equal, max, min;\nimport std.container.rbtree : RBT = RedBlackTree;\nimport std.string : strip;\nimport std.math : abs;\nimport core.memory : GC;\nimport std.typecons : tuple;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n uint T;\n readf(\" %s\\n\", T);\n\n foreach (l; 0 .. T) {\n auto count = new int[100];\n string s = readln().strip;\n auto s1 = s.filter!(e => (e - 'a') % 2 == 0).array().dup;\n auto s2 = s.filter!(e => (e - 'a') % 2 == 1).array().dup;\n sort(s1);\n sort(s2);\n\n auto c1 = s1 ~ s2;\n auto r1 = zip(c1[0 .. $ - 1], c1[1 .. $]).any!(a => abs(a[0] - a[1]) == 1);\n if (!r1) {\n writeln(c1);\n continue;\n }\n\n auto c2 = s2 ~ s1;\n auto r2 = zip(c2[0 .. $ - 1], c2[1 .. $]).any!(a => abs(a[0] - a[1]) == 1);\n if (!r2) {\n writeln(c2);\n continue;\n }\n\n writeln(\"No answer\");\n }\n\n}\n"}], "src_uid": "d62d0a9d827444a671029407f6a4ad39"} {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nvoid main()\n{\n ulong n, k, x;\n readf!\" %d %d %d \"(n, k, x);\n auto a = readln.chomp.split.map!(to!ulong).array.sort.array;\n ulong[] gaps;\n foreach (i ; 1 .. a.length) {\n if (a[i] - a[i - 1] > x) {\n gaps ~= a[i] - a[i - 1];\n }\n }\n ulong n_groups = gaps.length + 1;\n gaps.sort;\n foreach (gap ; gaps) {\n ulong n_filler = (gap - 1) / x;\n if (k >= n_filler) {\n n_groups -= 1;\n k -= n_filler;\n }\n }\n writeln(n_groups);\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 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 long n, k, x;\n read(n, k, x);\n \n auto arr = list!long.sort;\n \n long[] breakPoints;\n \n foreach (i; 1 .. n.to!int) {\n if (arr[i] - arr[i - 1] > x) {\n breakPoints ~= arr[i] - arr[i - 1];\n }\n }\n \n sort(breakPoints);\n \n long answer = breakPoints.length + 1;\n \n foreach (b; breakPoints) {\n auto req = (b - 1) / x;\n if (req <= k) {\n k -= req;\n answer--;\n } else {\n break;\n }\n }\n \n writeln(answer);\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nvoid main()\n{\n ulong n, k, x;\n readf!\" %d %d %d \"(n, k, x);\n auto a = readln.chomp.split.map!(to!ulong).array.sort.array;\n ulong[] gaps;\n foreach (i ; 1 .. a.length) {\n if (a[i] - a[i - 1] > x) {\n gaps ~= a[i] - a[i - 1];\n }\n }\n ulong n_groups = gaps.length + 1;\n gaps.sort;\n foreach (gap ; gaps) {\n ulong n_filler = gap / x;\n if (k >= n_filler) {\n n_groups -= 1;\n k -= n_filler;\n }\n }\n writeln(n_groups);\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nvoid main()\n{\n ulong n, k, x;\n readf!\" %d %d %d \"(n, k, x);\n auto a = readln.chomp.split.map!(to!ulong).array.sort.array;\n ulong[] gaps;\n foreach (i ; 1 .. a.length) {\n if (a[i] - a[i - 1] > x) {\n gaps ~= a[i] - a[i - 1];\n }\n }\n ulong n_groups = gaps.length + 1;\n gaps.sort;\n foreach (gap ; gaps) {\n ulong n_filler = gap / (x + 1);\n if (k >= n_filler) {\n if (n_groups > 0)\n n_groups -= 1;\n k -= n_filler;\n } else {\n break;\n }\n }\n writeln(n_groups);\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nvoid main()\n{\n ulong n, k, x;\n readf!\" %d %d %d \"(n, k, x);\n auto a = readln.chomp.split.map!(to!ulong).array.sort.array;\n ulong[] gaps;\n foreach (i ; 1 .. a.length) {\n if (a[i] - a[i - 1] > x) {\n gaps ~= a[i] - a[i - 1];\n }\n }\n ulong n_groups = gaps.length + 1;\n gaps.sort;\n foreach (gap ; gaps) {\n ulong n_filler = gap / (x + 1);\n if (k >= n_filler) {\n n_groups -= 1;\n k -= n_filler;\n } else {\n break;\n }\n }\n writeln(n_groups);\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\n\nvoid main()\n{\n ulong n, k, x;\n readf!\" %d %d %d \"(n, k, x);\n auto a = readln.chomp.split.map!(to!ulong).array.sort.array;\n ulong[] gaps;\n foreach (i ; 1 .. a.length) {\n if (a[i] - a[i - 1] > x) {\n gaps ~= a[i] - a[i - 1];\n }\n }\n ulong n_groups = gaps.length + 1;\n gaps.sort;\n foreach (gap ; gaps) {\n ulong n_filler = 0;\n/*\n while (gap > x) {\n n_filler++;\n gap -= x + 1;\n }\n*/\n n_filler = (gap + x) / (x + 1);\n\n if (k >= n_filler) {\n n_groups -= 1;\n k -= n_filler;\n } else {\n break;\n }\n }\n writeln(n_groups);\n}\n"}], "src_uid": "c6c07ef23cf2def9f99cbfb6076c9810"} {"source_code": "import std.stdio;\n\nvoid main() {\n int t;\n readf!\"%d\\n\"(t);\n for(int i = 0; i < t; i++) {\n int k;\n readf!\"%d\\n\"(k);\n int max = 0;\n int cur = 0;\n bool calm = true;\n for(int j = 0; j < k; j++) {\n char c;\n readf!\"%c\"(c);\n if(c == 'P') {\n if(calm) continue;\n cur++;\n if(cur > max) max = cur;\n }\n if(c == 'A') {\n calm = false;\n cur = 0;\n }\n }\n readf!\"\\n\"();\n writeln(max);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv : to;\nimport std.container;\nimport std.numeric : gcd;\nimport std.range;\nimport std.stdio;\nimport std.typecons : Tuple, tuple;\n\nstring readToken() {\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 return readToken.to!int;\n}\n\nvoid main() {\n int T = readInt;\n while (T--) {\n int n = readInt;\n string s = readToken;\n int result = 0, count = 0;\n for (int i = n; i--;) {\n if (s[i] == 'P') {\n count++;\n }\n else {\n result = max(result, count), count = 0;\n }\n }\n writeln(result);\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 k;\n string s;\n read(k, s);\n s ~= 'A';\n size_t last = -1;\n size_t maxspace = 0;\n foreach(i, c; s)\n {\n if (c == 'A')\n {\n if (last != -1)\n maxspace = max(maxspace, i - last - 1);\n last = i;\n }\n }\n writeln(maxspace);\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 int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto k = RD!int;\n\t\tauto s = RD!string;\n\t\tbool hasA;\n\t\tint streak;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tif (!hasA)\n\t\t\t{\n\t\t\t\tif (s[i] == 'A')\n\t\t\t\t\thasA = true;\n\t\t\t}\n\t\t\telse if (s[i] == 'P')\n\t\t\t{\n\t\t\t\t++streak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans[ti].chmax(streak);\n\t\t\t\tstreak = 0;\n\t\t\t}\n\t\t}\n\t\tans[ti].chmax(streak);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "1539fc8ef4f4cdcd1e14faf4f1b4ee8b"} {"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\tforeach (i; 0..n-1)\r\n\t\t{\r\n\t\t\tans[ti].chmax(a[i]*a[i+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;\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\tauto a = new int[](n); foreach(ref ai; a) ai = readInt!int;\n\tiota(0, n - 1).map!(i => cast(long)a[i] * a[i+1]).fold!max.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": "2deed55e860bd69ff0ba3973a1d73cac"} {"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 T = Tuple!(int, int);\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n auto p = r.nextA!int(n);\n p[] -= 1;\n auto q = new int[n];\n foreach (i; 0 .. n) {\n q[p[i]] = i;\n }\n int m = n / 2;\n T[] res;\n int s (int i, int j) {\n debug stderr.writefln (\"swap: %d %d\\n\", i + 1, j + 1);\n if (i == j) {\n return j;\n }\n debug stderr.writefln (\"%d %d\", 2 * abs (i - j), n);\n assert (2 * abs (i - j) >= n);\n res ~= tuple (i + 1, j + 1);\n swap (p[i], p[j]);\n q[p[i]] = i;\n q[p[j]] = j;\n return j;\n }\n immutable last = n - 1;\n debug stderr.writeln (\"m = \", m);\n foreach_reverse (i; 1 .. m) {\n int pos = m - i;\n int u = q[pos];\n debug stderr.writeln (\"p = \", p, \", pos = \", pos, \", u = \", u);\n if (u != pos) {\n if (u < m) {\n u = s (u, last);\n } else {\n u = s (u, 0);\n u = s (0, last);\n }\n assert (u == last);\n s (last, pos);\n }\n pos = m + i - 1;\n u = q[pos];\n debug stderr.writeln (\"p = \", p, \", pos = \", pos, \", u = \", u);\n if (u != pos) {\n if (u >= m) {\n u = s (u, 0);\n } else {\n u = s (u, last);\n u = s (last, 0);\n }\n assert (u == 0);\n s (0, pos);\n }\n }\n if (p[0] != 0) {\n s (0, last);\n }\n writeln (res.length);\n foreach (t; res) {\n writeln (t[0], ' ', t[1]);\n }\n debug {\n stderr.writeln (p);\n foreach (i; 0 .. n) {\n assert (p[i] == i);\n }\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\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint half = n / 2;\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, v; p)\n\t\t{\n\t\t\tq[v] = i;\n\t\t}\n\n\t\tint [] [] ans;\n\n\t\tvoid doSwap (int i, int j)\n\t\t{\n\t\t\tans ~= [i + 1, j + 1];\n\t\t\tp.swapAt (i, j);\n\t\t\tq.swapAt (p[i], p[j]);\n\t\t}\n\n\t\tforeach (i; 0..half)\n\t\t{\n\t\t\tint j = i + half;\n\t\t\tint last = n - 1;\n\n\t\t\tif (q[j] < j)\n\t\t\t{\n\t\t\t\tdoSwap (q[j], last);\n\t\t\t}\n\t\t\tif (q[j] > j)\n\t\t\t{\n\t\t\t\tdoSwap (q[j], i);\n\t\t\t}\n\t\t\tif (q[j] == i)\n\t\t\t{\n\t\t\t\tdoSwap (q[j], j);\n\t\t\t}\n\t\t\tif (q[j] != j)\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\n\t\t\tif (q[i] > i && q[i] < j)\n\t\t\t{\n\t\t\t\tdoSwap (q[i], last);\n\t\t\t}\n\t\t\tif (q[i] > j)\n\t\t\t{\n\t\t\t\tdoSwap (q[i], i);\n\t\t\t}\n\t\t\tif (q[i] != i)\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t}\n\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%(%s %)\\n%)\", ans);\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\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 - 1;\n\tprint!1(\"as:\", as);\n\t\n\tint[] bs = new int[](n);\n\tforeach(int i, a; as) bs[a] = i;\n\tprint!1(\"bs:\", bs);\n\t\n\tint[2][] ans;\n\tvoid swap(int i, int j){\n\t\tprint!1(\"i:\", i, \" j:\", j);\n\t\tif(i == j) return;\n\t\telse if(i > j){\n\t\t\tswap(j, i);\n\t\t\treturn;\n\t\t}\n\t\telse if(j - i >= n / 2){\n\t\t\tans ~= [i + 1, j + 1];\n\t\t\tint x = as[i], y = as[j];\n\t\t\tas[i] = y, as[j] = x;\n\t\t\tbs[y] = i, bs[x] = j;\n\t\t\tprint!1(\"-> i:\", i, \" j:\", j, \" as:\", as);\n\t\t\treturn;\n\t\t}\n\t\telse if(i < n / 2 && j < n / 2){\n\t\t\tswap(i, n - 1);\n\t\t\tswap(j, n - 1);\n\t\t\tswap(i, n - 1);\n\t\t\treturn;\n\t\t}\n\t\telse if(i < n / 2 && j >= n / 2){\n\t\t\tswap(i, n - 1);\n\t\t\tswap(0, j);\n\t\t\tswap(0, n - 1);\n\t\t\tswap(i, n - 1);\n\t\t\tswap(0, j);\n\t\t\treturn;\n\t\t}\n\t\telse if(i >= n / 2 && j >= n / 2){\n\t\t\tswap(0, i);\n\t\t\tswap(0, j);\n\t\t\tswap(0, i);\n\t\t\treturn;\n\t\t}\n\t\tassert(0);\n\t}\n\t\n\tforeach(i; 0 .. n){\n\t\tif(as[i] == i) continue;\n\t\tint j = bs[i];\n\t\tswap(i, j);\n\t}\n\t\n\tans.length.writeln;\n\tforeach(an; ans){\n\t\twriteln(an[0], \" \", an[1]);\n\t}\n\t\n}\n\n"}], "negative_code": [], "src_uid": "b1706815238eb940060231848e43ffa8"} {"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 ok = a.isSorted || (0 < b.sum && b.sum < n);\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 = 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\tauto b = RDA;\n\n\t\tlong cnt, cnt0, cnt1;\n\t\tlong last0, last1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] == 0)\n\t\t\t{\n\t\t\t\tif (a[i] < last0)\n\t\t\t\t{\n\t\t\t\t\t++cnt0;\n\t\t\t\t}\n\t\t\t\tlast0 = a[i];\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i] < last1)\n\t\t\t\t{\n\t\t\t\t\t++cnt1;\n\t\t\t\t}\n\t\t\t\tlast1 = a[i];\n\t\t\t}\n\t\t}\n\t\tif (min(cnt, n-cnt) == 0)\n\t\t\tans[ti] = max(cnt0, cnt1) == 0;\n\t\telse\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}\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 a = RDA;\n\t\tauto b = RDA;\n\n\t\tlong cnt, cnt0, cnt1;\n\t\tlong last0, last1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] == 0)\n\t\t\t{\n\t\t\t\tif (a[i] < last0)\n\t\t\t\t{\n\t\t\t\t\t++cnt0;\n\t\t\t\t}\n\t\t\t\tlast0 = a[i];\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i] < last1)\n\t\t\t\t{\n\t\t\t\t\t++cnt1;\n\t\t\t\t}\n\t\t\t\tlast1 = a[i];\n\t\t\t}\n\t\t}\n\t\tans[ti] = max(cnt0, cnt1) <= min(cnt, n-cnt);\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\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\tauto b = RDA;\n\n\t\tbool ok = true;\n\t\tlong last0, last1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] == 0)\n\t\t\t{\n\t\t\t\tif (a[i] < last0)\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\tlast0 = a[i];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (a[i] < last1)\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\tlast1 = a[i];\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}\n"}], "src_uid": "4bf3a94119d08a9cd6075a67d0014061"} {"source_code": "// cheese-cracker [2022-01-26]\n\nvoid solve(){\n int n = scan!int;\n int m = scan!int;\n auto arr = scanArray;\n auto pref = arr.cumulativeFold!((a, b) => a + b)(0L).array;\n tup[] selects;\n selects ~= tup(pref.front, 0L);\n for(int i = 1; i < n; ++i){\n if(pref[i] > selects.back[0]){\n selects ~= tup(pref[i], i.to!long);\n }\n }\n\n long summ = pref.back;\n long maxk = selects.back[0];\n\n long[] res;\n auto qrs = scanArray;\n foreach(x; qrs){\n // Rotations is ceil of this\n long num = x - maxk;\n long rots = 0;\n if(summ > 0 && num > 0){\n rots = num / summ + (num % summ != 0);\n }else{\n rots = 0;\n }\n /* show(x, num, summ, rots); */\n\n // Soln Exists\n\n long left = x - summ * rots;\n if(selects.back[0] < left){\n res ~= -1;\n continue;\n }\n /* show(left); */\n\n int lo = -1, hi = selects.length.to!int - 1;\n while(hi - lo > 1){\n int midd = (lo + hi)/2;\n /* show(lo, midd, hi); */\n ( (selects[midd][0] >= left ) ? hi : lo ) = midd;\n }\n res ~= (rots * n + selects[hi][1]);\n }\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, 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.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, M; get(N, M);\r\n long[] AA; get(AA);\r\n long[] XX; get(XX);\r\n\r\n auto ss = new long[](N);\r\n ss[0] = AA[0];\r\n foreach (i; 1..N) ss[i] += ss[i - 1] + AA[i];\r\n \r\n auto ms = new long[](N);\r\n ms[0] = ss[0];\r\n foreach (i; 1..N) ms[i] = max(ms[i-1], ss[i]);\r\n\r\n long[] res;\r\n foreach (x; XX) {\r\n if (ss[$-1] <= 0 && x > ms[$-1]) {\r\n res ~= -1;\r\n continue;\r\n }\r\n auto min_a = max(0, x - ms[$-1]);\r\n auto c = ss[$-1] <= 0 ? 0 : (min_a + ss[$-1] - 1) / ss[$-1];\r\n auto d = ss[$-1] * c;\r\n if (d + AA[0] >= x) {\r\n res ~= c * N;\r\n continue;\r\n }\r\n int l, r = (N-1).to!int;\r\n while (l + 1 < r) {\r\n auto m = (l + r) / 2;\r\n if (d + ms[m] >= x) {\r\n r = m;\r\n } else {\r\n l = m;\r\n }\r\n }\r\n res ~= c * N + r;\r\n }\r\n writefln!\"%(%d %)\"(res);\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\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 s = [0L];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\ts ~= s.back + c;\r\n\t\t}\r\n\t\tauto t = s.dup;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tt[i + 1] = max (t[i + 1], t[i]);\r\n\t\t}\r\n\t\tauto x = readln.splitter.map !(to !(int)).array;\r\n\t\tlong [] ans;\r\n\t\tforeach (long y; x)\r\n\t\t{\r\n\t\t\tif (t[n] < y && s[n] <= 0)\r\n\t\t\t{\r\n\t\t\t\tans ~= -1;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tlong steps = 0;\r\n\t\t\tif (t[n] < y)\r\n\t\t\t{\r\n\t\t\t\tsteps = (y + s[n] - 1 - t[n]) / s[n];\r\n\t\t\t}\r\n\t\t\ty -= steps * s[n];\r\n\t\t\tauto shift = t[1..n].assumeSorted.lowerBound (y)\r\n\t\t\t .length.to !(int);\r\n\t\t\tans ~= steps * n + shift;\r\n\t\t}\r\n\t\twritefln !(\"%(%s %)\") (ans);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "ecc9dc229b5d1f93809fb676eb6235c1"} {"source_code": "import std.stdio: writeln, readln;\nimport std.array: array, split;\nimport std.string: chomp, count;\nimport std.conv: to;\nimport std.algorithm: map;\n\nstring multi_str(string a, ulong times) {\n string result;\n foreach (ulong i; 0..times) {\n result ~= a;\n }\n return result;\n}\n// 7 6 --> 0001100\nvoid main() {\n int t = readln.chomp.to!int;\n foreach (int _; 0..t) {\n int[2] words = readln.split.map!(to!int).array;\n int[] a = [1];\n int i;\n while (a[$-1] <= words[1]) {\n a ~= ++i + a[$-1];\n }\n writeln(multi_str(\"a\", words[0] - a.count) ~ \"b\" ~ multi_str(\"a\", a.count - words[1] + a[$-2] - 2) ~ \"b\" ~ multi_str(\"a\", words[1] - a[$-2]));\n }\n}\n", "positive_code": [{"source_code": "// https://codeforces.com/problemset/problem/1328/B\nimport std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n int t = readln.chomp.to!int;\n\n int n, k;\nforeach(kase; 0..t) {\n readf(\"%d %d\\n\", &n, &k);\n\n char[] ans = \"\".dup;\n\n foreach(ch; 0..n) ans ~= \"a\";\n\n for(int idx = n-2; idx >= 0; idx--) {\n if(k <= (n-idx-1)) {\n ans[idx] = 'b';\n ans[n-k] = 'b';\n break;\n }\n k -= n-idx-1;\n }\n ans.writeln;\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\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 string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\t\n\t\tint x;\n\t\tsize_t pos1, pos2;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tx += i+1;\n\t\t\tif (x >= k)\n\t\t\t{\n\t\t\t\tpos1 = n-2-i;\n\t\t\t\tpos2 = pos1 + 1 + x - k;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"pos:\", pos1, \", \", pos2);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i == pos1 || i == pos2)\n\t\t\t\tans[ti] ~= 'b';\n\t\t\telse\n\t\t\t\tans[ti] ~= '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": "e32f0615541d97a025bc99c3cbf5380e"} {"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\nimmutable int mod = 107;\nimmutable int mod2 = mod ^^ 2;\n\nvoid main ()\n{\n\tint n;\n\tlong s;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\ts *= 2;\n\t\tint sp = (+s % mod + mod) % mod;\n\t\tint sn = (-s % mod + mod) % mod;\n\t\tauto b = new bool [mod2 * 2];\n\t\tforeach (i; -mod2..mod2)\n\t\t{\n\t\t\tif ((i % mod + mod) % mod == (sp % mod + mod) % mod ||\n\t\t\t (i % mod + mod) % mod == (sn % mod + mod) % mod)\n\t\t\t{\n\t\t\t\tb[i + mod2] = true;\n\t\t\t}\n\t\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 [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\tp[j].x -= p[i].x;\n\t\t\t\tp[j].y -= p[i].y;\n\t\t\t\tq[j].x = (p[j].x % mod + mod) % mod;\n\t\t\t\tq[j].y = (p[j].y % mod + mod) % mod;\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tint qjx = q[j].x;\n\t\t\t\tint qjy = q[j].y;\n\t\t\t\tint k;\n\t\t\t\tenum span = 4;\n\t\t\t\tfor (k = j + 1; k + span <= n; k += span)\n\t\t\t\t{\n\t\t\t\t\tbool ok = false;\n\t\t\t\t\tstatic foreach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = qjx * q[k + r].y -\n\t\t\t\t\t\t qjy * q[k + r].x;\n\t\t\t\t\t\tok |= b[t + mod2];\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\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tforeach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = cast (long) (p[j].x) *\n\t\t\t\t\t\t p[k + r].y -\n\t\t\t\t\t\t cast (long) (p[k + r].x) *\n\t\t\t\t\t\t p[j].y;\n\t\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\t\twriteln (p[i].x, \" \", p[i].y);\n\t\t\t\t\t\t\twriteln (p[j].x + p[i].x, \" \",\n\t\t\t\t\t\t\t p[j].y + p[i].y);\n\t\t\t\t\t\t\twriteln (p[k + r].x + p[i].x, \" \",\n\t\t\t\t\t\t\t p[k + r].y + p[i].y);\n\t\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t\tfor ( ; k < n; k++)\n\t\t\t\t{\n\t\t\t\t\tauto t = cast (long) (p[j].x) *\n\t\t\t\t\t p[k].y -\n\t\t\t\t\t cast (long) (p[k].x) *\n\t\t\t\t\t p[j].y;\n\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\twriteln (p[i].x, \" \", p[i].y);\n\t\t\t\t\t\twriteln (p[j].x + p[i].x, \" \",\n\t\t\t\t\t\t p[j].y + p[i].y);\n\t\t\t\t\t\twriteln (p[k].x + p[i].x, \" \",\n\t\t\t\t\t\t p[k].y + p[i].y);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tp[j].x += p[i].x;\n\t\t\t\tp[j].y += p[i].y;\n\t\t\t}\n\t\t}\n\t\twriteln (\"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\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nvoid main ()\n{\n\tint n;\n\tlong s;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\ts *= 2;\n\t\tint sp = cast (int) (s);\n\t\tint sn = -sp;\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\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tp[j].x -= p[i].x;\n\t\t\t\tp[j].y -= p[i].y;\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tint pjx = p[j].x;\n\t\t\t\tint pjy = p[j].y;\n\t\t\t\tint v;\n\t\t\t\tbool ok = false;\n\t\t\t\tenum span = 4;\n\t\t\t\tfor (v = j + 1; v + span <= n; v += span)\n\t\t\t\t{\n\t\t\t\t\tstatic foreach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = pjx * p[v + r].y -\n\t\t\t\t\t\t pjy * p[v + r].x;\n\t\t\t\t\t\tok |= (t == sp) || (t == sn);\n\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t\tfor ( ; v < n; v++)\n\t\t\t\t{\n\t\t\t\t\tauto t = pjx * p[v].y - pjy * p[v].x;\n\t\t\t\t\tok |= (t == sp || t == sn);\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (k; j + 1..n)\n\t\t\t\t{\n\t\t\t\t\tauto t = cast (long) (p[j].x) *\n\t\t\t\t\t p[k].y -\n\t\t\t\t\t cast (long) (p[k].x) *\n\t\t\t\t\t p[j].y;\n\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\twriteln (p[i].x, \" \", p[i].y);\n\t\t\t\t\t\twriteln (p[j].x + p[i].x, \" \",\n\t\t\t\t\t\t p[j].y + p[i].y);\n\t\t\t\t\t\twriteln (p[k].x + p[i].x, \" \",\n\t\t\t\t\t\t p[k].y + p[i].y);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tp[j].x += p[i].x;\n\t\t\t\tp[j].y += p[i].y;\n\t\t\t}\n\t\t}\n\t\twriteln (\"No\");\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\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nimmutable int mod = 44_221;\nimmutable int mod2 = mod ^^ 2;\n\nvoid main ()\n{\n\tint n;\n\tlong s;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\ts *= 2;\n\t\tint sp = cast (int) (s);\n\t\tint sn = -sp;\n\t\tsp = (sp % mod2 + mod2) % mod2;\n\t\tsn = (sn % mod2 + mod2) % mod2;\n\t\tint msp = -sp;\n\t\tint msn = -sn;\n\t\tauto q = new Point [n];\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 p = new Point [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\tp[j].x = ((q[j].x - q[i].x) % mod + mod) % mod;\n\t\t\t\tp[j].y = ((q[j].y - q[i].y) % mod + mod) % mod;\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tint pjx = p[j].x;\n\t\t\t\tint pjy = p[j].y;\n\t\t\t\tint v;\n\t\t\t\tbool ok = false;\n\t\t\t\tenum span = 4;\n\t\t\t\tfor (v = j + 1; v + span <= n; v += span)\n\t\t\t\t{\n\t\t\t\t\tstatic foreach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = pjx * p[v + r].y -\n\t\t\t\t\t\t pjy * p[v + r].x;\n\t\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t\tfor ( ; v < n; v++)\n\t\t\t\t{\n\t\t\t\t\tauto t = pjx * p[v].y - pjy * p[v].x;\n\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (k; j + 1..n)\n\t\t\t\t{\n\t\t\t\t\tauto t = cast (long) (q[j].x) *\n\t\t\t\t\t q[k].y -\n\t\t\t\t\t cast (long) (q[k].x) *\n\t\t\t\t\t q[j].y;\n\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\twriteln (q[i].x, \" \", q[i].y);\n\t\t\t\t\t\twriteln (q[j].x + q[i].x, \" \",\n\t\t\t\t\t\t q[j].y + q[i].y);\n\t\t\t\t\t\twriteln (q[k].x + q[i].x, \" \",\n\t\t\t\t\t\t q[k].y + q[i].y);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tp[j].x += p[i].x;\n\t\t\t\tp[j].y += p[i].y;\n\t\t\t}\n\t\t}\n\t\twriteln (\"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\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nimmutable int mod = 31627;\nimmutable int mod2 = mod ^^ 2;\nimmutable int mod2x2 = mod2 * 2;\n\nvoid main ()\n{\n\tint n;\n\tlong s;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\ts *= 2;\n\t\tint sp = (+s % mod2x2 + 1L * mod2x2) % mod2x2;\n\t\tint sn = (-s % mod2x2 + 1L * mod2x2) % mod2x2;\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 [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\tp[j].x -= p[i].x;\n\t\t\t\tp[j].y -= p[i].y;\n\t\t\t\tq[j].x = (p[j].x % mod + mod) % mod;\n\t\t\t\tq[j].y = (p[j].y % mod + mod) % mod;\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tint qjx = q[j].x;\n\t\t\t\tint qjy = q[j].y;\n\t\t\t\tint v;\n\t\t\t\tbool ok = false;\n\t\t\t\tenum span = 8;\n\t\t\t\tfor (v = j + 1; v + span <= n; v += span)\n\t\t\t\t{\n\t\t\t\t\tstatic foreach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = qjx * q[v + r].y -\n\t\t\t\t\t\t qjy * q[v + r].x;\n\t\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t\tfor ( ; v < n; v++)\n\t\t\t\t{\n\t\t\t\t\tauto t = qjx * q[v].y - qjy * q[v].x;\n\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (k; j + 1..n)\n\t\t\t\t{\n\t\t\t\t\tauto t = cast (long) (p[j].x) *\n\t\t\t\t\t p[k].y -\n\t\t\t\t\t cast (long) (p[k].x) *\n\t\t\t\t\t p[j].y;\n\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\twriteln (p[i].x, \" \", p[i].y);\n\t\t\t\t\t\twriteln (p[j].x + p[i].x, \" \",\n\t\t\t\t\t\t p[j].y + p[i].y);\n\t\t\t\t\t\twriteln (p[k].x + p[i].x, \" \",\n\t\t\t\t\t\t p[k].y + p[i].y);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tp[j].x += p[i].x;\n\t\t\t\tp[j].y += p[i].y;\n\t\t\t}\n\t\t}\n\t\twriteln (\"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\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nimmutable int mod = 31627;\nimmutable int mod2 = mod ^^ 2;\n\nvoid main ()\n{\n\tint n;\n\tlong s;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\ts *= 2;\n\t\tint sp = cast (int) (s);\n\t\tint sn = -sp;\n\t\tsp = (sp % mod2 + mod2) % mod2;\n\t\tsn = (sn % mod2 + mod2) % mod2;\n\t\tint msp = -sp;\n\t\tint msn = -sn;\n\t\tauto q = new Point [n];\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 p = new Point [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\tq[j].x -= q[i].x;\n\t\t\t\tq[j].y -= q[i].y;\n\t\t\t\tp[j].x = (q[j].x % mod + mod) % mod;\n\t\t\t\tp[j].y = (q[j].y % mod + mod) % mod;\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tint pjx = p[j].x;\n\t\t\t\tint pjy = p[j].y;\n\t\t\t\tint v;\n\t\t\t\tbool ok = false;\n\t\t\t\tenum span = 4;\n\t\t\t\tfor (v = j + 1; v + span <= n; v += span)\n\t\t\t\t{\n\t\t\t\t\tstatic foreach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = pjx * p[v + r].y -\n\t\t\t\t\t\t pjy * p[v + r].x;\n\t\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t\tfor ( ; v < n; v++)\n\t\t\t\t{\n\t\t\t\t\tauto t = pjx * p[v].y - pjy * p[v].x;\n\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (k; j + 1..n)\n\t\t\t\t{\n\t\t\t\t\tauto t = cast (long) (q[j].x) *\n\t\t\t\t\t q[k].y -\n\t\t\t\t\t cast (long) (q[k].x) *\n\t\t\t\t\t q[j].y;\n\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\twriteln (q[i].x, \" \", q[i].y);\n\t\t\t\t\t\twriteln (q[j].x + q[i].x, \" \",\n\t\t\t\t\t\t q[j].y + q[i].y);\n\t\t\t\t\t\twriteln (q[k].x + q[i].x, \" \",\n\t\t\t\t\t\t q[k].y + q[i].y);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tq[j].x += q[i].x;\n\t\t\t\tq[j].y += q[i].y;\n\t\t\t}\n\t\t}\n\t\twriteln (\"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\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nimmutable int mod = 31627;\nimmutable int mod2 = mod ^^ 2 * 2;\n\nvoid main ()\n{\n\tint n;\n\tlong s;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\ts *= 2;\n\t\tint sp = (+s % mod2 + mod2) % mod2;\n\t\tint sn = (-s % mod2 + mod2) % mod2;\n\t\tauto q = new Point [n];\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 p = new Point [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\tq[j].x -= q[i].x;\n\t\t\t\tq[j].y -= q[i].y;\n\t\t\t\tp[j].x = (q[j].x % mod + mod) % mod;\n\t\t\t\tp[j].y = (q[j].y % mod + mod) % mod;\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tint pjx = p[j].x;\n\t\t\t\tint pjy = p[j].y;\n\t\t\t\tint v;\n\t\t\t\tbool ok = false;\n\t\t\t\tenum span = 4;\n\t\t\t\tfor (v = j + 1; v + span <= n; v += span)\n\t\t\t\t{\n\t\t\t\t\tstatic foreach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = pjx * p[v + r].y -\n\t\t\t\t\t\t pjy * p[v + r].x;\n\t\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t\tfor ( ; v < n; v++)\n\t\t\t\t{\n\t\t\t\t\tauto t = pjx * p[v].y - pjy * p[v].x;\n\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (k; j + 1..n)\n\t\t\t\t{\n\t\t\t\t\tauto t = cast (long) (q[j].x) *\n\t\t\t\t\t q[k].y -\n\t\t\t\t\t cast (long) (q[k].x) *\n\t\t\t\t\t q[j].y;\n\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\twriteln (q[i].x, \" \", q[i].y);\n\t\t\t\t\t\twriteln (q[j].x + q[i].x, \" \",\n\t\t\t\t\t\t q[j].y + q[i].y);\n\t\t\t\t\t\twriteln (q[k].x + q[i].x, \" \",\n\t\t\t\t\t\t q[k].y + q[i].y);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tq[j].x += q[i].x;\n\t\t\t\tq[j].y += q[i].y;\n\t\t\t}\n\t\t}\n\t\twriteln (\"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\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nimmutable int mod = 31627;\nimmutable int mod2 = mod ^^ 2 * 2;\n\nvoid main ()\n{\n\tint n;\n\tlong s;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\ts *= 2;\n\t\tint sp = cast (int) (s);\n\t\tint sn = -sp;\n\t\tsp = (sp % mod2 + mod2) % mod2;\n\t\tsn = (sn % mod2 + mod2) % mod2;\n\t\tint msp = -sp;\n\t\tint msn = -sn;\n\t\tauto q = new Point [n];\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 p = new Point [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\tq[j].x -= q[i].x;\n\t\t\t\tq[j].y -= q[i].y;\n\t\t\t\tp[j].x = (q[j].x % mod + mod) % mod;\n\t\t\t\tp[j].y = (q[j].y % mod + mod) % mod;\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tint pjx = p[j].x;\n\t\t\t\tint pjy = p[j].y;\n\t\t\t\tint v;\n\t\t\t\tbool ok = false;\n\t\t\t\tenum span = 4;\n\t\t\t\tfor (v = j + 1; v + span <= n; v += span)\n\t\t\t\t{\n\t\t\t\t\tstatic foreach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = pjx * p[v + r].y -\n\t\t\t\t\t\t pjy * p[v + r].x;\n\t\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t\tfor ( ; v < n; v++)\n\t\t\t\t{\n\t\t\t\t\tauto t = pjx * p[v].y - pjy * p[v].x;\n\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (k; j + 1..n)\n\t\t\t\t{\n\t\t\t\t\tauto t = cast (long) (q[j].x) *\n\t\t\t\t\t q[k].y -\n\t\t\t\t\t cast (long) (q[k].x) *\n\t\t\t\t\t q[j].y;\n\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\twriteln (q[i].x, \" \", q[i].y);\n\t\t\t\t\t\twriteln (q[j].x + q[i].x, \" \",\n\t\t\t\t\t\t q[j].y + q[i].y);\n\t\t\t\t\t\twriteln (q[k].x + q[i].x, \" \",\n\t\t\t\t\t\t q[k].y + q[i].y);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tq[j].x += q[i].x;\n\t\t\t\tq[j].y += q[i].y;\n\t\t\t}\n\t\t}\n\t\twriteln (\"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\nalias Point = Tuple !(int, q{x}, int, q{y});\n\nimmutable int mod = 44_221;\nimmutable int mod2 = mod ^^ 2;\n\nvoid main ()\n{\n\tint n;\n\tlong s;\nmultitest_loop:\n\twhile (readf (\" %s %s\", &n, &s) > 0)\n\t{\n\t\ts *= 2;\n\t\tint sp = cast (int) (s);\n\t\tint sn = -sp;\n\t\tsp = (sp % mod2 + mod2) % mod2;\n\t\tsn = (sn % mod2 + mod2) % mod2;\n\t\tint msp = -sp;\n\t\tint msn = -sn;\n\t\tauto q = new Point [n];\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 p = new Point [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\tq[j].x -= q[i].x;\n\t\t\t\tq[j].y -= q[i].y;\n\t\t\t\tp[j].x = (q[j].x % mod + mod) % mod;\n\t\t\t\tp[j].y = (q[j].y % mod + mod) % mod;\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tint pjx = p[j].x;\n\t\t\t\tint pjy = p[j].y;\n\t\t\t\tint v;\n\t\t\t\tbool ok = false;\n\t\t\t\tenum span = 4;\n\t\t\t\tfor (v = j + 1; v + span <= n; v += span)\n\t\t\t\t{\n\t\t\t\t\tstatic foreach (r; 0..span)\n\t\t\t\t\t{{\n\t\t\t\t\t\tauto t = pjx * p[v + r].y -\n\t\t\t\t\t\t pjy * p[v + r].x;\n\t\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t\t}}\n\t\t\t\t}\n\t\t\t\tfor ( ; v < n; v++)\n\t\t\t\t{\n\t\t\t\t\tauto t = pjx * p[v].y - pjy * p[v].x;\n\t\t\t\t\tok |= (t == sp) || (t == sn) ||\n\t\t\t\t\t (-t == sp) || (-t == sn);\n\t\t\t\t}\n\t\t\t\tif (!ok)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tforeach (k; j + 1..n)\n\t\t\t\t{\n\t\t\t\t\tauto t = cast (long) (q[j].x) *\n\t\t\t\t\t q[k].y -\n\t\t\t\t\t cast (long) (q[k].x) *\n\t\t\t\t\t q[j].y;\n\t\t\t\t\tif (t == +s || t == -s)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Yes\");\n\t\t\t\t\t\twriteln (q[i].x, \" \", q[i].y);\n\t\t\t\t\t\twriteln (q[j].x + q[i].x, \" \",\n\t\t\t\t\t\t q[j].y + q[i].y);\n\t\t\t\t\t\twriteln (q[k].x + q[i].x, \" \",\n\t\t\t\t\t\t q[k].y + q[i].y);\n\t\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tq[j].x += q[i].x;\n\t\t\t\tq[j].y += q[i].y;\n\t\t\t}\n\t\t}\n\t\twriteln (\"No\");\n\t}\n}\n"}], "src_uid": "9b255ee194deff243e0b2259ebe379e7"} {"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 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 k = RD!int;\n\t\tauto a = RDR.ARR;\n\t\ta.sort();\n\t\tif (a[0] + k < a[$-1] - k)\n\t\t{\n\t\t\tans[i] = -1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[i] = a[0] + k;\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.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 T = readln.chomp.to!int;\n while (T--) {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1].to!long;\n auto A = readln.split.map!(to!long).array;\n long hi = INF;\n long lo = -INF;\n foreach (a; A) {\n hi = min(hi, a + K);\n lo = max(lo, a - K);\n }\n writeln(hi >= lo ? hi : -1);\n }\n}\n"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int q;\n rd(q);\n while (q--) {\n int n, k;\n rd(n, k);\n auto a = readln.split.to!(int[]);\n a.sort;\n auto lb = a[n - 1] - k, ub = a[0] + k;\n if (lb <= ub) {\n writeln(ub);\n } else {\n writeln(-1);\n }\n }\n}\n\n// [a[n - 1] - k, a[0] + k]\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": "3b158306d335459ff55dcf29e46010e8"} {"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 size_t[2][][](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto K = RD!int;\n\t\tauto s = RD!(char[]);\n\t\tint cnt = n/2 - K;\n\t\tforeach (j; 0..cnt+1)\n\t\t{\n\t\t\tif (s[j] == '(') continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] == ')') continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tans[i] ~= [j, k];\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tforeach (j; cnt+1..(cnt+1)*2)\n\t\t{\n\t\t\tif (s[j] == ')') continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] == '(') continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tans[i] ~= [j, k];\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tforeach (j; (cnt+1)*2..n)\n\t\t{\n\t\t\tauto c = j % 2 == 0 ? '(' : ')';\n\t\t\tif (s[j] == c) continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] != c) continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tans[i] ~= [j, k];\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\n\t\t\t\t}\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.length);\n\t\tforeach (ee; e)\n\t\t\twriteln(ee[0]+1, \" \", ee[1]+1);\n\t}\n\t\n\tstdout.flush();\n\tdebug readln();\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 numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const K = readInt();\n const S = readToken();\n \n string t;\n foreach (_; 0 .. N / 2 - (K - 1)) t ~= '(';\n foreach (_; 0 .. N / 2 - (K - 1)) t ~= ')';\n foreach (_; 0 .. K - 1) t ~= \"()\";\n debug {\n writeln(\"t = \", t);\n }\n \n auto s = S.dup;\n writeln(N);\n foreach (i; 0 .. N) {\n foreach (j; i .. N) {\n if (s[j] == t[i]) {\n s[i .. j + 1].reverse;\n writeln(i + 1, \" \", j + 1);\n goto found;\n }\n }\n assert(false);\n found:\n }\n assert(s == t);\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 size_t[2][][](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto K = RD!int;\n\t\tauto s = RD!(char[]);\n\t\tint cnt = n/2 - K;\n\t\tforeach (j; 0..cnt+1)\n\t\t{\n\t\t\tif (s[j] == '(') continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] == ')') continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\n\t\t\t\t\tans[i] ~= [l, r];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tforeach (j; cnt+1..(cnt+1)*2)\n\t\t{\n\t\t\tif (s[j] == ')') continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] == '(') continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\n\t\t\t\t\tans[i] ~= [l, r];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tforeach (j; (cnt+1)*2..n)\n\t\t{\n\t\t\tauto c = j % 2 == 0 ? '(' : ')';\n\t\t\tif (s[j] == c) continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] != c) continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\n\t\t\t\t\tans[i] ~= [l, r];\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.length);\n\t\tforeach (ee; e)\n\t\t\twriteln(ee[0]+1, \" \", ee[1]+1);\n\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 size_t[2][][](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto K = RD!int;\n\t\tauto s = RD!(char[]);\n\t\tint cnt = n/2 - K;\n\t\tforeach (j; 0..cnt+1)\n\t\t{\n\t\t\tif (s[j] == '(') continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] == ')') continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tans[i] ~= [j, k];\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tforeach (j; cnt+1..(cnt+1)*2)\n\t\t{\n\t\t\tif (s[j] == ')') continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] == '(') continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tans[i] ~= [j, k];\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tforeach (j; (cnt+1)*2..n)\n\t\t{\n\t\t\tauto c = j % 2 == 0 ? '(' : ')';\n\t\t\tif (s[j] == c) continue;\n\t\t\tforeach (k; j+1..n)\n\t\t\t{\n\t\t\t\tif (s[k] != c) continue;\n\t\t\t\tauto d = k - j;\n\t\t\t\tans[i] ~= [j, k];\n\t\t\t\tforeach (l; j..j+(d+1)/2)\n\t\t\t\t{\n\t\t\t\t\tauto r = k-(l-j);\n\t\t\t\t\tswap(s[l], s[r]);\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.length);\n\t\tforeach (ee; e)\n\t\t\twriteln(ee[0]+1, \" \", ee[1]+1);\n\t}\n\t\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "27faaaba7a79b7d4ba7f330cb13c0704"} {"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\nvoid main()\r\n{\r\n auto st = readln()[].chomp;\r\n int n = to!int(st);\r\n \r\n foreach(int _; 0..n)\r\n {\r\n auto a = readln()[].chomp;\r\n auto b = readln()[].chomp;\r\n \r\n auto m = min(a.length, b.length);\r\n int res = a.length+b.length;\r\n bool match=true;\r\n \r\n for(int i = 0; i < a.length; i++)\r\n {\r\n for(int j = i; j < a.length; j++)\r\n {\r\n if (b.canFind(a[i..j+1]))\r\n {\r\n res = min(res, abs(a.length-(j-i+1))+abs(b.length-(j-i+1)));\r\n }\r\n }\r\n }\r\n \r\n writeln(res);\r\n }\r\n}", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1506/problem/C\n// brute force\nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n string a, b;\n readf(\"%s\\n\", &a);\n readf(\"%s\\n\", &b);\n\n int n = cast(int)a.length;\n int m = cast(int)b.length;\n\n int minima = min(n, m);\n\n int maxima = 0;\n for(int z = 1; z <= minima; z++) {\n for(int i = 0; i + z <= n; i++) {\n for(int j = 0; j + z <= m; j++) {\n if(a[i..i+z] == b[j..j+z])\n maxima = max(maxima, z);\n }\n }\n }\n\n writefln(\"%s\", n - maxima + m - maxima);\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.functional;\r\nvoid main()\r\n{\r\n auto st = readln()[].chomp;\r\n int n = to!int(st);\r\n \r\n foreach(int _; 0..n)\r\n {\r\n auto a = readln()[].chomp;\r\n auto b = readln()[].chomp;\r\n \r\n auto m = min(a.length, b.length);\r\n int res = a.length+b.length;\r\n bool match=true;\r\n \r\n for(int i = 0; i < a.length; i++)\r\n {\r\n for(int j = i+1; j <= a.length; j++)\r\n {\r\n for(int k = 0; k < b.length; k++)\r\n {\r\n if(k+(j-i) > b.length)\r\n break;\r\n int l = k+(j-i);\r\n if(a[i..j].equal(b[k..l]))\r\n {\r\n int c = a.length - (j-i);\r\n int d = b.length-(l-k);\r\n res = min(res, c+d);\r\n }\r\n }\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.functional;\r\nvoid main()\r\n{\r\n auto st = readln()[].chomp;\r\n int n = to!int(st);\r\n \r\n foreach(int _; 0..n)\r\n {\r\n auto a = readln()[].chomp;\r\n auto b = readln()[].chomp;\r\n \r\n auto m = min(a.length, b.length);\r\n int res = a.length+b.length;\r\n bool match=true;\r\n \r\n for(int i = 0; i < a.length; i++)\r\n {\r\n for(int j = i+1; j <= a.length; j++)\r\n {\r\n for(int k = 0; k < b.length; k++)\r\n {\r\n for(int l = k+1; l <= b.length; l++)\r\n {\r\n if(a[i..j].equal(b[k..l]))\r\n {\r\n int c = a.length - (j-i);\r\n int d = b.length-(l-k);\r\n res = min(res, c+d);\r\n break;\r\n }\r\n }\r\n \r\n \r\n }\r\n }\r\n }\r\n \r\n writeln(res);\r\n }\r\n}"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1506/problem/C\n// brute force\nimport std.algorithm;\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n string a, b;\n readf(\"%s\\n\", &a);\n readf(\"%s\\n\", &b);\n\n int n = cast(int)a.length;\n int m = cast(int)b.length;\n\n int minima = min(n, m);\n\n int maxima = -1;\n for(int z = 1; z <= minima; ++z) {\n for(int i = 0; i + z <= n; ++i) {\n for(int j = 0; j + z <= m; ++j) {\n if(a[i..i+z] == b[j..j+z])\n maxima = max(maxima, z);\n }\n }\n }\n\n writefln(\"%s\", n - maxima + m - maxima);\n}\n}\n\n"}], "src_uid": "36aec7a06c02052f562ea3d44d4a62e4"} {"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, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto p = n - arr.find(m).length;\n \n debug { p.writeln; }\n \n int [bool][int] cnt;\n auto cur = 0, oddlen = false;\n long ans = 1L;\n foreach_reverse (i; 0 .. p) {\n oddlen ^= 1;\n cur = cur + (arr[i] > m ? 1 : -1);\n \n if (cur == 0 || (cur == 1 && oddlen)) ++ans;\n \n cnt[cur][oddlen] += 1;\n }\n \n cur = 0, oddlen = false;\n foreach (i; p+1 .. n) {\n oddlen ^= 1;\n cur = cur + (arr[i] > m ? 1 : -1);\n \n if (cur == 0 || (cur == 1 && oddlen)) ++ans;\n \n if (-cur in cnt) {\n ans += cnt[-cur].get(false, 0) + cnt[-cur].get(true, 0);\n }\n if ((-cur+1) in cnt) {\n ans += cnt[-cur+1].get(!oddlen, 0);\n }\n }\n \n ans.writeln;\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\n\nvoid main()\n{\n int n,m;\n readf!\" %s %s \"(n,m);\n auto p = readln.strip.split.map!(a => to!long(a)).array;\n\n int mi;\n foreach (i,v; p) {\n if (v == m) mi = to!int(i);\n }\n\n long[int] cnt1, cnt2;\n\n int x = 0, y = 0;\n for (int i = mi - 1; i >= 0; i--) {\n if (p[i] > m) x++;\n else y++;\n\n cnt1[x - y]++;\n }\n cnt1[0]++;\n\n x = 0, y = 0;\n for (int i = mi+1; i < n; i++) {\n if (p[i] > m) x++;\n else y++;\n\n cnt2[x - y]++;\n }\n\n long ans = 0;\n foreach (v,c; cnt1) {\n if (-v in cnt2)\n ans += c * cnt2[-v];\n if (-v+1 in cnt2)\n ans += c * cnt2[-v+1];\n }\n if (0 in cnt1)\n ans += cnt1[0];\n if (1 in cnt1)\n ans += cnt1[1];\n\n writeln(ans);\n}\n"}], "negative_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\n\nvoid main()\n{\n int n,m;\n readf!\" %s %s \"(n,m);\n auto p = readln.strip.split.map!(a => to!long(a)).array;\n\n int mi;\n foreach (i,v; p) {\n if (v == m) mi = to!int(i);\n }\n\n int[long] cnt1, cnt2;\n\n long x = 0, y = 0;\n for (int i = mi - 1; i >= 0; i--) {\n if (p[i] > m) x++;\n else y++;\n\n cnt1[x - y]++;\n }\n cnt1[0]++;\n\n x = 0, y = 0;\n for (int i = mi+1; i < n; i++) {\n if (p[i] > m) x++;\n else y++;\n\n cnt2[x - y]++;\n }\n\n long ans = 0;\n foreach (v,c; cnt1) {\n if (-v in cnt2)\n ans += c * cnt2[-v];\n if (-v+1 in cnt2)\n ans += c * cnt2[-v+1];\n }\n if (0 in cnt1)\n ans += cnt1[0];\n if (1 in cnt1)\n ans += cnt1[1];\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.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 auto p = n - arr.find(m).length;\n \n debug { p.writeln; }\n \n int [bool][int] cnt;\n auto cur = 0, oddlen = false;\n auto ans = 1;\n foreach_reverse (i; 0 .. p) {\n oddlen ^= 1;\n cur = cur + (arr[i] > m ? 1 : -1);\n \n if (cur == 0 || (cur == 1 && oddlen)) ++ans;\n \n cnt[cur][oddlen] += 1;\n }\n \n cur = 0, oddlen = false;\n foreach (i; p+1 .. n) {\n oddlen ^= 1;\n cur = cur + (arr[i] > m ? 1 : -1);\n \n if (cur == 0 || (cur == 1 && oddlen)) ++ans;\n \n if (-cur in cnt) {\n ans += cnt[-cur].get(false, 0) + cnt[-cur].get(true, 0);\n }\n if ((-cur+1) in cnt) {\n ans += cnt[-cur+1].get(!oddlen, 0);\n }\n }\n \n ans.writeln;\n}"}], "src_uid": "52e1fd9d3c82cd70c686e575c92c1442"} {"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 arr = readln.chomp.split.map!(to!int).array;\n \n auto d = arr.map!(x => x % k).fold!(gcd)(k);\n \n if (d == 0) d = k;\n \n debug { d.writeln; }\n \n auto ans = iota(0, k, d);\n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\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, 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\ta[] %= k;\n\t\tauto d = a.fold !(gcd) (k);\n\t\td += !d * k;\n\t\tauto r = iota (0, k, d);\n\t\twritefln (\"%s\\n%(%s %)\", r.walkLength, r);\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.numeric, std.range, std.stdio;\nvoid main () {\n\tint n, k;\n\treadf (\" %s %s \", &n, &k);\n\tint d = readln.split.map !(to!int).fold!gcd (k);\n\td += !d * k;\n\twritefln (\"%s\\n%(%s %)\", k / d, iota (0, k, d));\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 A = readln.split.map!(to!int).array;\n A = A.map!(a => a % K).array.sort().uniq().array;\n\n if (A.length == 1 && A[0] == 0) {\n writeln(1);\n writeln(0);\n return;\n }\n\n if (A[0] == 0) A.popFront;\n auto G = A.length > 1 ? A.reduce!gcd : A[0];\n G = gcd(G, K);\n\n int[] ans = [G];\n while (ans.front != (ans.back + G) % K) {\n ans ~= (ans.back + G) % K;\n }\n\n ans.sort();\n ans.length.writeln;\n foreach (a; ans) write(a, \" \");\n writeln;\n}\n"}], "negative_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, 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\ta[] %= k;\n\t\tauto d = a.reduce !(gcd);\n\t\td += !d * k;\n\t\tauto r = iota (0, k, d);\n\t\twritefln (\"%s\\n%(%s %)\", r.walkLength, r);\n\t}\n}\n"}], "src_uid": "c9c3fabde66856667c338d71e17f6418"} {"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 if (K >= N) {\r\n writeln(A.reduce!\"a+b\" + (K - N) * N + N * (N-1) / 2);\r\n } else {\r\n int k = cast(int)(K);\r\n long x = A[0 .. k].reduce!\"a+b\";\r\n long mx = x;\r\n for (int l = 0; l + k < N; l++) {\r\n int r = l + k;\r\n x = x - A[l] + A[r];\r\n mx = max(mx, x);\r\n }\r\n writeln(mx + K * (K-1) / 2);\r\n }\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\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 s = [0L];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\ts ~= s.back + c;\r\n\t\t}\r\n\t\tlong res = 0;\r\n\t\tif (k >= n)\r\n\t\t{\r\n\t\t\tres = a.sum (0L);\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tres += k - i - 1;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tres += zip (s, s.drop (k)).map !(q{a[1] - a[0]})\r\n\t\t\t .maxElement;\r\n\t\t\tforeach (i; 0..k)\r\n\t\t\t{\r\n\t\t\t\tres += i;\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;\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] = readLong;\n }\n \n auto ASum = new long[N + 1];\n foreach (i; 0 .. N) {\n ASum[i + 1] = ASum[i] + A[i];\n }\n \n const k = min(K, N);\n long ans;\n foreach (i; 0 .. N - k + 1) {\n chmax(ans, ASum[cast(int)(i + k)] - ASum[cast(int)(i)]);\n }\n foreach (j; 0 .. k) {\n ans += (K - 1 - j);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "e092d58ac58e1e41d17be946128234e5"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 n = RD!int;\n\tauto k = RD!int;\n\tauto p = RDA!int;\n\t\n\tlong ans0;\n\tint[] pos;\n\tforeach (i; 0..n)\n\t{\n\t\tif (p[i] > n-k)\n\t\t{\n\t\t\tpos ~= i;\n\t\t\tans0 += p[i];\n\t\t}\n\t}\n\n\tlong ans = 1;\n\tforeach (i; 1..pos.length)\n\t{\n\t\tauto d = pos[i] - pos[i-1];\n\t\tans.modm(d);\n\t}\n\n\twriteln(ans0, \" \", 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\nimmutable int mod = 998_244_353;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\n\t\tlong best = k;\n\t\tint res = 1;\n\t\tint prev = -1;\n\t\tforeach (i, ref c; p)\n\t\t{\n\t\t\tif (c + k >= n)\n\t\t\t{\n\t\t\t\tbest += c;\n\t\t\t\tif (prev >= 0)\n\t\t\t\t{\n\t\t\t\t\tres = (res * 1L * (i - prev)) % mod;\n\t\t\t\t}\n\t\t\t\tprev = i;\n\t\t\t}\n\t\t}\n\n\t\twriteln (best, \" \", res);\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\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\nimmutable Maxn = 200005;\n\nint n, k;\nint[Maxn] a;\nlong[Maxn] b;\n\n// FIXME\nvoid solve(in int testcase) {\n n.read, k.read;\n a[1 .. n + 1] = readarray!int.array;\n b[1 .. n + 1] = a[1 .. n + 1].map!(to!long).array.sort.array;\n b[n - k + 1 .. n + 1].sum.writef!\"%s \";\n int q = cast(int)(b[n - k + 1]);\n int[] vec;\n foreach(i; 1 .. n + 1)\n if (a[i] >= q)\n vec ~= i;\n modint ans = 1;\n foreach(i; 0 .. vec.length - 1) {\n ans *= cast(long)(vec[i + 1] - vec[i]);\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;\nalias set = RedBlackTree;\nalias Set = redBlackTree;\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 int n = scan!int, k = scan!int;\n int[] ps = scan!int(n);\n\n long[] us;\n long sum;\n foreach(i, p; ps){\n if(p >= n - k + 1) sum += p, us ~= i.to!long;\n }\n\n Finite.mod = 998_244_353;\n Finite ans = Finite(1);\n foreach(i; 0 .. us.length - 1){\n ans *= us[i + 1] - us[i];\n }\n print(sum, ans);\n\n}\n\n\nstruct Finite{\n\tlong value; static long mod = 1_000_000_007;\n\tthis(long v){ value = val(v); }\n\tstatic long val(long v){ return (v + mod - (v / mod) * mod) % mod; }\n\tbool opCast(T: bool)(){ return value != 0; }\n\tbool opEquals(Finite b){ return(value == b.value); }\n\tstring toString(){ return value.to!string; }\n\n\tFinite opUnary(string s){ long 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\n\tFinite opBinary(string s)(Finite b){ return opBinary!s(b.value); }\n\tFinite opBinary(string s)(long u){ long 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)(long u){ long 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(long v){ value = v; return this; }\n\n\tFinite opOpAssign(string s)(Finite b){ return opOpAssign!s(b.value); }\n\tFinite opOpAssign(string s)(long 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\t\n\tprivate static long[] _inv = [0, 1];\n\tlong invvalue(){ return inv(value); }\n\tlong inv(long v){ int i = val(v).to!int;\n\t\twhile(i >= _inv.length){\n\t\t\t_inv ~= _inv[(mod % $).to!int] * (mod - mod / _inv.length) % mod;\n\t\t}\n\t\treturn _inv[i];\n\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\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 = 998244353;\nalias Mint = ModInt!MO;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n auto P = new int[N];\n foreach (i; 0 .. N) {\n P[i] = readInt();\n }\n \n long ans0;\n foreach (k; 0 .. K) {\n ans0 += (N - k);\n }\n \n int[] xs;\n foreach (i; 0 .. N) {\n if (P[i] > N - K) {\n xs ~= i;\n }\n }\n Mint ans1 = 1;\n foreach (k; 0 .. K - 1) {\n ans1 *= (xs[k + 1] - xs[k]);\n }\n \n writeln(ans0, \" \", ans1);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_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\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\nimmutable Maxn = 200005;\n\nint n, k;\nint[Maxn] a, b;\n\n// FIXME\nvoid solve(in int testcase) {\n n.read, k.read;\n a[1 .. n + 1] = readarray!int.array;\n b[1 .. n + 1] = a[1 .. n + 1].dup.sort.array;\n b[n - k + 1 .. n + 1].sum.writef!\"%s \";\n int q = b[n - k + 1];\n int[] vec;\n foreach(i; 1 .. n + 1)\n if (a[i] >= q)\n vec ~= i;\n modint ans = 1;\n foreach(i; 0 .. vec.length - 1) {\n ans *= cast(long)(vec[i + 1] - vec[i]);\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;\nalias set = RedBlackTree;\nalias Set = redBlackTree;\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"}], "src_uid": "926c01419301caff034988aff98edc9d"} {"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\nint N;\nint[] colors;\nint[][] adj;\n\n\nvoid main() {\n N = readln.chomp.to!int;\n adj = new int[][](N);\n foreach (i; 0..N-1) {\n auto s = readln.split.map!(to!int).array;\n adj[s[0]-1] ~= s[1]-1;\n adj[s[1]-1] ~= s[0]-1;\n }\n colors = readln.split.map!(to!int).array;\n\n int[int] cnt;\n foreach (c; colors) {\n if (c in cnt) cnt[c]++;\n else cnt[c] = 1;\n }\n\n if (cnt.keys.length == 1) {\n writeln(\"YES\");\n writeln(1);\n }\n else {\n Tuple!(int, int)[] borders;\n foreach (i; 0..N) {\n foreach (j; adj[i]) {\n if (colors[i] != colors[j]) {\n borders ~= tuple(i, j);\n }\n }\n }\n\n foreach (a; borders[0]) {\n bool flag = true;\n foreach (b; borders) {\n if (a != b[0] && a != b[1]) {\n flag = false;\n break;\n }\n }\n if (flag) {\n writeln(\"YES\");\n writeln(a+1);\n return;\n }\n }\n\n writeln(\"NO\");\n }\n}\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,\"fi\",Y,\"se\");\nalias std.numeric.gcd gcd;\nimmutable int mod=10^^9+7;\npure nothrow \n{\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\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) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 0)\n{\n\tstring f;\n\tforeach(i;T)\n\t{\n\t\tif(isSomeChar!i)f~=\" %c\";\n\t\telse f~=\" %s\";\n\t}\n\treturn readf(f,ptrs)==ptrs.length;\n}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{\n\tstring f;\n\tforeach(i;T)\n\t{\n\t\tif(isSomeChar!i)f~=\" %c\";\n\t\telse f~=\" %s\";\n\t}\n\tf~='\\n';\n\treturn readf(f,ptrs)==ptrs.length;\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.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---------------------------------------\n\nvoid main()\n{\n\tint n;\n\tloop:while(read(&n))\n\t{\n\t\tauto g=new int[][n+1];\n\t\tforeach(i;0..n-1)\n\t\t{\n\t\t\tint u,v;\n\t\t\tread(&u,&v);\n\t\t\tu--;v--;\n\t\t\tg[u]~=v;\n\t\t\tg[v]~=u;\n\t\t}\n\t\tauto cl=arread!int;\n\t\tauto a=new int[n];\n\t\tint s;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tforeach(x;g[i])\n\t\t\t{\n\t\t\t\tif(cl[i]!=cl[x])\n\t\t\t\t{\n\t\t\t\t\ta[i]++;\n\t\t\t\t\ta[x]++;\n\t\t\t\t\ts++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tif(a[i]==s)\n\t\t\t{\n\t\t\t\twriteln(\"YES\\n\",i+1);\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t}\n\t\twriteln(\"NO\");\n\t}\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\nint N;\nint[] colors;\nint[][] adj;\n\n\nbool dfs(int n, int prev) {\n foreach (m; adj[n]) {\n if (m == prev) continue;\n if (colors[m] != colors[n]) return false;\n if (!dfs(m, n)) return false;\n }\n return true;\n}\n\n\nvoid main() {\n N = readln.chomp.to!int;\n adj = new int[][](N);\n foreach (i; 0..N-1) {\n auto s = readln.split.map!(to!int).array;\n adj[s[0]-1] ~= s[1]-1;\n adj[s[1]-1] ~= s[0]-1;\n }\n colors = readln.split.map!(to!int).array;\n\n int[int] cnt;\n foreach (c; colors) {\n if (c in cnt) cnt[c]++;\n else cnt[c] = 1;\n }\n\n if (N <= 3) {\n writeln(\"YES\");\n writeln(1);\n }\n else if (cnt.keys.length == 1) {\n writeln(\"YES\");\n writeln(1);\n }\n else if (cnt.keys.length == 2) {\n int n1 = -1;\n int n2 = -1;\n int c1 = 0;\n int c2 = 0;\n\n foreach (i; 0..N) {\n foreach (j; adj[i]) {\n if (colors[i] != colors[j]) {\n if (colors[i] < colors[j]) {\n c1++;\n n1 = i;\n }\n else {\n c2++;\n n2 = i;\n }\n break;\n }\n }\n }\n\n if (c1 == 1) {\n writeln(\"YES\");\n writeln(n1+1);\n }\n else if (c2 == 1) {\n writeln(\"YES\");\n writeln(n2+1);\n }\n else {\n writeln(\"NO\");\n }\n\n }\n else if (cnt.keys.length == 3) {\n foreach (i; 0..N) {\n if (cnt[colors[i]] == 1) {\n bool flag = true;\n foreach (j; adj[i]) {\n if (!dfs(j, i)) {\n flag = false;\n break;\n }\n }\n if (flag) {\n writeln(\"YES\");\n writeln(i+1);\n return;\n }\n }\n }\n writeln(\"NO\");\n }\n else {\n writeln(\"NO\");\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\nint N;\nint[] colors;\nint[][] adj;\n\n\nbool dfs(int n, int prev) {\n foreach (m; adj[n]) {\n if (m == prev) continue;\n if (colors[m] != colors[n]) return false;\n if (!dfs(m, n)) return false;\n }\n return true;\n}\n\n\nvoid main() {\n N = readln.chomp.to!int;\n adj = new int[][](N);\n foreach (i; 0..N-1) {\n auto s = readln.split.map!(to!int).array;\n adj[s[0]-1] ~= s[1]-1;\n adj[s[1]-1] ~= s[0]-1;\n }\n colors = readln.split.map!(to!int).array;\n\n int[int] cnt;\n foreach (c; colors) {\n if (c in cnt) cnt[c]++;\n else cnt[c] = 1;\n }\n\n if (cnt.keys.length == 1) {\n writeln(\"YES\");\n writeln(1);\n }\n else if (cnt.keys.length == 2) {\n int n1 = -1;\n int n2 = -1;\n int c1 = 0;\n int c2 = 0;\n\n foreach (i; 0..N) {\n foreach (j; adj[i]) {\n if (colors[i] != colors[j]) {\n if (colors[i] < colors[j]) {\n c1++;\n n1 = i;\n }\n else {\n c2++;\n n2 = i;\n }\n break;\n }\n }\n }\n\n if (c1 == 1) {\n writeln(\"YES\");\n writeln(n1+1);\n }\n else if (c2 == 1) {\n writeln(\"YES\");\n writeln(n2+1);\n }\n else {\n writeln(\"NO\");\n }\n\n }\n else if (cnt.keys.length == 3) {\n\n foreach (i; 0..N) {\n if (cnt[colors[i]] == 1) {\n bool flag = true;\n foreach (j; adj[i]) {\n if (!dfs(j, i)) {\n flag = false;\n break;\n }\n }\n if (flag) {\n writeln(\"YES\");\n writeln(i+1);\n return;\n }\n }\n }\n writeln(\"NO\");\n }\n else {\n writeln(\"NO\");\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\nint N;\nint[] colors;\nint[][] adj;\n\n\nbool dfs(int n, int prev) {\n foreach (m; adj[n]) {\n if (m == prev) continue;\n if (colors[m] != colors[n]) return false;\n if (!dfs(m, n)) return false;\n }\n return true;\n}\n\n\nvoid main() {\n N = readln.chomp.to!int;\n adj = new int[][](N);\n foreach (i; 0..N-1) {\n auto s = readln.split.map!(to!int).array;\n adj[s[0]-1] ~= s[1]-1;\n adj[s[1]-1] ~= s[0]-1;\n }\n colors = readln.split.map!(to!int).array;\n\n int[int] cnt;\n foreach (c; colors) {\n if (c in cnt) cnt[c]++;\n else cnt[c] = 1;\n }\n\n if (cnt.keys.length == 1) {\n writeln(\"YES\");\n writeln(1);\n }\n else if (cnt.keys.length == 2) {\n int n1 = -1;\n int n2 = -1;\n int c1 = 0;\n int c2 = 0;\n\n foreach (i; 0..N) {\n foreach (j; adj[i]) {\n if (colors[i] != colors[j]) {\n if (colors[i] < colors[j]) {\n c1++;\n n1 = i;\n }\n else {\n c2++;\n n2 = i;\n }\n break;\n }\n }\n }\n\n if (c1 == 1) {\n writeln(\"YES\");\n writeln(n1+1);\n }\n else if (c2 == 1) {\n writeln(\"YES\");\n writeln(n2+1);\n }\n else {\n writeln(\"NO\");\n }\n\n }\n else {\n foreach (i; 0..N) {\n if (cnt[colors[i]] == 1) {\n bool flag = true;\n foreach (j; adj[i]) {\n if (!dfs(j, i)) {\n flag = false;\n break;\n }\n }\n if (flag) {\n writeln(\"YES\");\n writeln(i+1);\n return;\n }\n }\n }\n writeln(\"NO\");\n }\n}\n"}], "src_uid": "aaca5d07795a42ecab210327c1cf6be9"} {"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 if (n == 4) {\n writefln(\"%.12f\", 1.0);\n continue;\n }\n auto r = 1.0 / sin(PI / n);\n\n auto d = 2.0 * PI / n;\n auto res = 0.0;\n foreach (x; 0..n.to!int) {\n auto t = 45.0 * PI / 180.0 + d * x;\n res = max(res, r * sin(t));\n }\n writefln(\"%.12f\", res);\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\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 / 4) * 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"}], "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 / 4) * 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": "c466c909fff92353ea676b643ca76908"} {"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// t -> max{t + a, b}\nstruct T {\n int a, b;\n T opBinary(string op)(const(T) t) const {\n return T(a + t.a, max(b + t.a, t.b));\n }\n}\nenum INF = 10^^9;\nenum ID_T = T(0, -INF);\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();\n }\n auto Q = new int[N];\n foreach (j; 0 .. N) {\n Q[j] = readInt() - 1;\n }\n \n auto poss = new int[N + 1];\n foreach (i; 0 .. N) {\n poss[P[i]] = i;\n }\n \n auto ans = new int[N];\n auto seg = new SegmentTree!(T, \"a * b\")(2 * N, ID_T);\n {\n int x = N + 1;\n foreach (j; 0 .. N) {\n for (; max(0 + seg.ts[1].a, seg.ts[1].b) <= 0; ) {\n // add large\n --x;\n seg.set(2 * poss[x], T(1, 0));\n debug {\n writeln(j, \" \", x, \": \", seg.ts[1]);\n }\n }\n ans[j] = x;\n // bomb\n seg.set(2 * Q[j] + 1, T(-1, 0));\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": "// 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 = 300005;\n\nint n;\nint[Maxn] p, q;\n\nstruct node {\n this()() {\n sum = suf = 0;\n }\n this()(in node x) { *this = x; }\n int sum, suf;\n void apply(int l, int r) {\n sum = suf = 0;\n }\n void apply(int l, int r, int x) {\n sum += x, suf += x;\n }\n}\nvoid pullup(ref node a, in node b, in node c) {\n a.suf = max(c.suf, b.suf + c.sum);\n a.sum = b.sum + c.sum;\n}\n\nstruct segment_tree {\n int N;\n node[] tr;\n private void pushup(int p) {\n pullup(tr[p], tr[p * 2], tr[p * 2 + 1]);\n }\n private void modify_(T...)(int p, int l, int r, int L, int R, T args) {\n if (L == l && r == R) return tr[p].apply(l, r, args);\n pushdown(p, l, r);\n int mid = (l + r) >> 1;\n if (R <= mid) modify_(p * 2, l, mid, L, R, args);\n else if (L > mid) modify_(p * 2 + 1, mid + 1, r, L, R, args);\n else {\n modify_(p * 2, l, mid, L, mid, args);\n modify_(p * 2 + 1, mid + 1, r, mid + 1, R, args);\n }\n pushup(p);\n }\n private node query_(int p, int l, int r, int L, int R) {\n if (L == l && r == R) return tr[p];\n pushdown(p, l, r);\n int mid = (l + r) >> 1;\n if (R <= mid) return query_(p * 2, l, mid, L, R);\n if (L > mid) return query_(p * 2 + 1, mid + 1, r, L, R);\n node left = query_(p * 2, l, mid, L, mid);\n node right = query_(p * 2 + 1, mid + 1, r, mid + 1, R);\n node ans; pullup(ans, left, right); return ans;\n }\n public void build(T...)(int len, T args) {\n N = len;\n tr.length = (N + 1) << 2;\n build(1, 1, N, args);\n }\n public void modify(T...)(int L, int R, T args) {\n if (L > R) return ;\n modify_(1, 1, N, L, R, args);\n }\n public node query(int L, int R) {\n if (L > R) return node();\n return query_(1, 1, N, L, R);\n }\n private void pushdown(int p, int l, int r) {\n int mid = (l + r) >> 1;\n }\n private void build(int p, int l, int r) {\n if (l == r) {\n tr[p].apply(l, r);\n return ;\n }\n int mid = (l + r) >> 1;\n build(p * 2, l, mid);\n build(p * 2 + 1, mid + 1, r);\n pushup(p);\n }\n}\nsegment_tree sgt;\n\n// FIXME\nvoid solve(in int testcase) {\n n.read;\n p[1 .. n + 1] = readarray!int;\n foreach(i; 1 .. n + 1) q[p[i]] = i;\n sgt.build(n);\n int now = n;\n foreach(i; 1 .. n + 1) {\n while (sgt.query(1, n).suf <= 0) {\n sgt.modify(q[now], q[now], 1);\n --now;\n }\n (now + 1).write, (\" \\n\"[i == n]).write;\n int pos = reader!int;\n sgt.modify(pos, pos, -1);\n }\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": [{"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// t -> max{t + a, b}\nstruct T {\n int a, b;\n T opBinary(string op)(const(T) t) const {\n return T(a + t.a, max(b + t.a, t.b));\n }\n}\nenum INF = 10^^9;\nenum ID_T = T(0, -INF);\n\n\nvoid main() {\nwriteln(T(-1,0)*T(-1,0));\nwriteln(T(-1,0)*T(-1,0)*T(1,0));\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new int[N];\n foreach (i; 0 .. N) {\n P[i] = readInt();\n }\n auto Q = new int[N];\n foreach (j; 0 .. N) {\n Q[j] = readInt() - 1;\n }\n \n auto poss = new int[N + 1];\n foreach (i; 0 .. N) {\n poss[P[i]] = i;\n }\n \n auto ans = new int[N];\n auto seg = new SegmentTree!(T, \"a * b\")(2 * N, ID_T);\n {\n int x = N + 1;\n foreach (j; 0 .. N) {\n for (; max(0 + seg.ts[1].a, seg.ts[1].b) <= 0; ) {\n // add large\n --x;\n seg.set(2 * poss[x], T(1, 0));\n debug {\n writeln(j, \" \", x, \": \", seg.ts[1]);\n }\n }\n ans[j] = x;\n // bomb\n seg.set(2 * Q[j] + 1, T(-1, 0));\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"}], "src_uid": "c8e71b942fac5c99c041ce032fbb9e4c"} {"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 B = RD;\n\tauto A = RD;\n\tauto s = RDR.ARR;\n\n\tlong a = A, b = B;\n\tlong ans;\n\tforeach (e; s)\n\t{\n\t\tif (e == 1 && b != 0 && a != A)\n\t\t{\n\t\t\t--b; ++a;\n\t\t}\n\t\telse if (a != 0)\n\t\t{\n\t\t\t--a;\n\t\t}\n\t\telse if (b != 0)\n\t\t{\n\t\t\t--b;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\t++ans;\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\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\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\t\n\tlong n = read.to!long;\n\tlong b = read.to!long;\n\tlong a = read.to!long;\n\t\n\tbool[] areSunny;\n\tforeach(i; 0 .. n) areSunny ~= read.to!int.to!bool;\n\t\n\tlong amax = a;\n\tlong ans = n;\n\tforeach(i, s; areSunny){\n\t\tif(s){\n\t\t\tif(a == amax && a > 0) a -= 1;\n\t\t\telse if(b > 0) b -= 1, a = min(amax, a + 1);\n\t\t\telse if(a > 0) a -= 1;\n\t\t\telse{\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif(a > 0) a -= 1;\n\t\t\telse if(b > 0) b -= 1;\n\t\t\telse{\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tans.writeln;\n\t\n\t\n}\n/*\n\nGreedy.\nUse battery when sunny and use accumlator when cloudy.\nPerform simulation of it.\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\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\t\n\tlong n = read.to!long;\n\tlong b = read.to!long;\n\tlong a = read.to!long;\n\t\n\tbool[] areSunny;\n\tforeach(i; 0 .. n) areSunny ~= read.to!int.to!bool;\n\t\n\tlong amax = a;\n\tlong ans = n;\n\tforeach(i, s; areSunny){\n\t\tif(s){\n\t\t\tif(b > 0) b -= 1, a = min(amax, a + 1);\n\t\t\telse if(a > 0) a -= 1;\n\t\t\telse{\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif(a > 0) a -= 1;\n\t\t\telse if(b > 0) b -= 1;\n\t\t\telse{\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tans.writeln;\n\t\n\t\n}\n/*\n\nGreedy.\nUse battery when sunny and use accumlator when cloudy.\nPerform simulation of it.\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\t\n\tlong n = read.to!long;\n\tlong b = read.to!long;\n\tlong a = read.to!long;\n\t\n\tbool[] areSunny;\n\tforeach(i; 0 .. n) areSunny ~= read.to!int.to!bool;\n\t\n\tlong amax = a;\n\tlong ans = n;\n\tforeach(i, s; areSunny){\n\t\tif(s){\n\t\t\tif(b > 0){\n\t\t\t\tb -= 1;\n\t\t\t\tif(a < amax) a += 1;\n\t\t\t}\n\t\t\telse if(a > 0){\n\t\t\t\ta -= 1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tans = i + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tif(a > 0){\n\t\t\t\ta -= 1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tans = i + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tans.writeln;\n\t\n\t\n}\n/*\n\nGreedy.\nUse battery when sunny and use accumlator when cloudy.\nPerform simulation of it.\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 B = RD;\n\tauto A = RD;\n\tauto s = RDR.ARR;\n\n\tlong a = A, b = B;\n\tlong ans;\n\tforeach (e; s)\n\t{\n\t\tif (e == 1 && b != 0)\n\t\t{\n\t\t\t--b; a = min(a+1, A);\n\t\t}\n\t\telse if (a != 0)\n\t\t{\n\t\t\t--a;\n\t\t}\n\t\telse if (b != 0)\n\t\t{\n\t\t\t--b;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\t++ans;\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "75ef1f52ef3a86992159eef566dddc89"} {"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 auto app = new bool[][](K, 2);\n foreach (i; 0 .. N) {\n if (S[i] != '?') {\n app[i % K][S[i] - '0'] = true;\n }\n }\n \n bool ok = true;\n auto cnt = new int[2];\n foreach (r; 0 .. K) {\n if (app[r][0] && app[r][1]) {\n ok = false;\n }\n foreach (s; 0 .. 2) {\n if (app[r][s]) {\n ++cnt[s];\n }\n }\n }\n \n bool ans;\n if (ok) {\n if (2 * cnt[0] <= K && 2 * cnt[1] <= K) {\n ans = true;\n }\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\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 = char)(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 int k = to!int(rd);\n dchar[] wordstr;\n readln(wordstr);\n wordstr.popBack;\n int[] word;\n foreach(cr; wordstr){\n word ~= (cr - '0');\n }\n // Set all initially\n foreach(i; 0..n-k){\n if(word[i] <= 1){\n if(word[i+k] <= 1 && word[i+k] != word[i]){\n writeln(\"NO\");\n return;\n }else{\n word[i+k] = word[i];\n }\n }else if(word[i+k] <= 1){\n word[i] = word[i+k];\n }\n }\n // Check 0s and 1s\n ll c0 = 0, c1 = 0, cq = 0;\n foreach(i; 0..k){\n if(word[i] == 1) ++c1;\n if(word[i] > 1) ++cq;\n }\n c0 = k - cq - c1;\n foreach(i; k..n-k+1){\n if(c1 > k/2 || c0 > k/2 || abs(c1 - c0) > cq){\n writeln(\"NO\");\n return;\n }\n // Remove\n c1 -= (word[i-k] == 1); c0 -= (word[i-k] == 0); cq -= (word[i-k] > 1);\n // Add\n c1 += (word[i] == 1); c0 += (word[i] == 0); cq += (word[i] > 1);\n\n }\n /* writeln(word); */\n if(c0 <= k/2 && c1 <= k/2 && abs(c1 - c0) <= cq){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\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.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto s = RD!(char[]);\n\t\t\n\t\tbool ok = true;\n\t\tforeach (i; 0..n-k)\n\t\t{\n\t\t\tif (s[i] == s[i+k]) continue;\n\t\t\tif (s[i] == '?')\n\t\t\t\ts[i] = s[i+k];\n\t\t\telse if (s[i+k] == '?')\n\t\t\t\ts[i+k] = s[i];\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\tif (!ok) continue;\n\n\t\tlong cnt0, cnt1;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tif (s[i] == '0')\n\t\t\t\t++cnt0;\n\t\t\telse if (s[i] == '1')\n\t\t\t\t++cnt1;\n\t\t}\n\t\tdebug writeln(\"cnt0:\", cnt0, \" cnt1:\", cnt1);\n\n\t\tauto k2 = k/2;\n\t\tforeach (i; 0..n-k)\n\t\t{\n\t\t\tif (cnt0 > k2 || cnt1 > k2)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (s[i] == '0')\n\t\t\t\t--cnt0;\n\t\t\telse if (s[i] == '1')\n\t\t\t\t--cnt1;\n\t\t\t\n\t\t\tif (s[i+k] == '0')\n\t\t\t\t++cnt0;\n\t\t\telse if (s[i+k] == '1')\n\t\t\t\t++cnt1;\n\t\t\tdebug writeln(\"i:\", i, \" cnt0:\", cnt0, \" cnt1:\", cnt1);\n\t\t}\n\t\tif (cnt0 > k2 || cnt1 > k2)\n\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}\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;\n\t\tauto p = new int [k];\n\t\tp[] = -1;\n\t\tforeach (d; 0..k)\n\t\t{\n\t\t\tfor (int i = d; i < n; i += k)\n\t\t\t{\n\t\t\t\tif (s[i] != '?')\n\t\t\t\t{\n\t\t\t\t\tauto cur = s[i] - '0';\n\t\t\t\t\tif (p[d] == -1)\n\t\t\t\t\t{\n\t\t\t\t\t\tp[d] = cur;\n\t\t\t\t\t}\n\t\t\t\t\telse if (p[d] != cur)\n\t\t\t\t\t{\n\t\t\t\t\t\tp[d] = -2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln ((p.count (-2) > 0 ||\n\t\t p.count (0) > k / 2 ||\n\t\t p.count (1) > k / 2) ? \"NO\" : \"YES\");\n\t}\n}\n"}], "negative_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 = char)(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 int k = to!int(rd);\n dchar[] wordstr;\n readln(wordstr);\n wordstr.popBack;\n int[] word;\n foreach(cr; wordstr){\n word ~= (cr - '0');\n }\n // Set all initially\n foreach(i; 0..n-k-1){\n if(word[i] <= 1){\n if(word[i+k] <= 1 && word[i+k] != word[i]){\n writeln(\"NO\");\n return;\n }else{\n word[i+k] = word[i];\n }\n }else if(word[i+k] <= 1){\n word[i] = word[i+k];\n }\n }\n // Check 0s and 1s\n ll c0 = 0, c1 = 0, cq = 0;\n foreach(i; 0..k){\n if(word[i] == 1) ++c1;\n if(word[i] > 1) ++cq;\n }\n c0 = k - cq - c1;\n foreach(i; k..n-k+1){\n if(c1 > k/2 || c0 > k/2 || abs(c1 - c0) > cq){\n writeln(\"NO\");\n return;\n }\n // Remove\n c1 -= (word[i-k] == 1); c0 -= (word[i-k] == 0); cq -= (word[i-k] > 1);\n // Add\n c1 += (word[i] == 1); c0 += (word[i] == 0); cq += (word[i] > 1);\n\n }\n /* writeln(word); */\n if(c0 <= k/2 && c1 <= k/2 && abs(c1 - c0) <= cq){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\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": "// 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 = char)(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 int k = to!int(rd);\n dchar[] wordstr;\n readln(wordstr);\n wordstr.popBack;\n int[] word;\n foreach(cr; wordstr){\n word ~= (cr - '0');\n }\n // Set all initially\n foreach(i; 0..n-k-1){\n if(word[i] <= 1){\n if(word[i+k] <= 1 && word[i+k] != word[i]){\n writeln(\"NO\");\n return;\n }else{\n word[i+k] = word[i];\n }\n }else if(word[i+k] <= 1){\n word[i] = word[i+k];\n }\n }\n // Check 0s and 1s\n ll roll = 0;\n foreach(i; 0..k){\n if(word[i] == 1) ++roll;\n }\n // Handle ?\n foreach(i; 0..k){\n if(word[i] > 1){\n word[i] = !(roll >= k/2);\n roll += word[i];\n }\n if(i + k < n){\n if(word[i+k] <= 1 && word[i+k] != word[i]){\n writeln(\"NO\");\n return;\n }else{\n word[i+k] = word[i];\n }\n }\n }\n foreach(i; k .. n-k-1){\n if(i != k){ roll += word[i]; }\n if(roll != k/2){\n writeln(\"NO\");\n return;\n }else{\n if(word[i+k] <= 1 && word[i+k] != word[i]){\n writeln(\"NO\");\n return;\n }else{\n word[i+k] = word[i];\n }\n }\n roll -= word[i-k];\n }\n /* writeln(word); */\n if(roll == k/2){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\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": "// 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 = char)(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 int k = to!int(rd);\n dchar[] wordstr;\n readln(wordstr);\n wordstr.popBack;\n int[] word;\n foreach(cr; wordstr){\n word ~= (cr - '0');\n }\n // Set all initially\n foreach(i; 0..n-k-1){\n if(word[i] <= 1){\n if(word[i+k] <= 1 && word[i+k] != word[i]){\n writeln(\"NO\");\n return;\n }else{\n word[i+k] = word[i];\n }\n }else if(word[i+k] <= 1){\n word[i] = word[i+k];\n }\n }\n // Check 0s and 1s\n ll roll = 0;\n foreach(i; 0..k){\n if(word[i] == 1) ++roll;\n }\n // Handle ?\n foreach(i; 0..k){\n // Handle\n if(word[i] > 1){\n word[i] = !(roll >= k/2);\n roll += word[i];\n }\n // HandleNext\n if(i + k < n){\n if(word[i+k] <= 1 && word[i+k] != word[i]){\n writeln(\"NO\");\n return;\n }else{\n word[i+k] = word[i];\n }\n }\n }\n foreach(i; k..n-k-1){\n // Handle Prev Check\n if(roll != k/2){\n writeln(\"NO\");\n return;\n }else{\n if(word[i+k] <= 1 && word[i+k] != word[i]){\n writeln(\"NO\");\n return;\n }else{\n word[i+k] = word[i];\n }\n }\n\n // Remove\n roll -= word[i-k];\n // Handle ?\n if(word[i] > 1){ word[i] = !(roll >= k/2); }\n // Add\n if(i != k-1){ roll += word[i]; }\n }\n /* writeln(word); */\n if(roll == k/2){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\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.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto s = RD!(char[]);\n\t\t\n\t\tbool ok = true;\n\t\tforeach (i; 0..n-k)\n\t\t{\n\t\t\tif (s[i] == s[i+k]) continue;\n\t\t\tif (s[i] == '?')\n\t\t\t\ts[i] = s[i+k];\n\t\t\telse if (s[i+k] == '?')\n\t\t\t\ts[i+k] = s[i];\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\tif (!ok) continue;\n\n\t\tlong cnt0, cnt1;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tif (s[i] == '0')\n\t\t\t\t++cnt0;\n\t\t\telse if (s[i] == '1')\n\t\t\t\t++cnt1;\n\t\t}\n\t\tdebug writeln(\"cnt0:\", cnt0, \" cnt1:\", cnt1);\n\n\t\tauto k2 = k/2;\n\t\tforeach (i; 0..n-k)\n\t\t{\n\t\t\tif (cnt0 > k2 || cnt1 > k2)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (s[i] == '0')\n\t\t\t\t--cnt0;\n\t\t\telse if (s[i] == '1')\n\t\t\t\t--cnt1;\n\t\t\t\n\t\t\tif (s[i+k] == '0')\n\t\t\t\t++cnt0;\n\t\t\telse if (s[i] == '1')\n\t\t\t\t++cnt1;\n\t\t\tdebug writeln(\"i:\", i, \" cnt0:\", cnt0, \" cnt1:\", cnt1);\n\t\t}\n\t\tif (cnt0 > k2 || cnt1 > k2)\n\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}\n"}], "src_uid": "8e448883014bf7cd35fcca3fe0128af0"} {"source_code": "module sigod.codeforces.p298A;\n\nimport std.stdio;\n\nvoid main()\n{\n\tstdin.readln();\n\tstring road = stdin.readln();\n\n\n\tint r_start = -1;\n\tint r_end = -1;\n\tint l_start = -1;\n\tint l_end = -1;\n\t\n\tforeach (index, c; road) {\n\t\tif (c == 'R') {\n\t\t\tr_end = index + 1;\n\n\t\t\tif (r_start == -1) r_start = index + 1;\n\t\t}\n\t\telse if (c == 'L') {\n\t\t\tl_end = index + 1;\n\n\t\t\tif (l_start == -1) l_start = index + 1;\n\t\t}\n\t}\n\n\n\tint start = -1;\n\tint target = -1;\n\n\tif (l_start == -1) {\n\t\tstart = r_start;\n\t\ttarget = r_end + 1;\n\t}\n\telse if (r_start == -1) {\n\t\tstart = l_end;\n\t\ttarget = l_start - 1;\n\t}\n\telse {\n\t\tstart = r_start;\n\t\ttarget = l_start - 1;\n\t}\n\n\tstdout.writeln(start, \" \", target);\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\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n char c;\n int n;\n readf(\"%s\\n\", &n);\n int fL = -1, fR = -1, lL = -1, lR = -1;\n foreach ( i ; 1 .. n + 1) {\n readf(\"%s\", &c);\n if (c == 'R') {\n if (fR == -1) fR = i;\n lR = i;\n }\n else if (c == 'L') {\n if (fL == -1) fL = i;\n lL = i;\n }\n }\n if (fR == -1) writeln(lL, \" \", fL - 1);\n else if (fL == -1) writeln(fR, \" \", lR + 1);\n else writeln(fR, \" \", lR);\n\n return 0;\n}"}], "negative_code": [], "src_uid": "3053cba2426ebd113fcd70a9b026dad0"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tint mx = max(n, m);\n\tint mn = min(n, m);\n\tif (mn > 1) return writeln(2);\n\tif (mx == 1) return writeln(0);\n\treturn writeln(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.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 M = readLong();\r\n const N = readLong();\r\n \r\n int ans;\r\n if (M == 1 && N == 1) {\r\n ans = 0;\r\n } else if (M == 1 || N == 1) {\r\n ans = 1;\r\n } else {\r\n ans = 2;\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, 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 foreach (casenum ; 1 .. t + 1) {\n long n, m;\n readf!\" %d %d \"(n, m);\n if (n == 1 && m == 1)\n writeln(0);\n else if (n == 1 || m == 1)\n writeln(1);\n else\n writeln(2);\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\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;\r\n\t\tauto m = RD;\r\n\t\t\r\n\t\tif (n == 1 && m == 1)\r\n\t\t\tans[ti] = 0;\r\n\t\telse if (n == 1 || m == 1)\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{\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 m, n;\r\n\t\treadf !(\" %s %s\") (m, n);\r\n\t\twriteln ((m > 1) + (n > 1));\r\n\t}\r\n}\r\n"}, {"source_code": "// 提出解\r\nvoid solve(){\r\n\tforeach(_; 0 .. scan!int){\r\n\t\tlong n = scan!long, m = scan!long;\r\n\t\tlong ans;\r\n\t\tif(n == 1 && m == 1) ans = 0;\r\n\t\telse if(n == 1 || m == 1) ans = 1;\r\n\t\telse ans = 2;\r\n\r\n\t\tans.print;\r\n\t}\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// 愚直解\r\nvoid jury(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テストケース\r\nvoid gen(){\r\n}\r\n\r\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\r\n// テンプレ\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// ライブラリ(基本)\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// ライブラリ(追加)\r\n\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 numCases = readInt();\r\n foreach (caseId; 0 .. numCases) {\r\n const M = readLong();\r\n const N = readLong();\r\n \r\n const ans = min(M, N, 2);\r\n writeln(ans);\r\n }\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 numCases = readInt();\r\n foreach (caseId; 0 .. numCases) {\r\n const M = readLong();\r\n const N = readLong();\r\n \r\n const ans = min(M, N, 3);\r\n writeln(ans);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "src_uid": "e5a01ebfdca3af987e93b68c96268c16"} {"source_code": "import std.stdio;\nimport std.conv:to;\nimport std.string:chomp, countchars;\nimport std.array;\n\n\nvoid main() {\n int eggs = to!int(readln().chomp);\n int A, G, iA, iG;\n auto result = appender!string();\n foreach(i; 0..eggs) {\n stdin.readf(\"%d %d\\n\", &iA, &iG);\n \n\n\n if((A + iA - G) <= 500) {\n A += iA;\n result.put(\"A\");\n } else {\n G += iG;\n result.put(\"G\");\n }\n }\n writeln(result.data);\n}", "positive_code": [{"source_code": "module cf_282B;\n\nimport std.stdio;\nimport std.algorithm;\nimport std.math;\n\nvoid main() {\n immutable MAX_PRICE = 1000;\n immutable HALF_PRICE = 500;\n\n int n;\n int[] eggs;\n\n readf(\"%d\", &n);\n eggs = new int[n];\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d\", &eggs[i], &eggs[i]);\n }\n\n string result;\n int a = 0, g = 0, cur = 0;\n\n while (cur < n) {\n while (cur < n && abs(a - g) <= HALF_PRICE) {\n if (abs(a + MAX_PRICE - eggs[cur] - g) > HALF_PRICE) {\n break;\n }\n\n a += MAX_PRICE - eggs[cur++];\n result ~= 'A';\n }\n\n while (cur < n && abs(a - g) <= HALF_PRICE) {\n if (abs(g + eggs[cur] - a) > HALF_PRICE) {\n break;\n }\n\n g += eggs[cur++];\n result ~= 'G';\n }\n }\n\n if (abs(a - g) > HALF_PRICE) {\n writeln(-1);\n } else {\n writeln(result);\n }\n}"}], "negative_code": [{"source_code": "module cf_282B;\n\nimport std.stdio;\nimport std.algorithm;\nimport std.math;\n\nstruct Egg {\n int price;\n int pos;\n}\n\nvoid main() {\n immutable MAX_PRICE = 1000;\n\n int n;\n Egg[] eggs;\n\n readf(\"%d\", &n);\n eggs = new Egg[n];\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d\", &eggs[i].price, &eggs[i].price);\n eggs[i].pos = i;\n }\n\n sort!((egg1, egg2) { return egg1.price < egg2.price; })(eggs);\n\n char[] result = new char[n];\n int a = 0, g = 0, left = 0, right = n - 1;\n\n while (left <= right) {\n g += eggs[left].price;\n result[eggs[left].pos] = 'G';\n ++left;\n a += MAX_PRICE - eggs[right].price;\n result[eggs[right].pos] = 'A';\n --right;\n }\n\n if (abs(a - g) > MAX_PRICE / 2) {\n writeln(-1);\n } else {\n writeln(result);\n }\n}"}, {"source_code": "module cf_282B;\n\nimport std.stdio;\nimport std.algorithm;\nimport std.math;\n\nstruct Egg {\n int price;\n int pos;\n}\n\nvoid main() {\n immutable MAX_PRICE = 1000;\n\n int n;\n Egg[] eggs;\n\n readf(\"%d\", &n);\n eggs = new Egg[n];\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d\", &eggs[i].price, &eggs[i].price);\n eggs[i].pos = i;\n }\n\n sort!((egg1, egg2) { return egg1.price < egg2.price; })(eggs);\n\n char[] result = new char[n];\n int a = 0, g = 0, left = 0, right = n - 1;\n\n while (left <= right) {\n if (a > g) {\n g += eggs[left].price;\n result[eggs[left].pos] = 'G';\n ++left;\n } else {\n a += MAX_PRICE - eggs[right].price;\n result[eggs[right].pos] = 'A';\n --right;\n }\n }\n\n if (abs(a - g) > MAX_PRICE / 2) {\n writeln(-1);\n } else {\n writeln(result);\n }\n}"}, {"source_code": "module cf_282B;\n\nimport std.stdio;\nimport std.algorithm;\nimport std.math;\n\nstruct Egg {\n int price;\n int pos;\n}\n\nvoid main() {\n immutable MAX_PRICE = 1000;\n\n int n;\n Egg[] eggs;\n\n readf(\"%d\", &n);\n eggs = new Egg[n];\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d\", &eggs[i].price, &eggs[i].price);\n eggs[i].pos = i;\n }\n\n sort!((egg1, egg2) { return egg1.price < egg2.price; })(eggs);\n\n char[] result = new char[n];\n int a = 0, g = 0, left = 0, right = n - 1;\n\n while (left <= right) {\n if (a > g) {\n g += eggs[left].price;\n result[eggs[left].pos] = 'G';\n ++left;\n } else {\n a += MAX_PRICE - eggs[right].price;\n result[eggs[right].pos] = 'A';\n --right;\n }\n }\n\n if (abs(a - g) > MAX_PRICE / 2 || n == 1) {\n writeln(-1);\n } else {\n writeln(result);\n }\n}"}, {"source_code": "module cf_282B;\n\nimport std.stdio;\nimport std.algorithm;\nimport std.math;\n\nstruct Egg {\n int price;\n int pos;\n}\n\nvoid main() {\n immutable MAX_PRICE = 1000;\n\n int n;\n Egg[] eggs;\n\n readf(\"%d\", &n);\n eggs = new Egg[n];\n for (int i = 0; i < n; ++i) {\n readf(\" %d %d\", &eggs[i].price, &eggs[i].price);\n eggs[i].pos = i;\n }\n\n sort!((egg1, egg2) { return egg1.price < egg2.price; })(eggs);\n\n char[] result = new char[n];\n int a = 0, g = 0, eggLeft = 0, eggRight = n - 1;\n\n while (eggLeft <= eggRight) {\n if (a > g) {\n while (eggLeft <= eggRight && a >= g) {\n g += eggs[eggLeft].price;\n result[eggs[eggLeft].pos] = 'G';\n ++eggLeft;\n }\n } else {\n while (eggLeft <= eggRight && g >= a) {\n a += MAX_PRICE - eggs[eggRight].price;\n result[eggs[eggRight].pos] = 'A';\n --eggRight;\n }\n }\n }\n\n if (abs(a - g) > MAX_PRICE / 2) {\n writeln(-1);\n } else {\n writeln(result);\n }\n}"}], "src_uid": "24fe280b88575516ec679ff78641440e"} {"source_code": "import std.stdio;\n \n \nint n, m, x, y, z, p, t;\n \nstruct coord {\n int x, y;\n}\n \nvoid transform(ref coord c) {\n int n_t = n, m_t = m;\n for (int i = 0; i < x; i++) {\n t = c.x; c.x = c.y; c.y = n_t-t+1;\n n_t ^= m_t; m_t ^= n_t; n_t ^= m_t;\n }\n if (y)\n c.y = m_t-c.y+1;\n \n for (int i = 0; i < z; i++) {\n t = c.y; c.y = c.x; c.x = m_t-t+1;\n n_t ^= m_t; m_t ^= n_t; n_t ^= m_t;\n }\n}\n \nvoid main() {\n scanf(\"%d %d %d %d %d %d\", &n, &m, &x, &y, &z, &p); coord c; x %= 4; y %=2; z %= 4;\n while (p--) {\n scanf(\"%d %d\", &c.x, &c.y); transform(c); writeln(c.x, ' ', c.y);\n }\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\n \nint n, m, x, y, z, p, t;\n \nstruct coord {\n int x, y;\n}\n \nvoid transform(ref coord c) {\n int n_t = n, m_t = m;\n for (int i = 0; i < x; i++) {\n t = c.x; c.x = c.y; c.y = n_t-t+1;\n n_t ^= m_t; m_t ^= n_t; n_t ^= m_t;\n }\n if (y)\n c.y = m_t-c.y+1;\n \n for (int i = 0; i < z; i++) {\n t = c.y; c.y = c.x; c.x = m_t-t+1;\n n_t ^= m_t; m_t ^= n_t; n_t ^= m_t;\n }\n}\n \nvoid main() {\n string str = \"\";\n scanf(\"%d %d %d %d %d %d\", &n, &m, &x, &y, &z, &p); coord c; x %= 4; y %=2; z %= 4;\n while (p--) {\n scanf(\"%d %d\", &c.x, &c.y); transform(c); str ~= to!string(c.x) ~ ' ' ~ to!string(c.y) ~ '\\n';\n }\n write(str);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\n\nint n, m, x, y, z, p, t;\n\nstruct coord {\n int x, y;\n}\n\nvoid transform(ref coord c) {\n int n_t = n, m_t = m;\n for (int i = 0; i < x; i++) {\n t = c.x; c.x = c.y; c.y = n_t-t+1;\n n_t ^= m_t; m_t ^= n_t; n_t ^= m_t;\n }\n if (y)\n c.y = m_t-c.y+1;\n \n for (int i = 0; i < z; i++) {\n t = c.y; c.y = c.x; c.x = n_t-t+1;\n n_t ^= m_t; m_t ^= n_t; n_t ^= m_t;\n }\n}\n\nvoid main() {\n scanf(\"%d %d %d %d %d %d\", &n, &m, &x, &y, &z, &p); coord c; x %= 4; y %=2; z %= 4;\n while (p--) {\n scanf(\"%d %d\", &c.x, &c.y); transform(c); writeln(c.x, ' ', c.y);\n }\n}\n"}], "src_uid": "14a56443e48c52c118788bd5c0031b0c"} {"source_code": "import std.string;\nimport std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.typecons;\nimport std.range;\nimport std.array;\n\nvoid main()\n{\n Tuple!(int,int[])[string] players;\n auto n = readln.chomp.to!int;\n foreach(i; 0..n )\n {\n auto m = readln.chomp.to!int;\n foreach(j; 0..m )\n {\n auto s = readln.chomp; \n auto t = players.require(s, tuple(0, repeat(0).take(50).array));\n players[s][0] = t[0] + ([25, 18, 15, 12, 10, 8, 6, 4, 2, 1] ~ repeat(0).take(40).array)[j];\n players[s][1] = t[1].zip(chain(repeat(0).take(j), only(1) , repeat(0).take(50-j-1))).map!\"a[0]+a[1]\".array;\n }\n }\n auto arr = players.byPair.array;\n arr.multiSort!(\n \"a.value[0] > b.value[0]\",\n \"a.value[1][0] > b.value[1][0] \",\n \"a.value[1][1] > b.value[1][1] \",\n \"a.value[1][2] > b.value[1][2] \",\n \"a.value[1][3] > b.value[1][3] \",\n \"a.value[1][4] > b.value[1][4] \",\n \"a.value[1][5] > b.value[1][5] \",\n \"a.value[1][6] > b.value[1][6] \",\n \"a.value[1][7] > b.value[1][7] \",\n \"a.value[1][8] > b.value[1][8] \",\n \"a.value[1][9] > b.value[1][9] \",\n \"a.value[1][10] > b.value[1][10] \",\n \"a.value[1][11] > b.value[1][11] \",\n \"a.value[1][12] > b.value[1][12] \",\n \"a.value[1][13] > b.value[1][13] \",\n \"a.value[1][14] > b.value[1][14] \",\n \"a.value[1][15] > b.value[1][15] \",\n \"a.value[1][16] > b.value[1][16] \",\n \"a.value[1][17] > b.value[1][17] \",\n \"a.value[1][18] > b.value[1][18] \",\n \"a.value[1][19] > b.value[1][19] \",\n \"a.value[1][20] > b.value[1][20] \",\n \"a.value[1][21] > b.value[1][21] \",\n \"a.value[1][22] > b.value[1][22] \",\n \"a.value[1][23] > b.value[1][23] \",\n \"a.value[1][24] > b.value[1][24] \",\n \"a.value[1][25] > b.value[1][25] \",\n \"a.value[1][26] > b.value[1][26] \",\n \"a.value[1][27] > b.value[1][27] \",\n \"a.value[1][28] > b.value[1][28] \",\n \"a.value[1][29] > b.value[1][29] \",\n \"a.value[1][30] > b.value[1][30] \",\n \"a.value[1][31] > b.value[1][31] \",\n \"a.value[1][32] > b.value[1][32] \",\n \"a.value[1][33] > b.value[1][33] \",\n \"a.value[1][34] > b.value[1][34] \",\n \"a.value[1][35] > b.value[1][35] \",\n \"a.value[1][36] > b.value[1][36] \",\n \"a.value[1][37] > b.value[1][37] \",\n \"a.value[1][38] > b.value[1][38] \",\n \"a.value[1][39] > b.value[1][39] \",\n \"a.value[1][40] > b.value[1][40] \");\n writeln(arr[0][0]);\n arr.multiSort!(\n \"a.value[1][0] > b.value[1][0] \",\n \"a.value[0] > b.value[0]\", \n \"a.value[1][1] > b.value[1][1] \",\n \"a.value[1][2] > b.value[1][2] \",\n \"a.value[1][3] > b.value[1][3] \",\n \"a.value[1][4] > b.value[1][4] \",\n \"a.value[1][5] > b.value[1][5] \",\n \"a.value[1][6] > b.value[1][6] \",\n \"a.value[1][7] > b.value[1][7] \",\n \"a.value[1][8] > b.value[1][8] \",\n \"a.value[1][9] > b.value[1][9] \",\n \"a.value[1][10] > b.value[1][10] \",\n \"a.value[1][11] > b.value[1][11] \",\n \"a.value[1][12] > b.value[1][12] \",\n \"a.value[1][13] > b.value[1][13] \",\n \"a.value[1][14] > b.value[1][14] \",\n \"a.value[1][15] > b.value[1][15] \",\n \"a.value[1][16] > b.value[1][16] \",\n \"a.value[1][17] > b.value[1][17] \",\n \"a.value[1][18] > b.value[1][18] \",\n \"a.value[1][19] > b.value[1][19] \",\n \"a.value[1][20] > b.value[1][20] \",\n \"a.value[1][21] > b.value[1][21] \",\n \"a.value[1][22] > b.value[1][22] \",\n \"a.value[1][23] > b.value[1][23] \",\n \"a.value[1][24] > b.value[1][24] \",\n \"a.value[1][25] > b.value[1][25] \",\n \"a.value[1][26] > b.value[1][26] \",\n \"a.value[1][27] > b.value[1][27] \",\n \"a.value[1][28] > b.value[1][28] \",\n \"a.value[1][29] > b.value[1][29] \",\n \"a.value[1][30] > b.value[1][30] \",\n \"a.value[1][31] > b.value[1][31] \",\n \"a.value[1][32] > b.value[1][32] \",\n \"a.value[1][33] > b.value[1][33] \",\n \"a.value[1][34] > b.value[1][34] \",\n \"a.value[1][35] > b.value[1][35] \",\n \"a.value[1][36] > b.value[1][36] \",\n \"a.value[1][37] > b.value[1][37] \",\n \"a.value[1][38] > b.value[1][38] \",\n \"a.value[1][39] > b.value[1][39] \",\n \"a.value[1][40] > b.value[1][40] \");\n writeln(arr[0][0]);\n}\n ", "positive_code": [{"source_code": "import std.string;\nimport std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.typecons;\nimport std.range;\nimport std.array;\n\nvoid main()\n{\n int[][string] positions;\n int [string] points;\n auto n = readln.chomp.to!int;\n foreach(i; 0..n )\n {\n auto m = readln.chomp.to!int;\n foreach(j; 0..m )\n {\n auto s = readln.chomp; \n if (! (s in positions)) \n positions[s] = repeat(0).take(50).array;\n positions[s] = positions[s].zip(repeat(0).take(j).array ~ [1] ~ repeat(0).take(50-j-1).array).map!\"a[0]+a[1]\".array;\n points[s] += ([25, 18, 15, 12, 10, 8, 6, 4, 2, 1] ~ repeat(0).take(40).array)[j];\n }\n }\n\n Tuple!(string, int,int[])[] arr;\n foreach(k,v; points) \n arr~=tuple(k,v,positions[k]);\n //writeln(arr);\n arr.multiSort!(\"a[1]>b[1]\", \n \"a[2][0] > b[2][0] \", \" a[2][1] > b[2][1] \", \" a[2][2] > b[2][2] \", \n \"a[2][3] > b[2][3] \", \" a[2][4] > b[2][4] \", \" a[2][5] > b[2][5] \", \n \"a[2][6] > b[2][6] \", \" a[2][7] > b[2][7] \", \" a[2][8] > b[2][8] \", \n \"a[2][9] > b[2][9] \", \" a[2][10] > b[2][10] \", \" a[2][11] > b[2][11] \", \n \"a[2][12] > b[2][12] \", \" a[2][13] > b[2][13] \", \" a[2][14] > b[2][14] \", \n \"a[2][15] > b[2][15] \", \" a[2][16] > b[2][16] \", \" a[2][17] > b[2][17] \", \n \"a[2][18] > b[2][18] \", \" a[2][19] > b[2][19] \", \" a[2][20] > b[2][20] \", \n \"a[2][21] > b[2][21] \", \" a[2][22] > b[2][22] \", \" a[2][23] > b[2][23] \", \n \"a[2][24] > b[2][24] \", \" a[2][25] > b[2][25] \", \" a[2][26] > b[2][26] \", \n \"a[2][27] > b[2][27] \", \" a[2][28] > b[2][28] \", \" a[2][29] > b[2][29] \", \n \"a[2][30] > b[2][30] \", \" a[2][31] > b[2][31] \", \" a[2][32] > b[2][32] \", \n \"a[2][33] > b[2][33] \", \" a[2][34] > b[2][34] \", \" a[2][35] > b[2][35] \", \n \"a[2][36] > b[2][36] \", \" a[2][37] > b[2][37] \", \" a[2][38] > b[2][38] \", \n \"a[2][39] > b[2][39] \", \" a[2][40] > b[2][40] \", \" a[2][41] > b[2][41] \", \n \"a[2][42] > b[2][42] \", \" a[2][43] > b[2][43] \", \" a[2][44] > b[2][44] \", \n \"a[2][45] > b[2][45] \", \" a[2][46] > b[2][46] \", \" a[2][47] > b[2][47] \", \n \"a[2][48] > b[2][48] \", \" a[2][49] > b[2][49] \");\n writeln(arr[0][0]);\n arr.multiSort!(\n \"a[2][0] > b[2][0] \", \"a[1]>b[1]\", \" a[2][1] > b[2][1] \", \" a[2][2] > b[2][2] \", \n \"a[2][3] > b[2][3] \", \" a[2][4] > b[2][4] \", \" a[2][5] > b[2][5] \", \n \"a[2][6] > b[2][6] \", \" a[2][7] > b[2][7] \", \" a[2][8] > b[2][8] \", \n \"a[2][9] > b[2][9] \", \" a[2][10] > b[2][10] \", \" a[2][11] > b[2][11] \", \n \"a[2][12] > b[2][12] \", \" a[2][13] > b[2][13] \", \" a[2][14] > b[2][14] \", \n \"a[2][15] > b[2][15] \", \" a[2][16] > b[2][16] \", \" a[2][17] > b[2][17] \", \n \"a[2][18] > b[2][18] \", \" a[2][19] > b[2][19] \", \" a[2][20] > b[2][20] \", \n \"a[2][21] > b[2][21] \", \" a[2][22] > b[2][22] \", \" a[2][23] > b[2][23] \", \n \"a[2][24] > b[2][24] \", \" a[2][25] > b[2][25] \", \" a[2][26] > b[2][26] \", \n \"a[2][27] > b[2][27] \", \" a[2][28] > b[2][28] \", \" a[2][29] > b[2][29] \", \n \"a[2][30] > b[2][30] \", \" a[2][31] > b[2][31] \", \" a[2][32] > b[2][32] \", \n \"a[2][33] > b[2][33] \", \" a[2][34] > b[2][34] \", \" a[2][35] > b[2][35] \", \n \"a[2][36] > b[2][36] \", \" a[2][37] > b[2][37] \", \" a[2][38] > b[2][38] \", \n \"a[2][39] > b[2][39] \", \" a[2][40] > b[2][40] \", \" a[2][41] > b[2][41] \", \n \"a[2][42] > b[2][42] \", \" a[2][43] > b[2][43] \", \" a[2][44] > b[2][44] \", \n \"a[2][45] > b[2][45] \", \" a[2][46] > b[2][46] \", \" a[2][47] > b[2][47] \", \n \"a[2][48] > b[2][48] \", \" a[2][49] > b[2][49] \");\n writeln(arr[0][0]);\n}\n "}], "negative_code": [{"source_code": "import std.string;\nimport std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.typecons;\nimport std.range;\nimport std.array;\n\nvoid main()\n{\n int[][string] positions;\n int [string] points;\n auto n = readln.chomp.to!int;\n foreach(i; 0..n )\n {\n auto m = readln.chomp.to!int;\n foreach(j; 0..m )\n {\n auto s = readln.chomp; \n if (! (s in positions)) \n positions[s] = repeat(0).take(50).array;\n positions[s] = positions[s].zip(repeat(0).take(j).array ~ [1] ~ repeat(0).take(50-j-1).array).map!\"a[0]+a[1]\".array;\n points[s] += ([25, 18, 15, 12, 10, 8, 6, 4, 2, 1] ~ repeat(0).take(40).array)[j];\n }\n }\n\n Tuple!(string, int,int[])[] arr;\n foreach(k,v; points) \n arr~=tuple(k,v,positions[k]);\n //writeln(arr);\n arr.multiSort!(\"a[1]>b[1]\", \n \"a[2][0] > b[2][0] \", \" a[2][1] > b[2][1] \", \" a[2][2] > b[2][2] \", \n \"a[2][3] > b[2][3] \", \" a[2][4] > b[2][4] \", \" a[2][5] > b[2][5] \", \n \"a[2][6] > b[2][6] \", \" a[2][7] > b[2][7] \", \" a[2][8] > b[2][8] \", \n \"a[2][9] > b[2][9] \", \" a[2][10] > b[2][10] \", \" a[2][11] > b[2][11] \", \n \"a[2][12] > b[2][12] \", \" a[2][13] > b[2][13] \", \" a[2][14] > b[2][14] \", \n \"a[2][15] > b[2][15] \", \" a[2][16] > b[2][16] \", \" a[2][17] > b[2][17] \", \n \"a[2][18] > b[2][18] \", \" a[2][19] > b[2][19] \", \" a[2][20] > b[2][20] \", \n \"a[2][21] > b[2][21] \", \" a[2][22] > b[2][22] \", \" a[2][23] > b[2][23] \", \n \"a[2][24] > b[2][24] \", \" a[2][25] > b[2][25] \", \" a[2][26] > b[2][26] \", \n \"a[2][27] > b[2][27] \", \" a[2][28] > b[2][28] \", \" a[2][29] > b[2][29] \", \n \"a[2][30] > b[2][30] \", \" a[2][31] > b[2][31] \", \" a[2][32] > b[2][32] \", \n \"a[2][33] > b[2][33] \", \" a[2][34] > b[2][34] \", \" a[2][35] > b[2][35] \", \n \"a[2][36] > b[2][36] \", \" a[2][37] > b[2][37] \", \" a[2][38] > b[2][38] \", \n \"a[2][39] > b[2][39] \", \" a[2][40] > b[2][40] \", \" a[2][41] > b[2][41] \", \n \"a[2][42] > b[2][42] \", \" a[2][43] > b[2][43] \", \" a[2][44] > b[2][44] \", \n \"a[2][45] > b[2][45] \", \" a[2][46] > b[2][46] \", \" a[2][47] > b[2][47] \", \n \"a[2][48] > b[2][48] \", \" a[2][49] > b[2][49] \");\n writeln(arr[0][0]);\n arr.multiSort!(\n \"a[2][0] > b[2][0] \", \" a[2][1] > b[2][1] \", \" a[2][2] > b[2][2] \", \n \"a[2][3] > b[2][3] \", \" a[2][4] > b[2][4] \", \" a[2][5] > b[2][5] \", \n \"a[2][6] > b[2][6] \", \" a[2][7] > b[2][7] \", \" a[2][8] > b[2][8] \", \n \"a[2][9] > b[2][9] \", \" a[2][10] > b[2][10] \", \" a[2][11] > b[2][11] \", \n \"a[2][12] > b[2][12] \", \" a[2][13] > b[2][13] \", \" a[2][14] > b[2][14] \", \n \"a[2][15] > b[2][15] \", \" a[2][16] > b[2][16] \", \" a[2][17] > b[2][17] \", \n \"a[2][18] > b[2][18] \", \" a[2][19] > b[2][19] \", \" a[2][20] > b[2][20] \", \n \"a[2][21] > b[2][21] \", \" a[2][22] > b[2][22] \", \" a[2][23] > b[2][23] \", \n \"a[2][24] > b[2][24] \", \" a[2][25] > b[2][25] \", \" a[2][26] > b[2][26] \", \n \"a[2][27] > b[2][27] \", \" a[2][28] > b[2][28] \", \" a[2][29] > b[2][29] \", \n \"a[2][30] > b[2][30] \", \" a[2][31] > b[2][31] \", \" a[2][32] > b[2][32] \", \n \"a[2][33] > b[2][33] \", \" a[2][34] > b[2][34] \", \" a[2][35] > b[2][35] \", \n \"a[2][36] > b[2][36] \", \" a[2][37] > b[2][37] \", \" a[2][38] > b[2][38] \", \n \"a[2][39] > b[2][39] \", \" a[2][40] > b[2][40] \", \" a[2][41] > b[2][41] \", \n \"a[2][42] > b[2][42] \", \" a[2][43] > b[2][43] \", \" a[2][44] > b[2][44] \", \n \"a[2][45] > b[2][45] \", \" a[2][46] > b[2][46] \", \" a[2][47] > b[2][47] \", \n \"a[2][48] > b[2][48] \", \" a[2][49] > b[2][49] \");\n writeln(arr[0][0]);\n}\n "}, {"source_code": "import std.string;\nimport std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.typecons;\n\n\n\nvoid main()\n{\n int[][string] positions;\n int [string] points;\n int maxPoints;\n int[50] maxWins;\n auto point_values = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1];\n int maxOriginalWin = 0;\n int maxProposedWin = 0;\n \n auto n = readln.chomp.to!int;\n foreach(i; 0..n )\n {\n auto m = readln.chomp.to!int;\n foreach(j; 0..m )\n {\n auto s = readln.chomp; \n if (! (s in positions)) positions[s].length = 50;\n positions[s][j]++;\n if (j < 10) points[s] += point_values[j];\n if (points[s] > maxPoints) {\n maxPoints = points[s];\n if (j == 0 && maxOriginalWin < positions[s][0]) maxOriginalWin = positions[s][0];\n }\n if (j == 0 && maxProposedWin < positions[s][0]) maxProposedWin = positions[s][0];\n }\n }\n\n Tuple!(string, int,int[])[] arr;\n foreach(k,v; points) {\n arr~=tuple(k,v,positions[k]);\n } \n arr.sort!(\"a[1]>b[1] &&\" ~ \n \"a[2][0] > b[2][0] && a[2][1] > b[2][1] && a[2][2] > b[2][2] && \" ~\n \"a[2][3] > b[2][3] && a[2][4] > b[2][4] && a[2][5] > b[2][5] && \" ~\n \"a[2][6] > b[2][6] && a[2][7] > b[2][7] && a[2][8] > b[2][8] && \"~\n \"a[2][9] > b[2][9] && a[2][10] > b[2][10] && a[2][11] > b[2][11] && \"~\n \"a[2][12] > b[2][12] && a[2][13] > b[2][13] && a[2][14] > b[2][14] && \"~\n \"a[2][15] > b[2][15] && a[2][16] > b[2][16] && a[2][17] > b[2][17] && \"~\n \"a[2][18] > b[2][18] && a[2][19] > b[2][19] && a[2][20] > b[2][20] && \"~\n \"a[2][21] > b[2][21] && a[2][22] > b[2][22] && a[2][23] > b[2][23] && \"~\n \"a[2][24] > b[2][24] && a[2][25] > b[2][25] && a[2][26] > b[2][26] && \"~\n \"a[2][27] > b[2][27] && a[2][28] > b[2][28] && a[2][29] > b[2][29] && \"~\n \"a[2][30] > b[2][30] && a[2][31] > b[2][31] && a[2][32] > b[2][32] && \"~\n \"a[2][33] > b[2][33] && a[2][34] > b[2][34] && a[2][35] > b[2][35] && \"~\n \"a[2][36] > b[2][36] && a[2][37] > b[2][37] && a[2][38] > b[2][38] && \"~\n \"a[2][39] > b[2][39] && a[2][40] > b[2][40] && a[2][41] > b[2][41] && \"~\n \"a[2][42] > b[2][42] && a[2][43] > b[2][43] && a[2][44] > b[2][44] && \"~\n \"a[2][45] > b[2][45] && a[2][46] > b[2][46] && a[2][47] > b[2][47] && \"~\n \"a[2][48] > b[2][48] && a[2][49] > b[2][49] \");\n writeln(arr[0][0]);\n arr.sort!(\n \"a[2][0] > b[2][0] && a[2][1] > b[2][1] && a[2][2] > b[2][2] && \" ~\n \"a[2][3] > b[2][3] && a[2][4] > b[2][4] && a[2][5] > b[2][5] && \" ~\n \"a[2][6] > b[2][6] && a[2][7] > b[2][7] && a[2][8] > b[2][8] && \"~\n \"a[2][9] > b[2][9] && a[2][10] > b[2][10] && a[2][11] > b[2][11] && \"~\n \"a[2][12] > b[2][12] && a[2][13] > b[2][13] && a[2][14] > b[2][14] && \"~\n \"a[2][15] > b[2][15] && a[2][16] > b[2][16] && a[2][17] > b[2][17] && \"~\n \"a[2][18] > b[2][18] && a[2][19] > b[2][19] && a[2][20] > b[2][20] && \"~\n \"a[2][21] > b[2][21] && a[2][22] > b[2][22] && a[2][23] > b[2][23] && \"~\n \"a[2][24] > b[2][24] && a[2][25] > b[2][25] && a[2][26] > b[2][26] && \"~\n \"a[2][27] > b[2][27] && a[2][28] > b[2][28] && a[2][29] > b[2][29] && \"~\n \"a[2][30] > b[2][30] && a[2][31] > b[2][31] && a[2][32] > b[2][32] && \"~\n \"a[2][33] > b[2][33] && a[2][34] > b[2][34] && a[2][35] > b[2][35] && \"~\n \"a[2][36] > b[2][36] && a[2][37] > b[2][37] && a[2][38] > b[2][38] && \"~\n \"a[2][39] > b[2][39] && a[2][40] > b[2][40] && a[2][41] > b[2][41] && \"~\n \"a[2][42] > b[2][42] && a[2][43] > b[2][43] && a[2][44] > b[2][44] && \"~\n \"a[2][45] > b[2][45] && a[2][46] > b[2][46] && a[2][47] > b[2][47] && \"~\n \"a[2][48] > b[2][48] && a[2][49] > b[2][49] \");\n writeln(arr[0][0]);\n}\n "}], "src_uid": "bd40f54a1e764ba226d5387fcd6b353f"} {"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 const Q = readInt();\n auto S = new int[Q];\n auto T = new int[Q];\n auto U = new int[Q];\n foreach (q; 0 .. Q) {\n S[q] = readInt() - 1;\n T[q] = readInt();\n U[q] = readInt() - 1;\n }\n \n auto us = new int[int][N];\n long now = A.sum;\n auto cs = new long[N];\n void add(int s, int t, int u) {\n if (cs[u] < A[u]) {\n --now;\n }\n ++cs[u];\n us[s][t] = u;\n }\n void remove(int s, int t) {\n const u = us[s][t];\n --cs[u];\n if (cs[u] < A[u]) {\n ++now;\n }\n us[s][t] = -1;\n }\n \n foreach (q; 0 .. Q) {\n if (T[q] in us[S[q]] && us[S[q]][T[q]] != -1) {\n remove(S[q], T[q]);\n }\n if (U[q] != -1) {\n add(S[q], T[q], U[q]);\n }\n writeln(now);\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 !(int)).array;\n\t\tauto q = readln.strip.to !(int);\n\t\talias Pair = Tuple !(int, q{num}, int, q{kind});\n\t\tint [Pair] b;\n\t\tlong total = sum (a, 0L);\n\t\tauto surplus = new int [n];\n\n\t\tvoid sub (const ref Pair cur)\n\t\t{\n\t\t\tif (cur !in b)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tauto kind = b[cur];\n\t\t\tb.remove (cur);\n\t\t\tsurplus[kind] -= 1;\n\t\t\tif (surplus[kind] < a[kind])\n\t\t\t{\n\t\t\t\ttotal += 1;\n\t\t\t}\n\t\t}\n\n\t\tvoid add (const ref Pair cur, int kind)\n\t\t{\n\t\t\tif (kind < 0)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (surplus[kind] < a[kind])\n\t\t\t{\n\t\t\t\ttotal -= 1;\n\t\t\t}\n\t\t\tb[cur] = kind;\n\t\t\tsurplus[kind] += 1;\n\t\t}\t\n\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tint s;\n\t\t\tint t;\n\t\t\tint u;\n\t\t\treadf !(\" %s %s %s\") (s, t, u);\n\t\t\tt -= 1;\n\t\t\tu -= 1;\n\t\t\tauto cur = Pair (s, t);\n\t\t\tsub (cur);\n\t\t\tadd (cur, u);\n\t\t\twriteln (total);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "789f80983015ca3d0342dfbffd48e6bf"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 n = RD!int;\n\tlong x1, y1, x2 = 1, y2;\n\tforeach (i; 0..n*n)\n\t{\n\t\tauto num = RD;\n\t\tif (num != 1)\n\t\t{\n\t\t\tif (x1 < n && y1 < n)\n\t\t\t{\n\t\t\t\twriteln(1, \" \", x1+1, \" \", y1+1);\n\t\t\t\tstdout.flush;\n\t\t\t\tif (x1+2 < n)\n\t\t\t\t\tx1 += 2;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t++y1;\n\t\t\t\t\tx1 = 1 - x1 % 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tauto z = num == 2 ? 3 : 2;\n\t\t\t\twriteln(z, \" \", x2+1, \" \", y2+1);\n\t\t\t\tstdout.flush;\n\t\t\t\tif (x2+2 < n)\n\t\t\t\t\tx2 += 2;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t++y2;\n\t\t\t\t\tx2 = 1 - x2 % 2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (x2 < n && y2 < n)\n\t\t\t{\n\t\t\t\twriteln(2, \" \", x2+1, \" \", y2+1);\n\t\t\t\tstdout.flush;\n\t\t\t\tif (x2+2 < n)\n\t\t\t\t\tx2 += 2;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t++y2;\n\t\t\t\t\tx2 = 1 - x2 % 2;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twriteln(3, \" \", x1+1, \" \", y1+1);\n\t\t\t\tstdout.flush;\n\t\t\t\tif (x1+2 < n)\n\t\t\t\t\tx1 += 2;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t++y1;\n\t\t\t\t\tx1 = 1 - x1 % 2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tdebug readln;\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!(int, \"x\", int, \"y\");\n\nvoid main() {\n const N = readInt();\n \n Pt[] ps, qs;\n foreach (x; 1 .. N + 1) foreach (y; 1 .. N + 1) {\n if ((x + y) % 2 == 0) {\n ps ~= Pt(x, y);\n } else {\n qs ~= Pt(x, y);\n }\n }\n const psLen = cast(int)(ps.length);\n const qsLen = cast(int)(qs.length);\n int posP, posQ;\n \n foreach (_; 0 .. N^^2) {\n const A = readInt();\n int b;\n Pt p;\n if (A != 1 && posP < psLen) {\n b = 1;\n p = ps[posP++];\n } else if (A != 2 && posQ < qsLen) {\n b = 2;\n p = qs[posQ++];\n } else if (A != 3 && posP < psLen) {\n b = 3;\n p = ps[posP++];\n } else if (A != 3 && posQ < qsLen) {\n b = 3;\n p = qs[posQ++];\n } else {\n assert(false);\n }\n writefln(\"%s %s %s\", b, p.x, p.y);\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\n\r\nint main(string[] args)\r\n{\r\n auto n = to!int(readln.strip);\r\n Tuple!(int, int)[] f, s;\r\n foreach (i; 1 .. n + 1) foreach (j; 1 .. n + 1)\r\n {\r\n if ((i + j) & 1) s ~= tuple(i, j);\r\n else f ~= tuple(i, j);\r\n }\r\n int c0, c1, fidx, sidx;\r\n foreach (i; 0 .. n * n)\r\n {\r\n auto r = to!int(readln.strip);\r\n int c, x, y;\r\n if (fidx == f.length)\r\n {\r\n foreach (j; 1 .. 4) if (j != c0 && j != r)\r\n {\r\n c = j;\r\n break;\r\n }\r\n x = s[sidx][0], y = s[sidx][1];\r\n ++ sidx;\r\n }\r\n else if (sidx == s.length)\r\n {\r\n foreach (j; 1 .. 4) if (j != c1 && j != r)\r\n {\r\n c = j;\r\n break;\r\n }\r\n x = f[fidx][0], y = f[fidx][1];\r\n ++ fidx;\r\n }\r\n else\r\n {\r\n if (r != c0)\r\n {\r\n if (c0 == 0) c0 = (r == 1 ? 2 : 1);\r\n c = c0;\r\n x = f[fidx][0], y = f[fidx][1];\r\n ++ fidx;\r\n }\r\n else\r\n {\r\n if (c1 == 0)\r\n {\r\n foreach (j; 1 .. 4) if (j != c0 && j != r)\r\n {\r\n c1 = j;\r\n break;\r\n }\r\n }\r\n c = c1;\r\n x = s[sidx][0], y = s[sidx][1];\r\n ++ sidx;\r\n }\r\n }\r\n writeln(c, \" \", x, \" \", y);\r\n stdout.flush;\r\n }\r\n return 0;\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\nalias Pt = Tuple!(int, \"x\", int, \"y\");\r\n\r\nvoid main() {\r\n const N = readInt();\r\n \r\n Pt[] ps, qs;\r\n foreach (x; 1 .. N + 1) foreach (y; 1 .. N + 1) {\r\n if ((x + y) % 2 == 0) {\r\n ps ~= Pt(x, y);\r\n } else {\r\n qs ~= Pt(x, y);\r\n }\r\n }\r\n const psLen = cast(int)(ps.length);\r\n const qsLen = cast(int)(ps.length);\r\n int posP, posQ;\r\n \r\n foreach (_; 0 .. N^^2) {\r\n const A = readInt();\r\n int b;\r\n Pt p;\r\n if (A != 1 && posP < psLen) {\r\n b = 1;\r\n p = ps[posP++];\r\n } else if (A != 2 && posQ < qsLen) {\r\n b = 2;\r\n p = qs[posQ++];\r\n } else if (A != 3 && posP < psLen) {\r\n b = 3;\r\n p = ps[posP++];\r\n } else if (A != 3 && posQ < qsLen) {\r\n b = 3;\r\n p = qs[posQ++];\r\n } else {\r\n assert(false);\r\n }\r\n writefln(\"%s %s %s\", b, p.x, p.y);\r\n stdout.flush;\r\n }\r\n}\r\n"}], "src_uid": "7c721cdb8e5709bba242957344851d48"} {"source_code": "module sigod.codeforces.p298C;\n\nimport std.algorithm;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n\tstring a = stdin.readln().strip();\n\tstring b = stdin.readln().strip();\n\n\tsize_t a_count = a.count('1');\n\tif (a_count % 2 == 1) ++a_count;\n\n\tsize_t b_count = b.count('1');\n\n\tstdout.writeln(a_count >= b_count ? \"YES\" : \"NO\");\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\n\nint main() {\n\tstring s1, s2;\n\ts1 = chomp(readln());\n\ts2 = chomp(readln());\n\tif ((count(s1, '1')+1)/2*2 >= count(s2, '1')) {\n\t\twriteln(\"YES\");\n\t} else {\n\t\twriteln(\"NO\");\n\t}\n return 0;\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\tstring s, t;\n\twhile ((s = readln ()) != null)\n\t{\n\t\tt = readln ();\n\t\tauto x = s.count ('1');\n\t\tx += x & 1;\n\t\tauto y = t.count ('1');\n\t\twritefln (\"%s\", x >= y ? \"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\nstring A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = readToken;\n\t\tB = readToken;\n\t\t\n\t\tint a = A.count('1');\n\t\tint b = B.count('1');\n\t\tif (a % 2 != 0) {\n\t\t\t++a;\n\t\t}\n\t\twriteln((a >= b) ? \"YES\" : \"NO\");\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "cf86add6c92fa8a72b8e23efbdb38613"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.container;\n\nimmutable int mod = cast(int)1e9 + 7;\nalias pair = Tuple!(int, \"x\", int, \"y\");\n\nint N, K;\npair[] A;\n\nint mul(int x, int y) {\n\tint ans = 1;\n\tfor (int i = 0; (1 << i) <= y; ++i) {\n\t\tif (y & (1 << i)) ans = cast(int)(cast(long)1 * ans * x % mod);\n\t\tx = cast(int)(cast(long)x * x % mod);\n\t}\n\treturn ans;\n}\n\nvoid main() {\n\treadf(\"%d %d\\n\", &N, &K);\n\tA ~= pair(cast(int)1e9 + 5, 0);\n\tforeach(i; 0..N) {\n\t\tint x, y; readf(\"%d %d\\n\", &x, &y);\n\t\tA ~= [pair(x, 1), pair(y + 1, -1)];\n\t}\n\tsort!`a.x < b.x`(A);\n\tint cnt = 0, ways = 0;\n\tint ans = 0;\n\tfor (int i = 0; i + 1 < A.length; ++i) {\n\t\tint st = i;\n\t\twhile (i + 1 < A.length && A[i].x == A[st].x) {\n\t\t\tif (A[i].y == 1) {\n\t\t\t\t++cnt;\n\t\t\t\tif (cnt == K) ways = 1;\n\t\t\t\telse ways = cast(int)(cast(long)cnt * ways % mod * mul(cnt - K, mod - 2) % mod);\n\t\t\t} else if (A[i].y == -1) {\n\t\t\t\t--cnt;\n\t\t\t\tif (cnt < K) ways = 0;\n\t\t\t\telse ways = cast(int)(cast(long)ways * mul(cnt + 1, mod - 2) % mod * (cnt - K + 1) % mod);\n\t\t\t}\n\t\t\t++i;\n\t\t} --i;\n\t\t//writeln(A[st].x, ' ', cnt, ' ', ways * (A[i + 1].x - A[i].x));\n\t\tans = (ans + cast(long)ways * (A[i + 1].x - A[i].x) % mod) % mod;\n\t}\n\twriteln(ans);\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\n\nint main() {\n immutable MN = 200200;\n Mint[] fact = new Mint[](MN), iFac = new Mint[](MN);\n fact[0] = Mint(1);\n foreach (i; 1..MN) {\n fact[i] = fact[i-1] * Mint(i);\n }\n foreach (i; 0..MN) {\n iFac[i] = Mint.inv(fact[i]);\n }\n Mint C(int n, int k) {\n return fact[n]*iFac[k]*iFac[n-k];\n }\n int n, k;\n readf(\"%d %d\\n\", &n, &k);\n alias P = int[2];\n int[2][] ev;\n foreach (i; 0..n) {\n int l, r;\n readf(\"%d %d\\n\", &l, &r);\n ev ~= [l, 0];\n ev ~= [r+1, 1];\n }\n ev.sort;\n int co = 0;\n Mint ans = 0;\n foreach (i, e; ev) {\n if (e[1] == 0) co++;\n else co--;\n\n if (i < ev.length-1 && ev[i+1][0] != ev[i][0]) {\n Mint di = Mint(ev[i+1][0]-ev[i][0]);\n if (k <= co) {\n ans += di * C(co, k);\n }\n }\n }\n writeln(ans);\n\treturn 0;\n}\n\nT pow(T)(T x, ulong n) {\n T r = 1;\n while (n) {\n if (n & 1) r *= x;\n x *= x;\n n >>= 1;\n }\n return r;\n}\n\n\nstruct ModInt(uint MD) {\n import std.conv : to;\n uint v;\n this(long v) {this.v = (v%MD+MD)%MD;}\n auto normS(uint x) {return (x 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[] as;\n\tforeach(i; 0 .. n) as ~= read.to!int;\n\t\n\tint f = 0;\n\tint last = -10;\n\tforeach(a; as){\n\t\tif(last < a){\n\t\t\tif(f == 1){\n\t\t\t\t\"NO\".writeln;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif(last > a){\n\t\t\tif(f == 0) f = 1;\n\t\t}\n\t\tlast = a;\n\t}\n\t\n\t\"YES\".writeln;\n\treturn;\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.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 a = RDA;\n\tlong pos = MIN_POS!\"a > b\"(a);\n\tint l = cast(int)pos-1, r = cast(int)pos+1;\n\tlong top = n;\n\tbool ans = true;\n\twhile (top != 1)\n\t{\n\t\tif (l >= 0)\n\t\t{\n\t\t\tif (a[l] == top-1)\n\t\t\t{\n\t\t\t\t--l;\n\t\t\t\t--top;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (r < n)\n\t\t{\n\t\t\tif (a[r] == top-1)\n\t\t\t{\n\t\t\t\t++r;\n\t\t\t\t--top;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tans = false;\n\t\tbreak;\n\t}\n\n\twriteln(ans ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.algorithm.searching : maxIndex;\nimport std.algorithm.sorting : isSorted;\nimport std.stdio;\n\nvoid main()\n{\n char c;\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\n auto i = maxIndex(a);\n if (isSorted(a[0..i]) && isSorted!\"a > b\"(a[i+1..$])) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\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\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 a = RDA;\n\tlong pos = MIN_POS!\"a > b\"(a);\n\tint l = cast(int)pos-1, r = cast(int)pos+1;\n\tlong top = n;\n\tbool ans = true;\n\twhile (top != 1)\n\t{\n\t\tif (l >= 0)\n\t\t{\n\t\t\tif (a[l] == top-1)\n\t\t\t{\n\t\t\t\t--l;\n\t\t\t\t--top;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (r < n)\n\t\t{\n\t\t\tif (a[r] == top-1)\n\t\t\t{\n\t\t\t\t--r;\n\t\t\t\t--top;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tans = false;\n\t\tbreak;\n\t}\n\n\twriteln(ans ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "12abfbe7118868a0b1237489b5c92760"} {"source_code": "import std.stdio, std.conv, std.range, std.algorithm, std.string;\nimport std.math;\n\nvoid main() {\n int n = readln.chomp.to!int;\n ulong[] s = readln.chomp.split.map!(to!ulong).array;\n\n ulong ans = s.sum;\n if (ans & 1) {\n ans -= s.filter!\"a & 1\".array.minPos[0];\n }\n\n ans.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string; \nimport std.array: Appender;\n\nvoid main()\n{\n\tauto n = split(strip(readln))[0];\n\tauto s = split(strip(readln));\n\tlong[] a = new long[to!int(n,10)];\n\tlong sum;\n\tlong min = long.max;\n\tforeach(i, el; s)\n\t{\n\t\ta[i] = to!long(el,10);\n\t\tsum += a[i];\n\t\tif (a[i] % 2 != 0 && min > a[i])\n\t\t{\n\t\t\tmin = a[i];\n\t\t}\n\t}\n\tif (sum % 2 != 0)\n\t\tsum -= min;\n\twriteln(sum);\n}\n\n"}, {"source_code": "import std.stdio,std.array,std.algorithm;\nvoid main()\n{\n\tstdin.readln;\n\tauto v=stdin.readln.split.map!\"to!ulong(a)\";\n\tauto s=v.sum;\n\twriteln(s%2?s-v.filter!\"a%2\".reduce!\"a\";\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", "positive_code": [{"source_code": "import std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tint n = s.length;\n\t\tauto t = '*'.repeat (n).array;\n\t\tt.reserve (n * 2);\n\t\tint res = 0;\n\t\tforeach (char c; s)\n\t\t{\n\t\t\tif (c == '<')\n\t\t\t{\n\t\t\t\tt ~= '>';\n\t\t\t}\n\t\t\telse if (c == '{')\n\t\t\t{\n\t\t\t\tt ~= '}';\n\t\t\t}\n\t\t\telse if (c == '[')\n\t\t\t{\n\t\t\t\tt ~= ']';\n\t\t\t}\n\t\t\telse if (c == '(')\n\t\t\t{\n\t\t\t\tt ~= ')';\n\t\t\t}\n\t\t\telse if (t.back == '*')\n\t\t\t{\n\t\t\t\tres = NA;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres += (c != t.back);\n\t\t\t\tt.popBack ();\n\t\t\t\tt.assumeSafeAppend ();\n\t\t\t}\n\t\t}\n\t\tif (t.length != n || res == NA)\n\t\t{\n\t\t\twriteln (\"Impossible\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (res);\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int NA = -1;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tint n = s.length;\n\t\tauto t = '*'.repeat (n).array;\n\t\tt.reserve (n * 2);\n\t\tint res = 0;\n\t\tforeach (char c; s)\n\t\t{\n\t\t\tif (c == '<')\n\t\t\t{\n\t\t\t\tt ~= '>';\n\t\t\t}\n\t\t\telse if (c == '{')\n\t\t\t{\n\t\t\t\tt ~= '}';\n\t\t\t}\n\t\t\telse if (c == '[')\n\t\t\t{\n\t\t\t\tt ~= ']';\n\t\t\t}\n\t\t\telse if (c == '(')\n\t\t\t{\n\t\t\t\tt ~= ')';\n\t\t\t}\n\t\t\telse if (t.back == '*')\n\t\t\t{\n\t\t\t\tres = NA;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres += (c != t.back);\n\t\t\t\tt.popBack ();\n\t\t\t\tt.assumeSafeAppend ();\n\t\t\t}\n\t\t}\n\t\twriteln (equal (t, '*'.repeat (n)) ? res : NA);\n\t}\n}\n"}], "src_uid": "4147fef7a151c52e92c010915b12c06b"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.stdio;\n\nvoid main ()\n{\n int n, k;\n while (readf (\" %s %s\", &n, &k) > 0)\n {\n if (k == 1)\n {\n k = 0;\n }\n\n auto c = redBlackTree !(long);\n foreach (i; 0..n)\n {\n int a;\n readf (\" %s\", &a);\n c.insert (a);\n }\n\n int res;\n foreach (e; c)\n {\n c.removeKey (e * k);\n res++;\n }\n writefln (\"%s\", res);\n }\n}\n", "positive_code": [{"source_code": "import std.container;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tif (k == 1)\n\t\t{\n\t\t\tk = 0;\n\t\t}\n\n\t\tauto c = redBlackTree !(long);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint a;\n\t\t\treadf (\" %s\", &a);\n\t\t\tc.insert (a);\n\t\t}\n\n\t\tint res;\n\t\tforeach (e; c)\n\t\t{\n\t\t\tc.removeKey (e * k);\n\t\t\tres++;\n\t\t}\n\t\twritefln (\"%s\", res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n int n, k;\n while (readf (\" %s %s\", &n, &k) > 0)\n {\n if (k == 1)\n {\n k = 0;\n }\n auto a = new long [n];\n foreach (i; 0..n)\n {\n readf (\" %s\", &a[i]);\n }\n sort (a);\n int j;\n int res = n;\n foreach (i; 0..n)\n {\n while (j < n && a[i] * k > a[j])\n {\n j++;\n }\n if (j < n && a[i] * k == a[j])\n {\n a[j] = -1;\n res--;\n j++;\n }\n }\n writefln (\"%s\", res);\n }\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n int n, k;\n while (readf (\" %s %s\", &n, &k) > 0)\n {\n auto a = new long [n];\n foreach (i; 0..n)\n {\n readf (\" %s\", &a[i]);\n }\n sort (a);\n int j;\n int res = n;\n foreach (i; 0..n)\n {\n while (j < n && a[i] * k > a[j])\n {\n j++;\n }\n if (j < n && a[i] * k == a[j])\n {\n a[i] = -1;\n res--;\n j++;\n }\n }\n writefln (\"%s\", res);\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n int n, k;\n while (readf (\" %s %s\", &n, &k) > 0)\n {\n auto a = new long [n];\n foreach (i; 0..n)\n {\n readf (\" %s\", &a[i]);\n }\n sort (a);\n int j;\n int res = n;\n foreach (i; 0..n)\n {\n while (j < n && a[i] * k > a[j])\n {\n j++;\n }\n if (j < n && a[i] * k == a[j])\n {\n a[j] = -1;\n res--;\n j++;\n }\n }\n writefln (\"%s\", res);\n }\n}\n"}], "src_uid": "4ea1de740aa131cae632c612e1d582ed"} {"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 numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readInt();\n const M = readInt();\n const A = readInt() - 1;\n const B = readInt() - 1;\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 long ans = 1L * (N - 2) * (N - 3) / 2;\n \n int[] doIt(int s) {\n auto uf = new int[N];\n uf[] = -1;\n foreach (i; 0 .. M) {\n if (U[i] != s && V[i] != s) {\n uf.connect(U[i], V[i]);\n }\n }\n foreach (u; 0 .. N) {\n if (uf[u] < 0) {\n long sz = -uf[u];\n if (u == uf.root(A)) --sz;\n if (u == uf.root(B)) --sz;\n ans -= sz * (sz - 1) / 2;\n }\n }\n return uf;\n }\n \n auto ufA = doIt(A);\n auto ufB = doIt(B);\n Tuple!(int, int)[] ts;\n foreach (u; 0 .. N) {\n if (u != A && u != B) {\n ts ~= tuple(ufA.root(u), ufB.root(u));\n }\n }\n ts.sort;\n foreach (grp; ts.group) {\n long sz = grp[1];\n ans += sz * (sz - 1) / 2;\n }\n writeln(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.typecons;\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n while (t--) {\n int n, m, a, b;\n readf(\"%s %s %s %s\", &n, &m, &a, &b);\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 mark = new bool[][] (2, n+1);\n foreach (i; 0 .. 2) { mark[i][] = false; }\n \n void dfs(int v, int p, int bad) {\n mark[p][v] = true;\n if (v == bad) { return; }\n \n foreach (u; g[v]) {\n if (mark[p][u]) { continue; }\n \n dfs(u, p, bad);\n }\n }\n \n dfs(a, 0, b);\n dfs(b, 1, a);\n \n debug { mark.each!writeln; }\n \n auto ans = mark[0].dropOne.count!(p => !p).to!long\n * mark[1].dropOne.count!(p => !p);\n \n ans.writeln;\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 debug scope(exit) inputFile.close;\n auto nt = next!int;\n foreach(tc; 0 .. nt)\n {\n auto n = next!int;\n auto m = next!int;\n auto a = next!int - 1;\n auto b = next!int - 1;\n auto nei = new int[][](n);\n foreach(e; 0 .. m)\n {\n auto u = next!int - 1;\n auto v = next!int - 1;\n nei[u] ~= v;\n nei[v] ~= u;\n }\n auto visited = new bool[](n);\n visited[] = false;\n auto size = new int[](n);\n size[] = 0;\n int searched = -1;\n int searchedAncestor = -1;\n void dfs(int nd, int bigAncestor, bool isRoot)\n {\n visited[nd] = true;\n size[nd] = 1;\n if (nd == searched)\n {\n searchedAncestor = bigAncestor;\n }\n if (isRoot)\n {\n foreach(ne; nei[nd])\n if (!visited[ne])\n {\n dfs(ne, ne, false);\n size[nd] += size[ne];\n }\n }\n else\n {\n foreach(ne; nei[nd])\n if (!visited[ne])\n {\n dfs(ne, bigAncestor, false);\n size[nd] += size[ne];\n }\n }\n }\n\n searched = b;\n dfs(a, -1, true);\n auto winga = size[a] - size[searchedAncestor] - 1;\n visited[] = false;\n size[] = 0;\n searched = a;\n dfs(b, -1, true);\n auto wingb = size[b] - size[searchedAncestor] - 1;\n writeln(cast(long) winga * cast(long) wingb);\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\nvoid main(string[] args)\n{\n inputFile = stdin;\n debug inputFile = File(args[1]);\n debug scope(exit) inputFile.close;\n bool[200_000] visitedPool;\n int[200_000] sizePool;\n auto nt = next!int;\n foreach(tc; 0 .. nt)\n {\n auto n = next!int;\n auto m = next!int;\n auto a = next!int - 1;\n auto b = next!int - 1;\n auto nei = new int[][](n);\n foreach(e; 0 .. m)\n {\n auto u = next!int - 1;\n auto v = next!int - 1;\n nei[u] ~= v;\n nei[v] ~= u;\n }\n auto visited = visitedPool[0 .. n];\n visited[] = false;\n auto size = sizePool[0 .. n];\n size[] = 0;\n int searched = -1;\n int searchedAncestor = -1;\n void dfs(int nd, int bigAncestor, bool isRoot)\n {\n visited[nd] = true;\n size[nd] = 1;\n if (nd == searched)\n {\n searchedAncestor = bigAncestor;\n }\n if (isRoot)\n {\n foreach(ne; nei[nd])\n if (!visited[ne])\n {\n dfs(ne, ne, false);\n size[nd] += size[ne];\n }\n }\n else\n {\n foreach(ne; nei[nd])\n if (!visited[ne])\n {\n dfs(ne, bigAncestor, false);\n size[nd] += size[ne];\n }\n }\n }\n\n searched = b;\n dfs(a, -1, true);\n auto winga = size[a] - size[searchedAncestor] - 1;\n visited[] = false;\n size[] = 0;\n searched = a;\n dfs(b, -1, true);\n auto wingb = size[b] - size[searchedAncestor] - 1;\n writeln(cast(long) winga * cast(long) wingb);\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": "7636c493ad91210ec7571895b4b71214"} {"source_code": "import std;\n\nT\nread (alias T, string end = \"\", string start = \"\") () @trusted {\n T x;\n readf!(\"%s\" ~ end)(x);\n return x;\n}\n\nclass BudgetStack (T, size_t N) {\npublic:\n const @property size_t length () { return _k; }\n alias opDollar = length;\n\n inout ref inout(T) opIndex (size_t i) { return _data[i]; }\n\n auto opSlice (size_t a, size_t b) { return _data[a .. b]; }\n auto opSlice () { return _data[0 .. _k]; }\n\n BudgetStack opOpAssign (string op: \"~\") (T val) {\n _data[_k ++] = val;\n return this;\n }\n alias pushBack = opOpAssign!(\"~\");\n\n void removeBack () { -- _k; }\n\n const @property empty () { return _k == 0; }\nprivate:\n T[N] _data;\n size_t _k;\n}\n\nvoid main () {\n immutable tests = read!(uint, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n readln;\n\n immutable v = readln\n .chomp\n .splitter(' ')\n .map!(to!uint)\n .array;\n\n class MexSuffixes {\n public:\n this () {\n uint[] result = new uint[v.length];\n\n bool[uint] seenSoFar;\n uint mex = 0;\n foreach (i, val; v.retro.enumerate) {\n seenSoFar[val] = true;\n\n while (mex in seenSoFar)\n ++ mex;\n\n result[$ - 1 - i] = mex;\n }\n\n _data = result;\n }\n\n alias _data this;\n private:\n uint[] _data;\n }\n\n\n const mexSuffixes = new MexSuffixes();\n\n size_t[] result;\n for (size_t p = 0; p < v.length ;) {\n immutable stop = mexSuffixes[p];\n\n //stderr.writeln(\"Am at position:\", p);\n\n bool[uint] seenSoFar;\n uint mex = 0;\n for (size_t i = p; i < v.length; ++ i) {\n seenSoFar[v[i]] = true;\n\n while (mex in seenSoFar)\n ++ mex;\n\n if (mex == stop) {\n p = i + 1;\n result ~= stop;\n break;\n }\n }\n }\n\n writefln!\"%s\\n%(%s %)\"(result.length, result);\n }\n}\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 enum int MAX = 2 * 10^^5 + 1;\r\n\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!int(N);\r\n auto indeciesRaw = new int[][](N + 1, 0);\r\n foreach(i, a; A) {\r\n indeciesRaw[a] ~= cast(int)i;\r\n }\r\n auto indecies = indeciesRaw.map!assumeSorted.array;\r\n \r\n int[] ans;\r\n int l = 0;\r\n while(l < N) {\r\n // [l].deb;\r\n int mex;\r\n int offset;\r\n foreach(n; 0..MAX) {\r\n if (indecies[n].empty) break;\r\n\r\n auto u = indecies[n].upperBound(l - 1);\r\n if (u.empty) break;\r\n\r\n mex = n + 1;\r\n offset = max(offset, u.front);\r\n // [n, offset].deb;\r\n }\r\n\r\n l = max(offset, l) + 1;\r\n ans ~= mex;\r\n // [mex, l].deb;\r\n }\r\n\r\n ans.length.writeln;\r\n ans.toAnswerString.writeln;\r\n }\r\n\r\n foreach(i; 0..QN) {\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>>\".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\nbool[] enumeratePrimes(int max)\r\n{\r\n auto primes = new bool[](max + 1);\r\n primes[] = true;\r\n primes[0] = false;\r\n primes[1] = false;\r\n foreach (i; 2..max+1) {\r\n if (primes[i]) {\r\n auto x = i*2;\r\n while (x <= max) {\r\n primes[x] = false;\r\n x += i;\r\n }\r\n }\r\n }\r\n\r\n return primes;\r\n}\r\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto arr = scanArray!int;\n auto imap = new int[][](n+2);\n\n for(int i = n-1; i >= 0; --i){\n imap[arr[i]] ~= i;\n }\n show(imap);\n int[] res;\n\n int lastix = 0;\n while(lastix < n && imap[0].length){\n int nextix = 0;\n for(int k = 0; k <= n+1; ++k){\n if(!imap[k].length){\n res ~= k;\n break;\n }\n nextix = max(imap[k].back, nextix);\n }\n assert(nextix >= lastix);\n for(int i = lastix; i <= nextix; ++i){\n imap[arr[i]].popBack;\n }\n lastix = nextix + 1;\n }\n for(int i = lastix; i < n; ++i){\n res ~= 0;\n }\n writeln(res.length);\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, 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\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 pos = new int [n + 1];\r\n\t\tforeach (int i, ref c; a)\r\n\t\t{\r\n\t\t\tpos[c] += 1;\r\n\t\t}\r\n\r\n\t\tvoid rem ()\r\n\t\t{\r\n\t\t\tpos[a.front] -= 1;\r\n\t\t\ta.popFront ();\r\n\t\t}\r\n\r\n\t\tint [] answer;\r\n\t\twhile (!a.empty)\r\n\t\t{\r\n\t\t\tint cur = 0;\r\n\t\t\twhile (pos[cur] > 0)\r\n\t\t\t{\r\n\t\t\t\tcur += 1;\r\n\t\t\t}\r\n\t\t\tanswer ~= cur;\r\n\r\n\t\t\tif (cur == 0)\r\n\t\t\t{\r\n\t\t\t\trem ();\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tauto vis = new bool [cur];\r\n\t\t\t\tvis[] = true;\r\n\t\t\t\tint total = cur;\r\n\t\t\t\twhile (total > 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto x = a.front;\r\n\t\t\t\t\tif (x < cur)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\ttotal -= vis[a.front];\r\n\t\t\t\t\t\tvis[a.front] = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t\trem ();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twriteln (answer.length);\r\n\t\twritefln !(\"%(%s %)\") (answer);\r\n\t}\r\n}\r\n"}], "negative_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\nclass BudgetStack (T, size_t maxSize) {\npublic:\n ref inout(T) opIndex (size_t i) inout { return _data[i]; }\n\n const @property length () { return _k; }\n alias opDollar = length;\n\n BudgetStack push (T a) { _data[_k ++] = a; return this; }\n alias opOpAssign (string s: \"~\") = push;\n\n void pop () { -- _k; }\n\n T front () { return _data[0]; }\n T back () { return _data[_k - 1]; }\n\n bool empty () const { return _k == 0; }\n\n T[] opSlice () { return _data[0 .. _k]; }\n T[] opSlice (size_t i, size_t j) { return _data[i .. j]; }\nprivate:\n T[maxSize] _data;\n size_t _k;\n}\n\nvoid main () {\n immutable tests = read!(uint, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n readln();\n\n immutable vec = readln().chomp\n .splitter(' ')\n .map!(to!uint)\n .array;\n\n\n alias GroupT = Tuple!(uint[uint], \"freq\", uint, \"mex\");\n\n GroupT[] groups;\n { // Building the array as groups of MEX given sequences\n immutable combine = (ref uint[uint] frec_l, in uint[uint] frec_r) {\n foreach (k, v; frec_r)\n frec_l[k] += v;\n };\n\n uint[uint][] range = (){\n static assert(true);\n auto result = new BudgetStack!(uint[uint], 200_000);\n\n foreach (val; vec) {\n while (result.length >= 2 && val !in result[$ - 1] && val !in result[$ - 2]) {\n combine(result[$ - 2], result[$ - 1]);\n result.pop();\n }\n\n if (result.empty())\n result.push([val: 1]);\n else {\n if (val in result.back())\n result.push([val: 1]);\n else\n result.back()[val] += 1;\n }\n\n }\n\n return result[];\n }();\n\n groups = range\n .map!(freq => GroupT(freq, MEX(freq)))\n .array;\n }\n\n uint ctz;\n { // Count how many values we can cut from the end of the vector\n auto input = vec.retro;\n\n bool removingWouldBreakMex (in GroupT g, in uint val) {\n return g.mex > val && g.freq[val] == 1;\n }\n\n void removeFromFreq (ref GroupT g, in uint val) {\n if (g.freq[val] == 1)\n g.freq.remove(val);\n else\n g.freq[val] -= 1;\n }\n\n ref GroupT firstWhichContains (GroupT[] g, in uint val) {\n return g.retro.find!(t => val in t.freq).front;\n }\n\n uint count (in GroupT g) {\n return g.freq.byValue.sum;\n }\n\n foreach (val; input) {\n auto g = firstWhichContains(groups, val);\n if (removingWouldBreakMex(g, val))\n break;\n ++ ctz;\n removeFromFreq(g, val);\n }\n\n while (!groups.empty && groups.back.mex == 0) {\n ctz += count(groups.back);\n groups.popBack();\n }\n }\n\n immutable length = groups.length + ctz;\n writeln(length);\n\n chain(\n groups.map!\"a.mex\",\n 0u.repeat(ctz)\n ).writefln!\"%(%s %)\";\n }\n}\n\n\nuint MEX (in uint[uint] freq) {\n return iota(uint.min, uint.max)\n .find!(val => val !in freq)\n .front;\n}\n// \"\"\n"}, {"source_code": "import std;\n\nT\nread (alias T, string end = \"\", string start = \"\") () @trusted {\n T x;\n readf!(\"%s\" ~ end)(x);\n return x;\n}\n\nclass BudgetStack (T, size_t N) {\npublic:\n const @property size_t length () { return _k; }\n alias opDollar = length;\n\n inout ref inout(T) opIndex (size_t i) { return _data[i]; }\n\n auto opSlice (size_t a, size_t b) { return _data[a .. b]; }\n auto opSlice () { return _data[0 .. _k]; }\n\n BudgetStack opOpAssign (string op: \"~\") (T val) {\n _data[_k ++] = val;\n return this;\n }\n alias insertBack = opOpAssign!(\"~\");\n\n void removeBack () { -- _k; }\n\n const @property empty () { return _k == 0; }\nprivate:\n T[N] _data;\n size_t _k;\n}\n\nvoid main () {\n immutable tests = read!(uint, \"\\n\");\n TEST_LOOP: foreach (test_index; 0 .. tests) {\n readln;\n\n immutable v = readln\n .chomp\n .splitter(' ')\n .map!(to!uint)\n .array;\n\n auto ans = new BudgetStack!(uint[uint], 200_000);\n\n foreach (val; v) {\n while (ans.length >= 2 && val !in ans[$ - 1] && val !in ans[$ - 2]) {\n reduce(ans[$ - 2], ans[$ - 1]);\n ans.removeBack();\n }\n\n\n if (ans.empty()) {\n ans ~= [val: 1u];\n continue;\n }\n\n if (val in ans[$ - 1])\n ans ~= [val: 1u];\n else\n ans[$ - 1][val] += 1;\n\n }\n\n assert(ans.length > 0);\n if (0 in ans[$ - 1]) {\n writeln(ans.length);\n writefln!\"%(%s %)\"(ans[].map!MEX);\n } else {\n immutable last_size = ans[$ - 1].countNumbers;\n ans.removeBack();\n\n writeln(ans.length + last_size);\n chain(ans[].map!MEX, 0u.repeat(last_size))\n .writefln!\"%(%s %)\";\n }\n }\n}\n// \"\"\n\nvoid reduce (ref uint[uint] lhs, in uint[uint] rhs) {\n foreach (k, v; rhs)\n lhs[k] += v;\n}\n\nuint MEX (in uint[uint] freq) {\n return iota(0, uint.max)\n .filter!(num => num !in freq)\n .front;\n}\n\nuint countNumbers (in uint[uint] freq) {\n return freq.byValue.sum;\n}\n"}, {"source_code": "import std;\n\nT\nread (alias T, string end = \"\") () @trusted {\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 readln();\n\n immutable uint[] v =\n readln.chomp\n .splitter(' ')\n .map!(to!uint)\n .array;\n\n bool[uint][200_000] ans;\n size_t k;\n\n foreach (val; v) {\n while (k >= 2 && val !in ans[k - 1] && val !in ans[k - 2]) {\n -- k;\n }\n\n\n if (k == 0)\n ans[k ++] = [val: true];\n else {\n if (val in ans[k - 1])\n ans[k ++] = [val: true];\n else\n ans[k - 1][val] = true;\n }\n }\n\n writeln(k);\n writefln!\"%(%s %)\"(ans[0 .. k].map!MEX);\n }\n}\n// \"\"\n\nuint\nMEX (in bool[uint] aa) {\n return iota(uint.min, uint.max)\n .filter!(a => a !in aa)\n .front;\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 isPrime = enumeratePrimes(200_000);\r\n auto primes = (100_001).iota.filter!(i => isPrime[i]).array;\r\n auto others = primes.filter!(p => isPrime[2 + p]).array;\r\n\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto A = scan!int(N);\r\n\r\n auto maximums = new int[](N);\r\n int tMax;\r\n foreach_reverse(int i, a; A) {\r\n tMax = max(tMax, a);\r\n maximums[i] = tMax;\r\n }\r\n // maximums.deb;\r\n \r\n int[] ans;\r\n int l;\r\n int shift;\r\n while(l < N) {\r\n const maxi = maximums[l];\r\n auto used = new bool[](maxi + 2);\r\n int c = 0;\r\n\r\n // maxi.deb;\r\n foreach(int i, a; A[l..$]) {\r\n if (used[a]) continue;\r\n\r\n used[a] = true;\r\n if (c == a) {\r\n shift = i;\r\n while(used[c]) c++;\r\n }\r\n if (c == maxi + 1) {\r\n ans ~= c;\r\n break;\r\n }\r\n }\r\n\r\n if (c < maxi + 1) {\r\n ans ~= c;\r\n }\r\n l += shift + 1;\r\n }\r\n\r\n ans.length.writeln;\r\n ans.toAnswerString.writeln;\r\n }\r\n\r\n foreach(i; 0..QN) {\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>>\".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\nbool[] enumeratePrimes(int max)\r\n{\r\n auto primes = new bool[](max + 1);\r\n primes[] = true;\r\n primes[0] = false;\r\n primes[1] = false;\r\n foreach (i; 2..max+1) {\r\n if (primes[i]) {\r\n auto x = i*2;\r\n while (x <= max) {\r\n primes[x] = false;\r\n x += i;\r\n }\r\n }\r\n }\r\n\r\n return primes;\r\n}\r\n"}], "src_uid": "962c4354c936030da78261871dd6d55b"} {"source_code": "import std.algorithm;\nimport std.format;\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\tint t;\n\t\tscanf (\" %d\", &t);\n\t\tauto r = new int [t];\n\t\tauto b = new bool [n];\n\t\tforeach (i; 0..t)\n\t\t{\n\t\t\tscanf (\" %d\", &r[i]);\n\t\t\tr[i]--;\n\t\t\tb[r[i]] = true;\n\t\t}\n\t\treverse (a);\n\t\treverse (b);\n\t\tauto s = new int [n + 1];\n\t\tint pos = 0;\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] || (s[pos] != a[i]))\n\t\t\t{\n\t\t\t\tpos++;\n\t\t\t\ts[pos] = a[i];\n\t\t\t\ta[i] = -a[i];\n\t\t\t}\n\t\t\telse if (s[pos] == a[i])\n\t\t\t{\n\t\t\t\tpos--;\n\t\t\t}\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\tok &= (pos == 0);\n\t\twritefln (\"%s\", ok ? \"YES\" : \"NO\");\n\t\tif (ok)\n\t\t{\n\t\t\treverse (a);\n\t\t\twritefln (\"%(%s %)\", a);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.format;\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\tint t;\n\t\tscanf (\" %d\", &t);\n\t\tauto r = new int [t];\n\t\tauto b = new bool [n];\n\t\tforeach (i; 0..t)\n\t\t{\n\t\t\tscanf (\" %d\", &r[i]);\n\t\t\tr[i]--;\n\t\t\tb[r[i]] = true;\n\t\t}\n\t\treverse (a);\n\t\treverse (b);\n\t\tauto s = new int [n + 1];\n\t\tint pos = 0;\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] || (s[pos] != a[i]))\n\t\t\t{\n\t\t\t\tpos++;\n\t\t\t\ts[pos] = a[i];\n\t\t\t\ta[i] = -a[i];\n\t\t\t}\n\t\t\telse if (s[pos] == a[i])\n\t\t\t{\n\t\t\t\tpos--;\n\t\t\t}\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\tok &= (pos == 0);\n\t\twritefln (\"%s\", ok ? \"YES\" : \"NO\");\n\t\tif (ok)\n\t\t{\n\t\t\treverse (a);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tprintf (\"%d%c\", a[i], i + 1 < n ? ' ' : '\\n');\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.format;\nimport std.stdio;\n\nint [] read_array (int n)\n{\n\tauto res = new int [n];\n\tauto rs = readln ();\n\trs ~= ' ';\n\tforeach (i; 0..n)\n\t{\n\t\twhile (rs[0] < '0')\n\t\t{\n\t\t\trs = rs[1..$];\n\t\t}\n\t\twhile (rs[0] >= '0')\n\t\t{\n\t\t\tres[i] = res[i] * 10 + (rs[0] - '0');\n\t\t\trs = rs[1..$];\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d \", &n) > 0)\n\t{\n\t\tauto a = read_array (n);\n\t\tint t;\n\t\tscanf (\" %d\", &t);\n\t\tauto r = read_array (t);\n\t\tauto b = new bool [n];\n\t\tforeach (i; 0..t)\n\t\t{\n\t\t\tr[i]--;\n\t\t\tb[r[i]] = true;\n\t\t}\n\t\treverse (a);\n\t\treverse (b);\n\t\tauto s = new int [n + 1];\n\t\tint pos = 0;\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] || (s[pos] != a[i]))\n\t\t\t{\n\t\t\t\tpos++;\n\t\t\t\ts[pos] = a[i];\n\t\t\t\ta[i] = -a[i];\n\t\t\t}\n\t\t\telse if (s[pos] == a[i])\n\t\t\t{\n\t\t\t\tpos--;\n\t\t\t}\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\tok &= (pos == 0);\n\t\twritefln (\"%s\", ok ? \"YES\" : \"NO\");\n\t\tif (ok)\n\t\t{\n\t\t\treverse (a);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tprintf (\"%d%c\", a[i], i + 1 < n ? ' ' : '\\n');\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import core.memory;\nimport std.algorithm;\nimport std.container;\nimport std.exception;\nimport std.format;\nimport std.math;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nint [] read_array (int n)\n{\n\tauto res = new int [n];\n\tauto rs = readln ();\n\trs ~= ' ';\n\tforeach (i; 0..n)\n\t{\n\t\twhile (rs[0] < '0')\n\t\t{\n\t\t\trs = rs[1..$];\n\t\t}\n\t\twhile (rs[0] >= '0')\n\t\t{\n\t\t\tres[i] = res[i] * 10 + (rs[0] - '0');\n\t\t\trs = rs[1..$];\n\t\t}\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tGC.disable ();\n\tint n;\n\twhile (scanf (\" %d \", &n) > 0)\n\t{\n\t\tauto a = read_array (n);\n\t\tint t;\n\t\tscanf (\" %d\", &t);\n\t\tauto r = read_array (t);\n\t\tauto b = new bool [n];\n\t\tforeach (i; 0..t)\n\t\t{\n\t\t\tr[i]--;\n\t\t\tb[r[i]] = true;\n\t\t}\n\t\treverse (a);\n\t\treverse (b);\n\t\tauto s = new int [n + 1];\n\t\tint pos = 0;\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (b[i] || (s[pos] != a[i]))\n\t\t\t{\n\t\t\t\tpos++;\n\t\t\t\ts[pos] = a[i];\n\t\t\t\ta[i] = -a[i];\n\t\t\t}\n\t\t\telse if (s[pos] == a[i])\n\t\t\t{\n\t\t\t\tpos--;\n\t\t\t}\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\tok &= (pos == 0);\n\t\twritefln (\"%s\", ok ? \"YES\" : \"NO\");\n\t\tif (ok)\n\t\t{\n\t\t\treverse (a);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tprintf (\"%d%c\", a[i], i + 1 < n ? ' ' : '\\n');\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "be82b8f209217875221ebe5de8675971"} {"source_code": "import std.stdio;\n\nimmutable int MOD = 1_000_000_007;\n\nvoid main ()\n{\n int n;\n while (readf (\" %s\", &n) > 0)\n {\n auto a = new int [] [n];\n foreach (i; 1..n)\n {\n int x;\n readf (\" %s\", &x);\n x--;\n a[x] ~= i;\n }\n\n auto f = new long [n];\n f[] = 1;\n\n foreach_reverse (v; 0..n)\n {\n foreach (u; a[v])\n {\n f[v] = (f[v] * (f[u] + 1)) % MOD;\n }\n }\n\n auto g = new long [n];\n g[] = 1;\n\n foreach (v; 0..n)\n {\n long [] lo = [1];\n foreach (u; a[v])\n {\n lo ~= (lo[$ - 1] * (f[u] + 1)) % MOD;\n }\n\n long [] hi = [1];\n foreach_reverse (u; a[v])\n {\n hi ~= (hi[$ - 1] * (f[u] + 1)) % MOD;\n }\n\n foreach (i, u; a[v])\n {\n long cur = (g[v] * lo[i]) % MOD;\n cur = (cur * hi[a[v].length - 1 - i]) % MOD;\n g[u] = (g[u] * (cur + 1)) % MOD;\n }\n }\n\n auto h = new long [n];\n h[] = (f[] * g[]) % MOD;\n writefln (\"%(%s %)\", h);\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 = 1_000_000_007;\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\tauto p = new int [n];\n\t\tp[0] = NA;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tx--;\n\t\t\tassert (x < i);\n\t\t\ta[x] ~= i;\n\t\t\tp[i] = x;\n\t\t}\n\n\t\tauto f = new long [n];\n\t\tf[] = 1;\n\n\t\tforeach_reverse (v; 0..n)\n\t\t{\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tf[v] = (f[v] * (f[u] + 1)) % MOD;\n\t\t\t}\n\t\t}\n\n\t\tdebug {writefln (\"%(%s %)\", f);}\n\n\t\tauto g = new long [n];\n\t\tg[] = 1;\n\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\tlong [] lo = [1];\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tlo ~= (lo[$ - 1] * (f[u] + 1)) % MOD;\n\t\t\t}\n\n\t\t\tlong [] hi = [1];\n\t\t\tforeach_reverse (u; a[v])\n\t\t\t{\n\t\t\t\thi ~= (hi[$ - 1] * (f[u] + 1)) % MOD;\n\t\t\t}\n\n\t\t\tdebug {writeln (v, ' ', lo, ' ', hi);}\n\n\t\t\tforeach (i, u; a[v])\n\t\t\t{\n\t\t\t\tlong cur = (g[v] * lo[i]) % MOD;\n\t\t\t\tcur = (cur * hi[a[v].length - 1 - i]) % MOD;\n\t\t\t\tg[u] = (g[u] * (cur + 1)) % MOD;\n\t\t\t}\n\t\t}\n\n\t\tdebug {writefln (\"%(%s %)\", g);}\n\n\t\tauto h = new long [n];\n\t\th[] = (f[] * g[]) % MOD;\n\t\twritefln (\"%(%s %)\", h);\n\t}\n}\n"}, {"source_code": "import std.stdio;\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 a = new int [] [n];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tx--;\n\t\t\ta[x] ~= i;\n\t\t}\n\n\t\tauto f = new long [n];\n\t\tf[] = 1;\n\n\t\tforeach_reverse (v; 0..n)\n\t\t{\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tf[v] = (f[v] * (f[u] + 1)) % MOD;\n\t\t\t}\n\t\t}\n\n\t\tauto g = new long [n];\n\t\tg[] = 1;\n\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\tlong [] lo = [1];\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tlo ~= (lo[$ - 1] * (f[u] + 1)) % MOD;\n\t\t\t}\n\n\t\t\tlong [] hi = [1];\n\t\t\tforeach_reverse (u; a[v])\n\t\t\t{\n\t\t\t\thi ~= (hi[$ - 1] * (f[u] + 1)) % MOD;\n\t\t\t}\n\n\t\t\tforeach (i, u; a[v])\n\t\t\t{\n\t\t\t\tlong cur = (g[v] * lo[i]) % MOD;\n\t\t\t\tcur = (cur * hi[a[v].length - 1 - i]) % MOD;\n\t\t\t\tg[u] = (g[u] * (cur + 1)) % MOD;\n\t\t\t}\n\t\t}\n\n\t\tauto h = new long [n];\n\t\th[] = (f[] * g[]) % MOD;\n\t\twritefln (\"%(%s %)\", h);\n\t}\n}\n"}], "negative_code": [{"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 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\tauto p = new int [n];\n\t\tp[0] = NA;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tint x;\n\t\t\treadf (\" %s\", &x);\n\t\t\tx--;\n\t\t\tassert (x < i);\n\t\t\ta[x] ~= i;\n\t\t\tp[i] = x;\n\t\t}\n\n\t\tauto f = new long [n];\n\t\tf[] = 1;\n\n\t\tforeach_reverse (v; 0..n)\n\t\t{\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tf[v] = (f[v] * (f[u] + 1)) % MOD;\n\t\t\t}\n\t\t}\n\n\t\tdebug {writefln (\"%(%s %)\", f);}\n\n\t\tauto g = new long [n];\n\t\tg[] = 1;\n\n\t\tforeach (v; 0..n)\n\t\t{\n\t\t\tauto lo = [1];\n\t\t\tforeach (u; a[v])\n\t\t\t{\n\t\t\t\tlo ~= (lo[$ - 1] * (f[u] + 1)) % MOD;\n\t\t\t}\n\n\t\t\tauto hi = [1];\n\t\t\tforeach_reverse (u; a[v])\n\t\t\t{\n\t\t\t\thi ~= (hi[$ - 1] * (f[u] + 1)) % MOD;\n\t\t\t}\n\n\t\t\tdebug {writeln (v, ' ', lo, ' ', hi);}\n\n\t\t\tforeach (i, u; a[v])\n\t\t\t{\n\t\t\t\tint cur = (g[v] * lo[i]) % MOD;\n\t\t\t\tcur = (cur * hi[a[v].length - 1 - i]) % MOD;\n\t\t\t\tg[u] = (g[u] * (cur + 1)) % MOD;\n\t\t\t}\n\t\t}\n\n\t\tdebug {writefln (\"%(%s %)\", g);}\n\n\t\tauto h = new long [n];\n\t\th[] = (f[] * g[]) % MOD;\n\t\twritefln (\"%(%s %)\", h);\n\t}\n}\n"}], "src_uid": "c01c7a6f289e6c4a7a1e2fb2492a069e"} {"source_code": "import std.algorithm;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nimmutable int LET = 26;\n\nstruct node\n{\n\tint [LET] p;\n}\n\nint main ()\n{\n\tstring s;\n\twhile (readf (\" \") >= 0 &&\n\t (s = strip (readln ())) != \"\" && !stdin.eof ())\n\t{\n\t\tstring buf;\n\t\tbuf = readln ();\n\t\tbuf = strip (buf);\n\t\tenforce (buf.length == LET);\n\t\tauto b = new bool [LET];\n\t\tforeach (i; 0..LET)\n\t\t{\n\t\t\tb[i] = (buf[i] == '1');\n\t\t}\n\t\tint k;\n\t\treadf (\" %s\", &k);\n\t\tint n = s.length;\n\n\t\tint res = 0;\n\t\tauto t = new node [0];\n\t\treserve (t, n * (n - 1) / 2 + 1);\n\t\tt ~= node ();\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v = 0;\n\t\t\tint z = 0;\n\t\t\tforeach (j; i..n)\n\t\t\t{\n\t\t\t\tint c = s[j] - 'a';\n\t\t\t\tz += !b[c];\n\t\t\t\tif (z > k)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (!t[v].p[c])\n\t\t\t\t{\n\t\t\t\t\tdebug {writefln (\"%s\", s[i..j + 1]);}\n\t\t\t\t\tt ~= node ();\n\t\t\t\t\tt[v].p[c] = t.length - 1;\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t\tv = t[v].p[c];\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%s\", res);\n\t}\n\treturn 0;\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.exception;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nimmutable int LET = 26;\n\nstruct node\n{\n\tint [LET] p;\n}\n\nint main ()\n{\n\tstring s;\n\twhile (readf (\" \") >= 0 &&\n\t (s = strip (readln ())) != \"\" && !stdin.eof ())\n\t{\n\t\tstring buf;\n\t\tbuf = readln ();\n\t\tbuf = strip (buf);\n\t\tenforce (buf.length == LET);\n\t\tauto b = new bool [LET];\n\t\tforeach (i; 0..LET)\n\t\t{\n\t\t\tb[i] = (buf[i] == '1');\n\t\t}\n\t\tint k;\n\t\treadf (\" %s\", &k);\n\t\tint n = s.length;\n\n\t\tint res = 0;\n\t\tauto t = new node [0];\n\t\tt ~= node ();\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint v = 0;\n\t\t\tint z = 0;\n\t\t\tforeach (j; i..n)\n\t\t\t{\n\t\t\t\tint c = s[j] - 'a';\n\t\t\t\tz += !b[c];\n\t\t\t\tif (z > k)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (!t[v].p[c])\n\t\t\t\t{\n\t\t\t\t\tdebug {writefln (\"%s\", s[i..j + 1]);}\n\t\t\t\t\tt ~= node ();\n\t\t\t\t\tt[v].p[c] = t.length - 1;\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t\tv = t[v].p[c];\n\t\t\t}\n\t\t}\n\n\t\twritefln (\"%s\", res);\n\t}\n\treturn 0;\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\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 len;\n Node*[char] next;\n Node* link;\n int[int] dp;\n\n this(this) {\n next = next.dup;\n dp = dp.dup;\n }\n\n Node* append(char c, Node* last) {\n auto cur = createNode(Node(last.len + 1));\n Node** 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 int calc(int badTaken) {\n if (badTaken > k)\n return 0;\n if (auto p = badTaken in dp)\n return *p;\n int result = 1;\n foreach (c, node; next)\n result += node.calc(badTaken + (good[c - 'a'] == '0'));\n dp[badTaken] = result;\n return result;\n }\n}\n\nchar[1501] _s;\nchar[ ] s;\nchar[27] good;\nint k;\nint nodesSize;\nNode[3000] nodes;\n\nauto createNode()(auto ref Node node) {\n nodes[nodesSize] = node;\n return &nodes[nodesSize++];\n}\n\nvoid main() {\n while (true) {\n s = _s[ ];\n readln(s);\n if (s.empty)\n break;\n s = s[0 .. $ - 1];\n auto temp = good[ ];\n readln(temp);\n read(&k);\n\n Node root;\n auto last = &root;\n nodesSize = 0;\n foreach (c; s)\n last = root.append(c, last);\n writeln(root.calc(0) - 1);\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\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 len;\n Node*[26] next;\n Node* link;\n int[int] dp;\n\n Node* append(int c, Node* last) {\n auto cur = createNode(Node(last.len + 1));\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 auto q = last.next[c];\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 for (; last !is null && last.next[c] == q; last = last.link)\n last.next[c] = clone;\n return cur;\n }\n\n int calc(int badTaken) {\n if (badTaken > k)\n return 0;\n if (auto p = badTaken in dp)\n return *p;\n int result = 1;\n foreach (i, node; next)\n if (node !is null)\n result += node.calc(badTaken + (good[i] == '0'));\n dp[badTaken] = result;\n return result;\n }\n}\n\nchar[1501] _s;\nchar[ ] s;\nchar[27] good;\nint k;\nint nodesSize;\nNode[3000] nodes;\n\nauto createNode()(auto ref Node node) {\n nodes[nodesSize] = node;\n return &nodes[nodesSize++];\n}\n\nvoid main() {\n while (true) {\n s = _s[ ];\n readln(s);\n if (s.empty)\n break;\n s = s[0 .. $ - 1];\n auto temp = good[ ];\n readln(temp);\n read(&k);\n\n Node root;\n auto last = &root;\n nodesSize = 0;\n foreach (c; s)\n last = root.append(c - 'a', last);\n writeln(root.calc(0) - 1);\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\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 len;\n Node*[char] next;\n Node* link;\n int[int] dp;\n\n Node* append(char c, Node* last) {\n auto cur = createNode(Node(last.len + 1));\n Node** 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 int calc(int badTaken) {\n if (badTaken > k)\n return 0;\n if (auto p = badTaken in dp)\n return *p;\n int result = 1;\n foreach (c, node; next)\n result += node.calc(badTaken + (good[c - 'a'] == '0'));\n dp[badTaken] = result;\n return result;\n }\n}\n\nchar[1501] _s;\nchar[ ] s;\nchar[27] good;\nint k;\nint nodesSize;\nNode[3000] nodes;\n\nauto createNode()(auto ref Node node) {\n nodes[nodesSize] = node;\n return &nodes[nodesSize++];\n}\n\nvoid main() {\n while (true) {\n s = _s[ ];\n readln(s);\n if (s.empty)\n break;\n s = s[0 .. $ - 1];\n auto temp = good[ ];\n readln(temp);\n read(&k);\n\n Node root;\n auto last = &root;\n nodesSize = 0;\n foreach (c; s)\n last = root.append(c, last);\n writeln(root.calc(0) - 1);\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\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 len;\n Node*[char] next;\n Node* link;\n int[int] dp;\n\n Node* append(char c, Node* last) {\n auto cur = createNode(Node(last.len + 1));\n for (; last !is null && c !in last.next; last = last.link)\n last.next[c] = cur;\n if (last is null) {\n cur.link = &this;\n return cur;\n }\n auto q = last.next[c];\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 for (; last !is null && last.next.get(c, null) == q; last = last.link)\n last.next[c] = clone;\n return cur;\n }\n\n int calc(int badTaken) {\n if (badTaken > k)\n return 0;\n if (auto p = badTaken in dp)\n return *p;\n int result = 1;\n foreach (c, node; next)\n result += node.calc(badTaken + (good[c - 'a'] == '0'));\n dp[badTaken] = result;\n return result;\n }\n}\n\nchar[1501] _s;\nchar[ ] s;\nchar[27] good;\nint k;\nint nodesSize;\nNode[3000] nodes;\n\nauto createNode()(auto ref Node node) {\n nodes[nodesSize] = node;\n return &nodes[nodesSize++];\n}\n\nvoid main() {\n while (true) {\n s = _s[ ];\n readln(s);\n if (s.empty)\n break;\n s = s[0 .. $ - 1];\n auto temp = good[ ];\n readln(temp);\n read(&k);\n\n Node root;\n auto last = &root;\n nodesSize = 0;\n foreach (c; s)\n last = root.append(c, last);\n writeln(root.calc(0) - 1);\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\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 len;\n bool cloned;\n Node*[char] next;\n Node* link;\n int[int] dp;\n\n Node* append(char c, Node* last) {\n auto cur = createNode(Node(last.len + 1));\n Node** 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.cloned = true;\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 int calc(int badTaken) {\n if (badTaken > k)\n return 0;\n if (auto p = badTaken in dp)\n return *p;\n int result = !cloned;\n foreach (k, v; next)\n result += v.calc(badTaken + (good[k - 'a'] == '0'));\n dp[badTaken] = result;\n return result;\n }\n}\n\nchar[1501] _s;\nchar[ ] s;\nchar[27] good;\nint k;\nint nodesSize;\nNode[3000] nodes;\n\nauto createNode()(auto ref Node node) {\n nodes[nodesSize] = node;\n return &nodes[nodesSize++];\n}\n\nvoid main() {\n while (true) {\n s = _s[ ];\n readln(s);\n if (s.empty)\n break;\n s = s[0 .. $ - 1];\n auto temp = good[ ];\n readln(temp);\n read(&k);\n\n Node root;\n auto last = &root;\n nodesSize = 0;\n foreach (c; s)\n last = root.append(c, last);\n writeln(root.calc(0) - 1);\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\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 len;\n Node*[char] next;\n Node* link;\n int[int] dp;\n\n Node* append(char c, Node* last) {\n auto cur = createNode(Node(last.len + 1));\n Node** 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 last.next[c] = 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 int calc(int badTaken) {\n if (badTaken > k)\n return 0;\n if (auto p = badTaken in dp)\n return *p;\n int result = 1;\n foreach (c, node; next)\n result += node.calc(badTaken + (good[c - 'a'] == '0'));\n dp[badTaken] = result;\n return result;\n }\n}\n\nchar[1501] _s;\nchar[ ] s;\nchar[27] good;\nint k;\nint nodesSize;\nNode[3000] nodes;\n\nauto createNode()(auto ref Node node) {\n nodes[nodesSize] = node;\n return &nodes[nodesSize++];\n}\n\nvoid main() {\n while (true) {\n s = _s[ ];\n readln(s);\n if (s.empty)\n break;\n s = s[0 .. $ - 1];\n auto temp = good[ ];\n readln(temp);\n read(&k);\n\n Node root;\n auto last = &root;\n nodesSize = 0;\n foreach (c; s)\n last = root.append(c, last);\n writeln(root.calc(0) - 1);\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\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 len;\n Node*[char] next;\n Node* link;\n int[int] dp;\n\n Node* append(char c, Node* last) {\n auto cur = createNode(Node(last.len + 1));\n Node** 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 int calc(int badTaken) {\n if (badTaken > k)\n return 0;\n if (auto p = badTaken in dp)\n return *p;\n int result = 1;\n foreach (k, v; next)\n result += v.calc(badTaken + (good[k - 'a'] == '0'));\n dp[badTaken] = result;\n return result;\n }\n}\n\nchar[1501] _s;\nchar[ ] s;\nchar[27] good;\nint k;\nint nodesSize;\nNode[3000] nodes;\n\nauto createNode()(auto ref Node node) {\n nodes[nodesSize] = node;\n return &nodes[nodesSize++];\n}\n\nvoid main() {\n while (true) {\n s = _s[ ];\n readln(s);\n if (s.empty)\n break;\n s = s[0 .. $ - 1];\n auto temp = good[ ];\n readln(temp);\n read(&k);\n\n Node root;\n auto last = &root;\n nodesSize = 0;\n foreach (c; s)\n last = root.append(c, last);\n writeln(root.calc(0) - 1);\n }\n}\n"}], "src_uid": "c0998741424cd53de41d31f0bbaef9a2"} {"source_code": "import std.stdio;\nimport std.array;\nimport std.string;\n\nint main()\n{\n\tstring line = readln();\n\tline = line.replace(\"{\", \"\").replace(\"}\", \"\");\n\tauto let = line.split(\",\");\n\tint[string] letters;\n\tint distinct = 0;\n\tforeach (string s; let)\n\t{\n\t\tstring p = s.strip();\n\t\tif (p.length == 0)\n\t\t\tcontinue;\n\t\tif (!(p in letters))\n\t\t{\n\t\t\tdistinct++;\n\t\t\tletters[p] = 1;\n\t\t}\n\t}\n\twrite(distinct);\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\n\n\nvoid main(string[] args) {\n\t// try {\n\tfor (string line; (line = readln) != null; ) {\n\t\tauto ss = line.chomp.removechars(\"{} \").split(\",\");\ndebug{\nwriteln(\"ss = \",ss);\n}\n\t\tbool[string] app;\n\t\tforeach (s; ss) {\n\t\t\tapp[s] = true;\n\t\t}\n\t\twriteln(app.keys.length);\n\t}\n\t// } catch (EOFException) {}\n}\n\n"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip;\nimport std.algorithm.iteration: uniq;\nimport std.algorithm.sorting: sort;\nimport std.regex;\nimport std.array;\n\nvoid main()\n{\n auto h = (stdin.readln.strip)[1..$-1].split(regex(` *, *`));\n h.sort;\n writeln (h.uniq.array.length);\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main() {\n\tstring s = readln.chomp;\n\tbool[char] chars;\n\tforeach (c; s) {\n\t\tif ('a' <= c && c <= 'z') {\n\t\t\tif (!(c in chars)) {\n\t\t\t\tchars[c] = true;\n\t\t\t}\n\t\t}\n\t}\n\n\tchars.length.writeln;\n}\n"}], "negative_code": [], "src_uid": "1cbbffd1941ed83b5f04e1ee33c77f61"} {"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\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n auto N = read!ulong;\r\n auto m = bsf(2*N);\r\n auto X = 1L<= int.max) return false;\r\n return N >= k * (k + 1L) / 2L;\r\n }\r\n\r\n if (check(X)) {\r\n writeln(X);\r\n } else if (check(Y)) {\r\n writeln(Y);\r\n } else {\r\n writeln(-1);\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\nlong solve (long n)\r\n{\r\n\tif (!(n & (n - 1)))\r\n\t{\r\n\t\treturn -1;\r\n\t}\r\n\tlong p2 = 1;\r\n\twhile (!(n & 1))\r\n\t{\r\n\t\tp2 <<= 1;\r\n\t\tn >>= 1;\r\n\t}\r\n\tif (p2 > (n >> 1))\r\n\t{\r\n\t\treturn n;\r\n\t}\r\n\telse\r\n\t{\r\n\t\treturn p2 * 2;\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\tauto n = readln.strip.to !(long);\r\n\t\twriteln (solve (n));\r\n\t}\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\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n auto N = read!ulong;\r\n auto m = bsf(2*N);\r\n auto X = 1L<= k * (k + 1L) / 2L;\r\n }\r\n\r\n if (check(X)) {\r\n writeln(X);\r\n } else if (check(Y)) {\r\n writeln(Y);\r\n } else {\r\n writeln(-1);\r\n }\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\nvoid main() {\r\n int T = read!int;\r\n foreach (t; 0 .. T) solve();\r\n}\r\n\r\nvoid solve() {\r\n auto N = read!long;\r\n auto m = bsf(2*N);\r\n auto X = 1L<= k * (k + 1L) / 2L;\r\n }\r\n\r\n if (check(X)) {\r\n writeln(X);\r\n } else if (check(Y)) {\r\n writeln(Y);\r\n } else {\r\n writeln(-1);\r\n }\r\n}\r\n"}], "src_uid": "8063c96cf62727f1b98e476e43679da2"} {"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 immutable int MX = 210;\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 \n auto lft = new int[][] (n+10, MX);\n auto lftpos = new int[][] (MX);\n auto rtcnt = new int[] (MX);\n \n foreach (i, e; arr) {\n foreach (v; 0 .. MX) { lft[i][v] = i > 0 ? lft[i-1][v] : 0; }\n lft[i][e] += 1;\n \n lftpos[e] ~= i.to!int;\n }\n \n int ans = 1;\n foreach_reverse (r, e; arr) {\n rtcnt[e] += 1;\n \n int le = lftpos[e][rtcnt[e]-1];\n \n if (le >= r) { continue; }\n \n int mxy = 0;\n foreach (v; 0 .. MX) {\n mxy = max(mxy, lft[r-1][v] - lft[le][v]);\n }\n \n ans = max(ans, mxy + 2 * rtcnt[e]);\n }\n \n ans.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 t;\n readf(\"%s\", &t);\n readln;\n \n immutable int MX = 30;\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 \n auto lft = new int[][] (n+10, MX);\n auto rt = new int[][] (n+10, MX);\n \n foreach (i, e; arr) {\n foreach (v; 0 .. MX) { lft[i][v] = i > 0 ? lft[i-1][v] : 0; }\n \n lft[i][e] += 1;\n }\n \n foreach (v; 0 .. MX) { rt[n][v] = 0; }\n foreach_reverse (i, e; arr) {\n foreach (v; 0 .. MX) { rt[i][v] = rt[i+1][v]; }\n \n rt[i][e] += 1;\n }\n \n int ans = 0;\n foreach (i; 0 .. n) {\n foreach (j; i+1 .. n+1) {\n int cur = 0;\n foreach (v; 0 .. MX) {\n cur = max(cur, lft[j-1][v] - (i > 0 ? lft[i-1][v] : 0));\n }\n \n int add = 0;\n foreach (v; 0 .. MX) {\n add = max(add, min((i > 0 ? lft[i-1][v] : 0), rt[j][v]));\n }\n \n ans = max(ans, cur + 2*add);\n }\n }\n \n ans.writeln;\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nenum MAX_C = 200;\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\n if (N == 1) {\n writeln(1);\n continue;\n } else if (N == 2) {\n writeln(as[0] == as[1] ? 2 : 1);\n continue;\n }\n\n auto cs = new int[][](N, MAX_C);\n foreach (i, ref a; as) {\n a -= 1;\n if (i) foreach (j; 0..MAX_C) cs[i][j] = cs[i-1][j];\n ++cs[i][a];\n }\n long res;\n foreach (i; 0..MAX_C) res = max(res, cs[N-1][i]);\n foreach (n; 0..MAX_C) {\n foreach (c; 1..cs[N-1][n]/2+1) {\n int i, j, l, r;\n\n if (cs[0][n] == c) {\n i = 0;\n } else {\n r = N-1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n if (cs[m][n] < c) {\n l = m;\n } else {\n r = m;\n }\n }\n i = r;\n }\n\n l = 0; r = N-1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n if (cs[N-1][n] - cs[m][n] < c) {\n r = m;\n } else {\n l = m;\n }\n }\n j = l;\n\n int max_d;\n foreach (d; 0..MAX_C) max_d = max(max_d, cs[j][d] - cs[i][d]);\n\n res = max(res, c*2 + max_d);\n }\n }\n writeln(res);\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 limit = 201;\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\tauto s = new int [limit];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts[a[i]] += 1;\n\t\t}\n\n\t\tauto c = new int [n + 3];\n\t\tint res = 0;\n\t\tforeach (u; 0..limit)\n\t\t{\n\t\t\tif (s[u] == 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto t = s.dup;\n\t\t\tc[0] = 0;\n\t\t\tc[1] = 0;\n\t\t\tc[2] = 0;\n\t\t\tforeach (v; 0..limit)\n\t\t\t{\n\t\t\t\tc[t[v]] += 1;\n\t\t\t}\n\t\t\tdebug {writeln (t); writeln (c);}\n\t\t\tint pos = n;\n\t\t\twhile (!c[pos])\n\t\t\t{\n\t\t\t\tpos -= 1;\n\t\t\t}\n\n\t\t\tvoid decrease (ref int x)\n\t\t\t{\n\t\t\t\tc[x] -= 1;\n\t\t\t\tx -= 1;\n\t\t\t\tc[x] += 1;\n\t\t\t\twhile (!c[pos])\n\t\t\t\t{\n\t\t\t\t\tpos -= 1;\n\t\t\t\t}\n\t\t\t}\t\n\n\t\t\tint lo = 0;\n\t\t\tint hi = n - 1;\n\t\t\tint add = 0;\n\t\t\tres = max (res, pos + add);\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\twhile (lo < hi && a[lo] != u)\n\t\t\t\t{\n\t\t\t\t\tdecrease (t[a[lo]]);\n\t\t\t\t\tlo += 1;\n\t\t\t\t}\n\n\t\t\t\twhile (lo < hi && a[hi] != u)\n\t\t\t\t{\n\t\t\t\t\tdecrease (t[a[hi]]);\n\t\t\t\t\thi -= 1;\n\t\t\t\t}\n\n\t\t\t\tif (lo >= hi)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdecrease (t[a[lo]]);\n\t\t\t\tlo += 1;\n\t\t\t\tdecrease (t[a[hi]]);\n\t\t\t\thi -= 1;\n\t\t\t\tdebug {writeln (lo, \" \", hi, \" \", pos);}\n\t\t\t\tadd += 2;\n\t\t\t\tres = max (res, pos + add);\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) { x.modm(y.modpow(mod - 2)); }\n\nvoid main()\n{\n\tauto M = 26;\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(-1);\n\n\t\tauto b = new int[][](n+1, M);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb[i+1][] += b[i][];\n\t\t\t++b[i+1][a[i]];\n\t\t}\n\t\tauto c = new int[][](n+1, M);\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tc[i][] += c[i+1][];\n\t\t\t++c[i][a[i]];\n\t\t}\n\n\t\tforeach (num; 0..M)\n\t\t{\n\t\t\tint l, r = n;\n\t\t\twhile (r-l > 0)\n\t\t\t{\n\t\t\t\tauto c1 = b[l][num];\n\t\t\t\tauto c2 = c[r][num];\n\t\t\t\tif (c1 == c2)\n\t\t\t\t{\n\t\t\t\t\tauto tmp = b[r].dup;\n\t\t\t\t\ttmp[] -= b[l][];\n\t\t\t\t\tauto p = tmp.MIN_POS!\"a > b\";\n\t\t\t\t\tans[ti].chmax(c1+c2+tmp[p]);\n\t\t\t\t\t++l;\n\t\t\t\t}\n\t\t\t\telse if (c1 < c2)\n\t\t\t\t\t++l;\n\t\t\t\telse\n\t\t\t\t\t--r;\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": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nenum MAX_C = 200;\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\n if (N == 1) {\n writeln(1);\n continue;\n } else if (N == 2) {\n writeln(as[0] == as[1] ? 2 : 1);\n continue;\n }\n\n auto cs = new int[][](N, MAX_C);\n foreach (i, ref a; as) {\n a -= 1;\n if (i) foreach (j; 0..MAX_C) cs[i][j] = cs[i-1][j];\n ++cs[i][a];\n }\n long res;\n foreach (i; 0..MAX_C) res = max(res, cs[N-1][i]);\n foreach (n; 0..MAX_C) {\n foreach (c; 1..cs[N-1][n]/2+1) {\n int i, j, l, r;\n\n if (cs[0][n] == c) {\n i = 0;\n } else {\n r = N-1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n if (cs[m][n] < c) {\n l = m;\n } else {\n r = m;\n }\n }\n i = r;\n }\n\n l = 0; r = N-1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n if (cs[N-1][n] - cs[m][n] < c) {\n r = m;\n } else {\n l = m;\n }\n }\n j = l;\n\n int max_d;\n foreach (d; 0..MAX_C) max_d = max(max_d, cs[j][d] - cs[i][d]);\n\n res = max(res, c*2 + max_d);\n }\n }\n writeln(res);\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 limit = 201;\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\tauto s = new int [limit];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts[a[i]] += 1;\n\t\t}\n\n\t\tauto c = new int [n + 3];\n\t\tint res = 0;\n\t\tforeach (u; 0..limit)\n\t\t{\n\t\t\tif (s[u] == 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tauto t = s.dup;\n\t\t\tc[0] = 0;\n\t\t\tc[1] = 0;\n\t\t\tc[2] = 0;\n\t\t\tforeach (v; 0..limit)\n\t\t\t{\n\t\t\t\tc[t[v]] += 1;\n\t\t\t}\n\t\t\tdebug {writeln (t); writeln (c);}\n\t\t\tint pos = n;\n\t\t\twhile (!c[pos])\n\t\t\t{\n\t\t\t\tpos -= 1;\n\t\t\t}\n\n\t\t\tvoid decrease (ref int x)\n\t\t\t{\n\t\t\t\tc[x] -= 1;\n\t\t\t\tx -= 1;\n\t\t\t\tc[x] += 1;\n\t\t\t\twhile (!c[pos])\n\t\t\t\t{\n\t\t\t\t\tpos -= 1;\n\t\t\t\t}\n\t\t\t}\t\n\n\t\t\tint lo = 0;\n\t\t\tint hi = n - 1;\n\t\t\tint add = 0;\n\t\t\tres = max (res, pos + add);\n\t\t\twhile (true)\n\t\t\t{\n\t\t\t\twhile (lo < hi && a[lo] != u)\n\t\t\t\t{\n\t\t\t\t\tdecrease (t[a[lo]]);\n\t\t\t\t\tlo += 1;\n\t\t\t\t}\n\n\t\t\t\twhile (lo < hi && a[hi] != u)\n\t\t\t\t{\n\t\t\t\t\tdecrease (t[a[hi]]);\n\t\t\t\t\thi -= 1;\n\t\t\t\t}\n\n\t\t\t\tif (lo >= hi)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdecrease (t[a[lo]]);\n\t\t\t\tlo += 1;\n\t\t\t\tdecrease (t[a[hi]]);\n\t\t\t\thi -= 1;\n\t\t\t\tdebug {writeln (lo, \" \", hi, \" \", pos);}\n\t\t\t\tadd += 2;\n\t\t\t\tres = max (res, pos + add);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "2c1ee398ea86209335c2248eaa723aca"} {"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!long;\n auto path = next!string;\n long[Tuple!(long, long)] lastPosition;\n auto acc = tuple!(long, long)(0, 0);\n lastPosition[acc] = 0;\n long lp, cp;\n foreach(i; 1 .. n + 1)\n {\n switch(path[(i - 1).ind])\n {\n case 'L':\n acc[0]--;\n break;\n case 'R':\n acc[0]++;\n break;\n case 'U':\n acc[1]++;\n break;\n case 'D':\n acc[1]--;\n break;\n default:\n assert(0);\n }\n if (acc in lastPosition)\n {\n if (cast(long) i - lastPosition[acc] < cp - lp || cp == lp)\n {\n cp = cast(long) i;\n lp = lastPosition[acc];\n }\n }\n lastPosition[acc] = cast(long) i;\n }\n if (lp == cp)\n {\n writeln(-1);\n }\n else\n {\n writeln(lp + 1, \" \", cp);\n }\n }\n}\n", "positive_code": [{"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 auto s = readToken;\n int[Tuple!(int, int)] tbl;\n tbl[tuple(0, 0)] = 0;\n int x = 0, y = 0;\n auto best = tuple(n + 1, 0, 0);\n for (int i = 0; i < n; ++i)\n {\n final switch (s[i])\n {\n case 'L':\n x--;\n break;\n case 'R':\n x++;\n break;\n case 'D':\n y--;\n break;\n case 'U':\n y++;\n }\n int idx = tbl.get(tuple(x, y), -1);\n if (idx != -1)\n best = min(best, tuple(i - idx + 1, idx + 1, i + 1));\n tbl[tuple(x, y)] = i + 1;\n }\n if (best[0] <= n)\n {\n writeln(best[1], \" \", best[2]);\n }\n else\n {\n writeln(-1);\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); }\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\t\tint[int[2]] set;\n\t\tset[[0, 0]] = 0;\n\t\tint[2] cnt;\n\t\tint len = int.max;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == 'L')\n\t\t\t\t--cnt[0];\n\t\t\telse if (s[i] == 'R')\n\t\t\t\t++cnt[0];\n\t\t\telse if (s[i] == 'U')\n\t\t\t\t--cnt[1];\n\t\t\telse\n\t\t\t\t++cnt[1];\n\n\t\t\tint[2] x = cnt.dup;\n\t\t\tauto pos = set.get(x, -1);\n\t\t\tif (pos != -1)\n\t\t\t{\n\t\t\t\tif (i - pos < len)\n\t\t\t\t{\n\t\t\t\t\tlen = i - pos;\n\t\t\t\t\tans[ti] = [pos+1, i+1];\n\t\t\t\t}\n\t\t\t}\n\t\t\tauto y = set.get(cnt, 0);\n\t\t\tset[cnt] = max(y, i+1);\n\t\t}\n\t\tdebug writeln(set);\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]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "1fc1d5ee79aaf823b246db5471ba7836"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = 1;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto Q = scan!int;\r\n\r\n auto xt = SegTree!(\"min(a, b)\", int)(new int[](N + 1), int.max/2);\r\n auto yt = SegTree!(\"min(a, b)\", int)(new int[](N + 1), int.max/2);\r\n\r\n foreach(qi; 0..Q) {\r\n auto q = scan!int;\r\n if (q == 1 || q == 2) {\r\n auto x = scan!int;\r\n auto y = scan!int;\r\n if (q == 1) {\r\n xt.update(x, xt.get(x) + 1);\r\n yt.update(y, yt.get(y) + 1);\r\n // xt.get(x).deb;\r\n } else {\r\n xt.update(x, xt.get(x) - 1);\r\n yt.update(y, yt.get(y) - 1);\r\n // xt.get(x).deb;\r\n }\r\n } else {\r\n auto x1 = scan!int;\r\n auto y1 = scan!int;\r\n auto x2 = scan!int;\r\n auto y2 = scan!int;\r\n\r\n // [x1, xt.get(x1)].deb;\r\n // [y1, y2, yt.get(y1)].deb;\r\n // [xt.sum(x1, x2), yt.sum(y1, y2)].deb;\r\n\r\n auto ans = max(xt.sum(x1, x2 + 1), yt.sum(y1, y2 + 1));\r\n writeln(ans == 0 ? \"No\" : \"Yes\");\r\n }\r\n }\r\n }\r\n\r\n foreach(i; 0..QN) {\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>>\".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;\r\nimport std.outbuffer;\r\n\r\nconst int MAXN = 100005;\r\n\r\nint n,q;\r\n\r\nstruct Bit\r\n{\r\n int[MAXN] t;\r\n\r\n int lowbit(int x) {\r\n return x & (-x);\r\n }\r\n\r\n void update(int x, int k) {\r\n while (x <= n) {\r\n t[x] += k;\r\n x += lowbit(x);\r\n }\r\n }\r\n\r\n int ask(int x) {\r\n int res = 0;\r\n while (x > 0) {\r\n res += t[x];\r\n x -= lowbit(x);\r\n }\r\n return res;\r\n }\r\n\r\n int query(int l, int r) {\r\n return ask(r) - ask(l - 1);\r\n }\r\n}\r\n\r\nBit bx, by;\r\n\r\nint[MAXN] cntRows, cntCols;\r\n\r\nvoid main()\r\n{\r\n OutBuffer buf = new OutBuffer();\r\n scanf(\"%d %d\", &n, &q);\r\n getchar();\r\n outer: foreach(_; 0..q)\r\n {\r\n int op, x1, x2, y1, y2;\r\n scanf(\"%d \", &op);\r\n if (op == 3) {\r\n scanf(\"%d %d %d %d\\n\", &x1, &y1, &x2, &y2);\r\n if (bx.query(x1,x2) == x2 - x1 + 1 || by.query(y1, y2) == y2 - y1 + 1)\r\n buf.printf(\"Yes\\n\");\r\n else\r\n buf.printf(\"No\\n\");\r\n }\r\n else {\r\n scanf(\"%d %d\\n\", &x1, &y1);\r\n if (op == 1) {\r\n if (cntRows[x1]++ == 0)\r\n bx.update(x1,1);\r\n if (cntCols[y1]++ == 0)\r\n by.update(y1,1);\r\n }\r\n else if (op == 2) {\r\n if (cntRows[x1]-- == 1)\r\n bx.update(x1,-1);\r\n if (cntCols[y1]-- == 1)\r\n by.update(y1,-1);\r\n }\r\n }\r\n }\r\n writeln(buf);\r\n}\r\n"}, {"source_code": "import std;\r\nimport core.stdc.stdio;\r\n\r\nconst int MAXN = 100005;\r\n\r\nint n,q;\r\n\r\nstruct Bit\r\n{\r\n int[MAXN] t;\r\n\r\n int lowbit(int x) {\r\n return x & (-x);\r\n }\r\n\r\n void update(int x, int k) {\r\n while (x <= n) {\r\n t[x] += k;\r\n x += lowbit(x);\r\n }\r\n }\r\n\r\n int ask(int x) {\r\n int res = 0;\r\n while (x > 0) {\r\n res += t[x];\r\n x -= lowbit(x);\r\n }\r\n return res;\r\n }\r\n\r\n int query(int l, int r) {\r\n return ask(r) - ask(l - 1);\r\n }\r\n}\r\n\r\nBit bx, by;\r\n\r\nint[MAXN] cntRows, cntCols;\r\n\r\nvoid main()\r\n{\r\n scanf(\"%d %d\", &n, &q);\r\n getchar();\r\n outer: foreach(_; 0..q)\r\n {\r\n int op, x1, x2, y1, y2;\r\n scanf(\"%d \", &op);\r\n if (op == 3) {\r\n scanf(\"%d %d %d %d\\n\", &x1, &y1, &x2, &y2);\r\n if (bx.query(x1,x2) == x2 - x1 + 1 || by.query(y1, y2) == y2 - y1 + 1)\r\n printf(\"Yes\\n\");\r\n else\r\n printf(\"No\\n\");\r\n }\r\n else {\r\n scanf(\"%d %d\\n\", &x1, &y1);\r\n if (op == 1) {\r\n if (cntRows[x1]++ == 0)\r\n bx.update(x1,1);\r\n if (cntCols[y1]++ == 0)\r\n by.update(y1,1);\r\n }\r\n else if (op == 2) {\r\n if (cntRows[x1]-- == 1)\r\n bx.update(x1,-1);\r\n if (cntCols[y1]-- == 1)\r\n by.update(y1,-1);\r\n }\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std;\r\nimport core.stdc.stdio;\r\n\r\nvoid main()\r\n{\r\n int n, q;\r\n scanf(\"%d %d\", &n, &q);\r\n getchar();\r\n auto freeRows = redBlackTree(iota(n+1));\r\n auto freeCols = redBlackTree(iota(n+1));\r\n int[] cntRows = new int[](n+1);\r\n int[] cntCols = new int[](n+1);\r\n outer: foreach(_; 0..q)\r\n {\r\n int qtype, x1, x2, y1, y2;\r\n scanf(\"%d \", &qtype);\r\n if (qtype == 3) {\r\n scanf(\"%d %d %d %d\\n\", &x1, &y1, &x2, &y2);\r\n auto l1 = freeRows.lowerBound(x2 + 1).array;\r\n auto u1 = freeRows.upperBound(x1 - 1).array;\r\n auto l2 = freeCols.lowerBound(y2 + 1).array;\r\n auto u2 = freeCols.upperBound(y1 - 1).array;\r\n if (l1[$-1]==u1[0] || l2[$-1]==u2[0])\r\n printf(\"No\\n\");\r\n else\r\n printf(\"Yes\\n\");\r\n }\r\n else {\r\n scanf(\"%d %d\\n\", &x1, &y1);\r\n if (qtype == 1) {\r\n if (cntRows[x1] == 0)\r\n freeRows.removeKey(x1);\r\n cntRows[x1]++;\r\n if (cntCols[y1] == 0)\r\n freeCols.removeKey(y1);\r\n cntCols[y1]++;\r\n }\r\n else {\r\n cntRows[x1]--;\r\n cntCols[y1]--;\r\n if (cntRows[x1] == 0)\r\n freeRows.insert(x1);\r\n if (cntCols[y1] == 0)\r\n freeCols.insert(y1);\r\n }\r\n }\r\n }\r\n}\r\n"}, {"source_code": "import std;\r\nimport core.stdc.stdio;\r\n\r\nvoid main()\r\n{\r\n int n, q;\r\n scanf(\"%d %d\", &n, &q);\r\n getchar();\r\n auto freeRows = redBlackTree(iota(n));\r\n auto freeCols = redBlackTree(iota(n));\r\n int[] cntRows = new int[](n+1);\r\n int[] cntCols = new int[](n+1);\r\n outer: foreach(_; 0..q)\r\n {\r\n int qtype, x1, x2, y1, y2;\r\n scanf(\"%d \", &qtype);\r\n if (qtype == 3) {\r\n scanf(\"%d %d %d %d\\n\", &x1, &y1, &x2, &y2);\r\n auto ll = freeRows.lowerBound(x2 + 1);\r\n auto uu = freeRows.upperBound(x1 - 1);\r\n bool t1 = setIntersection(ll, uu).array.length == 0;\r\n ll = freeCols.lowerBound(y2 + 1);\r\n uu = freeCols.upperBound(y1 - 1);\r\n bool t2 = setIntersection(ll, uu).array.length == 0;\r\n if (t1 || t2)\r\n printf(\"Yes\\n\");\r\n else\r\n printf(\"No\\n\");\r\n }\r\n else {\r\n scanf(\"%d %d\\n\", &x1, &y1);\r\n if (qtype == 1) {\r\n if (cntRows[x1] == 0)\r\n freeRows.removeKey(x1);\r\n cntRows[x1]++;\r\n if (cntCols[y1] == 0)\r\n freeCols.removeKey(y1);\r\n cntCols[y1]++;\r\n }\r\n else {\r\n cntRows[x1]--;\r\n cntCols[y1]--;\r\n if (cntRows[x1] == 0)\r\n freeRows.insert(x1);\r\n if (cntCols[y1] == 0)\r\n freeCols.insert(y1);\r\n }\r\n }\r\n }\r\n}\r\n"}], "src_uid": "bd95629c1698cf1d0cfd338afcf1ca93"} {"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\tauto s = a.group.map !(c => c[1]).array;\n\t\tauto hi = s.maxElement;\n\t\tauto num = s.count (hi);\n\t\twriteln ((n - num) / (hi - 1) - 1);\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 while (t--) {\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 foreach (e; arr) { cnt[e] += 1; }\n \n auto rbt = make!(RedBlackTree!(\n Tuple!(int, int), \n \"a[1] != b[1] ? a[1] > b[1] : a[0] > b[0]\", \n false));\n foreach (k; cnt.keys) { \n //debug { writeln(k, ' ', cnt[k]); }\n rbt.insert(tuple(k, cnt[k])); \n }\n \n debug { rbt.writeln; }\n \n bool isOk(int d) {\n auto crbt = rbt.dup;\n int[int] rest;\n int[] arr;\n foreach (i; n.iota) {\n if (i-1 >= d && rest.get(arr[i-1-d], 0) > 0) { crbt.insert(tuple(arr[i-1-d], rest[arr[i-1-d]])); }\n \n if (crbt.empty()) { return false; }\n \n auto kv = crbt.front;\n \n arr ~= kv[0];\n \n crbt.removeFront();\n \n rest[kv[0]] = kv[1] - 1;\n }\n \n return true;\n }\n \n int le = 0, r = n;\n while (le < r) {\n int m = (le + r) / 2 + 1;\n if (isOk(m)) { le = m; }\n else { r = m - 1; }\n }\n \n le.writeln;\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 long[long] cnt;\n long mx = long.min;\n foreach(ai; a)\n if (++cnt.require(ai, 0) > mx)\n {\n mx = cnt[ai];\n }\n long ts = 0;\n foreach(a, c; cnt)\n {\n if (c == mx)\n {\n ts++;\n }\n }\n writeln((n - ts * mx) / (mx - 1) + (ts - 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) { 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\n\t\tauto cnt = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\t++cnt[a[i]];\n\t\t}\n\t\tcnt.sort!\"a > b\";\n\t\tint cntcnt = 1;\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tif (cnt[0] != cnt[i]) break;\n\t\t\t++cntcnt;\n\t\t}\n\t\tans[ti] = (n-cntcnt) / (cnt[0]-1) - 1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "9d480b3979a7c9789fd8247120f31f03"} {"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\nTuple!(int, int) getCenter(int n, int mx, int rw) {\n int x = rw, y = 1 + mx - (n - x);\n return tuple(x, y);\n}\n\nbool solve(int n, int m, int mx, int rw, int[] cnt) {\n auto t = getCenter(n, mx, rw);\n int x = t[0], y = t[1];\n \n if (x < 1 || x > n || y < 1 || y > m) return false;\n \n auto curcnt = new int[] (n*m);\n curcnt[] = 0;\n foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];\n \n return curcnt == cnt[0 .. n*m];\n}\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto cnt = new int[10 ^^ 6 + 1];\n cnt[] = 0;\n arr.each!(x => ++cnt[x]);\n \n if (t == 1) {\n if (arr[0] == 0) {\n writeln(\"1 1\");\n writeln(\"1 1\");\n return;\n }\n \n writeln(\"-1\");\n return;\n }\n \n if (!cnt.dropOne.canFind!(x => x % 4 != 0)) { \n writeln(\"-1\");\n return;\n }\n \n auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;\n auto mx = arr.maxElement;\n \n foreach (n; t.iota.dropOne.until!(v => v > t / v)) {\n if (t % n != 0) continue;\n \n void writeAns(int n, int m) {\n writeln(n, ' ', m);\n auto c = getCenter(n, mx, rw);\n writeln(c[0], ' ', c[1]);\n }\n \n if (solve(n, t/n, mx, rw, cnt)) {\n writeAns(n, t/n);\n return;\n }\n if (solve(t/n, n, mx, rw, cnt)) {\n writeAns(t/n, n);\n return;\n }\n }\n \n writeln(\"-1\");\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\nTuple!(int, int) getCenter(int n, int mx, int rw) {\n int x = rw, y = 1 + mx - (n - x);\n return tuple(x, y);\n}\n\nbool solve(int n, int m, int mx, int rw, int[] cnt) {\n auto t = getCenter(n, mx, rw);\n int x = t[0], y = t[1];\n \n if (n == 4 && m == 5) debug { t.writeln; }\n \n if (x < 1 || x > n || y < 1 || y > m) return false;\n \n auto curcnt = new int[] (n*m);\n curcnt[] = 0;\n \n foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];\n \n if (n == 4 && m == 5) debug { curcnt.take(10).writeln; }\n \n return curcnt == cnt[0 .. n*m];\n}\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto cnt = new int[10 ^^ 6 + 1];\n cnt[] = 0;\n arr.each!(x => ++cnt[x]);\n \n debug { cnt.take(10).writeln; }\n \n if (t == 1) {\n if (arr[0] == 0) {\n writeln(\"1 1\");\n writeln(\"1 1\");\n return;\n }\n \n writeln(\"-1\");\n return;\n }\n \n if (!cnt.dropOne.canFind!(x => x % 4 != 0)) { \n writeln(\"-1\");\n return;\n }\n \n debug { cnt.enumerate.dropOne.take(10).writeln; }\n \n auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;\n auto mx = arr.maxElement;\n \n foreach (n; t.iota.dropOne.until!(v => v > t / v)) {\n if (t % n != 0) continue;\n \n debug { n.writeln; }\n \n void writeAns(int n, int m) {\n writeln(n, ' ', m);\n auto c = getCenter(n, mx, rw);\n writeln(c[0], ' ', c[1]);\n }\n \n if (solve(n, t/n, mx, rw, cnt)) {\n writeAns(n, t/n);\n return;\n }\n if (solve(t/n, n, mx, rw, cnt)) {\n writeAns(t/n, n);\n return;\n }\n }\n \n writeln(\"-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.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nTuple!(int, int) getCenter(int n, int mx, int rw) {\n int x = rw, y = 1 + mx - (n - x);\n return tuple(x, y);\n}\n\nbool solve(int n, int m, int mx, int rw, int[] cnt) {\n auto t = getCenter(n, mx, rw);\n int x = t[0], y = t[1];\n \n if (n == 4 && m == 5) debug { t.writeln; }\n \n if (x < 1 || x > n || y < 1 || y > m) return false;\n \n auto curcnt = new int[] (n*m);\n curcnt[] = 0;\n \n foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];\n \n if (n == 4 && m == 5) debug { curcnt.take(10).writeln; }\n \n return curcnt == cnt[0 .. n*m];\n}\n\nvoid main()\n{\n int t;\n readf(\"%s\", &t);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto cnt = new int[10 ^^ 6 + 1];\n cnt[] = 0;\n arr.each!(x => ++cnt[x]);\n \n debug { cnt.take(10).writeln; }\n \n if (!cnt.dropOne.canFind!(x => x % 4 != 0)) { \n writeln(\"-1\");\n return;\n }\n \n debug { cnt.enumerate.dropOne.take(10).writeln; }\n \n auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;\n auto mx = arr.maxElement;\n \n foreach (n; t.iota.dropOne.until!(v => v > t / v)) {\n if (t % n != 0) continue;\n \n debug { n.writeln; }\n \n void writeAns(int n, int m) {\n writeln(n, ' ', m);\n auto c = getCenter(n, mx, rw);\n writeln(c[0], ' ', c[1]);\n }\n \n if (solve(n, t/n, mx, rw, cnt)) {\n writeAns(n, t/n);\n return;\n }\n if (solve(t/n, n, mx, rw, cnt)) {\n writeAns(t/n, n);\n return;\n }\n }\n \n writeln(\"-1\");\n}"}], "src_uid": "fe24900ca557858ed8e6eb6e35a06c19"} {"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 q = RD!int;\r\n\tauto k = RD!int;\r\n\tauto a = RDA;\r\n\tauto w = new long[](n);\r\n\ta = 0L ~ a ~ (k+1L);\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tw[i] += a[i+1] - a[i] - 1;\r\n\t\tw[i] += a[i+2] - a[i+1] - 1;\r\n\t}\r\n\tauto ww = new long[](n+1);\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tww[i+1] = ww[i] + w[i];\r\n\t}\r\n\tdebug writeln(\"ww:\", ww);\r\n\r\n\tauto ans = new long[](q);\r\n\tforeach (i; 0..q)\r\n\t{\r\n\t\tauto l = RD!int-1;\r\n\t\tauto r = RD!int-1;\r\n\t\tans[i] = a[l] + a[$-1] - a[r+2];\r\n\t\tdebug writeln(\"a[l]:\", a[l] , \" a[r+2]:\", a[r+2] );\r\n\t\tans[i] += ww[r+1] - ww[l];\r\n\t\tdebug writeln(\"ww[r]:\", ww[r+1], \" ww[l]:\", ww[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}", "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 N, Q; long K; get(N, Q, K);\r\n long[] aa; get(aa);\r\n auto cs = new long[](N);\r\n foreach (i; 1..N-1) cs[i] = cs[i-1] + aa[i+1] - aa[i-1] - 2;\r\n\r\n while (Q--) {\r\n int l, r; get(l, r); --l; --r;\r\n writeln(l == r ? K-1 : aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);\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, q, k;\r\n\twhile (readf !(\" %s %s %s\") (n, q, k) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\ta = 0 ~ a ~ (k + 1);\r\n\t\tforeach (s; 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\tint res = a[l];\r\n\t\t\tres += k - a[r] - 1;\r\n\t\t\tres += 2 * (a[r] - a[l] - r + l);\r\n\t\t\twriteln (res);\r\n\t\t}\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 N, Q; long K; get(N, Q, K);\r\n long[] aa; get(aa);\r\n auto cs = new long[](N);\r\n foreach (i; 1..N-1) cs[i] = cs[i-1] + aa[i+1] - aa[i-1] - 2;\r\n\r\n while (Q--) {\r\n int l, r; get(l, r); --l; --r;\r\n writeln(aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);\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, Q, K; get(N, Q, K);\r\n int[] aa; get(aa);\r\n auto cs = new long[](N);\r\n foreach (i; 1..N-1) {\r\n cs[i] = cs[i-1];\r\n cs[i] += aa[i+1] - aa[i-1] - 2;\r\n }\r\n\r\n while (Q--) {\r\n int l, r; get(l, r); --l; --r;\r\n writeln(aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);\r\n }\r\n}"}], "src_uid": "740d2aba32f69b8cfe8f7cb624621a63"} {"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\nbool isSquare (int n)\r\n{\r\n\tauto p = cast (int) (sqrt (n * 1.0) + 0.5);\r\n\treturn p * p == 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\twhile (true)\r\n\t\t{\r\n\t\t\tif (n & 1)\r\n\t\t\t{\r\n\t\t\t\twriteln (\"NO\");\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tn /= 2;\r\n\t\t\tif (isSquare (n))\r\n\t\t\t{\r\n\t\t\t\twriteln (\"YES\");\r\n\t\t\t\tbreak;\r\n\t\t\t}\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\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\r\n\t\tif (n % 2) continue;\r\n\t\tfor (long i = 1; i*i <= n; ++i)\r\n\t\t{\r\n\t\t\tif (n % i) continue;\r\n\t\t\tif (i*i*2 == n || i*i*4 == n)\r\n\t\t\t{\r\n\t\t\t\tans[ti] = true;\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 ? \"YES\" : \"NO\");\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}, {"source_code": "import std.stdio;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\nimport std.math;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--)\n\t{\n\t\tlong n = readInt!int;\n\t\tbool isSquare(long q) { long r = cast(long) sqrt(cast(real)q); return r * r == q; }\n\t\tbool can = only(2, 4).any!(d => n % d == 0 && isSquare(n/d));\n\t\tif (can) \"YES\".writeln; else \"NO\".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"}], "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\n\r\nbool isSquare (int n)\r\n{\r\n\tauto p = cast (int) (sqrt (n * 1.0) + 0.5);\r\n\treturn p * p == 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\tforeach (j; 0..2)\r\n\t\t{\r\n\t\t\tif (n & 1)\r\n\t\t\t{\r\n\t\t\t\twriteln (\"NO\");\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\tn /= 2;\r\n\t\t\tif (isSquare (n))\r\n\t\t\t{\r\n\t\t\t\twriteln (\"YES\");\r\n\t\t\t\tbreak;\r\n\t\t\t}\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\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\r\n\t\tif (n == 1) continue;\r\n\t\tans[ti] = popcnt(n) == 1;\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}"}], "src_uid": "6ae754639d96790c890f9d1ab259332a"} {"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 M, N;\nint[][] A;\n\nbool check(int y0, int y1) {\n foreach (x; 0 .. M) {\n int cnt;\n foreach (y; 0 .. N) {\n const a = A[x][(y == y0) ? y1 : (y == y1) ? y0 : y];\n if (a != y) {\n ++cnt;\n }\n }\n if (cnt > 2) {\n return false;\n }\n }\n debug {\n writeln(\"ok \", y0, \" \", y1);\n }\n return true;\n}\n\nbool solve() {\n if (check(-1, -1)) {\n return true;\n }\n foreach (y0; 0 .. N) foreach (y1; y0 + 1 .. N) {\n if (check(y0, y1)) {\n return true;\n }\n }\n return false;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n M = readInt();\n N = readInt();\n A = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n A[x][y] = readInt() - 1;\n }\n \n const ans = solve();\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\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;\nint[20][20] a;\n\nbool check(const(int)[ ] where) {\n debug writeln(where);\n int[20][20] b = a;\n foreach (ref line; b[0 .. n]) {\n bool swapped = false;\n again:\n debug writeln(\"Line: \", line[0 .. m]);\n foreach (i; 0 .. m) {\n const what = line[i] - 1;\n debug writeln(i, ' ', what, ' ', where[what], ' ', i);\n if (where[what] != i) {\n if (swapped)\n return false;\n foreach (j; 0 .. m)\n if (where[line[j] - 1] == i) {\n swap(line[i], line[j]);\n debug writefln(\"Swapped %d and %d\", i, j);\n swapped = true;\n goto again;\n }\n }\n }\n }\n return true;\n}\n\nvoid main() {\n while (read(&n, &m)) {\n int[20] _trg;\n int[ ] trg = _trg[0 .. m];\n foreach (i; 0 .. m)\n trg[i] = i;\n foreach (ref line; a[0 .. n])\n foreach (ref x; line[0 .. m])\n read(&x);\n foreach (i; 0 .. n) {\n foreach (j; 0 .. m)\n debug write(a[i][j], ' ');\n debug writeln();\n }\n if (check(trg))\n write(\"YES\\n\");\n else {\n foreach (i, ref x; trg)\n foreach (ref y; trg[i + 1 .. m]) {\n swap(x, y);\n if (check(trg)) {\n write(\"YES\\n\");\n goto nextCase;\n }\n swap(x, y);\n }\n write(\"NO\\n\");\n }\n nextCase:\n ;\n }\n}\n"}], "negative_code": [], "src_uid": "8ab4db92e595b6a0a4c020693c5f2b24"} {"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 p = s[1];\n auto S = readln.chomp.to!(dchar[]);\n\n bool ans = false;\n\n for (int i = 0; i + p < N; ++i) {\n int j = i + p;\n if (S[i] == '.') {\n ans = true;\n if (S[i] == S[j]) {\n S[i] = '0';\n S[j] = '1';\n } else {\n S[i] = S[j] == '0' ? '1' : '0';\n }\n } else if (S[j] == '.') {\n ans = true;\n S[j] = S[i] == '0' ? '1' : '0';\n } else if (S[i] == '0' && S[j] == '1') {\n ans = true;\n } else if (S[i] == '1' && S[j] == '0') {\n ans = true;\n }\n }\n\n if (ans) {\n foreach (i; 0..N) if (S[i] == '.') S[i] = '0';\n S.writeln;\n } else {\n writeln(\"No\");\n }\n}\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\nvoid main()\n{\n int n, p;\n readf(\"%s %s\", &n, &p);\n readln;\n \n auto a = readln.chomp.to!(dchar[]);\n auto b = a.dup;\n foreach (ref e; b) if (e == '.') e = '0';\n \n auto c = b.dup;\n auto pos = a.indexOf('.');\n if (pos != -1) c[pos] = '1';\n \n auto d = b.dup;\n pos = a.lastIndexOf('.');\n if (pos != -1) d[pos] = '1';\n \n debug { b.writeln; c.writeln; d.writeln; }\n \n bool check(const dchar[] s, immutable int p) {\n foreach (st; 0..p) {\n auto sq = s.drop(st).stride(p);\n foreach (a, b; lockstep(sq, sq.dropOne)) {\n if (a != b) return true;\n }\n }\n return false;\n }\n \n writeln(check(b, p) ? b : check(c, p) ? c : check(d, p) ? d : \"No\");\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 p = s[1];\n auto S = readln.chomp.to!(dchar[]);\n\n bool ans = false;\n\n for (int i = 0; i + p < N; ++i) {\n int j = i + p;\n if (S[i] == '.') {\n ans = true;\n if (S[i] == S[j]) {\n S[i] = '0';\n S[j] = '1';\n } else {\n S[i] = S[j] == '0' ? '1' : '0';\n }\n } else if (S[j] == '.') {\n ans = true;\n S[j] = S[i] == '0' ? '1' : '0';\n } else if (S[i] == '0' && S[j] == '1') {\n ans = true;\n } else if (S[i] == '1' && S[j] == '0') {\n ans = true;\n }\n }\n\n if (ans) {\n writeln(\"Yes\");\n foreach (i; 0..N) if (S[i] == '.') S[i] = '0';\n S.writeln;\n } else {\n writeln(\"No\");\n }\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, p;\n readf(\"%s %s\", &n, &p);\n readln;\n \n auto a = readln.chomp.to!(dchar[]);\n auto b = a.dup;\n foreach (ref e; b) if (e == '.') e = '0';\n \n auto c = b.dup;\n auto pos = a.lastIndexOf('.');\n if (pos != -1) c[pos] = '1';\n \n debug { b.writeln; c.writeln; }\n \n bool check(const dchar[] s, immutable int p) {\n foreach (st; 0..p) {\n auto sq = s.drop(st).stride(p);\n foreach (a, b; lockstep(sq, sq.dropOne)) {\n if (a != b) return true;\n }\n }\n return false;\n }\n \n writeln(check(b, p) ? b : check(c, p) ? c : \"No\");\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, p;\n readf(\"%s %s\", &n, &p);\n readln;\n \n auto a = readln.chomp.to!(dchar[]);\n auto b = a.dup;\n foreach (ref e; b) if (e == '.') e = '0';\n \n auto c = b.dup;\n auto pos = a.indexOf('.');\n if (pos != -1) c[pos] = '1';\n \n debug { b.writeln; c.writeln; }\n \n bool check(const dchar[] s, immutable int p) {\n foreach (st; 0..p) {\n auto sq = s.drop(st).stride(p);\n foreach (a, b; lockstep(sq, sq.dropOne)) {\n if (a != b) return true;\n }\n }\n return false;\n }\n \n writeln(check(b, p) ? b : check(c, p) ? c : \"No\");\n}"}], "src_uid": "61a067dc6b8e04bfc661b7fa9ecb4eda"} {"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.array;\n string ans = a[0];\n string missing;\n int[] candel;\n foreach (x ; a[1 .. $]) {\n if (ans[$ - 1] == x[0]) {\n ans ~= x[1];\n } else if (missing == \"\") {\n missing ~= ans[$ - 1];\n missing ~= x[0];\n ans ~= missing[1];\n ans ~= x[1];\n } else {\n assert(false);\n }\n }\n if (missing == \"\") {\n ans ~= ans[$ - 1];\n }\n assert(n == ans.length);\n writeln(ans);\n }\n}\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n auto n = readInt!int;\n auto s = ma(n - 2, cast(byte[])readString);\n byte[] word;\n word ~= s[0][0];\n bool incident = false;\n foreach(i; 1 .. n - 2)\n {\n word ~= s[i-1][1];\n if (s[i][0] != s[i-1][1]) { assert(!incident); word ~= s[i][0]; incident = true; }\n }\n word ~= s[$-1][1];\n if (!incident) word ~= s[$-1][1];\n (cast(string)word).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": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n long n = scan;\n dchar[][] arr;\n for(int i = 0; i < n-2; ++i){\n arr ~= scan!(dchar[]);\n }\n show(arr);\n dchar[] w;\n w ~= arr[0];\n bool f = 0;\n for(int i = 1; i < n - 2; ++i){\n if(w.back == arr[i][0]){\n w ~= arr[i][1];\n }else{\n f = 1;\n w ~= arr[i];\n }\n }\n if(!f){\n w ~= 'a';\n }\n writeln(w);\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": "565056bfe716ee89230270bdc14c9051"} {"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 = readReal();\n auto X = new real[N];\n foreach (i; 0 .. N) {\n X[i] = readReal();\n }\n \n auto ans = new real[N];\n foreach (i; 0 .. N) {\n ans[i] = R;\n foreach (j; 0 .. i) {\n const dx = X[j] - X[i];\n if (dx <= 2 * R) {\n chmax(ans[i], ans[j] + sqrt((2 * R)^^2 - dx^^2));\n }\n }\n }\n \n foreach (i; 0 .. N) {\n if (i > 0) 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.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,r;\n scan(n,r);\n\n auto x = readln.split.to!(int[]);\n auto y = new double[](n);\n y[0] = r;\n\n foreach (i ; 1 .. n) {\n foreach (j ; 0 .. i) {\n if ((x[j] - x[i])^^2 <= 4*r*r) {\n real yi = y[j] + sqrt(4.0*r*r - pow(x[i] - x[j], 2));\n\n debug {\n writeln(yi);\n }\n\n if (y[i].isNaN) {\n y[i] = yi;\n }\n else if (yi > y[i]) {\n y[i] = yi;\n }\n }\n }\n\n if (y[i].isNaN) {\n y[i] = r;\n }\n }\n\n writefln(\"%(%.8f %)\", y);\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": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln, write, writef;\nimport std.string : chomp;\nimport std.array : split;\nimport std.conv : to;\nimport std.algorithm : min, max;\nimport std.math : sqrt;\n\nauto getVals(T)() {\n return readln.chomp.split.to!(T[]);\n}\n\nvoid main() {\n auto nr = getVals!int;\n auto n = nr[0], r = nr[1];\n auto ds = getVals!int;\n auto ans = new double[n];\n auto ps = new int[1001];\n auto rf = double(r);\n for (int i = 0; i < 1001; i++) { ps[i] = -1; }\n for (int i = 0; i < n; i++) {\n auto x = ds[i];\n auto lx = max(0, x - r);\n auto rx = min(1000, x + r);\n auto y = rf;\n for (int j = lx; j <= rx; j++) {\n if (ps[j] < 0) { continue; }\n auto pk = ps[j];\n auto px = ds[pk];\n auto ty = (rf+rf)*(rf+rf)-double(px-x)*double(px-x);\n if (ty < 0.0) { continue; }\n y = max(y, ans[pk] + sqrt(ty));\n }\n for (int j = lx; j <= rx; j++) {\n ps[j] = i;\n }\n ans[i] = y;\n }\n for (int i = 0; i < n; i++) {\n if (i > 0) { write(\" \"); }\n writef(\"%0.10f\", ans[i]);\n }\n writeln();\n}\n\n/*\ndef gs() gets.strip end\ndef gss() gs.split end\ndef gis() gss.map &:to_i end\ndef gfs() gss.map &:to_f end\n\nN, R = gis\nDS = gis\nRf = R.to_f\nps = [-1] * 1001\nans = []\nDS.each_with_index do |x,i|\n lx = [0, x - R].max\n rx = [1000, x + R].min\n y = Rf\n (lx..rx).each do |j|\n next if ps[j] < 0\n pk = ps[j]\n px = DS[pk]\n ty = (Rf+Rf)**2-(px-x).to_f**2\n next if ty < 0.0\n y = [y, ans[pk]+ty**0.5].max\n end\n (lx..rx).each do |j| ps[j] = i end\n ans << y\nend\n\nputs ans*' '\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;\nimport std.math;\n\nimmutable double EPS = 1e-9;\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) sc.read!true;\n\n int n;\n double r;\n sc.read(n, r);\n double[] x;\n sc.read(x);\n double[] y = new double[n];\n\n r *= 2;\n foreach (i; 0..n) {\n double pos = r/2;\n foreach (j; 0..i) {\n double di = abs(x[i]-x[j]);\n if (di > r + EPS) continue;\n double z = sqrt(max(0.0, r*r - di*di));\n pos = max(pos, y[j] + z);\n }\n y[i] = pos;\n writef(\"%.20f \", y[i]);\n }\n writeln;\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\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\nvoid main ()\n{\n\tint n;\n\treal r;\n\twhile (readf (\" %s %s\", &n, &r) > 0)\n\t{\n\t\treadln;\n\t\tr *= 2;\n\t\tauto x = readln.splitter.map !(to !(real)).array;\n\t\treal [] y;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto res = r * 0.5;\n\t\t\tforeach (j; 0..i)\n\t\t\t{\n\t\t\t\tauto d = abs (x[i] - x[j]);\n\t\t\t\tif (d <= r)\n\t\t\t\t{\n\t\t\t\t\tauto cur = sqrt (r ^^ 2 - d ^^ 2);\n\t\t\t\t\tres = max (res, y[j] + cur);\n\t\t\t\t}\n\t\t\t}\n\t\t\ty ~= res;\n\t\t}\n\t\twritefln (\"%(%.20g %)\", y);\n\t}\n}\n"}], "negative_code": [{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln, write, writef;\nimport std.string : chomp;\nimport std.array : split;\nimport std.conv : to;\nimport std.algorithm : min, max;\nimport std.math : sqrt;\n\nauto getVals(T)() {\n return readln.chomp.split.to!(T[]);\n}\n\nvoid main() {\n auto nr = getVals!int;\n auto n = nr[0], r = nr[1];\n auto ds = getVals!int;\n auto ans = new double[n];\n auto ps = new int[1001];\n auto rf = double(r);\n for (int i = 0; i < 1001; i++) { ps[i] = -1; }\n for (int i = 0; i < n; i++) {\n auto x = ds[i];\n auto lx = max(0, x - r);\n auto rx = min(1000, x + r);\n auto y = rf;\n for (int j = lx; j <= rx; j++) {\n if (ps[j] < 0) { continue; }\n auto pk = ps[j];\n auto px = ds[pk];\n auto ty = rf*rf*rf*rf-double(px-x)*double(px-x);\n if (ty < 0.0) { continue; }\n y = max(y, ans[pk] + sqrt(ty));\n }\n for (int j = lx; j <= rx; j++) {\n ps[j] = i;\n }\n ans[i] = y;\n }\n for (int i = 0; i < n; i++) {\n if (i > 0) { write(\" \"); }\n writef(\"%0.10f\", ans[i]);\n }\n writeln();\n}\n\n/*\ndef gs() gets.strip end\ndef gss() gs.split end\ndef gis() gss.map &:to_i end\ndef gfs() gss.map &:to_f end\n\nN, R = gis\nDS = gis\nRf = R.to_f\nps = [-1] * 1001\nans = []\nDS.each_with_index do |x,i|\n lx = [0, x - R].max\n rx = [1000, x + R].min\n y = Rf\n (lx..rx).each do |j|\n next if ps[j] < 0\n pk = ps[j]\n px = DS[pk]\n ty = (Rf+Rf)**2-(px-x).to_f**2\n next if ty < 0.0\n y = [y, ans[pk]+ty**0.5].max\n end\n (lx..rx).each do |j| ps[j] = i end\n ans << y\nend\n\nputs ans*' '\n\n*/"}], "src_uid": "3cd019d1016cb3b872ea956c312889eb"} {"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\nbool less (string s, string t)\n{\n\tif (s.length != t.length)\n\t{\n\t\treturn s.length < t.length;\n\t}\n\treturn s < t;\n}\n\nstring normalize (string s)\n{\n\tint [] a;\n\tforeach_reverse (c; s)\n\t{\n\t\ta ~= c - '0';\n\t}\n\ta ~= 0.repeat (a.length + 10).array;\n\tbool ok = false;\n\twhile (!ok)\n\t{\n\t\tok = true;\n\t\tforeach_reverse (i; 0..a.length - 2)\n\t\t{\n\t\t\tint e = a[i] / 2;\n\t\t\tif (e > 0)\n\t\t\t{\n\t\t\t\tassert (i >= 2);\n\t\t\t\tok = false;\n\t\t\t\ta[i] -= 2 * e;\n\t\t\t\ta[i - 2] += e;\n\t\t\t\ta[i + 1] += e;\n\t\t\t}\n\t\t\tint d = min (a[i], a[i + 1]);\n\t\t\tif (d > 0)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\ta[i + 2] += d;\n\t\t\t\ta[i] -= d;\n\t\t\t\ta[i + 1] -= d;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..a.length - 2)\n\t\t{\n\t\t\tint e = a[i] / 2;\n\t\t\tif (e > 0)\n\t\t\t{\n\t\t\t\tassert (i >= 2);\n\t\t\t\tok = false;\n\t\t\t\ta[i] -= 2 * e;\n\t\t\t\ta[i - 2] += e;\n\t\t\t\ta[i + 1] += e;\n\t\t\t}\n\t\t\tint d = min (a[i], a[i + 1]);\n\t\t\tif (d > 0)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\ta[i + 2] += d;\n\t\t\t\ta[i] -= d;\n\t\t\t\ta[i + 1] -= d;\n\t\t\t}\n\t\t}\n\t}\n\n\twhile (a.length > 1 && a[$ - 1] == 0)\n\t{\n\t\ta.length--;\n\t}\n\treverse (a);\n\treturn format (\"%(%s%)\", a);\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile (!(s = readln.strip).empty)\n\t{\n\t\tstring t = readln.strip;\n\t\ts = normalize (s);\n\t\tt = normalize (t);\n\t\tdebug {writeln (s, ' ', t);}\n\t\twriteln (less (s, t) ? '<' : less (t, s) ? '>' : '=');\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[] reduce(string s, int n) {\n\tint[] ret = new int[n];\n\tforeach (i; 0 .. s.length) {\n\t\tret[n - s.length + i] = s[i] - '0';\n\t}\n\tforeach (_; 0 .. 20) {\n\t\tforeach_reverse (i; 0 .. n - 2) {\n\t\t\tconst tmp = min(ret[i + 1], ret[i + 2]);\n\t\t\tret[i] += tmp;\n\t\t\tret[i + 1] -= tmp;\n\t\t\tret[i + 2] -= tmp;\n\t\t}\n\t\tforeach (i; 0 .. n - 3) {\n\t\t\tif (ret[i + 1] > 1) {\n\t\t\t\tret[i] += 1;\n\t\t\t\tret[i + 1] -= 2;\n\t\t\t\tret[i + 3] += 1;\n\t\t\t}\n\t\t}\n\t}\n\treturn ret;\n}\n\nstring A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = readToken;\n\t\tB = readToken;\n\t\t\n\t\tconst int n = max(A.length, B.length) + 1;\n\t\tauto as = A.reduce(n);\n\t\tauto bs = B.reduce(n);\ndebug{\nwriteln(as);\nwriteln(bs);\n}\n\t\t\n\t\tint ans;\n\t\t/*\n\t\tforeach (i; 0 .. n) {\n\t\t\tif (as[i] != bs[i]) {\n\t\t\t\tans = (as[i] < bs[i]) ? -1 : +1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t*/\n\t\t/*\n\t\tforeach (i; 0 .. n) {\n\t\t\tif (as[i] < bs[i]) {\n\t\t\t\tif (i < n - 2 && as[i + 1] && as[i + 2]) {\n\t\t\t\t\t--bs[i];\n\t\t\t\t\t--as[i + 1];\n\t\t\t\t\t--as[i + 2];\n\t\t\t\t} else {\n\t\t\t\t\tans = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (as[i] > bs[i]) {\n\t\t\t\tif (i < n - 2 && bs[i + 1] && bs[i + 2]) {\n\t\t\t\t\t--as[i];\n\t\t\t\t\t--bs[i + 1];\n\t\t\t\t\t--bs[i + 2];\n\t\t\t\t} else {\n\t\t\t\t\tans = +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 = (as < bs) ? -1 : (as > bs) ? +1 : 0;\n\t\twriteln(\"<=>\"[1 + ans]);\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.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nbool less (string s, string t)\n{\n\tif (s.length != t.length)\n\t{\n\t\treturn s.length < t.length;\n\t}\n\treturn s < t;\n}\n\nstring normalize (string s)\n{\n\tint [] a;\n\tforeach_reverse (c; s)\n\t{\n\t\ta ~= c - '0';\n\t}\n\ta ~= 0.repeat (a.length).array;\n\tint i = 0;\n\twhile (i < a.length)\n\t{\n\t\tif (a[i] >= 2)\n\t\t{\n\t\t\tassert (i >= 2);\n\t\t\ta[i] -= 2;\n\t\t\ta[i - 2]++;\n\t\t\ta[i + 1]++;\n\t\t\ti -= 2;\n\t\t\tcontinue;\n\t\t}\n\t\tint d = min (a[i], a[i + 1]);\n\t\tif (d > 0)\n\t\t{\n\t\t\ta[i + 2] += d;\n\t\t\ta[i] -= d;\n\t\t\ta[i + 1] -= d;\n\t\t}\n\t\ti++;\n\t}\n\n\twhile (a.length > 1 && a[$ - 1] == 0)\n\t{\n\t\ta.length--;\n\t}\n\treverse (a);\n\treturn format (\"%(%s%)\", a);\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile (!(s = readln.strip).empty)\n\t{\n\t\tstring t = readln.strip;\n\t\ts = normalize (s);\n\t\tt = normalize (t);\n\t\twriteln (less (s, t) ? '<' : less (t, s) ? '>' : '=');\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\nbool less (string s, string t)\n{\n\tif (s.length != t.length)\n\t{\n\t\treturn s.length < t.length;\n\t}\n\treturn s < t;\n}\n\nstring normalize (string s)\n{\n\tint [] a;\n\tforeach_reverse (c; s)\n\t{\n\t\ta ~= c - '0';\n\t}\n\ta ~= 0.repeat (a.length + 10).array;\n\tint i = 0;\n\twhile (i < a.length - 2)\n\t{\n\t\tif (a[i] >= 2)\n\t\t{\n\t\t\tassert (i >= 2);\n\t\t\ta[i] -= 2;\n\t\t\ta[i - 2]++;\n\t\t\ta[i + 1]++;\n\t\t\ti -= 2;\n\t\t\tcontinue;\n\t\t}\n\t\tint d = min (a[i], a[i + 1]);\n\t\ta[i + 2] += d;\n\t\ta[i] -= d;\n\t\ta[i + 1] -= d;\n\t\ti++;\n\t}\n\n\twhile (a.length > 1 && a[$ - 1] == 0)\n\t{\n\t\ta.length--;\n\t}\n\treverse (a);\n\treturn format (\"%(%s%)\", a);\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile (!(s = readln.strip).empty)\n\t{\n\t\tstring t = readln.strip;\n\t\ts = normalize (s);\n\t\tt = normalize (t);\n\t\twriteln (less (s, t) ? '<' : less (t, s) ? '>' : '=');\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[] reduce(string s, int n) {\n\tint[] ret = new int[n];\n\tforeach (i; 0 .. s.length) {\n\t\tret[n - s.length + i] = s[i] - '0';\n\t}\n\t/*\n\tforeach_reverse (i; 0 .. n - 2) {\n\t\tconst tmp = min(ret[i + 1], ret[i + 2]);\n\t\tret[i] += tmp;\n\t\tret[i + 1] -= tmp;\n\t\tret[i + 2] -= tmp;\n\t}\n\t*/\n\treturn ret;\n}\n\nstring A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = readToken;\n\t\tB = readToken;\n\t\t\n\t\tconst int n = max(A.length, B.length) + 1;\n\t\tauto as = A.reduce(n);\n\t\tauto bs = B.reduce(n);\ndebug{\nwriteln(as);\nwriteln(bs);\n}\n\t\t\n\t\tint ans;\n\t\t/*\n\t\tforeach (i; 0 .. n) {\n\t\t\tif (as[i] != bs[i]) {\n\t\t\t\tans = (as[i] < bs[i]) ? -1 : +1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t*/\n\t\tforeach (i; 0 .. n) {\n\t\t\tif (as[i] < bs[i]) {\n\t\t\t\tif (i < n - 2 && as[i + 1] && as[i + 2]) {\n\t\t\t\t\t--bs[i];\n\t\t\t\t\t--as[i + 1];\n\t\t\t\t\t--as[i + 2];\n\t\t\t\t} else {\n\t\t\t\t\tans = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (as[i] > bs[i]) {\n\t\t\t\tif (i < n - 2 && bs[i + 1] && bs[i + 2]) {\n\t\t\t\t\t--as[i];\n\t\t\t\t\t--bs[i + 1];\n\t\t\t\t\t--bs[i + 2];\n\t\t\t\t} else {\n\t\t\t\t\tans = +1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln(\"<=>\"[1 + 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\nchar[] reduce(string s, int n) {\n\tchar[] ret = new char[n];\n\tret[] = '0';\n\tforeach (i; 0 .. s.length) {\n\t\tret[n - s.length + i] = s[i];\n\t}\n\tforeach (i; 0 .. n - 2) {\n\t\tif (ret[i + 1] == '1' && ret[i + 2] == '1') {\n\t\t\tret[i] = '1';\n\t\t\tret[i + 1] = '0';\n\t\t\tret[i + 2] = '0';\n\t\t}\n\t}\n\treturn ret;\n}\n\nstring A, B;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = readToken;\n\t\tB = readToken;\n\t\t\n\t\tconst int n = max(A.length, B.length) + 1;\n\t\tchar[] as = A.reduce(n);\n\t\tchar[] bs = B.reduce(n);\ndebug{\nwriteln(as);\nwriteln(bs);\n}\n\t\t\n\t\tint ans;\n\t\tforeach (i; 0 .. n) {\n\t\t\tif (as[i] != bs[i]) {\n\t\t\t\tans = (as[i] < bs[i]) ? -1 : +1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\twriteln(\"<=>\"[1 + ans]);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "src_uid": "7c0a288a2777894bdfd75cb9703346e9"} {"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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]n/4){writeln(\"===\");return;}\n\t\tforeach(i;s)\n\t\t{\n\t\t\tif(i!='?')write(i);\n\t\t\telse if(d[0]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-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]n/4){writeln(\"===\");return;}\n\t\tforeach(i;s)\n\t\t{\n\t\t\tif(i!='?')write(i);\n\t\t\telse if(d[0] pows[i] != mostCommonPow).map!(i => b[i]).array);\n}\n\nvoid printArr(Arr)(Arr arr)\n{\n println(arr.length, arr);\n}\n\nint log2(long x)\n{\n int cnt = 0;\n while((x & 1) == 0) {cnt++; x >>= 1;}\n return cnt;\n}\n\nauto mode(Arr, size_t n = 0)(Arr arr)\n{\n alias Elem = typeof(arr.front);\n static if (n == 0)\n {\n size_t[Elem] cnt;\n Elem res;\n cnt[res] = 0;\n foreach(elem; arr)\n\t{\n\t cnt.require(elem, 0)++;\n\t if (cnt[elem] > cnt[res])\n\t res = elem;\n\t}\n return res;\n }\n else\n {\n size_t[n] cnt;\n Elem res = 0;\n foreach(elem; arr)\n\t{\n\t cnt[elem]++;\n\t if (cnt[elem] > cnt[res])\n\t res = elem;\n\t}\n return res;\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 (is(typeof((){foreach(e; ti) print(e);}())))\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 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 long pw = 1;\n int bestcnt = 0; long bestpw = -1;\n foreach (_; 0 .. 60) {\n int cur = 0;\n foreach (e; arr) {\n if (e % pw == 0 && e % (2*pw) != 0) {\n ++cur;\n }\n }\n \n debug { writeln(pw, ' ', cur); }\n if (cur > bestcnt) {\n bestcnt = cur;\n bestpw = pw;\n }\n \n pw *= 2;\n }\n \n debug { bestpw.writeln; }\n \n long[] ans;\n foreach (e; arr) {\n if (e % bestpw == 0 && e % (bestpw * 2) != 0) { continue; }\n \n ans ~= e;\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;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!long).array;\n \n long pw = 1;\n int bestcnt = 0; long bestpw = -1;\n foreach (_; 0 .. 60) {\n int cur = 0;\n foreach (e; arr) {\n if (e % pw == 0 && e % (2*pw) != 0) {\n ++cur;\n }\n }\n \n debug { writeln(pw, ' ', cur); }\n if (cur > bestcnt) {\n bestcnt = cur;\n bestpw = pw;\n }\n \n pw *= 2;\n }\n \n debug { bestpw.writeln; }\n \n long[] ans;\n foreach (e; arr) {\n if (e % bestpw == 0 && e % (bestpw * 2) != 0) { continue; }\n \n ans ~= e;\n }\n \n ans.length.writeln;\n ans.writefln!(\"%(%s %)\");\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!long).array;\n \n bool isExactlyDivisible(long x, long pw2) { \n return x % pw2 == 0 && x % (pw2 * 2) != 0;\n }\n \n long pw = 1;\n int bestcnt = 0; long bestpw = -1;\n foreach (_; 0 .. 60) {\n int cur = 0;\n foreach (e; arr) {\n if (isExactlyDivisible(e, pw)) {\n ++cur;\n }\n }\n \n debug { writeln(pw, ' ', cur); }\n if (cur > bestcnt) {\n bestcnt = cur;\n bestpw = pw;\n }\n \n pw *= 2;\n }\n \n debug { bestpw.writeln; }\n \n long[] ans;\n foreach (e; arr) {\n if (isExactlyDivisible(e, bestpw)) { continue; }\n \n ans ~= e;\n }\n \n ans.length.writeln;\n ans.map!(to!string).join(\" \").writeln;\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;\nlong[] B;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n B = new long[N];\n foreach (i; 0 .. N) {\n B[i] = readLong();\n }\n \n auto cnt = new int[64];\n foreach (i; 0 .. N) {\n ++cnt[bsf(B[i])];\n }\n const em = cnt.maxIndex;\n \n writeln(N - cnt[em]);\n int ou;\n foreach (i; 0 .. N) {\n if (em != bsf(B[i])) {\n if (ou++) write(\" \");\n write(B[i]);\n }\n }\n writeln();\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;\nimport std.range;\nimport std.numeric;\nimport std.traits;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto b = next!long(n);\n auto pows = b.map!log2.array;\n auto mostCommonPow = pows.mode!(int[], 65);\n auto indicesToRemove = iota(0, n).filter!(i => pows[i] != mostCommonPow).array; \n println(indicesToRemove.length, indicesToRemove.map!(i => b[i]));\n}\n\nint log2(long x)\n{\n int cnt = 0;\n while((x & 1) == 0) {cnt++; x >>= 1;}\n return cnt;\n}\n\nauto mode(Arr, size_t n = 0)(Arr arr)\n{\n alias Elem = typeof(arr.front);\n static if (n == 0)\n {\n size_t[Elem] cnt;\n Elem res;\n cnt[res] = 0;\n foreach(elem; arr)\n\t{\n\t cnt.require(elem, 0)++;\n\t if (cnt[elem] > cnt[res])\n\t res = elem;\n\t}\n return res;\n }\n else\n {\n size_t[n] cnt;\n Elem res = 0;\n foreach(elem; arr)\n\t{\n\t cnt[elem]++;\n\t if (cnt[elem] > cnt[res])\n\t res = elem;\n\t}\n return res;\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 (is(typeof((){foreach(e; ti) print(e);}())))\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;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto b = next!long(n);\n int[65] powcnt;\n int maxpow = 0;\n foreach(bi; b)\n {\n auto p = log2(bi);\n powcnt[p]++;\n if (powcnt[p] > powcnt[maxpow])\n\tmaxpow = p;\n }\n writeln(n - powcnt[maxpow]);\n foreach(bi; b)\n {\n auto p = log2(bi);\n if (p != maxpow) write(bi, \" \");\n }\n writeln;\n}\n\nint log2(long x)\n{\n int cnt = 0;\n while((x & 1) == 0) {cnt++; 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] = 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;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto b = next!long(n);\n auto pows = b.map!log2;\n auto mostCommonPow = pows.mode;\n auto indicesToRemove = iota(0, n).filter!(i => pows[i] != mostCommonPow).array;\n println(indicesToRemove.length, indicesToRemove.map!(i => b[i]));\n}\n\nint log2(long x)\n{\n int cnt = 0;\n while((x & 1) == 0) {cnt++; x >>= 1;}\n return cnt;\n}\n\nauto mode(Arr)(Arr arr)\n{\n alias Elem = typeof(arr.front);\n size_t[Elem] cnt;\n Elem res;\n cnt[res] = 0;\n foreach(elem; arr)\n {\n cnt.require(elem, 0)++;\n if (cnt[elem] > cnt[res])\n\tres = elem;\n }\n return res;\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 (is(typeof((){foreach(e; ti) print(e);}())))\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": [], "src_uid": "679f7243fe1e072af826a779c44b5056"} {"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, c, n;\n readf!\" %d %d %d \"(a, b, c);\n n = 2 * (max(a, b) - min(a, b));\n if (max(a, b, c) > n)\n writeln(-1);\n else\n writeln(((c - 1) + n / 2) % n + 1);\n }\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid theCode(){\n ll a = scan;\n ll b = scan;\n ll c = scan;\n ll hf = abs(a - b);\n ll n = 2 * hf;\n if(n < max(a, b, c)){\n writeln(-1);\n }else{\n ll rem = (c + hf) % n;\n if(rem == 0){\n writeln(n);\n }else{\n writeln(rem);\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"}], "negative_code": [], "src_uid": "07597a8d08b59d4f8f82369bb5d74a49"} {"source_code": "import std.stdio, std.algorithm, std.range, std.conv, std.string;\nimport std.math;\n\nvoid main() {\n int n, x;\n readf(\"%d %d\\n\", &n, &x);\n int[] hands = readln.chomp.split.map!(to!int).array;\n int rest = hands.sum.abs;\n ceil(cast(double)rest / x).writeln;\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, x;\n readf(\"%d %d\\n\", &n, &x);\n long sum = readln.chomp.split(\" \").map!(to!int).reduce!\"a + b\".abs;\n writeln(sum / x + (sum % x != 0));\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.range, std.conv, std.string;\nimport std.math;\n\nvoid main() {\n int n, x;\n readf(\"%d %d\\n\", &n, &x);\n int[] hands = readln.chomp.split.map!(to!int).array;\n int[] cards = new int[x + 1];\n foreach (e; hands) {\n if (e > 0) {\n cards[e]++;\n } else if (e < 0) {\n cards[-e]--;\n }\n }\n\n cards.map!\"abs(a)\".sum.writeln;\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.range, std.conv, std.string;\nimport std.math;\n\nvoid main() {\n int n, x;\n readf(\"%d %d\\n\", &n, &x);\n int[] hands = readln.chomp.split.map!(to!int).array;\n int rest = hands.sum;\n ceil(cast(double)rest / x).writeln;\n}\n"}], "src_uid": "066906ee58af5163636dac9334619ea7"} {"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\tif (x > y)\r\n\t\t{\r\n\t\t\twriteln (x + y);\r\n\t\t}\r\n\t\telse if (x == y)\r\n\t\t{\r\n\t\t\twriteln (x);\r\n\t\t}\r\n\t\telse if (x < y)\r\n\t\t{\r\n\t\t\tint rem = y % x;\r\n\t\t\tint eps = rem / 2;\r\n\t\t\twriteln (y - eps);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tassert (false);\r\n\t\t}\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto x = readInt!long;\n\tauto y = readInt!long;\n\tif (x == y) return writeln(x);\n\tif (x > y) return writeln(x + y);\n\tauto alpha = (y - 1) % x;\n\tassert (alpha % 2 == 1);\n\twriteln(y - 1 - (alpha - 1)/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"}, {"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\nlong solve(long X, long Y) {\r\n const c = Y / X, d = Y % X;\r\n long a, b, r;\r\n if (c == 0) {\r\n a = 1;\r\n b = 0;\r\n r = d;\r\n } else {\r\n a = c;\r\n b = 1;\r\n r = d / 2;\r\n }\r\n const n = X * a + r;\r\n debug {\r\n // writeln(X, \" \", Y, \": \", n);\r\n }\r\n assert(1 <= n); assert(n <= 2 * max(X, Y)^^2);\r\n assert(n % X == Y % n);\r\n return n;\r\n}\r\n\r\nvoid main() {\r\n debug {{\r\n enum lim = 100;\r\n for (long x = 2; x <= lim; x += 2) for (long y = 2; y <= lim; y += 2) {\r\n solve(x, y);\r\n }\r\n }}\r\n \r\n try {\r\n for (; ; ) {\r\n const numCases = readInt();\r\n foreach (_; 0 .. numCases) {\r\n const X = readLong();\r\n const Y = readLong();\r\n \r\n const ans = solve(X, Y);\r\n writeln(ans);\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "a24aac9152417527d43b9b422e3d2303"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.typecons;\n\n int n; rd(n);\n auto y=readln.split.to!(long[]);\n\n alias pt=Tuple!(long, \"x\", long ,\"y\");\n pt[] f(long dy, long dx){\n pt[] rt;\n foreach(x; 1..n){\n long dy_=y[x]-y[0];\n if(dy*x!=dy_*dx) rt~=pt(x, y[x]);\n }\n return rt;\n }\n\n bool g(long _dy, long _dx, pt[] ys){\n if(ys.length==0) return false;\n if(ys.length==1) return true;\n long dy=ys[1].y-ys[0].y;\n long dx=ys[1].x-ys[0].x;\n if(_dy*dx!=dy*_dx) return false;\n foreach(i; 1..ys.length){\n long dy_=ys[i].y-ys[0].y;\n long dx_=ys[i].x-ys[0].x;\n if(dy*dx_!=dy_*dx) return false;\n }\n return true;\n }\n\n foreach(x; 1..n){\n long dy=y[x]-y[0];\n // int dx=x;\n auto rs=f(dy, x);\n // writeln(x, \" \", rs);\n\n if(g(dy, x, rs)){\n writeln(\"Yes\");\n return;\n }\n }\n\n // l1={1}, l2={2, 3, ..., n};\n long dydy=y[2]-y[1];\n // int dxdx=2-1;\n pt[] rsrs;\n foreach(x; 2..y.length){\n long dy_dy=y[x]-y[1];\n if(dydy*(x-1)!=dy_dy*1) rsrs~=pt(x, y[x]);\n }\n if(rsrs.length==0){\n if(y[1]-y[0]!=dydy){\n writeln(\"Yes\"); return;\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 foreach(i, ref e; x){\n e=l[i].to!(typeof(e));\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 Y = new long[N];\n foreach (x; 0 .. N) {\n Y[x] = readLong();\n }\n \n bool ans;\n foreach (i; 0 .. 2) {\n foreach (j; 0 .. N) {\n if (i != j) {\n // (i, Y[i]), (j, Y[j])\n int[] xs;\n foreach (x; 0 .. N) {\n if ((j - i) * (Y[x] - Y[i]) != (Y[j] - Y[i]) * (x - i)) {\n xs ~= x;\n }\n }\n if (!xs.empty) {\n bool ok = true;\n foreach (x; xs) {\n if ((j - i) * (Y[x] - Y[xs[0]]) != (Y[j] - Y[i]) * (x - xs[0])) {\n ok = false;\n }\n }\n if (ok) {\n ans = true;\n }\n }\n }\n }\n }\n writeln(ans ? \"Yes\" : \"No\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "c54042eebaef01783a74d31521db9baa"} {"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 M = s[1];\n auto G = new Tuple!(int, int, int)[][](N);\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n G[s[0]-1] ~= tuple(s[1]-1, i, 0);\n G[s[1]-1] ~= tuple(s[0]-1, i, 1);\n }\n\n auto C = new int[](N);\n C[] = -1;\n\n bool dfs(int n, int c) {\n if (C[n] != -1) {\n return C[n] == c;\n }\n C[n] = c;\n foreach (m; G[n]) {\n if (!dfs(m[0], c^1)) {\n return false;\n }\n }\n return true;\n }\n\n if (!dfs(0, 0)) {\n writeln(\"NO\");\n return;\n }\n\n auto ans = new int[](M);\n foreach (i; 0..N) {\n foreach (e; G[i]) {\n if (C[i] != e[2]) {\n ans[e[1]] = 1;\n } \n }\n }\n\n writeln(\"YES\");\n ans.map!(to!string).join(\"\").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, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n Tuple!(int, int)[] edges;\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[u] ~= v;\n g[v] ~= u;\n edges ~= tuple(u, v);\n }\n \n auto clr = new int[] (n);\n bool dfs(int v, int clrnow) {\n auto ok = true;\n clr[v] = clrnow;\n foreach (u; g[v]) {\n if (clr[u] == 0) { ok &= dfs(u, 3 - clrnow); }\n else if (clr[u] == clrnow) { return false; }\n }\n \n return ok;\n }\n \n auto ok = dfs(1, 1);\n \n if (!ok) {\n writeln(\"NO\");\n return;\n }\n \n int[] ans;\n foreach (e; edges) {\n ans ~= clr[e[0]] - 1;\n }\n \n writeln(\"YES\");\n ans.writefln!\"%(%s%)\";\n}"}], "negative_code": [], "src_uid": "981e9991fb5dbd085db8a408c29564d4"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, k; rd(n, k);\n auto a=readln.split.to!(int[]);\n\n int num=0, c=1;\n sort(a);\n // writeln(a);\n foreach(i; 1..n){\n if(a[i-1]==a[i]){\n c++;\n }else{\n if(a[i-1]+k= 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, k;\n\tread(n, k);\n\tauto a = arread!int;\n\tsort(a);\n\tdebug writeln(a);\n\tint p;\n\tint c = 1;\n\tforeach (i; 1 .. n)\n\t{\n\t\tif (a[i] > a[i - 1] && a[i] <= a[i - 1] + k)\n\t\t{\n\t\t\tp += c;\n\t\t\tc = 1;\n\t\t}\n\t\telse if (a[i] == a[i - 1])\n\t\t\tc++;\n\t\telse\n\t\t\tc = 1;\n\t}\n\twriteln(n - p);\n}\n"}], "negative_code": [], "src_uid": "be8be333d036f6c19b9a6eb33f96ba75"} {"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\tbool [int] used;\n\t\tint [] p;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tif (c !in used)\n\t\t\t{\n\t\t\t\tp ~= c;\n\t\t\t\tused[c] = true;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%s %)\") (p);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string : split, strip;\nimport std.algorithm : map, joiner;\nimport std.conv : to, 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\n auto a = readln.strip.split.map!(to!int);\n bool[] s = new bool[n];\n int[] o = new int[n];\n\n int p = 0;\n\n foreach (j; a) {\n if (s[j-1]) continue;\n s[j-1] = true;\n\n o[p++] = j;\n }\n\n writeln(o.map!text.joiner(\" \"));\n }\n}"}], "negative_code": [], "src_uid": "aaf91874cf5aa0fa302ffed2ccecdc76"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1497/problem/A\n// sorting, greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.container;\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 auto unique = redBlackTree(a);\n auto dups = redBlackTree!true(a);\n\n foreach(number; unique) {\n writef(\"%s \", number);\n dups.removeKey(number);\n }\n foreach(number; dups) {\n writef(\"%s \", number);\n }\n \"\".writeln;\n}\n}\n\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, res;\r\n a.sort();\r\n foreach (i; 0 .. n)\r\n if (!i || a[i] != a[i - 1])\r\n res ~= [a[i]];\r\n foreach (i; 0 .. n)\r\n if (i && a[i] == a[i - 1])\r\n res ~= [a[i]];\r\n res.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 a = RDA!int;\r\n\r\n\t\tauto cnt = new long[](101);\r\n\t\tforeach (e; a)\r\n\t\t\t++cnt[e];\r\n\r\n\t\tint[] rem;\r\n\t\tforeach (i; 0..cnt.length)\r\n\t\t{\r\n\t\t\tif (cnt[i] == 0) continue;\r\n\t\t\tans[ti] ~= cast(int)i;\r\n\t\t\tforeach (j; 1..cnt[i])\r\n\t\t\t\trem ~= cast(int)i;\r\n\t\t}\r\n\t\tans[ti] ~= rem;\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": "// Vicfred\n// https://codeforces.com/contest/1497/problem/A\n// sorting, greedy\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nlong mex(long[] numbers) {\n long[long] missing;\n foreach(number; numbers) {\n missing[number] = 1L;\n }\n\n long mex = 0L;\n for(long i = 0L; i <= 100L; ++i) {\n auto p = (i in missing);\n if(p is null) {\n mex = i;\n return mex;\n }\n }\n return mex;\n}\n\nvoid main() {\n long t = readln.chomp.to!long;\n\nwhile(t--) {\n long n = readln.chomp.to!long;\n long[] a = readln.split.map!(to!long).array;\n a.sort;\n \n foreach(number; a) {\n writef(\"%s \", number);\n } \"\".writeln;\n}\n}\n\n"}], "src_uid": "69838d9f9214c65b84a21d4eb546ea4b"} {"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 long infinity = long.max / 8;\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\r\n\t\talias Rain = Tuple !(long, q{x}, long, q{p});\r\n\t\tauto r = new Rain [n];\r\n\t\tforeach (ref c; r)\r\n\t\t{\r\n\t\t\treadf !(\" %s %s\") (c.x, c.p);\r\n\t\t}\r\n\r\n\t\talias Event = Tuple !(long, q{x}, long, q{delta});\r\n\t\tEvent [] e;\r\n\t\te.reserve (n * 3);\r\n\t\tforeach (ref c; r)\r\n\t\t{\r\n\t\t\te ~= Event (c.x - c.p, +1);\r\n\t\t\te ~= Event (c.x, -2);\r\n\t\t\te ~= Event (c.x + c.p, +1);\r\n\t\t}\r\n\t\tsort (e);\r\n\r\n\t\tauto x = new long [n * 3];\r\n\t\tauto y = new long [n * 3];\r\n\t\tlong cur = e[0].delta;\r\n\t\tx[0] = e[0].x;\r\n\t\tforeach (i; 1..n * 3)\r\n\t\t{\r\n\t\t\tx[i] = e[i].x;\r\n\t\t\ty[i] = y[i - 1] + cur * (x[i] - x[i - 1]);\r\n\t\t\tcur += e[i].delta;\r\n\t\t}\r\n\r\n\t\tauto lo = new long [n * 3];\r\n\t\tlo[0] = -infinity;\r\n\t\tforeach (i; 1..n * 3)\r\n\t\t{\r\n\t\t\tlo[i] = lo[i - 1];\r\n\t\t\tif (y[i] > m)\r\n\t\t\t{\r\n\t\t\t\tlo[i] = max (lo[i], y[i] - x[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto hi = new long [n * 3];\r\n\t\thi[$ - 1] = -infinity;\r\n\t\tforeach_reverse (i; 0..n * 3 - 1)\r\n\t\t{\r\n\t\t\thi[i] = hi[i + 1];\r\n\t\t\tif (y[i] > m)\r\n\t\t\t{\r\n\t\t\t\thi[i] = max (hi[i], y[i] + x[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto xs = x.assumeSorted ();\r\n\r\n\t\tauto answer = new bool [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tanswer[i] = true;\r\n\t\t\tauto pos = xs.lowerBound (r[i].x).length;\r\n\t\t\tanswer[i] &= (lo[pos] + x[pos] - r[i].p <= m);\r\n\t\t\tanswer[i] &= (hi[pos] - x[pos] - r[i].p <= m);\r\n\t\t}\r\n\r\n\t\twritefln !(\"%(%d%)\") (answer);\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 = readLong;\n auto X = new long[N];\n auto P = new long[N];\n foreach (i; 0 .. N) {\n X[i] = readLong;\n P[i] = readLong;\n }\n \n alias Entry = Tuple!(long, \"x\", long, \"a\", long, \"b\");\n auto es = new Entry[3 * N];\n foreach (i; 0 .. N) {\n es[i * 3 + 0] = Entry(X[i] - P[i], +1, -(X[i] - P[i]));\n es[i * 3 + 1] = Entry(X[i] , -2, +2 * X[i]);\n es[i * 3 + 2] = Entry(X[i] + P[i], +1, -(X[i] + P[i]));\n }\n es.sort;\n \n long maxS = long.min;\n long maxT = long.min;\n {\n long a, b;\n foreach (ref e; es) {\n const x = e.x;\n const y = (a * x + b) - M;\n debug {\n writeln(x, \" \", y);\n }\n if (y > 0) {\n chmax(maxS, y + x);\n chmax(maxT, y - x);\n }\n a += e.a;\n b += e.b;\n }\n }\n \n auto ans = new char[N];\n foreach (i; 0 .. N) {\n const s = P[i] + X[i];\n const t = P[i] - X[i];\n ans[i] = (s >= maxS && t >= maxT) ? '1' : '0';\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "268cf03c271d691c3c1e3922e884753e"} {"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\tforeach (i; 0..n/2)\r\n\t\t{\r\n\t\t\tans[ti] ~= [1, i+1, n-i];\r\n\t\t\tans[ti] ~= [1, i+1, n-i];\r\n\t\t\tans[ti] ~= [2, i+1, n-i];\r\n\t\t\tans[ti] ~= [1, i+1, n-i];\r\n\t\t\tans[ti] ~= [1, i+1, n-i];\r\n\t\t\tans[ti] ~= [2, i+1, n-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\tforeach (ee; e)\r\n\t\t\twriteln(ee[0], \" \", ee[1], \" \", ee[2]);\r\n\t}\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 swaptwo(int i, int j)\n{\n int opcount = 6;\n int oplist = 0x9;\n while (opcount-- > 0) {\n if (oplist & 1)\n printf(\"1 %d %d\\n\", i, j);\n else\n printf(\"2 %d %d\\n\", i, j);\n oplist >>= 1;\n }\n}\n\nvoid main()\n{\n int t, n;\n readf!\" %d\"(t);\n while (t--) {\n readf!\" %d\"(n);\n readln;\n auto a = readln.chomp.split.map!(to!int).array;\n\n writeln(n / 2 * 6);\n int idx = 1;\n while (idx <= a.length) {\n swaptwo(idx, idx + 1);\n idx += 2;\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 n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (n * 3);\r\n\t\tfor (int i = 1; i <= n; i += 2)\r\n\t\t{\r\n\t\t\twriteln (1, \" \", i, \" \", i + 1);\r\n\t\t\twriteln (2, \" \", i, \" \", i + 1);\r\n\t\t\twriteln (1, \" \", i, \" \", i + 1);\r\n\r\n\t\t\twriteln (1, \" \", i, \" \", i + 1);\r\n\t\t\twriteln (2, \" \", i, \" \", i + 1);\r\n\t\t\twriteln (1, \" \", i, \" \", i + 1);\r\n\t\t}\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range;\n\nvoid swaptwo(int i, int j)\n{\n int opcount = 6;\n int oplist = 0x9;\n while (opcount-- > 0) {\n if (oplist & 1)\n printf(\"1 %d %d\\n\", i, j);\n else\n printf(\"2 %d %d\\n\", i, j);\n oplist >>= 1;\n }\n}\n\nvoid main()\n{\n int t, n;\n readf!\" %d\"(t);\n while (t--) {\n readf!\" %d\"(n);\n readln;\n auto a = readln.chomp.split.map!(to!int).array;\n\n writeln(n / 2 * 6);\n int idx = 0;\n while (idx < a.length) {\n swaptwo(idx, idx + 1);\n idx += 2;\n }\n }\n}\n"}], "src_uid": "980d2b3b6b80358b3757db8fe19e8287"} {"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 solve(const(int) N, const(int[]) P) {\n auto ans = new int[][](N + 2, N + 2);\n foreach (i; 1 .. N + 1) {\n int x = i, y = i;\n ans[x][y] = P[i];\n foreach (_; 1 .. P[i]) {\n if (y - 1 >= 1 && !ans[x][y - 1]) {\n ans[x][y - 1] = P[i];\n --y;\n } else if (x + 1 <= N && !ans[x + 1][y]) {\n ans[x + 1][y] = P[i];\n ++x;\n } else {\n assert(false);\n }\n }\n }\n foreach (i; 1 .. N + 1) {\n foreach (j; 1 .. i + 1) {\n if (j > 1) write(\" \");\n write(ans[i][j]);\n }\n writeln;\n }\n}\n\nvoid main() {\n debug {\n foreach (n; 1 .. 8 + 1) {\n auto perm = iota(n + 1).array;\n do {\n writeln(perm);\n solve(n, perm);\n } while (perm[1 .. n + 1].nextPermutation);\n }\n }\n \n try {\n for (; ; ) {\n const N = readInt();\n auto P = new int[N + 1];\n foreach (i; 1 .. N + 1) {\n P[i] = readInt();\n }\n \n solve(N, P);\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\tint n;\r\n\twhile (readf !(\" %s\") (n) > 0)\r\n\t{\r\n\t\treadln;\r\n\t\tauto p = readln.splitter.map !(to !(int)).array;\r\n\t\tint [] [] answer;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tanswer ~= new int [i + 1];\r\n\t\t}\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tanswer[i][i] = p[i];\r\n\t\t}\r\n\t\tforeach (d; 0..n - 1)\r\n\t\t{\r\n\t\t\tbool shift = false;\r\n\t\t\tforeach (i; d..n)\r\n\t\t\t{\r\n\t\t\t\tauto value = answer[i][i - d];\r\n\t\t\t\tif (value == d + 1)\r\n\t\t\t\t{\r\n\t\t\t\t\tshift = true;\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 (shift)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tanswer[i][i - d - 1] = value;\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tanswer[i + 1][i - d] = value;\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\twritefln !(\"%(%(%s %)\\n%)\") (answer);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "5e95cb608bca3c3e9fc581b97f0dbc65"} {"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 S = readln.chomp;\n auto A = readln.split.map!(a => a.front.to!dchar).array;\n\n auto B = new bool[](26);\n foreach (a; A) B[a-'a'] = true;\n\n long tmp = 0;\n long ans = 0;\n\n foreach (i; 0..N) {\n if (!B[S[i]-'a']) {\n ans += tmp * (tmp + 1) / 2;\n tmp = 0;\n } else {\n tmp += 1;\n }\n }\n\n ans += tmp * (tmp + 1) / 2;\n ans.writeln;\n}\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}\nvoid main()\n{\n int n, k; get(n, k);\n string str; get(str);\n bool[26] ap = false;\n foreach(i; 0 .. k)\n {\n string r; get(r);\n ap[r[0] - 'a'] = true;\n }\n int i = 0;\n long res = 0;\n for(; i < str.length;)\n {\n long count = 0;\n while(i < str.length && ap[str[i] - 'a'])\n\t{\n\t count++;\n\t i++;\n\t}\n res += count * (count + 1) / 2;\n if(!count)\n\ti++;\n }\n ans(res);\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, k = rint;\n\tstring s = rstring;\n\tchar[] cs = readln.chomp.split.join.to!(char[]);\n\n\tbool[char] cset;\n\tforeach(c; cs) cset[c] = 1;\n\n\tlong ans;\n\tlong t;\n\tforeach(c; s){\n\t\tif(c !in cset){\n\t\t\tans += t * (t + 1) / 2;\n\t\t\tt = 0;\n\t\t}\n\t\telse{\n\t\t\tt += 1;\n\t\t}\n\t}\n\tans += t * (t + 1) / 2;\n\n\tans.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 n = RD!int;\n\tauto k = RD!int;\n\tauto s = RD!string;\n\tbool[char] set;\n\tforeach (i; 0..k)\n\t{\n\t\tauto c = RD!string;\n\t\tset[c[0]] = true;\n\t}\n\n\tlong ans;\n\tlong cnt;\n\tforeach (c; s)\n\t{\n\t\tif (set.get(c, false))\n\t\t\t++cnt;\n\t\telse\n\t\t{\n\t\t\tans += cnt * (cnt+1) / 2;\n\t\t\tcnt = 0;\n\t\t}\n\t}\n\tans += cnt * (cnt+1) / 2;\n\tcnt = 0;\n\t\n\twriteln(ans);\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;\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, k; get(n, k);\n string str; get(str);\n bool[26] ap = false;\n foreach(i; 0 .. k)\n {\n string r; get(r);\n ap[r[0] - 'a'] = true;\n }\n \n int i = 0;\n long res = 0;\n for(; i < str.length; i++)\n {\n int count = 0;\n while(i < str.length && ap[str[i] - 'a'])\n\t{\n\t count++;\n\t i++;\n\t}\n res += count * (count + 1) / 2;\n }\n ans(res);\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}\nvoid main()\n{\n int n, k; get(n, k);\n string str; get(str);\n bool[26] ap = false;\n foreach(i; 0 .. k)\n {\n string r; get(r);\n ap[r[0] - 'a'] = true;\n }\n int i = 0;\n long res = 0;\n for(; i < str.length;)\n {\n int count = 0;\n while(i < str.length && ap[str[i] - 'a'])\n\t{\n\t count++;\n\t i++;\n\t}\n res += count * (count + 1) / 2;\n if(!count)\n\ti++;\n }\n ans(res);\n}\n"}], "src_uid": "4c260e7c6fd9c573ee4f3b1822f3c7c3"} {"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 p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\tauto board = new char [] [] (n, n);\n\t\tforeach (ref line; board)\n\t\t{\n\t\t\tline[] = '.';\n\t\t}\n\n\t\tauto b = new bool [n];\n\t\tint k = 1;\n\t\tint res = 0;\n\t\tint prev = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i == p[i])\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\tif (i != p[i] && !b[i])\n\t\t\t{\n\t\t\t\tint m = k;\n\t\t\t\tb[i] = true;\n\t\t\t\tint j = i;\n\t\t\t\tint last = -1;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tres += 1;\n\t\t\t\t\tdebug {writeln (\"?\", k, \" \", j);}\n\t\t\t\t\tif (j < p[j])\n\t\t\t\t\t{\n\t\t\t\t\t\tboard[k][j] = '/';\n\t\t\t\t\t\tboard[k][p[j]] = '/';\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tboard[k][j] = '\\\\';\n\t\t\t\t\t\tboard[k][p[j]] = '\\\\';\n\t\t\t\t\t}\n\t\t\t\t\tk += 1;\n\t\t\t\t\tlast = j;\n\t\t\t\t\tj = p[j];\n\t\t\t\t\tb[j] = true;\n\t\t\t\t}\n\t\t\t\twhile (p[j] != i);\n\n\t\t\t\tif (prev != -1)\n\t\t\t\t{\n\t\t\t\t\tres += 1;\n\t\t\t\t\tboard[k][j] = '\\\\';\n\t\t\t\t\tboard[k][prev] = '\\\\';\n\t\t\t\t\tboard[0][prev] = '/';\n\t\t\t\t\tboard[0][i] = '/';\n\t\t\t\t\tk += 1;\n\t\t\t\t}\n\t\t\t\tprev = i;\n\n\t\t\t\tdebug {writeln (m, \" \", k, \"!\");}\n\t\t\t\tbringToFront (board[1..m], board[m..k]);\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t\twritefln (\"%-(%s\\n%)\", board);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main ()\n{\n\tauto n = readln.strip.to !(int);\n\tauto p = readln.splitter.map !(to !(int)).array;\n\tp[] -= 1;\n\tauto board = new char [] [] (n, n);\n\tforeach (ref line; board)\n\t\tline[] = '.';\n\n\tauto b = new bool [n];\n\tint k = 1, res = 0, prev = -1;\n\tforeach (i; 0..n)\n\t{\n\t\tres += (i == p[i]);\n\t\tif (i != p[i] && !b[i])\n\t\t{\n\t\t\tint m = k, j = i;\n\t\t\tb[i] = true;\n\t\t\tdo\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t\tauto dir = \"\\\\/\"[j < p[j]];\n\t\t\t\tboard[k][j] = dir;\n\t\t\t\tboard[k][p[j]] = dir;\n\t\t\t\tk += 1;\n\t\t\t\tj = p[j];\n\t\t\t\tb[j] = true;\n\t\t\t}\n\t\t\twhile (p[j] != i);\n\n\t\t\tif (prev != -1)\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t\tboard[k][j] = '\\\\';\n\t\t\t\tboard[k][prev] = '\\\\';\n\t\t\t\tboard[0][prev] = '/';\n\t\t\t\tboard[0][i] = '/';\n\t\t\t\tk += 1;\n\t\t\t}\n\t\t\tprev = i;\n\n\t\t\tbringToFront (board[1..m], board[m..k]);\n\t\t}\n\t}\n\n\twriteln (res);\n\twritefln (\"%-(%s\\n%)\", board);\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 p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\tauto board = new char [] [] (n, n);\n\t\tforeach (ref line; board)\n\t\t{\n\t\t\tline[] = '.';\n\t\t}\n\n\t\tauto b = new bool [n];\n\t\tint k = 0;\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i == p[i])\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\tif (i != p[i] && !b[i])\n\t\t\t{\n\t\t\t\tb[i] = true;\n\t\t\t\tint j = p[i];\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tb[j] = true;\n\t\t\t\t\tres += 1;\n\t\t\t\t\tif (j < p[j])\n\t\t\t\t\t{\n\t\t\t\t\t\tboard[k][j] = '/';\n\t\t\t\t\t\tboard[k][p[j]] = '/';\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tboard[k][j] = '\\\\';\n\t\t\t\t\t\tboard[k][p[j]] = '\\\\';\n\t\t\t\t\t}\n\t\t\t\t\tk += 1;\n\t\t\t\t\tj = p[j];\n\t\t\t\t}\n\t\t\t\twhile (j != i);\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t\twritefln (\"%-(%s\\n%)\", board);\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 p = readln.splitter.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\tauto board = new char [] [] (n, n);\n\t\tforeach (ref line; board)\n\t\t{\n\t\t\tline[] = '.';\n\t\t}\n\n\t\tauto b = new bool [n];\n\t\tint k = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i != p[i] && !b[i])\n\t\t\t{\n\t\t\t\tb[i] = true;\n\t\t\t\tint j = p[i];\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tb[j] = true;\n\t\t\t\t\tif (j < p[j])\n\t\t\t\t\t{\n\t\t\t\t\t\tboard[k][j] = '/';\n\t\t\t\t\t\tboard[k][p[j]] = '/';\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tboard[k][j] = '\\\\';\n\t\t\t\t\t\tboard[k][p[j]] = '\\\\';\n\t\t\t\t\t}\n\t\t\t\t\tk += 1;\n\t\t\t\t\tj = p[j];\n\t\t\t\t}\n\t\t\t\twhile (j != i);\n\t\t\t}\n\t\t}\n\t\twritefln (\"%-(%s\\n%)\", board);\n\t}\n}\n"}], "src_uid": "e22759043edcab508aa0944aa9d61160"} {"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 mxcost = 101;\n \n int n, m, q;\n readf(\"%s %s %s\", &n, &m, &q);\n readln;\n\n auto w = readln.chomp.split.map!(to!int).array;\n reverse(w);\n \n auto cnt = new int[] (1 << n);\n foreach (_; 0 .. m) {\n auto x = readln.chomp.to!(int)(2);\n ++cnt[x];\n }\n \n auto v = new int[][] (1 << n, mxcost+1);\n foreach (e; 0 .. 1 << n) {\n foreach (o; e .. 1 << n) {\n auto xr = e ^ o;\n auto cost = 0;\n foreach (b; 0 .. n) {\n if ((xr & (1 << b)) == 0) cost += w[b];\n }\n cost = min(cost, mxcost);\n \n v[e][cost] += cnt[o];\n if (e != o) v[o][cost] += cnt[e];\n }\n }\n \n foreach (e; 0 .. 1 << n) {\n foreach (i; 0 .. mxcost) v[e][i+1] += v[e][i];\n \n }\n \n debug { v.each!(arr => arr.take(20).writeln); }\n \n while (q--) {\n auto line = readln.splitter;\n auto x = line.front.to !(int) (2);\n line.popFront ();\n auto k = line.front.to !(int);\n /*\n string t; int k;\n readf(\"%s %s\", &t, &k);\n readln;\n auto x = t.to!(int)(2);\n */\n v[x][k].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.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n immutable int mxcost = 101;\n \n int n, m, q;\n readf(\"%s %s %s\", &n, &m, &q);\n readln;\n\n auto w = readln.chomp.split.map!(to!int).array;\n reverse(w);\n \n auto cnt = new int[] (1 << n);\n foreach (_; 0 .. m) {\n auto x = readln.chomp.to!(int)(2);\n ++cnt[x];\n }\n \n auto v = new int[][] (1 << n, mxcost+1);\n foreach (e; 0 .. 1 << n) {\n foreach (o; e .. 1 << n) {\n auto xr = e ^ o;\n auto cost = 0;\n foreach (b; 0 .. n) {\n if ((xr & (1 << b)) == 0) cost += w[b];\n }\n cost = min(cost, mxcost);\n \n v[e][cost] += cnt[o];\n if (e != o) v[o][cost] += cnt[e];\n }\n }\n \n foreach (ref rw; v) {\n rw = rw.cumulativeFold!((a, b) => a + b).array;\n }\n \n debug { v.each!(arr => arr.take(20).writeln); }\n \n while (q--) {\n string t; int k;\n readf(\"%s %s\", &t, &k);\n readln;\n auto x = t.to!(int)(2);\n v[x][k].writeln;\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 immutable int mxcost = 101;\n \n int n, m, q;\n readf(\"%s %s %s\", &n, &m, &q);\n readln;\n\n auto w = readln.chomp.split.map!(to!int).array;\n reverse(w);\n \n auto cnt = new int[] (1 << n);\n foreach (_; 0 .. m) {\n auto x = readln.chomp.to!(int)(2);\n ++cnt[x];\n }\n \n auto v = new int[][] (1 << n, mxcost+1);\n foreach (e; 0 .. 1 << n) {\n foreach (o; e .. 1 << n) {\n auto xr = e ^ o;\n auto cost = 0;\n foreach (b; 0 .. n) {\n if ((xr & (1 << b)) == 0) cost += w[b];\n }\n cost = min(cost, mxcost);\n \n v[e][cost] += cnt[o];\n if (e != o) v[o][cost] += cnt[e];\n }\n }\n \n foreach (ref rw; v) {\n rw = rw.cumulativeFold!((a, b) => a + b).array;\n }\n \n debug { v.each!(arr => arr.take(20).writeln); }\n \n while (q--) {\n auto line = readln.splitter;\n auto x = line.front.to !(int) (2);\n line.popFront ();\n auto k = line.front.to !(int);\n /*\n string t; int k;\n readf(\"%s %s\", &t, &k);\n readln;\n auto x = t.to!(int)(2);\n */\n v[x][k].writeln;\n }\n \n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int limit = 102;\n\nvoid main ()\n{\n\tint n, m, q;\n\twhile (readf (\" %s %s %s\", &n, &m, &q) > 0)\n\t{\n\t\treadln;\n\t\tauto w = readln.splitter.map !(to !(int)).array;\n\t\treverse (w);\n\t\tauto num = new int [1 << n];\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tauto b = readln.strip.to !(int) (2);\n\t\t\tnum[b] += 1;\n\t\t}\n\t\tdebug {writeln (num);}\n\n\t\tauto numAtCost = new int [] [] (1 << n, limit + 1);\n\t\tforeach (s; 0..1 << n)\n\t\t{\n\t\t\tforeach (t; s..1 << n)\n\t\t\t{\n\t\t\t\tint cost = 0;\n\t\t\t\tauto r = s ^ t;\n\t\t\t\tforeach (k; 0..n)\n\t\t\t\t{\n\t\t\t\t\tif (!((r >> k) & 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tcost += w[k];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcost = min (cost, limit);\n\t\t\t\tnumAtCost[s][cost] += num[t];\n\t\t\t\tif (s < t)\n\t\t\t\t{\n\t\t\t\t\tnumAtCost[t][cost] += num[s];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tforeach (s; 0..1 << n)\n\t\t{\n\t\t\tforeach (cost; 0..limit)\n\t\t\t{\n\t\t\t\tnumAtCost[s][cost + 1] += numAtCost[s][cost];\n\t\t\t}\n\t\t\tdebug {writeln (s, \": \", numAtCost[s]);}\n\t\t}\n\n\t\tforeach (j; 0..q)\n\t\t{\n\t\t\tauto v = readln.splitter;\n\t\t\tauto b = v.front.to !(int) (2);\n\t\t\tv.popFront ();\n\t\t\tauto k = v.front.to !(int);\n\t\t\tdebug {writeln (b, \", \", k, \": \");}\n\t\t\twriteln (numAtCost[b][k]);\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\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"}], "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 mxcost = 100;\n \n int n, m, q;\n readf(\"%s %s %s\", &n, &m, &q);\n readln;\n\n auto w = readln.chomp.split.map!(to!int).array;\n reverse(w);\n \n auto cnt = new int[] (1 << n);\n foreach (_; 0 .. m) {\n auto x = readln.chomp.to!(int)(2);\n ++cnt[x];\n }\n \n auto v = new int[][] (1 << n, mxcost+1);\n foreach (e; 0 .. 1 << n) {\n foreach (o; e .. 1 << n) {\n auto xr = e ^ o;\n auto cost = 0;\n foreach (b; 0 .. n) {\n if ((xr & (1 << b)) != 0) cost += w[b];\n }\n cost = min(cost, mxcost);\n \n v[e][cost] += cnt[o];\n if (e != o) v[o][cost] += cnt[e];\n }\n }\n \n foreach (e; 0 .. 1 << n) {\n foreach (i; 0 .. mxcost) v[e][i+1] += v[e][i];\n \n }\n \n debug { v.each!(arr => arr.take(20).writeln); }\n \n while (q--) {\n auto line = readln.splitter;\n auto x = line.front.to !(int) (2);\n line.popFront ();\n auto k = line.front.to !(int);\n /*\n string t; int k;\n readf(\"%s %s\", &t, &k);\n readln;\n auto x = t.to!(int)(2);\n */\n v[x][k].writeln;\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 immutable int mxcost = 100;\n \n int n, m, q;\n readf(\"%s %s %s\", &n, &m, &q);\n readln;\n\n auto w = readln.chomp.split.map!(to!int).array;\n reverse(w);\n \n auto cnt = new int[] (1 << n);\n foreach (_; 0 .. m) {\n auto x = readln.chomp.to!(int)(2);\n ++cnt[x];\n }\n \n auto v = new int[][] (1 << n, mxcost+1);\n foreach (e; 0 .. 1 << n) {\n foreach (o; e .. 1 << n) {\n auto xr = e ^ o;\n auto cost = 0;\n foreach (b; 0 .. n) {\n if ((xr & (1 << b)) == 0) cost += w[b];\n }\n cost = min(cost, mxcost);\n \n v[e][cost] += cnt[o];\n if (e != o) v[o][cost] += cnt[e];\n }\n }\n \n foreach (e; 0 .. 1 << n) {\n foreach (i; 0 .. mxcost) v[e][i+1] += v[e][i];\n \n }\n \n debug { v.each!(arr => arr.take(20).writeln); }\n \n while (q--) {\n auto line = readln.splitter;\n auto x = line.front.to !(int) (2);\n line.popFront ();\n auto k = line.front.to !(int);\n /*\n string t; int k;\n readf(\"%s %s\", &t, &k);\n readln;\n auto x = t.to!(int)(2);\n */\n v[x][k].writeln;\n }\n \n}"}], "src_uid": "736b35e915e67ca63e07386059aca2e5"} {"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\tlong[] ps = rlong(n);\n\n\tFinite[] prods = [Finite(1)];\n\tforeach(p; ps) prods ~= (prods[$ - 1] * p) / 100;\n\tlog(\"prods:\", prods);\n\n\tFinite[] invprods = [Finite(1)];\n\tforeach(p; ps) invprods ~= (invprods[$ - 1] * 100) / p;\n\tlog(\"invprods:\", invprods);\n\n\tFinite[] sums = [Finite(0)];\n\tforeach(pr; prods) sums ~= sums[$ - 1] + pr;\n\tlog(\"sums:\", sums);\n\n\tauto seg1 = new SegTree!int(0, n, (x, y) => y, 0);\n\tseg1.setValue(0, n, 0);\n\tlog(\"seg1:\\n\", seg1);\n\n\tauto seg2 = new SegTree!int(0, n, (x, y) => y, 0);\n\tseg2.setValue(0, n, n);\n\tlog(\"seg2:\\n\", seg2);\n\n\tFinite ans = (sums[n] - sums[0]) * invprods[n];\n\tlog(\"ans:\", ans);\n\tforeach(_; 0 .. q){\n\t\tint u = rint - 1;\n\t\tint i = seg1.getValue(u), j = seg2.getValue(u);\n\t\tif(i < u){ // u is not a checkpoint\n\t\t\tseg2.setValue(i, u, u), seg1.setValue(u, j, u);\n\t\t\tlog(\"u:\", u, \"i:\", i, \"j:\", j);\n\t\t\tlog(\"seg1:\\n\", seg1);\n\t\t\tlog(\"seg2:\\n\", seg2);\n\t\t\tans -= (sums[j] - sums[i]) * invprods[j];\n\t\t\tans += (sums[u] - sums[i]) * invprods[u];\n\t\t\tans += (sums[j] - sums[u]) * invprods[j];\n\t\t}\n\t\telse{ // u is a checkpoint\n\t\t\ti = seg1.getValue(u - 1);\n\t\t\tseg2.setValue(i, u, j), seg1.setValue(u, j, i);\n\t\t\tlog(\"u:\", u, \"i:\", i, \"j:\", j);\n\t\t\tlog(\"seg1:\\n\", seg1);\n\t\t\tlog(\"seg2:\\n\", seg2);\n\t\t\tans -= (sums[u] - sums[i]) * invprods[u];\n\t\t\tans -= (sums[j] - sums[u]) * invprods[j];\n\t\t\tans += (sums[j] - sums[i]) * invprods[j];\n\t\t}\n\t\tans.writeln;\n\t}\n}\n\n\n\nconst long mod = 998244353;\nstruct Finite{\n\tlong value;\n\tprivate static long[] _inv = [0, 1], _frac = [1, 1], _invfrac = [1, 1];\n\tthis(long v){ value = val(v); }\n\tstatic long val(long v){\n\t\tif(v >= 0) return v % mod;\n\t\telse return (v + mod - (v / mod) * mod) % mod;\n\t}\n\tbool opCast(T: bool)(){ return value != 0; }\n\tFinite opUnary(string s){ long 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)(long u){ long 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)(long u){ long 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(long 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)(long 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\tlong inv(long v){\n\t\tv = val(v);\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!int];\n\t}\n\tlong invvalue(){\n\t\treturn inv(value);\n\t}\n\tstatic Finite opCall(long v){ return Finite(val(v)); }\n\t\n}\n\nclass SegTree(T){\n\tT delegate(T, T) apply;\n\tT initial;\n\tint a, b; // a <= x < b を担当する\n\tbool hasValue;\n\tSegTree left, right; // 左の子(a <= x < c)、右の子(c <= x < b)\n\tT value;\n\tthis(int a, int b, T delegate(T, T) apply, T initial = T.init){\n\t\tthis.a = a, this.b = b;\n\t\tthis.apply = apply;\n\t\tthis.initial = initial;\n\t\tthis.value = initial;\n\t\tif(b - a == 1){\n\t\t\tthis.hasValue = 1;\n\t\t}\n\t\telse{\n\t\t\tint c = (a + b) / 2;\n\t\t\tthis.left = new SegTree(a, c, apply, initial);\n\t\t\tthis.right = new SegTree(c, b, apply, initial);\n\t\t}\n\t}\n\t\n\t// [a, b) に値を設定する ※[a, b) はこのノードの担当区間とかぶっていなくてもよい\n\tvoid setValue(int a, int b, T value){\n\t\tif(b <= this.a || this.b <= a) return;\n\t\tif(a <= this.a && this.b <= b){\n\t\t\tthis.hasValue = true;\n\t\t\tthis.value = apply(this.value, value);\n\t\t}\n\t\telse{\n\t\t\tif(this.hasValue){\n\t\t\t\tleft.setValue(left.a, left.b, this.value);\n\t\t\t\tright.setValue(right.a, right.b, this.value);\n\t\t\t\tthis.hasValue = false;\n\t\t\t}\n\t\t\tleft.setValue(a, b, value);\n\t\t\tright.setValue(a, b, value);\n\t\t}\n\t}\n\t\n\t// iにおける値 ※iは必ずこのノードの担当区間内である前提\n\tT getValue(int i){\n\t\tassert(a <= i && i < b);\n\t\tif(this.hasValue) return this.value;\n\t\telse if(i < left.b) return left.getValue(i);\n\t\telse return right.getValue(i);\n\t}\n\t\n\t// 配列に変換したもの(デバッグ用)\n\tT[] array(){\n\t\tT[] res;\n\t\tforeach(i; a .. b) res ~= this.value;\n\t\treturn res;\n\t}\n\t\n\t// 文字列に変換したもの(デバッグ用)\n\toverride string toString(){\n\t\tif(this.hasValue) return this.array.to!string;\n\t\telse return left.toString ~ right.toString;\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\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\n// 1 + p0 + p0 p1 + p0 p1 p2\nstruct Info {\n Mint prod, sum;\n Info opBinary(string op)(Info a) const if (op == \"*\") {\n return Info(prod * a.prod, sum + prod * a.sum);\n }\n}\nenum IDENTITY = Info(Mint(1), Mint(0));\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const Q = readInt();\n auto P = new int[N];\n foreach (i; 0 .. N) {\n P[i] = readInt();\n }\n auto U = new int[Q];\n foreach (q; 0 .. Q) {\n U[q] = readInt() - 1;\n }\n \n int segN;\n for (segN = 1; segN < N; segN <<= 1) {}\n auto seg = new Info[segN << 1];\n seg[] = IDENTITY;\n foreach (i; 0 .. N) {\n seg[segN + i] = Info(Mint(P[i]) / 100, Mint(1));\n }\n foreach_reverse (a; 1 .. segN) {\n seg[a] = seg[a << 1] * seg[a << 1 | 1];\n }\n Info rangeProd(int a, int b) {\n Info retL = IDENTITY, retR = IDENTITY;\n for (a += segN, b += segN; a < b; a >>= 1, b >>= 1) {\n if (a & 1) retL = retL * seg[a++];\n if (b & 1) retR = seg[--b] * retR;\n }\n return retL * retR;\n }\n Mint calc(int a, int b) {\n const res = rangeProd(a, b);\n const ret = res.sum / res.prod;\n debug {\n writeln(\"calc \", a, \" \", b, \": \", res, \" \", ret);\n }\n return ret;\n }\n \n auto set = new RedBlackTree!int;\n set.insert(0);\n set.insert(N);\n Mint now = calc(0, N);\n foreach (q; 0 .. Q) {\n const l = set.lowerBound(U[q]).back;\n const r = set.upperBound(U[q]).front;\n if (set.removeKey(U[q])) {\n debug {\n writeln(\"remove \", U[q], \"; \", l, \" \", r);\n }\n now -= calc(l, U[q]);\n now -= calc(U[q], r);\n now += calc(l, r);\n } else {\n debug {\n writeln(\"insert \", U[q], \"; \", l, \" \", r);\n }\n set.insert(U[q]);\n now -= calc(l, r);\n now += calc(l, U[q]);\n now += calc(U[q], r);\n }\n writeln(now);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "1461fca52a0310fff725b476bfbd3b29"} {"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;\r\n readf!\" %d %d \"(n, q);\r\n auto a = readarray!long;\r\n long odds, evens;\r\n long oddn, evenn;\r\n foreach(el; a) {\r\n if (el & 1) {\r\n odds += el;\r\n oddn++;\r\n }\r\n else {\r\n evens += el;\r\n evenn++;\r\n }\r\n }\r\n foreach(casenum; 0 .. q) {\r\n byte type;\r\n long x;\r\n readf!\" %d %d \"(type, x);\r\n if (type == 0) {\r\n evens += evenn*x;\r\n writeln(odds + evens);\r\n if (x & 1) {\r\n oddn += evenn;\r\n odds += evens;\r\n evenn = 0;\r\n evens = 0;\r\n }\r\n }\r\n else {\r\n odds += oddn*x;\r\n writeln(odds + evens);\r\n if (x & 1) {\r\n evenn += oddn;\r\n evens += odds;\r\n oddn = 0;\r\n odds = 0;\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, 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, q;\n readf!\" %d %d \"(n, q);\n auto a = readln.splitter.map!(to!long).array;\n long cntodd, cnteven, ans;\n foreach (x ; a) {\n if (x % 2 == 0)\n cnteven++;\n else\n cntodd++;\n ans += x;\n }\n foreach (i ; 0 .. q) {\n long type, xj;\n readf!\" %d %d \"(type, xj);\n if (type == 0) {\n ans += cnteven * xj;\n if (xj % 2 != 0) {\n cntodd += cnteven;\n cnteven = 0;\n }\n } else {\n ans += cntodd * xj;\n if (xj % 2 != 0) {\n cnteven += cntodd;\n cntodd = 0;\n }\n }\n writeln(ans);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "d15cffca07768f8ce6fab7e13a6e7976"} {"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 = 998244353;\nalias Mint = ModInt!MO;\n\nenum LIM = 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 (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\nvoid main() {\n prepare;\n \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 Mint ans;\n ans -= A[0 .. N].sum;\n ans += A[N .. 2 * N].sum;\n ans *= binom(2 * N, N);\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "// B \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\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 = 998244353;\nalias Mint = ModInt!MO;\n\nenum LIM = 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 (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\nvoid main() {\n prepare;\n \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 Mint ans;\n ans -= A[0 .. N].sum;\n ans += A[N .. 2 * N].sum;\n ans *= binom(2 * N, N);\n writeln(ans);\n }\n } catch (EOFException e) {\n }\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 mod = 998_244_353;\n\nint powMod (int a, int p)\n{\n\tint res = 1 % mod;\n\tfor ( ; p > 0; p >>= 1)\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}\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 a = readln.splitter.map !(to !(int)).array;\n\t\tsort (a);\n\n\t\tint f = 1;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tf = (f * 1L * i) % mod;\n\t\t}\n\n\t\tint invF = powMod (f, mod - 2);\n\n\t\tint g = f;\n\t\tforeach (i; n + 1..n * 2 + 1)\n\t\t{\n\t\t\tg = (g * 1L * i) % mod;\n\t\t}\n\n\t\tint add = g;\n\t\tadd = (add * 1L * invF) % mod;\n\t\tadd = (add * 1L * invF) % mod;\n\n\t\tint res = 0;\n\t\tforeach (i; 1..n * 2)\n\t\t{\n\t\t\tint mult = n - abs (n - i);\n\t\t\tint cur = (add * 1L * (a[i] - a[i - 1])) % mod;\n\t\t\tres = (res + cur * 1L * mult) % mod;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nconst ll PRIME = 998244353;\n\nll modinv(ll num){\n ll res = 1;\n ll x = num;\n ll y = PRIME-2;\n while(y > 0){\n if(y & 1){\n res *= x;\n res %= PRIME;\n }\n x = x * x;\n x %= PRIME;\n y >>= 1;\n }\n return res;\n}\n\nvoid play(){\n int n;\n n = rd!int;\n ll[] arr = rdarr;\n arr.sort;\n\n ll s1 = 0, s2 = 0;\n // 1st half\n foreach(i; 0..n){ s1 += arr[i]; }\n // 2nd half\n foreach(i; n..2*n){ s2 += arr[i]; }\n\n ll res = s2 - s1;\n show(res);\n res %= PRIME;\n\n ll combi = 1;\n // Multiply 2nCn\n foreach(k; n+1..2*n+1){\n combi *= k;\n combi %= PRIME;\n }\n ll divi = 1;\n foreach(k; 1..n+1){\n divi *= k;\n divi %= PRIME;\n }\n combi *= modinv(divi);\n combi %= PRIME;\n res *= combi;\n res %= PRIME;\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;\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": [], "src_uid": "0ff34aebe5e06774b1ad0eadad022ace"} {"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 p = a.length - a.findAdjacent !(q{a >= b}).length;\n\t\tauto q = a.length - a.retro.findAdjacent !(q{a >= b}).length;\n\t\tauto lo = a.take (min (p + 1, n)).array;\n\t\tauto hi = a.retro.take (min (q + 1, n)).array;\n\t\tdebug {writeln (lo, \" \", hi);}\n\n\t\tstring res;\n\t\twhile (true)\n\t\t{\n\t\t\tif (lo.empty)\n\t\t\t{\n\t\t\t\tres ~= 'R'.repeat (hi.length).text;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (hi.empty)\n\t\t\t{\n\t\t\t\tres ~= 'L'.repeat (lo.length).text;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (lo.front < hi.front)\n\t\t\t{\n\t\t\t\tres ~= 'L';\n\t\t\t\tlo.popFront ();\n\t\t\t}\n\t\t\telse if (lo.front > hi.front)\n\t\t\t{\n\t\t\t\tres ~= 'R';\n\t\t\t\thi.popFront ();\n\t\t\t}\n\t\t\telse if (lo.length < hi.length)\n\t\t\t{\n\t\t\t\tres ~= 'R'.repeat (hi.length).text;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres ~= 'L'.repeat (lo.length).text;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tres.length = min (res.length, n);\n\t\twriteln (res.length);\n\t\twriteln (res);\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\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\t\n\tstring ans;\n\tint i = 0, j = n - 1;\n\tlong x = -1;\n\twhile(i <= j){\n\t\tif(as[i] < as[j]){\n\t\t\tif(x < as[i]) x = as[i], ans ~= \"L\", i += 1;\n\t\t\telse if(x < as[j]) x = as[j], ans ~= \"R\", j -= 1;\n\t\t\telse break;\n\t\t}\n\t\telse{\n\t\t\tif(x < as[j]) x = as[j], ans ~= \"R\", j -= 1;\n\t\t\telse if(x < as[i]) x = as[i], ans ~= \"L\", i += 1;\n\t\t\telse break;\n\t\t}\n\t}\n\t\n\tans.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.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 a = RDR.ARR;\n\n\tstring ans;\n\tlong last;\n\twhile (!a.empty)\n\t{\n\t\tif (a.front > last && a.front < a.back)\n\t\t{\n\t\t\tlast = a.front;\n\t\t\ta.popFront;\n\t\t\tans ~= \"L\";\n\t\t}\n\t\telse if (a.back > last && a.back < a.front)\n\t\t{\n\t\t\tlast = a.back;\n\t\t\ta.popBack;\n\t\t\tans ~= \"R\";\n\t\t}\n\t\telse if (a.front > last)\n\t\t{\n\t\t\tlast = a.front;\n\t\t\ta.popFront;\n\t\t\tans ~= \"L\";\n\t\t}\n\t\telse if (a.back > last)\n\t\t{\n\t\t\tlast = a.back;\n\t\t\ta.popBack;\n\t\t\tans ~= \"R\";\n\t\t}\n\t\telse\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\twriteln(ans.length);\n\twriteln(ans);\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 n;\n readf(\"%s\", &n);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n void gole(int p, int lm, int lst, ref dchar[] ans) {\n while (p <= lm && a[p] > lst) {\n ans ~= 'L';\n lst = a[p];\n ++p;\n }\n \n debug { writeln(ans.length); }\n }\n void gor(int p, int lm, int lst, ref dchar[] ans) {\n while (p >= lm && a[p] > lst) {\n ans ~= 'R';\n lst = a[p];\n --p;\n }\n \n debug { writeln(ans.length); }\n }\n int lst = 0;\n int le = 0, r = n-1;\n dchar[] ans;\n while (le <= r) {\n int leok = lst < a[le];\n int rok = lst < a[r];\n if (!leok && !rok) {\n break;\n }\n if (!leok) {\n gor(r, le, lst, ans);\n break;\n }\n if (!rok) {\n gole(le, r, lst, ans);\n break;\n }\n \n if (a[le] < a[r]) {\n ans ~= 'L';\n lst = a[le];\n ++le;\n } else if (a[r] < a[le]) {\n ans ~= 'R';\n lst = a[r];\n --r;\n } else {\n dchar[] ansle;\n dchar[] ansr;\n gole(le, r, lst, ansle);\n gor(r, le, lst, ansr);\n \n if (ansle.length > ansr.length) { ans ~= ansle; }\n else { ans ~= ansr; }\n break;\n }\n }\n \n ans.length.writeln;\n ans.writeln;\n}"}], "negative_code": [], "src_uid": "50c4b8fe3ab738e6e97058499791ac7b"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tbool hasPlus;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] >= 0)\n\t\t\t\thasPlus = true;\n\t\t}\n\n\t\tif (!hasPlus || n == 5)\n\t\t{\n\t\t\tans[ti] = 1;\n\t\t\tforeach (i; 0..5)\n\t\t\t{\n\t\t\t\tans[ti] *= a[n-i-1];\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong best = long.min;\n\t\t\tforeach (i; 0..3)\n\t\t\t{\n\t\t\t\tauto cnt = i * 2;\n\t\t\t\tlong x = 1;\n\t\t\t\tforeach (j; 0..cnt)\n\t\t\t\t{\n\t\t\t\t\tif (a[j] >= 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tx = long.min;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tx *= a[j];\n\t\t\t\t}\n\t\t\t\tif (x == long.min) continue;\n\n\t\t\t\tforeach (j; 0..5-cnt)\n\t\t\t\t{\n\t\t\t\t\tif (a[n-j-1] < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tx = long.min;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tx *= a[n-j-1];\n\t\t\t\t}\n\t\t\t\tbest.chmax(x);\n\t\t\t}\n\t\t\tans[ti] = best;\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.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 long[] as = scan!long(n);\n\n long[] xs, ys, zs; // +, -, 0\n foreach(a; as) if(a > 0) xs ~= a; else if(a < 0) ys ~= a; else zs ~= a;\n\n xs.sort();\n ys.sort();\n\n long ans = as[0] * as[1] * as[2] * as[3] * as[4];\n\n if(xs.length >= 5) ans.raiseTo(xs[$ - 1] * xs[$ - 2] * xs[$ - 3] * xs[$ - 4] * xs[$ - 5]);\n if(xs.length >= 4 && ys.length >= 1) ans.raiseTo(xs[0] * xs[1] * xs[2] * xs[3] * ys[$ - 1]);\n if(xs.length >= 3 && ys.length >= 2) ans.raiseTo(xs[$ - 1] * xs[$ - 2] * xs[$ - 3] * ys[0] * ys[1]);\n if(xs.length >= 2 && ys.length >= 3) ans.raiseTo(xs[0] * xs[1] * ys[$ - 1] * ys[$ - 2] * ys[$ - 3]);\n if(xs.length >= 1 && ys.length >= 4) ans.raiseTo(xs[$ - 1] * ys[0] * ys[1] * ys[2] * ys[3]);\n if(ys.length >= 5) ans.raiseTo(ys[$ - 1] * ys[$ - 2] * ys[$ - 3] * ys[$ - 4] * ys[$ - 5]);\n \n if(zs.length >= 1) ans.raiseTo(0);\n\n ans.writeln;\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 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\tbool hasPlus;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] >= 0)\n\t\t\t\thasPlus = true;\n\t\t}\n\n\t\tif (!hasPlus)\n\t\t{\n\t\t\tans[ti] = 1;\n\t\t\tforeach_reverse (i; 0..5)\n\t\t\t{\n\t\t\t\tans[ti] *= a[i];\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong best = long.min;\n\t\t\tforeach (i; 0..3)\n\t\t\t{\n\t\t\t\tauto cnt = i * 2;\n\t\t\t\tlong x = 1;\n\t\t\t\tforeach (j; 0..cnt)\n\t\t\t\t{\n\t\t\t\t\tif (a[j] >= 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tx = long.min;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tx *= a[j];\n\t\t\t\t}\n\t\t\t\tif (x == long.min) continue;\n\n\t\t\t\tforeach (j; 0..5-cnt)\n\t\t\t\t{\n\t\t\t\t\tif (a[n-j-1] < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tx = long.min;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tx *= a[n-j-1];\n\t\t\t\t}\n\t\t\t\tbest.chmax(x);\n\t\t\t}\n\t\t\tans[ti] = best;\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\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\tbool hasPlus;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] >= 0)\n\t\t\t\thasPlus = true;\n\t\t}\n\n\t\tif (!hasPlus || n == 5)\n\t\t{\n\t\t\tans[ti] = 1;\n\t\t\tforeach_reverse (i; 0..5)\n\t\t\t{\n\t\t\t\tans[ti] *= a[i];\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong best = long.min;\n\t\t\tforeach (i; 0..3)\n\t\t\t{\n\t\t\t\tauto cnt = i * 2;\n\t\t\t\tlong x = 1;\n\t\t\t\tforeach (j; 0..cnt)\n\t\t\t\t{\n\t\t\t\t\tif (a[j] >= 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tx = long.min;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tx *= a[j];\n\t\t\t\t}\n\t\t\t\tif (x == long.min) continue;\n\n\t\t\t\tforeach (j; 0..5-cnt)\n\t\t\t\t{\n\t\t\t\t\tif (a[n-j-1] < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tx = long.min;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tx *= a[n-j-1];\n\t\t\t\t}\n\t\t\t\tbest.chmax(x);\n\t\t\t}\n\t\t\tans[ti] = best;\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": "a3a64c3c7e9349d6e663c2d8113d2676"} {"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 y = next!int(n);\n int[] can(int max)\n {\n auto used = redBlackTree!int();\n auto res = new int[](n);\n foreach(i, yi; y)\n {\n\twhile(yi > max)\n\t yi >>= 1;\n\twhile(yi && yi in used)\n\t yi >>= 1;\n\tif (yi == 0) return null;\n\tused.insert(yi);\n\tres[i] = yi;\n }\n return res;\n }\n int low = 1;\n int high = y.fold!max;\n int[] lowestCan = null;\n while(low <= high)\n {\n int mid = (low + high) / 2;\n if (auto res = can(mid))\n\t{\n\t lowestCan = res;\n\t high = mid - 1;\n\t}\n else\n\t{\n\t low = mid + 1;\n\t}\n }\n foreach(yi; lowestCan)\n write(yi, \" \");\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", "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\", 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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 q=rbt!(true,int);\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tint k;\n\t\t\tinput(&k);\n\t\t\tq.insert(k);\n\t\t}\n\t\tfor(;;)\n\t\t{\n\t\t\tint t=q.back;\n\t\t\tint d;\n\t\t\tfor(int i=2;i<=t;i*=2)\n\t\t\t{\n\t\t\t\tif(q.equalRange(t/i).empty){\n\t\t\t\t\td=t/i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(d==0)break;\n\t\t\tq.removeKey(t);\n\t\t\tq.insert(d);\n\t\t}\n\t\tputarr(q);\n\t\twriteln;\n\t}\n\tdebug system(\"pause\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\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\tauto r = redBlackTree !(q{a > b}, int) ();\n\t\tforeach (c; a)\n\t\t{\n\t\t\tr.insert (c);\n\t\t}\n\t\twhile (true)\n\t\t{\n\t\t\tauto v = r.front ();\n\t\t\tauto w = v;\n\t\t\twhile (w > 1)\n\t\t\t{\n\t\t\t\tw /= 2;\n\t\t\t\tif (w !in r)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (w !in r)\n\t\t\t{\n\t\t\t\tr.removeKey (v);\n\t\t\t\tr.insert (w);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", r[]);\n\t}\n}\n"}], "negative_code": [], "src_uid": "1ccbcc5986bf7e7272b7dd65e061d66d"} {"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 auto a = readln.splitter.map!(to!long).array.sort.array;\n long totalsum = a.sum;\n long xsum = 0;\n long ans = 0;\n foreach (x ; a) {\n xsum += x;\n ans = max(ans, abs(abs(xsum) - abs(totalsum - xsum)));\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\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 long plus, minus;\r\n foreach(e; a)\r\n if (e > 0)\r\n plus += e;\r\n else\r\n minus += e;\r\n writeln(abs(plus - abs(minus)));\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": "f59f92a80f719cdb87ad92cd8c211942"} {"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 na = cin.readInt;\n int nb = cin.readInt;\n int a = cin.readInt;\n int b = cin.readInt;\n int[] arr1 = new int[na];\n int[] arr2 = new int[nb];\n foreach (ref i; arr1) i = cin.readInt;\n foreach (ref i; arr2) i = cin.readInt;\n bool possible = true;\n for (int i = 0; i < a; i++) if (arr1[i] >= arr2[nb - b]) possible = false;\n writeln(possible ? \"YES\" : \"NO\");\n } \n}", "positive_code": [{"source_code": "module main;\nimport std.c.stdio;\n\nint main() {\n int na, nb;\n scanf(\"%d %d\", &na, &nb);\n int k, m;\n scanf(\"%d %d\", &k, &m);\n int a[100005];\n int b[100005];\n for (int i = 0; i < na; i++) {\n scanf(\"%d\", &a[i]);\n }\n for (int i = 0; i < nb; i++) {\n scanf(\"%d\", &b[i]);\n }\n if (a[k - 1] < b[nb - m]) {\n printf(\"YES\\n\");\n } else {\n printf(\"NO\\n\");\n }\n return 0;\n}"}, {"source_code": "import std.stdio, std.range, std.string, std.conv, std.algorithm;\nimport std.math;\n\nvoid main() {\n readln;\n int k, m;\n readf(\"%d %d\\n\", &k, &m);\n int[] a = readln.chomp.split.map!(to!int).array;\n int[] b = readln.chomp.split.map!(to!int).array;\n\n if (a[k - 1] < b[$ - m]) {\n \"YES\".writeln;\n } else {\n \"NO\".writeln;\n }\n}"}], "negative_code": [{"source_code": "import std.stdio, std.range, std.string, std.conv, std.algorithm;\nimport std.math;\n\nvoid main() {\n readln;\n int k, m;\n readf(\"%d %d\\n\", &k, &m);\n int[] a = readln.chomp.split.map!(to!int).array;\n int[] b = readln.chomp.split.map!(to!int).array;\n\n if (a[k - 1] < b[0]) {\n \"YES\".writeln;\n } else {\n \"NO\".writeln;\n }\n}"}], "src_uid": "8e0581cce19d6bf5eba30a0aebee9a08"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main ()\n{\n\tauto d = readln.strip.to !(int).iota.array;\n\tauto a = readln.split.map !(to !(int)).array;\n\ta[] += d[];\n\tsort (a);\n\ta[] -= d[];\n\twriteln (isSorted (a) ? a.map !(text).join (\" \") : \":(\");\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.array, std.conv, std.range, std.stdio, std.string;\nvoid main ()\n{\n\tauto d = readln.strip.to !(int).iota.array;\n\tauto a = readln.split.map !(to !(int)).array;\n\ta[] += d[];\n\tsort (a);\n\ta[] -= d[];\n\tif (!isSorted (a))\n\t{\n\t\twriteln (\":(\");\n\t}\n\telse\n\t{\n\t\twritefln (\"%(%s %)\", a);\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 a = readln.split.map !(to !(int)).array;\n\t\ta[] -= n.iota.retro.array[];\n\t\tif (!equal (a, a.uniq))\n\t\t{\n\t\t\twriteln (\":(\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tsort !(q{a < b}, SwapStrategy.stable) (a);\n\t\t\ta[] += n.iota.retro.array[];\n\t\t\tif (a.canFind !(q{a < 0}))\n\t\t\t{\n\t\t\t\twriteln (\":(\");\n\t\t\t}\n\t\t\telse if (!isSorted !(q{a < b}) (a))\n\t\t\t{\n\t\t\t\twriteln (\":(\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twritefln (\"%(%s %)\", a);\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.array, std.conv, std.range, std.stdio, std.string;\nvoid main ()\n{\n\treadln;\n\tauto a = readln.split.map !(to !(uint)).array;\n\ta[] -= a.length.iota.retro.array[];\n\tsort (a);\n\ta[] += a.length.iota.retro.array[];\n\tif (!isSorted (a))\n\t{\n\t\twriteln (\":(\");\n\t}\n\telse\n\t{\n\t\twritefln (\"%(%s %)\", a);\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 a = readln.split.map !(to !(int)).array;\n\t\ta[] -= n.iota.retro.array[];\n\t\tif (!equal (a, a.uniq))\n\t\t{\n\t\t\twriteln (\":(\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tsort !(q{a < b}, SwapStrategy.stable) (a);\n\t\t\ta[] += n.iota.retro.array[];\n\t\t\twritefln (\"%(%s %)\", a);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.array, std.conv, std.range, std.stdio, std.string;\nvoid main ()\n{\n\treadln;\n\tauto a = readln.split.map !(to !(uint)).array;\n\ta[] -= a.length.iota.retro.array[];\n\tsort (a);\n\ta[] += a.length.iota.retro.array[];\n\tif (!equal (a, a.uniq) || !isSorted (a))\n\t{\n\t\twriteln (\":(\");\n\t}\n\telse\n\t{\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}], "src_uid": "27ef62139533982f0857d733fad5c0d6"} {"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\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 X = readLong;\r\n auto A = new long[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readLong;\r\n }\r\n \r\n int ans;\r\n long lb = -INF, ub = INF;\r\n foreach (i; 0 .. N) {\r\n const llb = max(lb, A[i] - X);\r\n const uub = min(ub, A[i] + X);\r\n if (llb <= uub) {\r\n lb = llb;\r\n ub = uub;\r\n } else {\r\n ++ans;\r\n lb = A[i] - X;\r\n ub = A[i] + X;\r\n }\r\n }\r\n writeln(ans);\r\n }\r\n }\r\n } catch (EOFException e) {\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 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\tint lo = a.front;\r\n\t\tint hi = a.front;\r\n\t\tint res = 0;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tlo = min (lo, c);\r\n\t\t\thi = max (hi, c);\r\n\t\t\tif (hi - lo > x * 2)\r\n\t\t\t{\r\n\t\t\t\tres += 1;\r\n\t\t\t\tlo = c;\r\n\t\t\t\thi = c;\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": "1f520f2796094b0f0c4e11e231f9ca8c"} {"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[] token;\nT rd(T = long)() { while(!token.length) token = readln.chomp.split; string res = token[0]; token.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;\n n = rd!int;\n ll[] arr = rdarr;\n ll[] res;\n ll cnt0 = 0, cnt1 = 0;\n foreach(el; arr){\n cnt0 += (el == 0);\n cnt1 += (el == 1);\n }\n ll hf = n / 2;\n ll put = hf + (hf % 2);\n if(cnt1 > hf || (hf % 2 == 0 && cnt1 == hf)){\n writeln(put);\n foreach(i; 0..put){\n write(1, \" \");\n }\n }else if(cnt0 >= hf){\n writeln(cnt0);\n foreach(i; 0..cnt0){\n write(0, \" \");\n }\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", "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 t = next!int;\n foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto a = next!int(n);\n int[2] cnt;\n foreach(ai; a) cnt[ai]++;\n if (cnt[0] >= cnt[1])\n\t{\n\t writeln(cnt[0]);\n\t foreach(i; 0 .. cnt[0]) write(\"0 \");\n\t writeln;\n\t}\n else\n\t{\n\t cnt[1] -= cnt[1] % 2;\n\t writeln(cnt[1]);\n\t foreach(i; 0 .. cnt[1]) write(\"1 \");\n\t writeln;\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"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 cnt0, cnt1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0)\n\t\t\t\t++cnt0;\n\t\t\telse\n\t\t\t\t++cnt1;\n\t\t}\n\t\tif (cnt0 >= cnt1)\n\t\t{\n\t\t\tforeach (i; 0..cnt0)\n\t\t\t\tans[ti] ~= 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif ((n/2) % 2)\n\t\t\t{\n\t\t\t\tforeach (i; 0..n/2+1)\n\t\t\t\t\tans[ti] ~= 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach (i; 0..n/2)\n\t\t\t\t\tans[ti] ~= 1;\n\t\t\t}\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}\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[] token;\nT rd(T = long)() { while(!token.length) token = readln.chomp.split; string res = token[0]; token.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;\n n = rd!int;\n ll[] arr = rdarr;\n ll[] res;\n ll cnt0 = 0, cnt1 = 0;\n foreach(el; arr){\n cnt0 += (el == 0);\n cnt1 += (el == 1);\n }\n ll put = (n/2) + (n % 2);\n ll hf = n / 2;\n if(cnt1 > hf || (hf % 2 == 0 && cnt1 == hf)){\n writeln(put);\n foreach(i; 0..put){\n write(1, \" \");\n }\n }else if(cnt0 >= hf){\n writeln(cnt0);\n foreach(i; 0..cnt0){\n write(0, \" \");\n }\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"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tbool hasZero;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0)\n\t\t\t\thasZero = true;\n\t\t}\n\t\tif (hasZero)\n\t\t\tans[ti] = [0];\n\t\telse\n\t\t\tans[ti] = [1, 1];\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}\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 cnt0, cnt1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0)\n\t\t\t\t++cnt0;\n\t\t\telse\n\t\t\t\t++cnt1;\n\t\t}\n\t\tif (cnt0 >= cnt1)\n\t\t{\n\t\t\tforeach (i; 0..n/2)\n\t\t\t\tans[ti] ~= 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 0..n/2)\n\t\t\t\tans[ti] ~= 1;\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}\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 cnt0, cnt1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (a[i] == 0)\n\t\t\t\t++cnt0;\n\t\t\telse\n\t\t\t\t++cnt1;\n\t\t}\n\t\tif (cnt0 > cnt1)\n\t\t{\n\t\t\tforeach (i; 0..(n+2)/2)\n\t\t\t\tans[ti] ~= 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif ((n/2) % 2)\n\t\t\t{\n\t\t\t\tforeach (i; 0..n/2-1)\n\t\t\t\t\tans[ti] ~= 1;\n\t\t\t\tif (cnt0 == 0)\n\t\t\t\t\tans[ti] ~= [1, 1];\n\t\t\t\telse\n\t\t\t\t\tans[ti] ~= 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach (i; 0..n/2)\n\t\t\t\t\tans[ti] ~= 1;\n\t\t\t}\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}\n"}], "src_uid": "eca92beb189c4788e8c4744af1428bc7"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 a = RDA;\n\n\t\tlong m = a[0];\n\t\tlong x;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = m - a[i];\n\t\t\tif (d > 0)\n\t\t\t{\n\t\t\t\tforeach (j; 0..32)\n\t\t\t\t{\n\t\t\t\t\tauto bit = 1L << j;\n\t\t\t\t\tif (d & bit)\n\t\t\t\t\t{\n\t\t\t\t\t\tx.chmax(j+1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tm.chmax(a[i]);\n\t\t}\n\t\tans[ti] = x;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"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\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\tauto a0 = a.front;\n\t\ta[] -= a0;\n\t\tint res = 0;\n\t\tint prev = 0;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tres = max (res, prev - c);\n\t\t\tprev = max (prev, c);\n\t\t}\n\t\tres = (res == 0) ? 0 : bsr (res) + 1;\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(); } 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 long[] as = scan!long(n);\n\n long t = as[0];\n long maxg = 0;\n foreach(a; as){\n if(a < t) maxg.raiseTo(t - a);\n else t = a;\n }\n if(maxg == 0) \"0\".writeln;\n else foreach(i; 0 .. 60){\n if((1L<= as[i]) continue;\n foreach (j, n; ns) if (as[i] - as[i+1] <= n) {\n ++cs[j];\n as[i+1] = as[i];\n break;\n }\n }\n foreach_reverse (i, c; cs) if (c > 0) {\n writeln(i+1);\n goto ok;\n }\n writeln(0);\n ok:\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 mx;\n long now = long.min;\n foreach (i; 0 .. N) {\n chmax(now, A[i]);\n chmax(mx, now - A[i]);\n }\n debug {\n writeln(\"mx = \", mx);\n }\n for (int e = 0; ; ++e) {\n if (mx < 2L^^e) {\n writeln(e);\n break;\n }\n }\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 long maxdiff = long.min;\n long bar = long.min;\n foreach(ai; a)\n {\n bar = max(bar, ai);\n maxdiff = max(maxdiff, bar - ai);\n }\n long bits = 0;\n while(maxdiff)\n {\n maxdiff /= 2;\n bits++;\n }\n writeln(bits);\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": "//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\nint test (const int n, const long[] a) {\n if (isSorted (a)) return 0;\n long d = 1;\n long x = 0;\n long lastD;\n long maxD;\n foreach (i; 1 .. n) {\n long t = max (0L, (a[i-1] + lastD) - a[i]);\n maxD = max (maxD, t);\n lastD = t;\n }\n debug stderr.writeln (\"maxD = \", maxD);\n foreach (l; 1 .. 50) {\n x += d;\n if (x >= maxD) return l;\n d *= 2;\n }\n return -1;\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!long(n);\n writeln (test (n, a));\n }\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(); } 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 long[] as = scan!long(n);\n\n long t = as[0];\n long maxg = 0;\n foreach(a; as){\n if(a < t) maxg.raiseTo(t - a);\n else t = a;\n }\n if(maxg == 0) \"0\".writeln;\n else foreach(i; 0 .. 30){\n if((1L< 0) {\n ++cs[j];\n as[i+1] += n;\n }\n }\n foreach_reverse (i, c; cs) if (c > 0) {\n writeln(i+1);\n goto ok;\n }\n writeln(0);\n ok:\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 long[32] ns, cs;\n foreach (i; 0..32) ns[i] = (1L<<(i+1))-1;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(long[]);\n cs[] = 0;\n long cnt;\n foreach (i; 0..N-1) {\n if (as[i] - as[i+1] <= 0) continue;\n foreach (j, n; ns) if (n >= as[i] - as[i+1]) {\n ++cs[j];\n ++cnt;\n break;\n }\n }\n if (cnt == 0) {\n writeln(0);\n continue;\n }\n long rest, res;\n foreach (i, c; cs) {\n rest += c;\n cnt -= c;\n if (rest) rest -= 1;\n res += 1;\n if (cnt == 0) break;\n }\n writeln(res + rest);\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 long[32] ns, cs;\n foreach (i; 0..32) ns[i] = (1L<<(i+1))-1;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(long[]);\n cs[] = 0;\n long cnt;\n foreach (i; 0..N-1) {\n if (as[i] - as[i+1] <= 0) continue;\n foreach (j, n; ns) if (n >= as[i] - as[i+1]) {\n ++cs[j];\n as[i+1] += n;\n ++cnt;\n break;\n }\n }\n if (cnt == 0) {\n writeln(0);\n continue;\n }\n foreach_reverse (i, c; cs) if (c > 0) {\n writeln(i+1);\n break;\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 long[32] ns, cs;\n foreach (i; 0..32) ns[i] = 1L<= as[i] - as[i+1]) {\n ++cs[j];\n ++cnt;\n break;\n }\n }\n if (cnt == 0) {\n writeln(0);\n continue;\n }\n long rest, res;\n foreach (i, c; cs) {\n rest += c;\n cnt -= c;\n if (rest) --rest;\n res += 1;\n if (cnt == 0) break;\n }\n writeln(res + rest);\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 long[63] ns, cs;\n foreach (i; 0..63) ns[i] = 1L<<(i+1)-1;\n foreach (_; 0..T) {\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(long[]);\n cs[] = 0;\n foreach (i; 0..N-1) {\n if (as[i+1] >= as[i]) continue;\n foreach (j, n; ns) if (as[i] - as[i+1] <= n) {\n ++cs[j];\n as[i+1] = as[i];\n break;\n }\n }\n foreach_reverse (i, c; cs) if (c > 0) {\n writeln(i+1);\n goto ok;\n }\n writeln(0);\n ok:\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!int;\n\t\tauto a = RDA;\n\t\t\n\t\tlong m = a[0], dd;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = a[i] - m;\n\t\t\tif (d == -2)\n\t\t\t{\n\t\t\t\td = -3;\n\t\t\t\tm.chmax(a[i]+3);\n\t\t\t}\n\t\t\tif (d < 0)\n\t\t\t{\n\t\t\t\tdd.chmax(-d);\n\t\t\t}\n\t\t\tm.chmax(a[i]);\n\t\t}\n\n\t\tlong x;\n\t\twhile (dd > 0)\n\t\t{\n\t\t\t++x;\n\t\t\tdd -= x;\n\t\t}\n\t\tans[ti] = x;\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\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 a = RDA;\n\t\t\n\t\tlong m, dd;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = a[i] - m;\n\t\t\tif (d < 0)\n\t\t\t{\n\t\t\t\tdd.chmax(-d);\n\t\t\t}\n\t\t\tm.chmax(a[i]);\n\t\t}\n\n\t\tlong x;\n\t\twhile (dd > 0)\n\t\t{\n\t\t\t++x;\n\t\t\tdd -= x;\n\t\t}\n\t\tans[ti] = x;\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\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 a = RDA;\n\t\t\n\t\tlong m = a[0], dd;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = a[i] - m;\n\t\t\tif (d < 0)\n\t\t\t{\n\t\t\t\tdd.chmax(-d);\n\t\t\t}\n\t\t\tm.chmax(a[i]);\n\t\t}\n\n\t\tlong x;\n\t\twhile (dd > 0)\n\t\t{\n\t\t\t++x;\n\t\t\tdd -= x;\n\t\t}\n\t\tans[ti] = x;\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\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 a = RDA;\n\t\t\n\t\tlong m = a[0], dd = long.min;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto d = a[i] - m;\n\t\t\tif (d < 0)\n\t\t\t{\n\t\t\t\tdd.chmax(-d);\n\t\t\t}\n\t\t\tm.chmax(a[i]);\n\t\t}\n\n\t\tlong x;\n\t\twhile (dd > 0)\n\t\t{\n\t\t\t++x;\n\t\t\tdd -= x;\n\t\t}\n\t\tans[ti] = x;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "bfc2e7de37db4a0a74cdd55f2124424a"} {"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[] as = rint(n).map!(x => x - 1).array;\n\tint[] bs = rint(n).map!(x => x - 1).array;\n\tlog(\"as:\", as, \"bs:\", bs);\n\t\n\tint[] xs = new int[](n);\n\tforeach(int i, a; as) xs[a] = i;\n\tlog(\"xs:\", xs);\n\t\n\tint[] ys = new int[](n);\n\tforeach(int i, b; bs) ys[i] = xs[b];\n\tlog(\"ys:\", ys);\n\t\n\tint t;\n\tint ans;\n\tbool[] us = new bool[](n);\n\tforeach(y; ys){\n\t\tus[y] = 1;\n\t\tif(y > t) ans += 1;\n\t\telse while(t < n && us[t]) t += 1;\n\t\tlog(\"y:\", y, \"t:\", t, \"us:\", us, \"ans:\", ans);\n\t}\n\t\n\tans.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;\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\ta[] -= 1;\n\t\tb[] -= 1;\n\n\t\tauto ia = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tia[a[i]] = i;\n\t\t}\n\t\tauto pb = new int [n];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tpb[i] = ia[b[i]];\n\t\t}\n\t\tdebug {writeln (pb);}\n\n\t\tint res = 0;\n\t\tauto vis = new bool [n + 1];\n\t\tint p = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tif (p != pb[i])\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\tvis[pb[i]] = true;\n\t\t\twhile (vis[p])\n\t\t\t{\n\t\t\t\tp += 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.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 int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt() - 1;\n }\n auto B = new int[N];\n foreach (i; 0 .. N) {\n B[i] = readInt() - 1;\n }\n \n auto ordB = new int[N];\n foreach (i; 0 .. N) {\n ordB[B[i]] = i;\n }\n \n int ans;\n int mx = -1;\n foreach (i; 0 .. N) {\n if (mx > ordB[A[i]]) {\n ++ans;\n }\n chmax(mx, ordB[A[i]]);\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.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\tauto a = RDA;\n\tauto b = RDA;\n\tint ans;\n\tbool[long] set;\n\twhile (true)\n\t{\n\t\tif (b.empty)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tif (set.get(a.front, false))\n\t\t{\n\t\t\ta.popFront;\n\t\t}\n\t\telse if (a.front != b.front)\n\t\t{\n\t\t\tif (set.get(a.front, false) == false)\n\t\t\t{\n\t\t\t\t++ans;\n\t\t\t\tset[b.front] = true;\n\t\t\t}\n\t\t\tb.popFront;\n\t\t}\n\t\telse\n\t\t{\n\t\t\ta.popFront;\n\t\t\tset[b.front] = true;\n\t\t\tb.popFront;\n\t\t}\n\t}\n\n\twriteln(ans);\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 n = RD!int;\n\tauto a = RDA;\n\tauto b = RDA;\n\tint ans;\n\tbool[long] set;\n\twhile (true)\n\t{\n\t\tif (b.empty)\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\tif (a.front != b.front)\n\t\t{\n\t\t\tif (set.get(a.front, false) == false)\n\t\t\t{\n\t\t\t\t++ans;\n\t\t\t\tset[b.front] = true;\n\t\t\t}\n\t\t\tb.popFront;\n\t\t}\n\t\telse\n\t\t{\n\t\t\ta.popFront;\n\t\t\tset[b.front] = true;\n\t\t\tb.popFront;\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "f5178609cc7782edd40bc50b8797522e"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int q;\n rd(q);\n bool enough(long k, long n, long a, long b, long m) {\n return a * m + b * (n - m) < k;\n }\n\n while (q--) {\n long k, n, a, b;\n rd(k, n, a, b);\n if (b * n >= k) {\n writeln(-1);\n continue;\n }\n long ok = 0, ng = n + 1;\n while (ng - ok > 1) {\n auto m = (ok + ng) / 2;\n if (enough(k, n, a, b, m)) {\n ok = m;\n } else {\n ng = m;\n }\n }\n writeln(ok);\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", "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 T = readln.chomp.to!int;\n while (T--) {\n auto s = readln.split.map!(to!long);\n auto K = s[0];\n auto N = s[1];\n auto A = s[2];\n auto B = s[3];\n long hi = N + 1;\n long lo = -1;\n while (hi - lo > 1) {\n long mid = (hi + lo) / 2;\n long k = K - mid * A;\n if (k + A <= A) {\n hi = mid;\n continue;\n }\n k = k - (N - mid) * B;\n if (k + B <= B) {\n hi = mid;\n continue;\n }\n lo = mid;\n }\n lo.writeln;\n }\n}\n"}], "negative_code": [], "src_uid": "2005224ffffb90411db3678ac4996f84"} {"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 S = N.iota.map!(_ => readln.chomp).array;\n S.sort!((a, b) => a.length < b.length)();\n\n foreach (i; 1..N) {\n if (!canFind(S[i], S[i-1])) {\n writeln(\"NO\");\n return;\n }\n }\n\n writeln(\"YES\");\n S.each!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.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=readln.chomp.to!int;\n auto s=new string[n];\n foreach(i;0..n)\n s[i]=readln.strip;\n sort(s);\n sort!\"a.length x.length < y.length);\n \n bool ok = zip(a, a.dropOne).array.all!(t => t[1].canFind(t[0]));\n \n if (! ok) {\n writeln(\"NO\");\n return;\n }\n \n writeln(\"YES\");\n a.each!writeln;\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.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=readln.chomp.to!int;\n auto s=new string[n];\n foreach(i;0..n)\n s[i]=readln.strip;\n sort!\"a.length= 1 && start[$ - 1] == e)\n\t{\n\t\treturn false;\n\t}\n\tif (start.length >= 2 && start[$ - 2] == e)\n\t{\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nstring build (string start, int n, int p)\n{\nmain_loop:\n\twhile (start.length < n)\n\t{\n\t\tforeach (d; 0..p)\n\t\t{\n\t\t\tchar e = cast (char) (d + 'a');\n\t\t\tif (!can_add (start, e))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tstart ~= e;\n\t\t\tcontinue main_loop;\n\t\t}\n\t\treturn null;\n\t}\n\tif (start.length == n)\n\t{\n\t\treturn start;\n\t}\n\treturn null;\n}\n\nstring solve (int n, int p, string s)\n{\n\tforeach_reverse (i, c; s)\n\t{\n\t\tforeach (d; c - 'a' + 1..p)\n\t\t{\n\t\t\tchar e = cast (char) (d + 'a');\n\t\t\tstring t = s[0..i];\n\t\t\tif (!can_add (t, e))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tt = build (t ~ e, n, p);\n\t\t\tif (t !is null)\n\t\t\t{\n\t\t\t\treturn t;\n\t\t\t}\n\t\t}\n\t}\n\treturn \"NO\";\n}\n\nvoid main ()\n{\n\tint n;\n\tint p;\n\twhile (readf (\" %s %s \", &n, &p) > 0)\n\t{\n\t\tstring s = readln ().strip ();\n\t\twriteln (solve (n, p, s));\n\t}\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\nbool nextstr(char[] carr, int idx, int p) {\n if (idx < 0) return false;\n if (carr[idx] - 'a' + 1 == p) {\n carr[idx] = 'a';\n return nextstr(carr, idx - 1, p);\n }\n else {\n carr[idx] += 1;\n return true;\n }\n}\n\nvoid setabc(char[] carr, int idx, int n) {\n char ch = 'a';\n while (idx < n) {\n carr[idx++] = ch;\n ch += 1;\n if (ch == 'd') ch = 'a';\n }\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, p;\n readf(\" %s %s\\n\", &n, &p);\n char[] mstr;\n readf(\" %s\\n\", &mstr);\n \n if (p < 3) {\n if (n == 1 && p == 2 && mstr[0] == 'a') writeln(\"b\");\n else if (n == 2 && mstr[0] == 'a' && mstr[1] == 'b') writeln(\"ba\");\n else writeln(\"NO\");\n return 0;\n }\n\n int idx = n - 1;\n while (nextstr(mstr, idx, p)) {\n foreach (i; 0 .. n - 2) {\n if (mstr[i] == mstr[i + 1]) {\n idx = i + 1;\n goto cont;\n }\n if (mstr[i] == mstr[i + 2]) {\n idx = i + 2;\n goto cont;\n }\n }\n if (n > 1 && mstr[n - 2] == mstr[n - 1]) {\n idx = n - 1;\n goto cont;\n }\n writeln(mstr);\n return 0;\ncont:\n setabc(mstr, idx + 1, n);\n }\n writeln(\"NO\");\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, P;\nstring S;\n\nstring solve() {\n\tif (P == 1) {\n\t\tif (N == 1) {\n\t\t\tif (S < \"a\") return \"a\";\n\t\t\treturn \"\";\n\t\t} else {\n\t\t\treturn \"\";\n\t\t}\n\t} else if (P == 2) {\n\t\tif (N == 1) {\n\t\t\tif (S < \"a\") return \"a\";\n\t\t\tif (S < \"b\") return \"b\";\n\t\t\treturn \"\";\n\t\t} else if (N == 2) {\n\t\t\tif (S < \"ab\") return \"ab\";\n\t\t\tif (S < \"ba\") return \"ba\";\n\t\t\treturn \"\";\n\t\t} else {\n\t\t\treturn \"\";\n\t\t}\n\t} else {\n\t\tforeach_reverse (k; 0 .. N) {\n\t\t\tstring ret = S[0 .. k];\n\t\t\tbool ok = true;\n\t\t\tforeach (i; k .. N) {\n\t\t\t\tbool found;\n\t\t\t\tforeach (x; 0 .. P) {\n\t\t\t\t\tif (i == k && x <= S[k] - 'a') {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (i >= 1 && ret[i - 1] - 'a' == x) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (i >= 2 && ret[i - 2] - 'a' == x) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tfound = true;\n\t\t\t\t\tret ~= cast(char)('a' + x);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (!found) {\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\treturn ret;\n\t\t\t}\n\t\t}\n\t\treturn \"\";\n\t}\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tP = readInt;\n\t\tS = readToken;\n\t\t\n\t\tstring res = solve;\n\t\tif (res == \"\") {\n\t\t\twriteln(\"NO\");\n\t\t} else {\n\t\t\twriteln(res);\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\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\nbool nextstr(char[] carr, int idx, int p) {\n if (idx < 0) return false;\n if (carr[idx] - 'a' + 1 == p) {\n carr[idx] = 'a';\n return nextstr(carr, idx - 1, p);\n }\n else {\n carr[idx] += 1;\n return true;\n }\n}\n\nbool ispalin(char[] carr, int bi, int ei) {\n foreach (i; 0 .. (ei - bi + 1) / 2) {\n if (carr[bi + i] != carr[ei - i]) return false;\n }\n return true;\n}\n\nvoid setabc(char[] carr, int idx, int n) {\n char ch = 'a';\n while (idx < n) {\n carr[idx++] = ch;\n ch += 1;\n if (ch == 'd') ch = 'a';\n }\n\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, p;\n readf(\" %s %s\\n\", &n, &p);\n char[] mstr;\n readf(\" %s\\n\", &mstr);\n \n if (n < 4 || p < 3) {\n while (nextstr(mstr, n - 1, p)) {\n bool palinfree = true;\n outer:\n foreach (i; 0 .. n - 1) {\n foreach (j; i + 1 .. n) {\n if (ispalin(mstr, i, j)) {\n palinfree = false;\n break outer;\n }\n }\n }\n if (palinfree) {\n writeln(mstr);\n return 0;\n }\n }\n writeln(\"NO\");\n return 0;\n }\n\n int idx = n - 1;\n while (nextstr(mstr, idx, p)) {\n foreach (i; 0 .. n - 2) {\n if (mstr[i] == mstr[i + 1]) {\n idx = i + 1;\n goto cont;\n }\n if (mstr[i] == mstr[i + 2]) {\n idx = i + 2;\n goto cont;\n }\n }\n if (mstr[n - 2] == mstr[n - 1]) {\n idx = n - 1;\n goto cont;\n }\n writeln(mstr);\n return 0;\ncont:\n setabc(mstr, idx + 1, n);\n }\n writeln(\"NO\");\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\nbool nextstr(char[] carr, int idx, int p) {\n if (idx < 0) return false;\n if (carr[idx] - 'a' + 1 == p) {\n carr[idx] = 'a';\n return nextstr(carr, idx - 1, p);\n }\n else {\n carr[idx] += 1;\n return true;\n }\n}\n\nvoid setabc(char[] carr, int idx, int n) {\n char ch = 'a';\n while (idx < n) {\n carr[idx++] = ch;\n ch += 1;\n if (ch == 'd') ch = 'a';\n }\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n, p;\n readf(\" %s %s\\n\", &n, &p);\n char[] mstr;\n readf(\" %s\\n\", &mstr);\n \n if (p < 3) {\n if (p == 1 || n > 1 || mstr[0] != 'a') {\n writeln(\"NO\");\n return 0;\n }\n else {\n writeln(\"b\");\n return 0;\n }\n }\n\n int idx = n - 1;\n while (nextstr(mstr, idx, p)) {\n foreach (i; 0 .. n - 2) {\n if (mstr[i] == mstr[i + 1]) {\n idx = i + 1;\n goto cont;\n }\n if (mstr[i] == mstr[i + 2]) {\n idx = i + 2;\n goto cont;\n }\n }\n if (n > 1 && mstr[n - 2] == mstr[n - 1]) {\n idx = n - 1;\n goto cont;\n }\n writeln(mstr);\n return 0;\ncont:\n setabc(mstr, idx + 1, n);\n }\n writeln(\"NO\");\n\n return 0;\n}"}], "src_uid": "788ae500235ca7b7a7cd320f745d1070"} {"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\tstring[string] dic = [\n\t\t\"purple\" : \"Power\",\n\t\t\"green\" : \"Time\",\n\t\t\"blue\" : \"Space\",\n\t\t\"orange\" : \"Soul\",\n\t\t\"red\" : \"Reality\",\n\t\t\"yellow\" : \"Mind\"\n\t];\n\tint m = readln.chomp.to!int;\n\tforeach (i; 0..m) {\n\t\tstring s = readln.chomp;\n\t\tdic.remove(s);\n\t}\n\tdic.length.writeln;\n\tforeach (k, v; dic) {\n\t\tv.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", "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\nvoid main()\n{\n string [string] mp = [\n \"purple\": \"Power\",\n \"green\": \"Time\",\n \"blue\": \"Space\",\n \"orange\": \"Soul\",\n \"red\": \"Reality\",\n \"yellow\": \"Mind\"\n ];\n \n readln;\n string s;\n while ((s = readln.chomp) != \"\") {\n debug { s.writeln; }\n mp.remove(s);\n }\n \n auto ans = mp.values;\n ans.length.writeln;\n ans.each!writeln;\n}"}], "negative_code": [], "src_uid": "7eff98fbcf4e4a3284e2d2f98351fe4a"} {"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\nchar[] favor(string s, bool first) {\n char[] t;\n foreach (i; 0 .. 10) {\n if (s[i] == '?') {\n bool isFirstTeam = i % 2 == 0;\n t ~= (isFirstTeam == first) ? '1' : '0';\n } else {\n t ~= s[i];\n }\n }\n return t;\n}\n\nint solve(char[] s) {\n auto score = [0, 0];\n auto rem = [5, 5];\n foreach (i; 0 .. 10) {\n if (s[i] == '1') {\n score[i % 2]++;\n }\n rem[i % 2]--;\n \n if (score[0] - score[1] > rem[1] || score[1] - score[0] > rem[0]) return i + 1;\n }\n \n return 10;\n}\n\nvoid main() {\n int T;\n read(T);\n \n while (T--) {\n string s;\n s = readln.strip;\n \n writeln(min(solve(s.favor(false)), solve(s.favor(true))));\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.ascii;\nimport core.stdc.stdio;\n\nvoid main()\n{\n\tint t = readInt!int;\n\twhile (t--)\n\t{\n\t\tchar[] str = cast(char[])readString;\n\t\tint minkicks = int.max;\n\t\tforeach(p; 0 .. 2)\n\t\t{\n\t\t\tint[2] pos = [5, 5];\n\t\t\tint[2] scr = [0, 0];\n\t\t\tint kicks = 0;\n\t\t\tforeach(i; 0 .. 10)\n\t\t\t{\n\t\t\t\tkicks++;\n\t\t\t\tint s = i & 1;\n\t\t\t\tint o = s ^ 1;\n\t\t\t\tif (str[i] == '1') scr[s]++;\n\t\t\t\telse if (str[i] == '?' && s == p) scr[s]++;\n\t\t\t\tpos[s]--;\n\t\t\t\tif (scr[o]+pos[o] < scr[s] || scr[s]+pos[s] < scr[o]) break;\n\t\t\t}\n\t\t\tminkicks = min(kicks, minkicks);\n\t\t}\n\t\tminkicks.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.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(int[] a)\n{\n long odd = 0;\n long even = 0;\n foreach (round ; 0 .. 5) {\n int remrounds = 4 - round;\n even += a[round * 2 + 0];\n if ((even > odd && even - odd > remrounds + 1) || (odd > even && odd - even > remrounds))\n return round * 2 + 1;\n odd += a[round * 2 + 1];\n if ((even > odd && even - odd > remrounds) || (odd > even && odd - even > remrounds))\n return round * 2 + 2;\n }\n return 10;\n}\n\nvoid main()\n{\n long t;\n readf!\" %d \"(t);\n while (t--) {\n string s = readln.strip;\n int[] a;\n int[] b;\n foreach (i; 0 .. s.length) {\n if (s[i] == '?') {\n if (i % 2 == 0) {\n a ~= 0;\n b ~= 1;\n } else {\n a ~= 1;\n b ~= 0;\n }\n } else {\n a ~= s[i] - '0';\n b ~= s[i] - '0';\n }\n }\n/*\n writeln(s);\n writeln(a);\n writeln(solve(a));\n writeln(b);\n writeln(solve(b));\n*/\n writeln(min(solve(a), solve(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\nimmutable int steps = 10;\r\n\r\nint solve (string s, int team)\r\n{\r\n\tint [2] goals;\r\n\tforeach (step; 0..steps)\r\n\t{\r\n\t\tauto cur = (s[step] == '0') ? 0 :\r\n\t\t (s[step] == '1') ? 1 : (step % 2 == team);\r\n\t\tgoals[step % 2] += cur;\r\n\t\tif (goals[0] + (steps - 1 - step + 0) / 2 < goals[1] ||\r\n\t\t goals[1] + (steps - 1 - step + 1) / 2 < goals[0])\r\n\t\t{\r\n\t\t\treturn step + 1;\r\n\t\t}\r\n\t}\r\n\treturn steps;\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\twriteln (min (solve (s, 0), solve (s, 1)));\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\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 s = RD!string;\r\n\r\n\t\tans[ti] = s.length;\r\n\t\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 0..s.length)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] == '?')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2 == 0)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s[i] == '1')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t--cnt;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tlong rem1 = (s.length - i) / 2 - (i % 2 == 0 ? 1 : 0);\r\n\t\t\t\t\tlong rem2 = (s.length - i) / 2;\r\n\t\t\t\t\tif (cnt > rem2 || cnt + rem1 < 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tans[ti].chmin(i+1);\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\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 0..s.length)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] == '?')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s[i] == '1')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\t--cnt;\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tlong rem1 = (s.length - i) / 2 - (i % 2 == 0 ? 1 : 0);\r\n\t\t\t\t\tlong rem2 = (s.length - i) / 2;\r\n\t\t\t\t\tif (cnt > rem1 || cnt + rem2 < 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tans[ti].chmin(i+1);\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}\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.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 s = RD!string;\r\n\r\n\t\tans[ti] = s.length;\r\n\t\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 0..s.length)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] == '?')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2 == 0)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s[i] == '1')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t--cnt;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tlong rem1 = (s.length - i) / 2 - (i % 2 == 0 ? 1 : 0);\r\n\t\t\t\t\tlong rem2 = (s.length - i) / 2;\r\n\t\t\t\t\tif (cnt > rem2 || cnt + rem1 < 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tans[ti].chmin(i+1);\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\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 0..s.length)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] == '?')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s[i] == '1')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\t--cnt;\r\n\t\t\t\t}\r\n\t\t\t\tif (i % 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tlong rem1 = (s.length - i) / 2 - (i % 2 == 0 ? 1 : 0);\r\n\t\t\t\t\tlong rem2 = (s.length - i) / 2;\r\n\t\t\t\t\tif (cnt > rem1 || cnt + rem2 < 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tans[ti].chmin(i+1);\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}\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 s = RD!string;\r\n\r\n\t\tans[ti] = s.length;\r\n\t\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 0..s.length)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] == '?')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2 == 0)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s[i] == '1')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t--cnt;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\tif (i % 2 == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tlong rem = (s.length - i) / 2;\r\n\t\t\t\t\tdebug writeln(\"i:\", i, \" cnt:\", cnt, \" rem:\", rem);\r\n\t\t\t\t\tif (cnt > rem || -cnt > rem-1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tans[ti].chmin(i+1);\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\t{\r\n\t\t\tlong cnt;\r\n\t\t\tforeach (i; 0..s.length)\r\n\t\t\t{\r\n\t\t\t\tif (s[i] == '?')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t}\r\n\t\t\t\telse if (s[i] == '1')\r\n\t\t\t\t{\r\n\t\t\t\t\tif (i % 2)\r\n\t\t\t\t\t\t++cnt;\r\n\t\t\t\t\telse\r\n\t\t\t\t\t\t--cnt;\r\n\t\t\t\t}\r\n\t\t\t\tif (i % 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tlong rem = (s.length - i) / 2;\r\n\t\t\t\t\tif (cnt > rem || -cnt > rem-1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tans[ti].chmin(i+1);\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}\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": "ba1aa2483f88164c1f281eebaab2cfbd"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n// Main Logic Here\nvoid play(){\n int n, q;\n n = rd!int; q = rd!int;\n dchar[] arr = rd!(dchar[]);\n auto before = new ll[2][n+1];\n auto after = new ll[2][n+1];\n bool is1 = 0, is0 = 0;\n\n foreach(i; 0..n){\n before[i][0] = is0;\n before[i][1] = is1;\n is0 = (arr[i] == '0' || is0);\n is1 = (arr[i] == '1' || is1);\n }\n is1 = 0; is0 = 0;\n foreach_reverse(i; 0..n){\n after[i][0] = is0;\n after[i][1] = is1;\n is0 = (arr[i] == '0' || is0);\n is1 = (arr[i] == '1' || is1);\n }\n show(before);\n show(after);\n while(q--){\n int l = rd!int;\n int r = rd!int;\n show(l, r);\n if(before[l-1][to!int(arr[l-1] - '0')] || after[r-1][to!int(arr[r-1] - '0')]){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\n }\n }\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.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 q = RD!int;\n\t\tauto s = RD!string;\n\t\tans[ti].length = q;\n\t\tforeach (i; 0..q)\n\t\t{\n\t\t\tauto l = RD!int-1;\n\t\t\tauto r = RD!int-1;\n\t\t\tbool ok;\n\t\t\tforeach (j; 0..l)\n\t\t\t{\n\t\t\t\tif (s[j] == s[l])\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\tforeach (j; r+1..n)\n\t\t\t{\n\t\t\t\tif (s[j] == s[r])\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\tans[ti][i] = ok;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (ee; e)\n\t\t\twriteln(ee ? \"YES\" : \"NO\");\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 int n, q;\n n = rd!int; q = rd!int;\n dchar[] arr = rd!(dchar[]);\n auto before = new ll[2][n+1];\n auto after = new ll[2][n+1];\n bool is1 = 0, is0 = 0;\n\n foreach(i; 0..n){\n before[i][0] = is0;\n before[i][1] = is1;\n is0 = (arr[i] == '0' || is0);\n is1 = (arr[i] == '1' || is1);\n }\n is1 = 0; is0 = 1;\n foreach_reverse(i; 0..n){\n after[i][0] = is0;\n after[i][1] = is1;\n is0 = (arr[i] == '0' || is0);\n is1 = (arr[i] == '1' || is1);\n }\n show(before);\n show(after);\n while(q--){\n int l = rd!int;\n int r = rd!int;\n show(l, r);\n if(before[l-1][to!int(arr[l-1] - '0')] || after[r-1][to!int(arr[r-1] - '0')]){\n writeln(\"YES\");\n }else{\n writeln(\"NO\");\n }\n }\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": "cbd91ac0fc9e4ca01996791e4c94bd6e"} {"source_code": "import std.stdio;\n\nint n, m;\n\nint[] col;\nint[][] edge, child;\nint[2][][] query;\n\nint size[];\nvoid root(int u) {\n size[u] = 1;\n foreach(v; edge[u]) {\n if (size[v] == 0) {\n child[u] ~= v;\n root(v);\n size[u] += size[v];\n }\n }\n}\n\nint[][] least, num, cols;\nvoid add(int lv, int c, bool rt) {\n ++least[lv][++num[lv][c]];\n cols[lv].assumeSafeAppend;\n cols[lv] ~= c;\n if (!rt) --least[lv+1][num[lv+1][c]--];\n}\n\nint[] ans;\nvoid dfs(int u, int lv) {\n int maxv = -1;\n foreach(v; child[u]) {\n if (maxv == -1 || size[v] > size[maxv]) {\n maxv = v;\n }\n }\n\n if (maxv != -1) {\n dfs(maxv, lv);\n foreach(v; child[u]) {\n if (v == maxv) continue;\n dfs(v, lv+1);\n foreach(c; cols[lv+1]) {\n add(lv, c, false);\n }\n cols[lv+1].length = 0;\n }\n }\n add(lv, col[u], true);\n\n foreach(q; query[u]) {\n ans[q[0]] = q[1] > n ? 0 : least[lv][q[1]];\n }\n}\n\nvoid main() {\n readf(\" %d %d\", &n, &m);\n\n col = new int[](n);\n foreach(i; 0..n) {\n readf(\" %d\", &col[i]);\n --col[i];\n }\n\n edge = new int[][](n, 0);\n foreach(i; 0..n-1) {\n int a, b;\n readf(\" %d %d\", &a, &b);\n --a, --b;\n\n edge[a] ~= b;\n edge[b] ~= a;\n }\n\n query = new int[2][][](n, 0);\n foreach(i; 0..m) {\n int v, k;\n readf(\" %d %d\", &v, &k);\n --v;\n\n query[v] ~= [i, k];\n }\n\n child = new int[][](n, 0);\n size = new int[](n);\n root(0);\n\n int log = 1;\n while (1 << log < n) { ++log; }\n\n least = new int[][](log, n+1);\n num = new int[][](log, 10^^5);\n cols = new int[][](log, 0);\n\n ans = new int[](m);\n dfs(0, 0);\n\n foreach(a; ans) {\n writeln(a);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nint n, m;\n\nint[] col;\nint[][] edge, child;\nint[2][][] query;\n\nint size[];\nvoid root(int u) {\n size[u] = 1;\n foreach(v; edge[u]) {\n if (size[v] == 0) {\n child[u] ~= v;\n root(v);\n size[u] += size[v];\n }\n }\n}\n\nint[][] least, num, cols;\nvoid add(int lv, int c, bool rt) {\n ++least[lv][++num[lv][c]];\n cols[lv] ~= c;\n if (!rt) --least[lv+1][num[lv+1][c]--];\n}\n\nint[] ans;\nvoid dfs(int u, int lv) {\n int maxv = -1;\n foreach(v; child[u]) {\n if (maxv == -1 || size[v] > size[maxv]) {\n maxv = v;\n }\n }\n\n if (maxv != -1) {\n dfs(maxv, lv);\n foreach(v; child[u]) {\n if (v == maxv) continue;\n dfs(v, lv+1);\n foreach(c; cols[lv+1]) {\n add(lv, c, false);\n }\n cols[lv+1].length = 0;\n }\n }\n add(lv, col[u], true);\n\n foreach(q; query[u]) {\n ans[q[0]] = q[1] > n ? 0 : least[lv][q[1]];\n }\n}\n\nvoid main() {\n readf(\" %d %d\", &n, &m);\n\n col = new int[](n);\n foreach(i; 0..n) {\n readf(\" %d\", &col[i]);\n --col[i];\n }\n\n edge = new int[][](n, 0);\n foreach(i; 0..n-1) {\n int a, b;\n readf(\" %d %d\", &a, &b);\n --a, --b;\n\n edge[a] ~= b;\n edge[b] ~= a;\n }\n\n query = new int[2][][](n, 0);\n foreach(i; 0..m) {\n int v, k;\n readf(\" %d %d\", &v, &k);\n --v;\n\n query[v] ~= [i, k];\n }\n\n child = new int[][](n, 0);\n size = new int[](n);\n root(0);\n\n int log = 1;\n while (1 << log < n) { ++log; }\n\n least = new int[][](log, n+1);\n num = new int[][](log, 10^^5);\n cols = new int[][](log, 0);\n\n ans = new int[](m);\n dfs(0, 0);\n\n foreach(a; ans) {\n writeln(a);\n }\n}\n"}, {"source_code": "import std.stdio;\n\nint n, m;\n\nint[] col;\nint[][] edge, child;\nint[2][][] query;\n\nint size[];\nvoid root(int u) {\n size[u] = 1;\n foreach(v; edge[u]) {\n if (size[v] == 0) {\n child[u] ~= v;\n root(v);\n size[u] += size[v];\n }\n }\n}\n\nint[][] least, num, cols;\nvoid add(int lv, int c, bool rt) {\n ++least[lv][++num[lv][c]];\n cols[lv] ~= c;\n if (!rt) --least[lv+1][num[lv+1][c]--];\n}\n\nint[] ans;\nvoid dfs(int u, int lv) {\n int maxv = -1;\n foreach(v; child[u]) {\n if (maxv == -1 || size[v] > size[maxv]) {\n maxv = v;\n }\n }\n\n if (maxv != -1) {\n dfs(maxv, lv);\n foreach(v; child[u]) {\n if (v == maxv) continue;\n dfs(v, lv+1);\n foreach(c; cols[lv+1]) {\n add(lv, c, false);\n }\n cols[lv+1].length = 0;\n }\n }\n add(lv, col[u], true);\n\n foreach(q; query[u]) {\n ans[q[0]] = q[1] > n ? 0 : least[lv][q[1]];\n }\n}\n\nvoid main() {\n readf(\" %d %d\", &n, &m);\n\n col = new int[](n);\n foreach(i; 0..n) {\n readf(\" %d\", &col[i]);\n --col[i];\n }\n\n edge = new int[][](n, 0);\n foreach(i; 0..n-1) {\n int a, b;\n readf(\" %d %d\", &a, &b);\n --a, --b;\n\n edge[a] ~= b;\n edge[b] ~= a;\n }\n\n query = new int[2][][](n, 0);\n foreach(i; 0..m) {\n int v, k;\n readf(\" %d %d\", &v, &k);\n --v;\n\n query[v] ~= [i, k];\n }\n\n child = new int[][](n, 0);\n size = new int[](n);\n root(0);\n\n int lg = 0;\n while (1 << lg <= n) ++lg;\n\n least = new int[][](lg, n+1);\n num = new int[][](lg, 10^^5);\n cols = new int[][](lg, 0);\n\n ans = new int[](m);\n dfs(0, 0);\n\n foreach(a; ans) {\n writeln(a);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nint n, m;\n\nint[] col;\nint[][] edge, child;\nint[2][][] query;\n\nint size[];\nvoid root(int u) {\n size[u] = 1;\n foreach(v; edge[u]) {\n if (size[v] == 0) {\n child[u] ~= v;\n root(v);\n size[u] += size[v];\n }\n }\n}\n\nint[][] least, num, cols;\nvoid add(int lv, int c, bool rt) {\n ++least[lv][++num[lv][c]];\n cols[lv].assumeSafeAppend;\n cols[lv] ~= c;\n if (!rt) --least[lv+1][num[lv+1][c]--];\n}\n\nint[] ans;\nvoid dfs(int u, int lv) {\n if (child[u] !is null) {\n int maxv = -1;\n foreach(v; child[u]) {\n if (maxv == -1 || size[v] > size[maxv]) {\n maxv = v;\n }\n }\n\n dfs(maxv, lv);\n foreach(v; child[u]) {\n if (v == maxv) continue;\n dfs(v, lv+1);\n foreach(c; cols[lv+1]) {\n add(lv, c, false);\n }\n cols[lv+1].length = 0;\n }\n }\n add(lv, col[u], true);\n\n foreach(q; query[u]) {\n ans[q[0]] = least[lv][q[1]];\n }\n}\n\nvoid main() {\n readf(\" %d %d\", &n, &m);\n\n col = new int[](n);\n foreach(i; 0..n) {\n readf(\" %d\", &col[i]);\n --col[i];\n }\n\n edge = new int[][](n, 0);\n foreach(i; 0..n-1) {\n int a, b;\n readf(\" %d %d\", &a, &b);\n --a, --b;\n\n edge[a] ~= b;\n edge[b] ~= a;\n }\n\n query = new int[2][][](n, 0);\n foreach(i; 0..m) {\n int v, k;\n readf(\" %d %d\", &v, &k);\n --v;\n\n query[v] ~= [i, k];\n }\n\n child = new int[][](n, 0);\n size = new int[](n);\n root(0);\n\n int log = 1;\n while (1 << log < n) { ++log; }\n\n least = new int[][](log, n+1);\n num = new int[][](log, 10^^5);\n cols = new int[][](log, 0);\n\n ans = new int[](m);\n dfs(0, 0);\n\n foreach(a; ans) {\n writeln(a);\n }\n}\n"}], "src_uid": "3cbcff4327aff975378d45fa30935de0"} {"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 x1, y1, x2, y2;\n\t\treadf !(\" %s %s %s %s\") (x1, y1, x2, y2);\n\t\twriteln (abs (x1 - x2) + abs (y1 - y2) +\n\t\t 2 * (x1 != x2 && y1 != y2));\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 int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x1 = RD!int;\n\t\tauto y1 = RD!int;\n\t\tauto x2 = RD!int;\n\t\tauto y2 = RD!int;\n\n\t\tans[ti] = abs(x1-x2) + abs(y1-y2);\n\t\tif (x1 != x2 && y1 != y2)\n\t\t\tans[ti] += 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\t\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "6a333044e2ed8f9f4fa44bc16b994418"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int mod = 10 ^^ 9 + 7;\n\nvoid main ()\n{\n\tint n, m, q;\n\twhile (readf !(\" %s %s %s\") (n, m, q) > 0)\n\t{\n\t\tauto d = new long [n];\n\t\talias Edge = Tuple !(int, q{u}, int, q{v}, int, q{w});\n\t\tauto e = new Edge [m];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v, w;\n\t\t\treadf !(\" %s %s %s\") (u, v, w);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\te ~= Edge (u, v, w);\n\t\t\td[u] = max (d[u], w);\n\t\t\td[v] = max (d[v], w);\n\t\t}\n\n\t\tlong res = 0;\n\t\tauto cur = new long [] [] (2, n);\n\t\tint b = 0;\n\t\tcur[b][] = long.min;\n\t\tcur[b][0] = 0;\n\t\tint oldQ = q;\n\t\twhile (q > 0 && oldQ - q <= 2000)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tcur[b][] = long.min;\n\t\t\tforeach (ref edge; e)\n\t\t\t{\n\t\t\t\tcur[b][edge.v] = max (cur[b][edge.v],\n\t\t\t\t cur[!b][edge.u] + edge.w);\n\t\t\t\tcur[b][edge.u] = max (cur[b][edge.u],\n\t\t\t\t cur[!b][edge.v] + edge.w);\n\t\t\t}\n\t\t\tres = (res + cur[b].maxElement) % mod;\n\t\t\tq -= 1;\n\t\t}\n\n\t\tauto p = n.iota.array;\n\t\twhile (q > 0)\n\t\t{\n\t\t\tmakeIndex (cur[b], p);\n\t\t\tb ^= 1;\n\t\t\tint lo = 1;\n\t\t\tint hi = q;\n\t\t\twhile (lo < hi)\n\t\t\t{\n\t\t\t\tint me = (lo + hi) / 2;\n\t\t\t\tcur[b][] = cur[!b][] + d[] * me;\n\t\t\t\tif (cur[b].countUntil (cur[b].maxElement) ==\n\t\t\t\t cur[!b].countUntil (cur[!b].maxElement))\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 (\"q = \", q, \", lo = \", lo);}\n\t\t\tlong top = cur[!b].maxElement;\n\t\t\tlong add = top % mod;\n\t\t\tint pos = cur[!b].countUntil (top).to !(int);\n\t\t\tlong arithm = ((lo - 0L) * (lo - 1L) / 2) % mod;\n\t\t\tres = (res + add * (lo - 1L)) % mod;\n\t\t\tres = (res + d[pos] * arithm) % mod;\n\t\t\tcur[b][] = cur[!b][] + d[] * lo;\n\t\t\tres = (res + cur[b].maxElement) % mod;\n\t\t\tq -= lo;\n\t\t}\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 mod = 10 ^^ 9 + 7;\n\nvoid main ()\n{\n\tint n, m, q;\n\twhile (readf !(\" %s %s %s\") (n, m, q) > 0)\n\t{\n\t\tauto d = new long [n];\n\t\talias Edge = Tuple !(int, q{u}, int, q{v}, int, q{w});\n\t\tauto e = new Edge [m];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u, v, w;\n\t\t\treadf !(\" %s %s %s\") (u, v, w);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\te ~= Edge (u, v, w);\n\t\t\td[u] = max (d[u], w);\n\t\t\td[v] = max (d[v], w);\n\t\t}\n\n\t\tlong res = 0;\n\t\tauto cur = new long [] [] (2, n);\n\t\tint b = 0;\n\t\tcur[b][] = long.min;\n\t\tcur[b][0] = 0;\n\t\tint oldQ = q;\n\t\twhile (q > 0 && oldQ - q <= 2000)\n\t\t{\n\t\t\tb ^= 1;\n\t\t\tcur[b][] = long.min;\n\t\t\tforeach (ref edge; e)\n\t\t\t{\n\t\t\t\tcur[b][edge.v] = max (cur[b][edge.v],\n\t\t\t\t cur[!b][edge.u] + edge.w);\n\t\t\t\tcur[b][edge.u] = max (cur[b][edge.u],\n\t\t\t\t cur[!b][edge.v] + edge.w);\n\t\t\t}\n\t\t\tres = (res + cur[b].maxElement) % mod;\n\t\t\tq -= 1;\n\t\t}\n\n\t\tauto p = n.iota.array;\n\t\twhile (q > 0)\n\t\t{\n\t\t\tmakeIndex (cur[b], p);\n\t\t\tb ^= 1;\n\t\t\tint lo = 1;\n\t\t\tint hi = q;\n\t\t\twhile (lo < hi)\n\t\t\t{\n\t\t\t\tint me = (lo + hi) / 2;\n\t\t\t\tcur[b][] = cur[!b][] + d[] * me;\n\t\t\t\tif (cur[b].countUntil (cur[b].maxElement) ==\n\t\t\t\t cur[!b].countUntil (cur[!b].maxElement))\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 (\"q = \", q, \", lo = \", lo);}\n\t\t\tlong top = cur[!b].maxElement;\n\t\t\tlong add = top % mod;\n\t\t\tint pos = cur[!b].countUntil (top).to !(int);\n\t\t\tlong arithm = ((lo - 0L) * (lo - 1L) / 2) % mod;\n\t\t\tres = (res + add * (lo - 1L)) % mod;\n\t\t\tres = (res + d[pos] * arithm) % mod;\n\t\t\tcur[b][] = cur[!b][] + d[] * lo;\n\t\t\tres = (res + cur[b].maxElement) % mod;\n\t\t\tq -= lo;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "8f34d2a146ff44ff4ea82fb6481d10e2"} {"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\nbool solve (int [] p)\n{\n\tstatic immutable int MAX_LIMIT = 60;\n\n\tint n = to !(int) (p.length);\n\n\tauto q = new int [n];\n\tforeach (i; 0..n)\n\t{\n\t\tq[p[i]] = i;\n\t}\n\n\tforeach (i; 0..n)\n\t{\n\t\tint k = 0;\n\t\tint lim = min (i + 1, n - i);\n\t\tif (lim <= 2 * MAX_LIMIT)\n\t\t{\n\t\t\tforeach (j; 1..lim)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (j; 1..MAX_LIMIT)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (j; lim - MAX_LIMIT..lim)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (i; 0..n)\n\t{\n\t\tint lo = max (0, i - MAX_LIMIT);\n\t\tforeach_reverse (j; lo..i)\n\t\t{\n\t\t\tint k = p[i] * 2 - p[j];\n\t\t\tif (k < 0 || n <= k)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (q[k] > i)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tint hi = min (n - 1, i + MAX_LIMIT);\n\t\tforeach (j; i + 1..hi + 1)\n\t\t{\n\t\t\tint k = p[i] * 2 - p[j];\n\t\t\tif (k < 0 || n <= k)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (q[k] < i)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false;\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 (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tp[] -= 1;\n\t\twriteln (solve (p) ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\n\nbool solve (int [] p)\n{\n\tstatic immutable int MAX_LIMIT = 60;\n\n\tint n = p.length;\n\n\tauto q = new int [n];\n\tforeach (i; 0..n)\n\t{\n\t\tq[p[i]] = i;\n\t}\n\n\tforeach (i; 0..n)\n\t{\n\t\tint lo = max (0, i - MAX_LIMIT);\n\t\tforeach_reverse (j; lo..i)\n\t\t{\n\t\t\tint k = p[i] * 2 - p[j];\n\t\t\tif (k < 0 || n <= k)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (q[k] > i)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tint hi = min (n - 1, i + MAX_LIMIT);\n\t\tforeach (j; i + 1..hi + 1)\n\t\t{\n\t\t\tint k = p[i] * 2 - p[j];\n\t\t\tif (k < 0 || n <= k)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (q[k] < i)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false;\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 (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tp[] -= 1;\n\t\twriteln (solve (p) ? \"YES\" : \"NO\");\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\nbool solve (int [] p)\n{\n\tstatic immutable int MAX_LIMIT = 60;\n\n\tint n = to !(int) (p.length);\n\n\tauto q = new int [n];\n\tforeach (i; 0..n)\n\t{\n\t\tq[p[i]] = i;\n\t}\n\n\tforeach (i; 0..n)\n\t{\n\t\tint k = 0;\n\t\tint lim = min (i + 1, n - i);\n\t\tif (lim <= 2 * MAX_LIMIT)\n\t\t{\n\t\t\tforeach (j; 1..lim)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (j; 1..MAX_LIMIT)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (j; lim - MAX_LIMIT..lim)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (i; 0..n)\n\t{\n\t\tint lo = max (0, i - MAX_LIMIT);\n\t\tforeach_reverse (j; lo..i)\n\t\t{\n\t\t\tint k = p[i] * 2 - p[j];\n\t\t\tif (k < 0 || n <= k)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (q[k] > i)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tint hi = min (n - 1, i + MAX_LIMIT);\n\t\tforeach (j; i + 1..hi + 1)\n\t\t{\n\t\t\tint k = p[i] * 2 - p[j];\n\t\t\tif (k < 0 || n <= k)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (q[k] < i)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false;\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 (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tp[] -= 1;\n\t\twriteln (solve (p) ? \"YES\" : \"NO\");\n\t}\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\n\nbool solve (int [] p)\n{\n\tstatic immutable int MAX_LIMIT = 60;\n\n\tint n = p.length;\n\n\tauto q = new int [n];\n\tforeach (i; 0..n)\n\t{\n\t\tq[p[i]] = i;\n\t}\n\n\tforeach (i; 0..n)\n\t{\n\t\tint k = 0;\n\t\tint lim = min (i + 1, n - i);\n\t\tif (lim <= 2 * MAX_LIMIT)\n\t\t{\n\t\t\tforeach (j; 1..lim)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (j; 1..MAX_LIMIT)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (j; lim - MAX_LIMIT..lim)\n\t\t\t{\n\t\t\t\tif ((q[i - j] < q[i]) != (q[i + j] < q[i]))\n\t\t\t\t{\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false;\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 (ref x; p)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tp[] -= 1;\n\t\twriteln (solve (p) ? \"YES\" : \"NO\");\n\t}\n}\n"}], "src_uid": "a34671c03f26e45e858fd552dac52062"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1494/problem/B\n// brute force\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n, U, R, D, L;\n readf(\"%s %s %s %s %s\\n\", &n, &U, &R, &D, &L);\n bool found = false;\n for(int mask = 0; mask < (1 << 4); mask++) {\n long up = U;\n long right = R;\n long down = D;\n long left = L;\n if(mask & (1 << 0)) {\n up -= 1;\n left -= 1;\n }\n if(mask & (1 << 1)) {\n left -= 1;\n down -= 1;\n }\n if(mask & (1 << 2)) {\n down -= 1;\n right -= 1;\n }\n if(mask & (1 << 3)) {\n right -= 1;\n up -= 1;\n }\n if((up >= 0 && right >= 0 && down >= 0 && left >= 0) &&\n (up <= n - 2 && right <= n - 2 && down <= n - 2 && left <= n - 2)) {\n found = true;\n break;\n }\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\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 U = RD;\r\n\t\tauto R = RD;\r\n\t\tauto D = RD;\r\n\t\tauto L = RD;\r\n\r\n\t\tforeach (i; 0..2^^4)\r\n\t\t{\r\n\t\t\tauto arr = new int[](4);\r\n\t\t\tarr[0] = i & 1;\r\n\t\t\tarr[1] = (i>>1) & 1;\r\n\t\t\tarr[2] = (i>>2) & 1;\r\n\t\t\tarr[3] = (i>>3) & 1;\r\n\t\t\tdebug writeln(arr);\r\n\r\n\t\t\tauto u = n - arr[0] - arr[1];\r\n\t\t\tauto r = n - arr[1] - arr[2];\r\n\t\t\tauto d = n - arr[2] - arr[3];\r\n\t\t\tauto l = n - arr[3] - arr[0];\r\n\t\t\tif (inside(U, 2 - arr[0] - arr[1], u+1) && inside(R, 2 - arr[1] - arr[2], r+1) &&\r\n\t\t\t\tinside(D, 2 - arr[2] - arr[3], d+1) && inside(L, 2 - arr[3] - arr[0], l+1))\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.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\tauto n = a[0] - 2;\r\n\t\ta = a[1..$];\r\n\t\tbool ok = false;\r\n\t\tforeach (i; 0..16)\r\n\t\t{\r\n\t\t\tauto corners = 4.iota.map !(k => (i >> k) & 1).array;\r\n\t\t\tauto b = a.dup;\r\n\t\t\tforeach (k; 0..4)\r\n\t\t\t{\r\n\t\t\t\tb[k] -= corners[k];\r\n\t\t\t\tb[(k + 1) & 3] -= corners[k];\r\n\t\t\t}\r\n\t\t\tok |= b.all !(v => 0 <= v && v <= n);\r\n\t\t}\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "1c94596da439c56b56e59da36734a912"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int letters = 26;\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 s = readln.strip;\n\t\tauto d = new int [letters];\n\t\tforeach (char c; s)\n\t\t{\n\t\t\td[c - 'a'] += 1;\n\t\t}\n int lo = 0;\n int let = 0;\n foreach (i; 0..k)\n {\n\t\t\twhile (d[let] == 0)\n\t\t\t{\n\t\t\t\tlet += 1;\n\t\t\t\tlo = i;\n\t\t\t}\n\t\t\td[let] -= 1;\n\t\t\tn -= 1;\n }\n\n\t\tstring res = \"\" ~ cast (char) (let + 'a');\n\t\tif (lo == 0)\n\t\t{\n\t\t\twhile (d[let] == 0)\n\t\t\t{\n\t\t\t\tlet += 1;\n\t\t\t}\n\t\t\tif (d[let] == n)\n\t\t\t{\n\t\t\t\tforeach (z; 0..(d[let] + k - 1) / k)\n\t\t\t\t{\n\t\t\t\t\tres ~= cast (char) (let + 'a');\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach (cur; 0..letters)\n\t\t\t\t{\n\t\t\t\t\tforeach (z; 0..d[cur])\n\t\t\t\t\t{\n\t\t\t\t\t\tres ~= cast (char) (cur + 'a');\n\t\t\t\t\t}\n\t\t\t\t}\n\t \t}\n\t\t}\n\t\twriteln (res);\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 (_t; 0..T) {\n auto nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n\n auto SS = readln.chomp.to!(dchar[]);\n sort(SS);\n auto S = SS.to!(char[]);\n\n char[] a;\n if (N == 1) {\n a = S;\n } else if (S[0] != S[K-1]) {\n a = [S[K-1]];\n } else if (S[0] == S[$-1]) {\n foreach (_c; 0..(S.length.to!int+K-1)/K) a ~= S[0];\n } else if (S[K] == S[$-1]) {\n auto n = S.length.to!int-K;\n a ~= S[0];\n foreach (_c; 0..(n+K-1)/K) a ~= S[K];\n } else {\n a = [S[0]] ~ S[K..$];\n }\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.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto s = RD!string;\n\n\t\tauto a = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t\ta[i] = s[i] - 'a';\n\t\ta.sort();\n\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\n\t\t\tint c, cc;\n\t\t\tforeach (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] != 0)\n\t\t\t\t{\n\t\t\t\t\t++c;\n\t\t\t\t\tif (cc == 0)\n\t\t\t\t\t\tcc = cnt[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug writeln(\"c:\", c);\n\t\t\tif (c == 1)\n\t\t\t{\n\t\t\t\tforeach (i; 0..(n+k-1)/k)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= cast(char)('a'+a[i*k]);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse if (c == 2 && cc == k)\n\t\t\t{\n\t\t\t\tforeach (i; 0..(n+k-1)/k)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= cast(char)('a'+a[i*k]);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..k)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p;\n\t\t\tforeach_reverse (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[ti] ~= cast(char)('a'+p);\n\t\t\tif (cnt[p] != k) continue;\n\t\t}\n\t\tdebug writeln(\"ans:\", ans[ti]);\n\t\tforeach (i; k..n)\n\t\t\tans[ti] ~= cast(char)('a'+a[i]);\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": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto s = RD!string;\n\n\t\tauto a = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t\ta[i] = s[i] - 'a';\n\t\ta.sort();\n\n\t\tint l;\n\t\twhile (l < n)\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; l..min(l+k, n))\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p, p2;\n\t\t\tforeach_reverse (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tforeach (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp2 = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdebug writeln(cnt);\n\t\t\t\n\t\t\tauto c = cast(char)('a'+p);\n\t\t\tif (k != cnt[p] || l+k >= n)\n\t\t\t{\n\t\t\t\tans[ti] ~= c;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (l == 0)\n\t\t\t\t\tans[ti] ~= c;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tforeach (i; 0..cnt[p2])\n\t\t\t\t\t\tans[ti] ~= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\tl += k;\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}"}, {"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\n auto SS = readln.chomp.to!(dchar[]);\n sort(SS);\n auto S = SS.to!(char[]);\n\n char[] a;\n if (N == 1) {\n a = S;\n } else if (S[0] != S[K-1]) {\n a = [S[K-1]];\n continue;\n } else if (S[0] == S[$-1]) {\n foreach (_c; 0..(S.length.to!int+K-1)/K) a ~= S[0];\n } else if (S[K] == S[$-1]) {\n auto n = S.length.to!int-K;\n a ~= S[0];\n foreach (_c; 0..(n+K-1)/K) a ~= S[K];\n } else {\n a = [S[0]] ~ S[K..$];\n }\n writeln(a);\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\n auto SS = readln.chomp.to!(dchar[]);\n sort(SS);\n auto S = SS.to!(char[]);\n\n char[] a;\n if (N == 1) {\n writeln(S);\n continue;\n } else if (S[0] != S[K-1]) {\n writeln(S[K-1]);\n continue;\n } else if (S[0] == S[$-1]) {\n foreach (_c; 0..(S.length.to!int+K-1)/K) a ~= S[0];\n writeln(a);\n continue;\n }\n\n int[26] cs;\n foreach (c; S) ++cs[c-'a'];\n bool b;\n foreach (c; cs) if (c%K != 0) b = true;\n if (b) {\n if (S[K] == S[$-1]) {\n auto n = S.length.to!int-K;\n a ~= S[0];\n foreach (_c; 0..(n+K-1)/K) a ~= S[K];\n } else {\n a = [S[0]] ~ S[K..$];\n }\n } else {\n foreach (i, c; cs) foreach (_c; 0..c/K) a ~= i.to!char+'a';\n }\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.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto s = RD!string;\n\n\t\tauto a = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t\ta[i] = s[i] - 'a';\n\t\ta.sort();\n\n\t\tint l;\n\t\twhile (l < n)\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; l..min(l+k, n))\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p;\n\t\t\tforeach_reverse (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdebug writeln(cnt);\n\t\t\t\n\t\t\tauto c = cast(char)('a'+p);\n\t\t\tif (k != cnt[p] || l+k >= n)\n\t\t\t{\n\t\t\t\tans[ti] ~= c;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (l == 0)\n\t\t\t\t\tans[ti] ~= c;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tforeach (i; 0..cnt[p])\n\t\t\t\t\t\tans[ti] ~= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\tl += k;\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}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto s = RD!string;\n\n\t\tauto a = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t\ta[i] = s[i] - 'a';\n\t\ta.sort();\n\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\t\n\t\t\tint c;\n\t\t\tforeach (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] != 0)\n\t\t\t\t\t++c;\n\t\t\t}\n\t\t\tbool ok = true;\n\t\t\tif (c != 1)\n\t\t\t{\n\t\t\t\tforeach (i; 0..26)\n\t\t\t\t{\n\t\t\t\t\tif (cnt[i] % k)\n\t\t\t\t\t\tok = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t{\n\t\t\t\tforeach (i; 0..(n+k-1)/k)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= cast(char)('a'+a[i*k]);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..k)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p;\n\t\t\tforeach_reverse (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[ti] ~= cast(char)('a'+p);\n\t\t\tif (cnt[p] != k) continue;\n\t\t}\n\t\tforeach (i; k..n)\n\t\t\tans[ti] ~= cast(char)('a'+a[i]);\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\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 string[](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 a = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t\ta[i] = s[i] - 'a';\n\t\ta.sort();\n\n\t\tif (k == 1)\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tans[ti] ~= cast(char)('a'+a[i]);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..k)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p;\n\t\t\tforeach_reverse (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[ti] ~= cast(char)('a'+p);\n\t\t\tif (cnt[p] != k) continue;\n\t\t}\n\t\tint l = k;\n\t\twhile (l < n)\n\t\t{\n\t\t\tif (l+k < n)\n\t\t\t{\n\t\t\t\tforeach (i; l..min(l+k, n))\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= cast(char)('a'+a[i]);\n\t\t\t\t}\n\t\t\t\tl += k;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; l..min(l+k, n))\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p;\n\t\t\tforeach (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdebug writeln(cnt);\n\t\t\t\n\t\t\tif (cnt[p] == min(k, n-l) && l+k >= n)\n\t\t\t{\n\t\t\t\tans[ti] ~= cast(char)('a'+p);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tl += k;\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}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 k = RD!int;\n\t\tauto s = RD!string;\n\n\t\tauto a = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t\ta[i] = s[i] - 'a';\n\t\ta.sort();\n\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\n\t\t\tint c;\n\t\t\tforeach (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] != 0)\n\t\t\t\t\t++c;\n\t\t\t}\n\t\t\tdebug writeln(\"c:\", c);\n\t\t\tif (c <= 2)\n\t\t\t{\n\t\t\t\tforeach (i; 0..(n+k-1)/k)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= cast(char)('a'+a[i*k]);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..k)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p;\n\t\t\tforeach_reverse (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[ti] ~= cast(char)('a'+p);\n\t\t\tif (cnt[p] != k) continue;\n\t\t}\n\t\tdebug writeln(\"ans:\", ans[ti]);\n\t\tforeach (i; k..n)\n\t\t\tans[ti] ~= cast(char)('a'+a[i]);\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\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 string[](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 a = new int[](n);\n\t\tforeach (i; 0..n)\n\t\t\ta[i] = s[i] - 'a';\n\t\ta.sort();\n\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tbool ok = true;\n\t\t\tforeach (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] % k)\n\t\t\t\t\tok = false;\n\t\t\t}\n\t\t\tif (ok)\n\t\t\t{\n\t\t\t\tforeach (i; 0..n/k)\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= cast(char)('a'+a[i*k]);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; 0..k)\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p;\n\t\t\tforeach_reverse (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans[ti] ~= cast(char)('a'+p);\n\t\t\tif (cnt[p] != k) continue;\n\t\t}\n\t\tint l = k;\n\t\twhile (l < n)\n\t\t{\n\t\t\tif (l+k < n)\n\t\t\t{\n\t\t\t\tforeach (i; l..min(l+k, n))\n\t\t\t\t{\n\t\t\t\t\tans[ti] ~= cast(char)('a'+a[i]);\n\t\t\t\t}\n\t\t\t\tl += k;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tauto cnt = new int[](26);\n\t\t\tforeach (i; l..min(l+k, n))\n\t\t\t{\n\t\t\t\t++cnt[a[i]];\n\t\t\t}\n\t\t\tint p;\n\t\t\tforeach (i; 0..26)\n\t\t\t{\n\t\t\t\tif (cnt[i] == 0) continue;\n\t\t\t\tp = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdebug writeln(cnt);\n\t\t\t\n\t\t\tif (cnt[p] == min(k, n-l) && l+k >= n)\n\t\t\t{\n\t\t\t\tans[ti] ~= cast(char)('a'+p);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tl += k;\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}"}], "src_uid": "df778e55a2c676acca7311d885f61d7a"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nstruct XD\n{\n int a;\n int b;\n int opCmp(ref const XD xd) const\n {\n if (a - b > xd.a - xd.b) return 1;\n if (a - b < xd.a - xd.b) return -1;\n return 0;\n }\n}\n\nvoid solve(XD[] xds, int n, int k)\n{\n sort(xds);\n auto bs = new int[n];\n bs[n - 1] = xds[n - 1].b;\n for (int i = n - 2; i >= 0; -- i)\n {\n bs[i] = bs[i + 1] + xds[i].b;\n }\n auto ans = int.max;\n auto sum = 0;\n foreach (i; 0 .. k)\n {\n sum += xds[i].a;\n }\n for (int i = k; i < n; ++ i)\n {\n ans = min(ans, sum + bs[i]);\n sum += xds[i].a;\n }\n ans = min(ans, sum);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto xds = new XD[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &xds[i].a);\n }\n readln;\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &xds[i].b);\n }\n readln;\n solve(xds, n, k);\n }\n return 0;\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\nalias Tuple!(int, \"diff\", int, \"i\") Prod;\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 auto B = readln.split.map!(to!int).array;\n\n auto P = new Prod[](N);\n foreach (i; 0..N) {\n P[i] = Prod(A[i]-B[i], i);\n }\n P.sort!\"a.diff < b.diff\"();\n\n long ans = 0;\n foreach (i, p; enumerate(P)) {\n if (i < K) ans += A[p.i];\n else if (p.diff <= 0) ans += A[p.i];\n else ans += B[p.i];\n }\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nstruct XD\n{\n int a;\n int b;\n int opCmp(ref const XD xd) const\n {\n if (a - b > xd.a - xd.b) return 1;\n if (a - b < xd.a - xd.b) return -1;\n return 0;\n }\n}\n\nvoid solve(XD[] xds, int n, int k)\n{\n sort(xds);\n auto ans = 0;\n foreach (i; 0 .. k)\n {\n ans += xds[i].a;\n }\n int i;\n for (i = k; i < n && xds[i].a < xds[i].b; ++ i)\n {\n ans += xds[i].a;\n }\n for (; i < n; ++ i)\n {\n ans += xds[i].b;\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n auto xds = new XD[n];\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &xds[i].a);\n }\n readln;\n foreach (i; 0 .. n)\n {\n readf(\" %d\", &xds[i].b);\n }\n readln;\n solve(xds, n, k);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "b5355e1f4439b198d2cc7dea01bc4bc3"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\nimport std.string;\nimport std.uni;\nimport std.math;\nimport std.container.rbtree;\nimport std.range;\n\nlong[5000] a;\nlong[5000] b;\nlong[][] dp;\nlong nonrev;\n\nlong solve(int first, int last)\n{\n if (last - first >= 2) {\n long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else if (last - first == 1) {\n long result = nonrev -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else {\n dp[first][last] = nonrev;\n return nonrev;\n }\n}\n\nvoid main()\n{\n int n, i, j, first, last;\n\n dp = new long[][](5000, 5000);\n\n readf!(\" %d\")(n);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(a[i]);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(b[i]);\n\n nonrev = 0;\n for (i = 0; i < n; i++)\n nonrev += a[i] * b[i];\n\n for (i = 0; i < n; i++)\n for (j = 0; j < n; j++)\n dp[i][j] = 0;\n\n long best = 0;\n for (first = 0; first < n; first++) {\n for (last = first; last < n; last++) {\n long result = solve(first, last);\n if (result > best) {\n best = result;\n }\n }\n }\n writeln(best);\n}\n", "positive_code": [{"source_code": "import std;\n\nlong[5000] a;\nlong[5000] b;\nlong[][] dp;\nlong nonrev;\n\nlong solve(int first, int last)\n{\n if (last - first >= 2) {\n long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else if (last - first == 1) {\n long result = nonrev -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else {\n dp[first][last] = nonrev;\n return nonrev;\n }\n}\n\nvoid main()\n{\n int n, i, j, first, last;\n\n dp = new long[][](5000, 5000);\n\n readf!(\" %d\")(n);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(a[i]);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(b[i]);\n\n nonrev = 0;\n for (i = 0; i < n; i++)\n nonrev += a[i] * b[i];\n\n for (i = 0; i < n; i++)\n for (j = 0; j < n; j++)\n dp[i][j] = 0;\n\n long best = 0;\n for (first = 0; first < n; first++) {\n for (last = first; last < n; last++) {\n long result = solve(first, last);\n if (result > best) {\n best = result;\n }\n }\n }\n writeln(best);\n}\n"}, {"source_code": "import std.stdio;\n\nlong[5000] a;\nlong[5000] b;\nlong[][] dp;\nlong nonrev;\n\nlong solve(int first, int last)\n{\n if (dp[first][last] != 0)\n return dp[first][last];\n if (last - first >= 2) {\n long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else if (last - first == 1) {\n long result = nonrev -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else {\n dp[first][last] = nonrev;\n return nonrev;\n }\n}\n\nvoid main()\n{\n int n, i, j, first, last;\n\n dp = new long[][](5000, 5000);\n\n readf!(\" %d\")(n);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(a[i]);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(b[i]);\n\n nonrev = 0;\n for (i = 0; i < n; i++)\n nonrev += a[i] * b[i];\n\n for (i = 0; i < n; i++)\n for (j = 0; j < n; j++)\n dp[i][j] = 0;\n\n long best = 0;\n for (first = n - 1; first >= 0; first--) {\n for (last = first; last < n; last++) {\n long result = solve(first, last);\n if (result > best) {\n best = result;\n }\n }\n }\n writeln(best);\n}\n"}, {"source_code": "import std.stdio;\n\nlong[5000] a;\nlong[5000] b;\nlong[][] dp;\nlong nonrev;\n\nlong solve(int first, int last)\n{\n if (dp[first][last] != 0)\n return dp[first][last];\n if (last - first >= 2) {\n long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else if (last - first == 1) {\n long result = nonrev -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else {\n dp[first][last] = nonrev;\n return nonrev;\n }\n}\n\nvoid main()\n{\n int n, i, j, first, last;\n\n dp = new long[][](5000, 5000);\n\n readf!(\" %d\")(n);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(a[i]);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(b[i]);\n\n nonrev = 0;\n for (i = 0; i < n; i++)\n nonrev += a[i] * b[i];\n\n for (i = 0; i < n; i++)\n for (j = 0; j < n; j++)\n dp[i][j] = 0;\n\n long best = 0;\n for (first = 0; first < n; first++) {\n for (last = first; last < n; last++) {\n long result = solve(first, last);\n if (result > best) {\n best = result;\n }\n }\n }\n writeln(best);\n}\n"}, {"source_code": "import std.stdio;\n\nlong[5000] a;\nlong[5000] b;\nlong[][] dp;\nlong nonrev;\n\nlong solve(int first, int last)\n{\n if (last - first >= 2) {\n long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else if (last - first == 1) {\n long result = nonrev -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else {\n dp[first][last] = nonrev;\n return nonrev;\n }\n}\n\nvoid main()\n{\n int n, i, j, first, last;\n\n dp = new long[][](5000, 5000);\n\n readf!(\" %d\")(n);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(a[i]);\n for (i = 0; i < n; i++)\n readf!(\" %d\")(b[i]);\n\n nonrev = 0;\n for (i = 0; i < n; i++)\n nonrev += a[i] * b[i];\n\n for (i = 0; i < n; i++)\n for (j = 0; j < n; j++)\n dp[i][j] = 0;\n\n long best = 0;\n for (first = 0; first < n; first++) {\n for (last = first; last < n; last++) {\n long result = solve(first, last);\n if (result > best) {\n best = result;\n }\n }\n }\n writeln(best);\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 n = RD!int;\r\n\tauto a = RDA;\r\n\tauto b = RDA;\r\n\r\n\tauto c = new long[](n+1);\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tc[i+1] = c[i] + a[i] * b[i];\r\n\t}\r\n\r\n\tlong ans = c[n];\r\n\tforeach (m; 0..n-1)\r\n\t{\r\n\t\tauto l = m;\r\n\t\tauto r = m+1;\r\n\t\tlong x;\r\n\t\twhile (l >= 0 && r < n)\r\n\t\t{\r\n\t\t\tx += a[r] * b[l] + a[l] * b[r];\r\n\t\t\tlong tmp = c[l] + c[n] - c[r+1] + x;\r\n\t\t\tans.chmax(tmp);\r\n\t\t\t--l; ++ r;\r\n\t\t}\r\n\t}\r\n\tforeach (m; 1..n-1)\r\n\t{\r\n\t\tauto l = m-1;\r\n\t\tauto r = m+1;\r\n\t\tlong x = a[m] * b[m];\r\n\t\twhile (l >= 0 && r < n)\r\n\t\t{\r\n\t\t\tx += a[r] * b[l] + a[l] * b[r];\r\n\t\t\tlong tmp = c[l] + c[n] - c[r+1] + x;\r\n\t\t\tans.chmax(tmp);\r\n\t\t\t--l; ++r;\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.conv;\r\nimport std.string, std.array;\r\nimport std.typecons, std.range;\r\nimport std.math, std.algorithm;\r\n\r\nlong solve(long[] a, long[] b)\r\n{\r\n auto n = to!int(a.length);\r\n auto s = new long[n];\r\n s[0] = a[0] * b[0];\r\n foreach (i; 1 .. n) s[i] = s[i - 1] + a[i] * b[i];\r\n auto dp = new long[][](n, 3);\r\n foreach (i; 0 .. n) dp[i][1] = a[i] * b[i];\r\n long res = s[n - 1];\r\n foreach (i; 1 .. n)\r\n {\r\n foreach (j; 0 .. n - i)\r\n {\r\n dp[j][2] = dp[j + 1][0] + a[j] * b[j + i] + a[j + i] * b[j];\r\n long v = dp[j][2] + (s[n - 1] - s[j + i]);\r\n if (j > 0) v += s[j - 1];\r\n res = max(res, v);\r\n }\r\n foreach (j; 0 .. n)\r\n {\r\n dp[j][0] = dp[j][1];\r\n dp[j][1] = dp[j][2];\r\n }\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!long)(readln.strip.split(\" \")).array;\r\n auto b = map!(to!long)(readln.strip.split(\" \")).array;\r\n auto ret = solve(a, b);\r\n writeln(ret);\r\n return 0;\r\n}"}], "negative_code": [{"source_code": "//import std;\nimport std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\nimport std.string;\nimport std.uni;\nimport std.math;\nimport std.container.rbtree;\nimport std.range;\n\nlong[] a;\nlong[] b;\nlong[][] dp;\nlong nonrev;\n\nlong solve(int first, int last)\n{\n if (last - first >= 2) {\n long result = ((dp[first + 1][last - 1] != 0) ? (dp[first + 1][last - 1]) : solve(first + 1, last - 1)) -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else if (last - first == 1) {\n long result = nonrev -\n a[first] * b[first] - a[last] * b[last] +\n a[first] * b[last] + a[last] * b[first];\n dp[first][last] = result;\n return result;\n } else {\n dp[first][last] = nonrev;\n return nonrev;\n }\n}\n\nvoid main()\n{\n int n, x, i, j, first, last;\n\n writeln(0);\n stdout.flush;\n return;\n\n readf!\" %s \"(n);\n dp = new long[][](n, n);\n a = new long[](n);\n b = new long[](n);\n\n for (i = 0; i < n; i++)\n readf!\" %s \"(a[i]);\n for (i = 0; i < n; i++)\n readf!\" %s \"(b[i]);\n\n nonrev = 0;\n for (i = 0; i < n; i++)\n nonrev += a[i] * b[i];\n\n for (i = 0; i < n; i++)\n for (j = 0; j < n; j++)\n dp[i][j] = 0;\n\n long best = 0;\n for (first = 0; first < n; first++) {\n for (last = first; last < n; last++) {\n long result = solve(first, last);\n if (result > best) {\n best = result;\n }\n }\n }\n writeln(best);\n stdout.flush;\n}\n"}], "src_uid": "7a3108216f400a4f5bb809353ceb18d4"} {"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];\n\tfor (int i=0; i readln.split.drop (1).each !(x => b[x]++));\n\twriteln (b.length == m ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s \", &n, &m) > 0)\n\t{\n\t\tint [] [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta ~= readln.split.drop (1).map !(to !(int)).array;\n\t\t}\n\t\twriteln (m.iota.map !(q{a + 1})\n\t\t .all !(x => a.any !(b => b.canFind (x))) ? \"YES\" : \"NO\");\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s \", &n, &m) > 0)\n\t{\n\t\tint [] [] a;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\ta ~= readln.split.drop (1).map !(to !(int)).array;\n\t\t}\n\t\twriteln (n.iota.map !(q{a + 1})\n\t\t .all !(x => a.any !(b => b.canFind (x))) ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.range, std.string;\n\nvoid main() {\n int n, m;\n readf(\"%d %d\\n\", &n, &m);\n int[] bulbs = new int[m];\n foreach (i; 0..n) {\n int[] buttons = readln.chomp.split.map!(to!int).array;\n foreach (e; buttons) {\n bulbs[e - 1]++;\n }\n }\n\n if (bulbs.all) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n}\n"}], "src_uid": "9438ce92e10e846dd3ab7c61a1a2e3af"} {"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 !(long);\r\n\t\twriteln ((n & (n - 1)) == 0 ? \"NO\" : \"YES\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1475/problem/A\n// math\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n long n;\n readf(\"%s\\n\", &n);\n\n while(n % 2 == 0) {\n n /= 2;\n }\n\n if(n > 1)\n \"Yes\".writeln;\n else\n \"No\".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\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\twhile (n % 2 == 0)\r\n\t\t{\r\n\t\t\tn /= 2;\r\n\t\t}\r\n\t\tans[ti] = n > 1;\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.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 N; get(N);\r\n while (N % 2 == 0) N /= 2;\r\n writeln(N == 1 ? \"NO\" : \"YES\");\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 !(long);\r\n\t\twriteln (n % 2 == 0 ? \"NO\" : \"YES\");\r\n\t}\r\n}\r\n"}], "src_uid": "f4958b4833cafa46fa71357ab1ae41af"} {"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport core.stdc.stdlib, core.stdc.string;\nimport std.stdio, std.array, std.string, std.math, std.uni;\nimport std.algorithm, std.range, std.random, std.container;\nimport std.conv, std.typecons, std.functional;\n\nimmutable Maxn = 4005;\n\nint n, m, st, ed;\nint[Maxn] p;\nTuple!(int, long)[][Maxn] g;\nlong[Maxn] dists, distt;\nlong[][Maxn] sum;\nint[][Maxn] cnt;\nlong[][Maxn] dp1, dp2;\nTuple!(Tuple!(long, int), Tuple!(long, int))[Maxn] suf1, suf2;\n\nvoid dijkstra(int st, ref long[Maxn] dist) {\n Tuple!(long, int)[] fucking = new Tuple!(long, int)[Maxn * 20];\n BinaryHeap!(Tuple!(long, int)[]) pq = BinaryHeap!(Tuple!(long, int)[])(fucking, 0);\n pq.insert(tuple(0L, st));\n dist[] = lnf;\n dist[st] = 0;\n while (!pq.empty) {\n auto pr = pq.front; pq.popFront;\n int u = pr[1];\n long d = -pr[0];\n if (d != dist[u]) continue;\n foreach(fuck; g[u]) {\n int v = fuck[0];\n long w = fuck[1];\n if (dist[v] > d + w) {\n dist[v] = d + w;\n pq.insert(tuple(-dist[v], v));\n }\n }\n }\n}\n\n// FIXME\nvoid solve(in int testcase) {\n n.read, m.read, st.read, ed.read;\n p[1 .. n + 1] = readarray!int;\n foreach(i; 1 .. m + 1) {\n int u, v; long w;\n u.read, v.read, w.read;\n g[u] ~= tuple(v, w);\n g[v] ~= tuple(u, w);\n }\n dijkstra(st, dists);\n dijkstra(ed, distt);\n \n long[] vec;\n foreach(i; 1 .. n + 1)\n vec ~= [dists[i], distt[i]];\n vec = vec.sort.unique.array;\n int len = cast(int)vec.length + 1;\n foreach(i; 0 .. vec.length + 2)\n dp1[i].length = dp2[i].length = sum[i].length = cnt[i].length = len + 1;\n foreach(i; 1 .. n + 1) {\n dists[i] = vec.lower_bound(dists[i]);\n distt[i] = vec.lower_bound(distt[i]);\n cnt[cast(int)dists[i]][cast(int)distt[i]]++;\n sum[cast(int)dists[i]][cast(int)distt[i]] += p[i];\n }\n for (int i = len - 1; i >= 0; --i) {\n for (int j = len - 1; j >= 0; --j) {\n cnt[i][j] += cnt[i][j + 1] + cnt[i + 1][j] - cnt[i + 1][j + 1];\n sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];\n }\n }\n \n void update_answer(ref Tuple!(Tuple!(long, int), Tuple!(long, int)) x, Tuple!(long, int) y) {\n if (y < x[0]) swap(y, x[0]);\n if (y[1] == x[0][1]) return ;\n x[1] = min(x[1], y);\n }\n for (int i = len - 1; i >= 0; --i) {\n for (int j = len - 1; j >= 0; --j) {\n if (!cnt[i][j]) continue;\n dp1[i][j] = sum[i][j] - (cnt[i][j] != suf1[j][0][1] ? suf1[j][0] : suf1[j][1])[0];\n dp2[i][j] = sum[i][j] - (cnt[i][j] != suf2[i][0][1] ? suf2[i][0] : suf2[i][1])[0];\n update_answer(suf1[j], tuple(dp2[i][j], cnt[i][j]));\n update_answer(suf2[i], tuple(dp1[i][j], cnt[i][j]));\n }\n }\n \n long ans1 = dp1[0][0], ans2 = sum[0][0] - dp1[0][0];\n if (ans1 == ans2) \"Flowers\".writeln;\n else if (ans1 < ans2) \"Cry\".writeln;\n else \"Break a heart\".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", "positive_code": [{"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport core.stdc.stdlib, core.stdc.string;\nimport std.stdio, std.array, std.string, std.math, std.uni;\nimport std.algorithm, std.range, std.random, std.container;\nimport std.conv, std.typecons, std.functional;\n\nimmutable Maxn = 4005;\n\nint n, m, st, ed;\nint[Maxn] p;\nTuple!(int, long)[][Maxn] g;\nlong[Maxn] dists, distt;\nlong[][Maxn] sum;\nint[][Maxn] cnt;\nlong[][Maxn] dp1, dp2;\nTuple!(Tuple!(long, int), Tuple!(long, int))[Maxn] suf1, suf2;\n\nvoid dijkstra(int st, ref long[Maxn] dist) {\n set!(Tuple!(long, int)) pq = Set(tuple!(long, int)(lnf, 0));\n pq.insert(tuple(0L, st));\n dist[] = lnf;\n dist[st] = 0;\n while (pq.length > 1) {\n auto pr = pq.front; pq.removeFront;\n int u = pr[1];\n long d = pr[0];\n if (d != dist[u]) continue;\n foreach(fuck; g[u]) {\n int v = fuck[0];\n long w = fuck[1];\n if (dist[v] > d + w) {\n dist[v] = d + w;\n pq.insert(tuple(dist[v], v));\n }\n }\n }\n}\n\n// FIXME\nvoid solve(in int testcase) {\n n.read, m.read, st.read, ed.read;\n p[1 .. n + 1] = readarray!int;\n foreach(i; 1 .. m + 1) {\n int u, v; long w;\n u.read, v.read, w.read;\n g[u] ~= tuple(v, w);\n g[v] ~= tuple(u, w);\n }\n dijkstra(st, dists);\n dijkstra(ed, distt);\n \n long[] vec;\n foreach(i; 1 .. n + 1)\n vec ~= [dists[i], distt[i]];\n vec = vec.sort.unique.array;\n int len = cast(int)vec.length + 1;\n foreach(i; 0 .. vec.length + 2)\n dp1[i].length = dp2[i].length = sum[i].length = cnt[i].length = len + 1;\n foreach(i; 1 .. n + 1) {\n dists[i] = vec.lower_bound(dists[i]);\n distt[i] = vec.lower_bound(distt[i]);\n cnt[cast(int)dists[i]][cast(int)distt[i]]++;\n sum[cast(int)dists[i]][cast(int)distt[i]] += p[i];\n }\n for (int i = len - 1; i >= 0; --i) {\n for (int j = len - 1; j >= 0; --j) {\n cnt[i][j] += cnt[i][j + 1] + cnt[i + 1][j] - cnt[i + 1][j + 1];\n sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];\n }\n }\n \n void update_answer(ref Tuple!(Tuple!(long, int), Tuple!(long, int)) x, Tuple!(long, int) y) {\n if (y < x[0]) swap(y, x[0]);\n if (y[1] == x[0][1]) return ;\n x[1] = min(x[1], y);\n }\n for (int i = len - 1; i >= 0; --i) {\n for (int j = len - 1; j >= 0; --j) {\n if (!cnt[i][j]) continue;\n dp1[i][j] = sum[i][j] - (cnt[i][j] != suf1[j][0][1] ? suf1[j][0] : suf1[j][1])[0];\n dp2[i][j] = sum[i][j] - (cnt[i][j] != suf2[i][0][1] ? suf2[i][0] : suf2[i][1])[0];\n update_answer(suf1[j], tuple(dp2[i][j], cnt[i][j]));\n update_answer(suf2[i], tuple(dp1[i][j], cnt[i][j]));\n }\n }\n \n long ans1 = dp1[0][0], ans2 = sum[0][0] - dp1[0][0];\n if (ans1 == ans2) \"Flowers\".writeln;\n else if (ans1 < ans2) \"Cry\".writeln;\n else \"Break a heart\".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;\nalias set = RedBlackTree;\nalias Set = redBlackTree;\nalias priority_queue(T, alias less = \"a < b\") = BinaryHeap!(T[], less);\nalias min_heap(T) = priority_queue!(T, \"a > b\");\nalias max_heap(T) = priority_queue!(T, \"a < b\");\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": [{"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport core.stdc.stdlib, core.stdc.string;\nimport std.stdio, std.array, std.string, std.math, std.uni;\nimport std.algorithm, std.range, std.random, std.container;\nimport std.conv, std.typecons, std.functional;\n\nimmutable Maxn = 4005;\n\nint n, m, st, ed;\nint[Maxn] p;\nTuple!(int, long)[][Maxn] g;\nlong[Maxn] dists, distt;\nlong[][Maxn] sum;\nint[][Maxn] cnt;\nlong[][Maxn] dp1, dp2;\nTuple!(Tuple!(long, int), Tuple!(long, int))[Maxn] suf1, suf2;\n\nvoid dijkstra(int st, ref long[Maxn] dist) {\n set!(Tuple!(long, int)) pq = Set(tuple!(long, int)(-lnf - 1, 0));\n pq.insert(tuple(0L, st));\n dist[] = lnf;\n dist[st] = 0;\n while (pq.length > 1) {\n auto pr = pq.front; pq.removeFront;\n int u = pr[1];\n long d = pr[0];\n if (d != dist[u]) continue;\n foreach(fuck; g[u]) {\n int v = fuck[0];\n long w = fuck[1];\n if (dist[v] > d + w) {\n dist[v] = d + w;\n pq.insert(tuple(dist[v], v));\n }\n }\n }\n}\n\n// FIXME\nvoid solve(in int testcase) {\n n.read, m.read, st.read, ed.read;\n p[1 .. n + 1] = readarray!int;\n foreach(i; 1 .. m + 1) {\n int u, v; long w;\n u.read, v.read, w.read;\n g[u] ~= tuple(v, w);\n g[v] ~= tuple(u, w);\n }\n dijkstra(st, dists);\n dijkstra(ed, distt);\n \n long[] vec;\n foreach(i; 1 .. n + 1)\n vec ~= [dists[i], distt[i]];\n vec = vec.sort.unique.array;\n int len = cast(int)vec.length + 1;\n foreach(i; 0 .. vec.length + 2)\n dp1[i].length = dp2[i].length = sum[i].length = cnt[i].length = len + 1;\n foreach(i; 1 .. n + 1) {\n dists[i] = vec.lower_bound(dists[i]);\n distt[i] = vec.lower_bound(distt[i]);\n cnt[cast(int)dists[i]][cast(int)distt[i]]++;\n sum[cast(int)dists[i]][cast(int)distt[i]] += p[i];\n }\n for (int i = len - 1; i >= 0; --i) {\n for (int j = len - 1; j >= 0; --j) {\n cnt[i][j] += cnt[i][j + 1] + cnt[i + 1][j] - cnt[i + 1][j + 1];\n sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];\n }\n }\n \n void update_answer(ref Tuple!(Tuple!(long, int), Tuple!(long, int)) x, Tuple!(long, int) y) {\n if (y < x[0]) swap(y, x[0]);\n if (y[1] == x[0][1]) return ;\n x[1] = min(x[1], y);\n }\n for (int i = len - 1; i >= 0; --i) {\n for (int j = len - 1; j >= 0; --j) {\n if (!cnt[i][j]) continue;\n dp1[i][j] = sum[i][j] - (cnt[i][j] != suf1[j][0][1] ? suf1[j][0] : suf1[j][1])[0];\n dp2[i][j] = sum[i][j] - (cnt[i][j] != suf2[i][0][1] ? suf2[i][0] : suf2[i][1])[0];\n update_answer(suf1[j], tuple(dp2[i][j], cnt[i][j]));\n update_answer(suf2[i], tuple(dp1[i][j], cnt[i][j]));\n }\n }\n \n long ans1 = dp1[0][0], ans2 = sum[0][0] - dp1[0][0];\n if (ans1 == ans2) \"Flowers\".writeln;\n else if (ans1 < ans2) \"Cry\".writeln;\n else \"Break a heart\".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;\nalias set = RedBlackTree;\nalias Set = redBlackTree;\nalias priority_queue(T, alias less = \"a < b\") = BinaryHeap!(T[], less);\nalias min_heap(T) = priority_queue!(T, \"a > b\");\nalias max_heap(T) = priority_queue!(T, \"a < b\");\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": "// Code By H~$~C\n\nmodule main;\n\nimport core.stdc.stdlib, core.stdc.string;\nimport std.stdio, std.array, std.string, std.math, std.uni;\nimport std.algorithm, std.range, std.random, std.container;\nimport std.conv, std.typecons, std.functional;\n\nimmutable Maxn = 4005;\n\nint n, m, st, ed;\nint[Maxn] p;\nTuple!(int, long)[][Maxn] g;\nlong[Maxn] dists, distt;\nlong[][Maxn] sum;\nint[][Maxn] cnt;\nlong[][Maxn] dp1, dp2;\nTuple!(Tuple!(long, int), Tuple!(long, int))[Maxn] suf1, suf2;\n\nvoid dijkstra(int st, ref long[Maxn] dist) {\n set!(Tuple!(long, int)) pq = Set(tuple!(long, int)(-1, 0));\n pq.insert(tuple(0L, st));\n dist[] = lnf;\n dist[st] = 0;\n while (pq.length > 1) {\n auto pr = pq.front; pq.removeFront;\n int u = pr[1];\n long d = pr[0];\n if (d != dist[u]) continue;\n foreach(fuck; g[u]) {\n int v = fuck[0];\n long w = fuck[1];\n if (dist[v] > d + w) {\n dist[v] = d + w;\n pq.insert(tuple(dist[v], v));\n }\n }\n }\n}\n\n// FIXME\nvoid solve(in int testcase) {\n n.read, m.read, st.read, ed.read;\n p[1 .. n + 1] = readarray!int;\n foreach(i; 1 .. m + 1) {\n int u, v; long w;\n u.read, v.read, w.read;\n g[u] ~= tuple(v, w);\n g[v] ~= tuple(u, w);\n }\n dijkstra(st, dists);\n dijkstra(ed, distt);\n \n long[] vec;\n foreach(i; 1 .. n + 1)\n vec ~= [dists[i], distt[i]];\n vec = vec.sort.unique.array;\n int len = cast(int)vec.length + 1;\n foreach(i; 0 .. vec.length + 2)\n dp1[i].length = dp2[i].length = sum[i].length = cnt[i].length = len + 1;\n foreach(i; 1 .. n + 1) {\n dists[i] = vec.lower_bound(dists[i]);\n distt[i] = vec.lower_bound(distt[i]);\n cnt[cast(int)dists[i]][cast(int)distt[i]]++;\n sum[cast(int)dists[i]][cast(int)distt[i]] += p[i];\n }\n for (int i = len - 1; i >= 0; --i) {\n for (int j = len - 1; j >= 0; --j) {\n cnt[i][j] += cnt[i][j + 1] + cnt[i + 1][j] - cnt[i + 1][j + 1];\n sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];\n }\n }\n \n void update_answer(ref Tuple!(Tuple!(long, int), Tuple!(long, int)) x, Tuple!(long, int) y) {\n if (y < x[0]) swap(y, x[0]);\n if (y[1] == x[0][1]) return ;\n x[1] = min(x[1], y);\n }\n for (int i = len - 1; i >= 0; --i) {\n for (int j = len - 1; j >= 0; --j) {\n if (!cnt[i][j]) continue;\n dp1[i][j] = sum[i][j] - (cnt[i][j] != suf1[j][0][1] ? suf1[j][0] : suf1[j][1])[0];\n dp2[i][j] = sum[i][j] - (cnt[i][j] != suf2[i][0][1] ? suf2[i][0] : suf2[i][1])[0];\n update_answer(suf1[j], tuple(dp2[i][j], cnt[i][j]));\n update_answer(suf2[i], tuple(dp1[i][j], cnt[i][j]));\n }\n }\n \n long ans1 = dp1[0][0], ans2 = sum[0][0] - dp1[0][0];\n if (ans1 == ans2) \"Flowers\".writeln;\n else if (ans1 < ans2) \"Cry\".writeln;\n else \"Break a heart\".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;\nalias set = RedBlackTree;\nalias Set = redBlackTree;\nalias priority_queue(T, alias less = \"a < b\") = BinaryHeap!(T[], less);\nalias min_heap(T) = priority_queue!(T, \"a > b\");\nalias max_heap(T) = priority_queue!(T, \"a < b\");\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"}], "src_uid": "abe5c12553340f054b7161b523a925b2"} {"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\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});\n\t\tauto e = new Edge [m];\n\t\tauto d = new int [n];\n\t\tauto a = new bool [int] [n];\n\t\tforeach (ref edge; e)\n\t\t{\n\t\t\treadf (\" %s %s\", &edge.u, &edge.v);\n\t\t\tedge.u -= 1;\n\t\t\tedge.v -= 1;\n\t\t\td[edge.u] += 1;\n\t\t\td[edge.v] += 1;\n\t\t\ta[edge.u][edge.v] = true;\n\t\t\ta[edge.v][edge.u] = true;\n\t\t}\n\t\tdebug {writeln (a);}\n\t\tdebug {writeln (d);}\n\t\tdebug {writeln (e);}\n\n\t\talias Record = Tuple !(int, q{deg}, int, q{num});\n\t\tauto t = redBlackTree !(Record);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tt.insert (Record (d[i], i));\n\t\t}\n\n\t\tvoid changeDegree (int v, int delta)\n\t\t{\n\t\t\tauto cur = Record (d[v], v);\n\t\t\tauto r = t.equalRange (cur);\n\t\t\tif (r.empty)\n\t\t\t{\n\t\t\t\td[v] += delta;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tt.removeKey (cur);\n\t\t\t\td[v] += delta;\n\t\t\t\tcur.deg = d[v];\n\t\t\t\tt.insert (cur);\n\t\t\t}\n\t\t}\n\n\t\tvoid removeVertex (int v)\n\t\t{\n\t\t\tdebug {writeln (v, \": \", a[v].length, \" \", d[v]);}\n\t\t\tassert (a[v].length == d[v]);\n\t\t\tforeach (u, _; a[v])\n\t\t\t{\n\t\t\t\tchangeDegree (u, -1);\n\t\t\t\ta[u].remove (v);\n\t\t\t}\n\t\t\ta[v] = null;\n\t\t\tt.removeKey (Record (d[v], v));\n\t\t\tchangeDegree (v, -d[v]);\n\t\t}\n\n\t\tauto ans = new int [m];\n\t\tforeach_reverse (int j, ref edge; e)\n\t\t{\n\t\t\twhile (!t.empty && t.front.deg < k)\n\t\t\t{\n\t\t\t\tdebug {writeln (\"step \", j, \": \", t);}\n\t\t\t\tremoveVertex (t.front.num);\n\t\t\t}\n\t\t\tdebug {writeln (\"step \", j, \": \", t);}\n\t\t\tans[j] = t.length.to !(int);\n\t\t\tif (edge.v in a[edge.u])\n\t\t\t{\n\t\t\t\tchangeDegree (edge.u, -1);\n\t\t\t\tchangeDegree (edge.v, -1);\n\t\t\t\ta[edge.u].remove (edge.v);\n\t\t\t\ta[edge.v].remove (edge.u);\n\t\t\t\tdebug {writeln (\"step \", j, \": \", t);}\n\t\t\t}\n\t\t}\n\n\t\tforeach (ref c; ans)\n\t\t{\n\t\t\twriteln (c);\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;\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 G = new bool[int][](N);\n auto D = new int[](N);\n auto Q = new Tuple!(int, int)[](M);\n foreach (i; 0..M) {\n s = readln.split.map!(to!int);\n G[s[0]-1][s[1]-1] = true;\n G[s[1]-1][s[0]-1] = true;\n D[s[0]-1] += 1;\n D[s[1]-1] += 1;\n Q[i] = tuple(s[0]-1, s[1]-1);\n }\n\n int sm = N;\n auto valid = new bool[](N);\n fill(valid, true);\n\n void dfs(int n) {\n if (!valid[n]) return;\n valid[n] = false;\n sm -= 1;\n foreach (m; G[n].keys) {\n if (!G[n][m]) continue;\n D[m] -= 1;\n G[n][m] = false;\n G[m][n] = false;\n if (valid[m] && D[m] < K) {\n dfs(m);\n }\n }\n }\n\n foreach (i; 0..N) {\n if (D[i] < K) dfs(i);\n }\n\n int[] ans;\n foreach_reverse (q; Q) {\n ans ~= sm;\n int u = q[0];\n int v = q[1];\n if (!valid[u] || !valid[v]) continue;\n D[u] -= 1;\n D[v] -= 1;\n G[u][v] = false;\n G[v][u] = false;\n if (valid[u] && D[u] < K) dfs(u);\n if (valid[v] && D[v] < K) dfs(v);\n }\n\n ans.reverse();\n ans.each!writeln;\n}\n"}], "negative_code": [], "src_uid": "d795e0f49617b1aa281c72f24a632f67"} {"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\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\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\ta[] -= 1;\n\t\tauto next = new int [n];\n\t\tnext[] = NA;\n\t\tauto prev = new int [n];\n\t\tprev[] = NA;\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tprev[a[i + 1]] = a[i];\n\t\t\tnext[a[i]] = a[i + 1];\n\t\t}\n\n\t\tauto b = readln.splitter.map !(to !(int)).array;\n\t\tb[] -= 1;\n\t\tauto used = new bool [n];\n\t\tforeach (ref cur; b)\n\t\t{\n\t\t\tused[cur] = true;\n\t\t}\n\n\t\tint res = 1;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tint mult = 0;\n\t\t\tif (prev[b[i]] != NA && !used[prev[b[i]]])\n\t\t\t{\n\t\t\t\tmult += 1;\n\t\t\t}\n\t\t\tif (next[b[i]] != NA && !used[next[b[i]]])\n\t\t\t{\n\t\t\t\tmult += 1;\n\t\t\t}\n\t\t\tres = (res * mult) % mod;\n\t\t\tif (next[b[i]] != NA)\n\t\t\t{\n\t\t\t\tprev[next[b[i]]] = prev[b[i]];\n\t\t\t}\n\t\t\tif (prev[b[i]] != NA)\n\t\t\t{\n\t\t\t\tnext[prev[b[i]]] = next[b[i]];\n\t\t\t}\n\t\t\tused[b[i]] = false;\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 MO = 998244353;\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 auto B = new int[K];\n foreach (k; 0 .. K) {\n B[k] = readInt();\n }\n \n auto lef = new int[N + 1];\n auto rig = new int[N + 1];\n rig[0] = A[0];\n lef[A[0]] = 0;\n foreach (i; 0 .. N - 1) {\n rig[A[i]] = A[i + 1];\n lef[A[i + 1]] = A[i];\n }\n rig[A[N - 1]] = 0;\n lef[0] = A[N - 1];\n \n auto del = new bool[N + 1];\n del[0] = true;\n foreach (k; 0 .. K) {\n del[B[k]] = true;\n }\n \n long ans = 1;\n foreach (k; 0 .. K) {\n const l = lef[B[k]];\n const r = rig[B[k]];\n rig[l] = r;\n lef[r] = l;\n int num;\n if (!del[l]) ++num;\n if (!del[r]) ++num;\n (ans *= num) %= MO;\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 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(-1);\n\t\tauto b = RDA(-1);\n\n\t\tauto need = new bool[](n);\n\t\tforeach (e; b)\n\t\t{\n\t\t\tneed[e] = true;\n\t\t}\n\n\t\tauto pos = new int[](n);\n\t\tauto link = new int[][](n);\n\t\tforeach (int i; 0..n)\n\t\t{\n\t\t\tpos[a[i]] = i;\n\t\t\tlink[i] = [i-1, i+1];\n\t\t}\n\n\t\tlong tmp = 1;\n\t\tforeach (e; b)\n\t\t{\n\t\t\tauto p = pos[e];\n\t\t\tauto l = link[p][0];\n\t\t\tauto r = link[p][1];\n\t\t\tint cnt;\n\t\t\tif (l != -1)\n\t\t\t{\n\t\t\t\tif (!need[a[l]])\n\t\t\t\t\t++cnt;\n\t\t\t\tlink[l][1] = r;\n\t\t\t}\n\t\t\tif (r != n)\n\t\t\t{\n\t\t\t\tif (!need[a[r]])\n\t\t\t\t\t++cnt;\n\t\t\t\tlink[r][0] = l;\n\t\t\t}\n\t\t\ttmp.modm(cnt);\n\t\t\tneed[e] = false;\n\t\t}\n\t\tans[ti] = tmp;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "d4249cd3147e888e13e85767d3457d0b"} {"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 S = readToken();\n N = cast(int)(S.length);\n \n auto sum = new long[N];\n foreach (i; 0 .. N - 1) {\n sum[i + 1] = sum[i] + ((S[i .. i + 2] == \"vv\") ? 1 : 0);\n }\n long ans;\n foreach (i; 0 .. N) {\n if (S[i] == 'o') {\n ans += sum[max(i - 1, 0)] * (sum[$ - 1] - sum[min(i + 1, $ - 1)]);\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=\"1.0.1\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv, std.string;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n string s;\n sc.read(s);\n\n auto li = s.group.array;\n\n debug writeln(li);\n\n long ans = 0;\n auto m = li.length;\n long[] cnt = new long[m + 1];\n long lsm = 0, rsm = 0;\n foreach (tok; li) {\n if (tok[0] == 'v') {\n rsm += tok[1] - 1;\n }\n }\n foreach (tok; li) {\n if (tok[0] == 'v') {\n lsm += tok[1] - 1;\n rsm -= tok[1] - 1;\n }\n if (tok[0] == 'o') {\n ans += lsm * tok[1] * rsm;\n }\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/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"}], "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;\nstring S;\n\nvoid main() {\n try {\n for (; ; ) {\n S = readToken();\n N = cast(int)(S.length);\n \n auto sum = new long[N];\n foreach (i; 0 .. N - 1) {\n sum[i + 1] = sum[i] + ((S[i .. i + 2] == \"vv\") ? 1 : 0);\n }\n long ans;\n foreach (i; 0 .. N) {\n if (S[i] == 'o') {\n ans += sum[i - 1] * (sum[$ - 1] - sum[i + 1]);\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "6cc6db6f426bb1bce59f23bfcb762b08"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, k; rd(n, k);\n\n auto dp=new int[][](4, k+10);\n const int mod=998244353;\n\n void add(ref int x, int y){\n x+=y;\n if(x>=mod) x-=mod;\n }\n dp[0][1]=dp[3][1]=1;\n dp[1][2]=dp[2][2]=1;\n for(int i=1; i MD) a -= MD;\n return a;\n}\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n auto dp = new int[][][] (n+1, 2*k+10, 4);\n dp[1][1][0] = dp[1][1][1] = dp[1][2][2] = dp[1][2][3] = 1;\n foreach (i; 2 .. n+1) {\n foreach (j; 1 .. 2*k+1) {\n dp[i][j][0] = add(dp[i-1][j][0], add(dp[i-1][j-1][1], add(dp[i-1][j][2], dp[i-1][j][3])));\n dp[i][j][1] = add(dp[i-1][j-1][0], add(dp[i-1][j][1], add(dp[i-1][j][2], dp[i-1][j][3])));\n \n dp[i][j][2] = add(dp[i-1][j-1][0], add(dp[i-1][j-1][1], dp[i-1][j][2]));\n if (j > 1) dp[i][j][2] = add(dp[i][j][2], dp[i-1][j-2][3]);\n \n dp[i][j][3] = add(dp[i-1][j-1][0], add(dp[i-1][j-1][1], dp[i-1][j][3]));\n if (j > 1) dp[i][j][3] = add(dp[i][j][3], dp[i-1][j-2][2]);\n \n debug { writeln(i, ' ', j, ' ', dp[i][j]); }\n }\n }\n \n auto ans = dp[n][k].fold!((a, b) => add(a, b));\n ans.writeln;\n}"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint saiki(int idx, int cnt, int s, int n, int k, int[][] c, int[][][] dp)\n{\n if (cnt > k)\n {\n return 0;\n }\n if (dp[idx][cnt][s] != -1)\n {\n return dp[idx][cnt][s];\n }\n if (idx == n)\n {\n dp[idx][cnt][s] = (cnt == k) ? 1 : 0;\n return dp[idx][cnt][s];\n }\n const static int mod = 998244353;\n auto res = 0;\n foreach (i; 0 .. 4)\n {\n auto ret = saiki(idx + 1, cnt + c[s][i], i, n, k, c, dp);\n res = (res + ret) % mod;\n }\n dp[idx][cnt][s] = res;\n return res;\n}\n\nvoid solve(int n, int k)\n{\n auto c = new int[][](4, 4);\n foreach (i; 0 .. 4) fill(c[i], 0);\n foreach (i; 1 .. 4) c[0][i] = 1;\n foreach (i; 0 .. 3) c[3][i] = 1;\n c[1][2] = c[2][1] = 2;\n auto dp = new int[][][](n + 1, k + 1, 4);\n foreach (i; 0 .. n + 1)\n {\n foreach (j; 0 .. k + 1)\n {\n fill(dp[i][j], -1);\n }\n }\n const static int mod = 998244353;\n auto res = 0;\n res = (res + saiki(1, 1, 0, n, k, c, dp)) % mod;\n res = (res + saiki(1, 2, 1, n, k, c, dp)) % mod;\n res = (res + saiki(1, 2, 2, n, k, c, dp)) % mod;\n res = (res + saiki(1, 1, 3, n, k, c, dp)) % mod;\n writeln(res);\n}\n\nint main(string[] args)\n{\n int n, k;\n while (readf(\"%d %d\\n\", &n, &k) == 2)\n {\n solve(n, k);\n }\n return 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\nimmutable int MD = 998244353;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n\n auto dp = new uint[][][] (n+1, 2*k+1, 4);\n dp[1][1][0] = dp[1][1][1] = dp[1][2][2] = dp[1][2][3] = 1;\n foreach (i; 2 .. n+1) {\n foreach (j; 1 .. 2*k+1) {\n dp[i][j][0] = dp[i-1][j][0] + dp[i-1][j-1][1] + dp[i-1][j][2] + dp[i-1][j][3];\n dp[i][j][1] = dp[i-1][j-1][0] + dp[i-1][j][1] + dp[i-1][j][2] + dp[i-1][j][3];\n \n dp[i][j][2] = dp[i-1][j-1][0] + dp[i-1][j-1][1] + dp[i-1][j][2];\n if (j > 1) dp[i][j][2] += dp[i-1][j-2][3];\n \n dp[i][j][3] = dp[i-1][j-1][0] + dp[i-1][j-1][1] + dp[i-1][j][3];\n if (j > 1) dp[i][j][3] += dp[i-1][j-2][2];\n \n dp[i][j][] %= MD;\n debug { writeln(i, ' ', j, ' ', dp[i][j]); }\n }\n }\n \n auto ans = dp[n][k].sum() % MD;\n ans.writeln;\n}"}], "negative_code": [], "src_uid": "7e6a2329633ee283e3327413114901d1"} {"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 int t;\r\n readf!\"%s\"(t);\r\n readln;\r\n \r\n while (t--) {\r\n int n, d;\r\n readf!\"%s %s\"(n, d);\r\n readln;\r\n \r\n auto arr = readln.chomp.split.map!(to!int).array;\r\n \r\n auto vis = new bool[] (n);\r\n vis[] = false;\r\n \r\n int ans = -1;\r\n foreach (i; 0 .. n) {\r\n if (vis[i]) { continue; }\r\n \r\n int[] tmp;\r\n int p = i;\r\n while (!vis[p]) {\r\n vis[p] = true;\r\n tmp ~= arr[p];\r\n p = (p + d) % n;\r\n }\r\n \r\n tmp = tmp ~ tmp;\r\n \r\n int longest = 0;\r\n int cur = 0;\r\n foreach (e; tmp) {\r\n if (e == 0) { cur = 0; }\r\n else { cur += 1; }\r\n \r\n longest = max(longest, cur);\r\n }\r\n \r\n if (longest == tmp.length) { \r\n ans = -1;\r\n break;\r\n }\r\n \r\n ans = max(ans, longest);\r\n }\r\n \r\n ans.writeln;\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 d = readInt!int;\n\tauto a = ma(n, readInt!int);\n\tauto inCycle = new bool[](n);\n\tint steps = 0;\n\tbool processCycle(int[] cycle)\n\t{\n\t\tdebug writeln(\"processing cycle \", cycle);\n\t\tif (cycle.length == 0) return false;\n\t\tauto isBad = true;\n\t\tforeach(i; cycle)\n\t\t\tif (a[i] == 0)\n\t\t\t\tisBad = false;\n\t\tif (isBad) { return isBad; }\n\t\tauto doubleCycle = cycle ~ cycle;\n\t\tint last0 = -1;\n\t\tforeach(i, ci; doubleCycle)\n\t\t{\n\t\t\tif (a[ci] == 0) last0 = cast(int)i;\n\t\t\tif (i >= cycle.length)\n\t\t\t{\n\t\t\t\tsteps = max(steps, cast(int)i - last0);\n\t\t\t}\n\t\t}\n\t\treturn isBad;\n\t}\n\tauto bad = false;\n\tforeach(i; 0 .. n)\n\t{\n\t\tint[] cycle;\n\t\twhile (!inCycle[i])\n\t\t{\n\t\t\tinCycle[i] = true;\n\t\t\tcycle ~= i;\n\t\t\ti = (i+d)%n;\n\t\t}\n\t\tbad = bad || processCycle(cycle);\n\t}\n\tif (!bad) steps.writeln; else (-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"}], "negative_code": [], "src_uid": "c15bce9c4b9eddf5c8c3421b768da98c"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1421/problem/B\n// greedy\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 string[] grid;\n for(int i = 0; i < n; i++) {\n string str;\n readf(\"%s\\n\", &str);\n grid ~= str;\n }\n if(grid[$-1][$-2] == grid[$-2][$-1]) {\n int c = 0;\n if(grid[0][1] == grid[$-1][$-2])\n c += 1;\n if(grid[1][0] == grid[$-1][$-2])\n c += 1;\n c.writeln;\n if(grid[0][1] == grid[$-1][$-2])\n writeln(\"1 2\");\n if(grid[1][0] == grid[$-1][$-2])\n writeln(\"2 1\");\n continue;\n }\n if(grid[0][1] == grid[1][0]) {\n int c = 0;\n if(grid[$-1][$-2] == grid[0][1])\n c += 1;\n if(grid[$-2][$-1] == grid[0][1])\n c += 1;\n c.writeln;\n if(grid[$-1][$-2] == grid[0][1])\n writefln(\"%s %s\", n, n - 1);\n if(grid[$-2][$-1] == grid[0][1])\n writefln(\"%s %s\", n - 1, n);\n continue;\n }\n \"2\".writeln;\n if(grid[0][1] == '1')\n writeln(\"1 2\");\n if(grid[1][0] == '1')\n writeln(\"2 1\");\n if(grid[$-1][$-2] == '0')\n writefln(\"%s %s\", n, n - 1);\n if(grid[$-2][$-1] == '0')\n writefln(\"%s %s\", n- 1, 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 s = new string[](n);\n\t\tforeach (i; 0..n)\n\t\t\ts[i] = RD!string;\n\n\t\tif (s[0][1] == s[1][0])\n\t\t{\n\t\t\tif (s[n-1][n-2] == s[0][1])\n\t\t\t\tans[ti] ~= [n, n-1];\n\t\t\tif (s[n-2][n-1] == s[0][1])\n\t\t\t\tans[ti] ~= [n-1, n];\n\t\t}\n\t\telse if (s[n-1][n-2] == s[n-2][n-1])\n\t\t{\n\t\t\tif (s[0][1] == s[n-1][n-2])\n\t\t\t\tans[ti] ~= [1, 2];\n\t\t\tif (s[1][0] == s[n-1][n-2])\n\t\t\t\tans[ti] ~= [2, 1];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (s[0][1] == '1')\n\t\t\t\tans[ti] ~= [1, 2];\n\t\t\tif (s[1][0] == '1')\n\t\t\t\tans[ti] ~= [2, 1];\n\t\t\tif (s[n-1][n-2] == '0')\n\t\t\t\tans[ti] ~= [n, n-1];\n\t\t\tif (s[n-2][n-1] == '0')\n\t\t\t\tans[ti] ~= [n-1, n];\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\tforeach (ee; e)\n\t\t\twriteln(ee[0], \" \", ee[1]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1421/problem/B\n// greedy\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 string[] grid;\n for(int i = 0; i < n; i++) {\n string str;\n readf(\"%s\\n\", &str);\n grid ~= str;\n }\n if(grid[$-1][$-2] == grid[$-2][$-1]) {\n int c = 0;\n if(grid[0][1] == grid[$-1][$-2])\n c += 1;\n if(grid[1][0] == grid[$-1][$-2])\n c += 1;\n c.writeln;\n if(grid[0][1] == grid[$-1][$-2])\n writeln(\"1 2\");\n if(grid[1][0] == grid[$-1][$-2])\n writeln(\"2 1\");\n continue;\n }\n if(grid[0][1] == grid[1][0]) {\n int c = 0;\n if(grid[$-1][$-2] == grid[0][1])\n c += 1;\n if(grid[$-2][$-1] == grid[0][1])\n c += 1;\n c.writeln;\n if(grid[$-1][$-2] == grid[0][1])\n writefln(\"%s %s\", n - 1, n - 2);\n if(grid[$-2][$-1] == grid[0][1])\n writefln(\"%s %s\", n - 2, n - 1);\n continue;\n }\n \"2\".writeln;\n if(grid[0][1] == '1')\n writeln(\"1 2\");\n if(grid[1][0] == '1')\n writeln(\"2 1\");\n if(grid[$-1][$-2] == '0')\n writefln(\"%s %s\", n - 1, n - 2);\n if(grid[$-2][$-1] == '0')\n writefln(\"%s %s\", n - 2, n - 1);\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 s = new string[](n);\n\t\tforeach (i; 0..n)\n\t\t\ts[i] = RD!string;\n\n\t\tif (s[0][1] == s[1][0])\n\t\t{\n\t\t\tif (s[n-1][n-2] == s[0][1])\n\t\t\t\tans[ti] ~= [n, n-1];\n\t\t\tif (s[n-2][n-1] == s[0][1])\n\t\t\t\tans[ti] ~= [n-1, n];\n\t\t}\n\t\telse if (s[n-1][n-2] == s[n-2][n-1])\n\t\t{\n\t\t\tif (s[0][1] == s[n-1][n-2])\n\t\t\t\tans[ti] ~= [1, 2];\n\t\t\tif (s[1][2] == s[n-1][n-2])\n\t\t\t\tans[ti] ~= [2, 1];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (s[0][1] == '1')\n\t\t\t\tans[ti] ~= [1, 2];\n\t\t\tif (s[1][2] == '1')\n\t\t\t\tans[ti] ~= [2, 1];\n\t\t\tif (s[n-1][n-2] == '0')\n\t\t\t\tans[ti] ~= [n, n-1];\n\t\t\tif (s[n-2][n-1] == '0')\n\t\t\t\tans[ti] ~= [n-1, n];\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\tforeach (ee; e)\n\t\t\twriteln(ee[0], \" \", ee[1]);\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\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 = new string[](n);\n\t\tforeach (i; 0..n)\n\t\t\ts[i] = RD!string;\n\n\t\tif (s[0][1] == s[1][0])\n\t\t{\n\t\t\tif (s[n-1][n-2] == s[0][1])\n\t\t\t\tans[ti] ~= [n, n-1];\n\t\t\tif (s[n-2][n-1] == s[0][1])\n\t\t\t\tans[ti] ~= [n-1, n];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (s[0][1] == '1')\n\t\t\t\tans[ti] ~= [1, 2];\n\t\t\tif (s[1][2] == '1')\n\t\t\t\tans[ti] ~= [2, 1];\n\t\t\tif (s[n-1][n-2] == '0')\n\t\t\t\tans[ti] ~= [n, n-1];\n\t\t\tif (s[n-2][n-1] == '0')\n\t\t\t\tans[ti] ~= [n-1, n];\n\t\t}\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\tforeach (ee; e)\n\t\t\twriteln(ee[0], \" \", ee[1]);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "be60cca56505e4b04d24c9b4990553c7"} {"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<<28;\r\n\r\nvoid solve() {\r\n enum int L = 1000;\r\n int N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto B = readarray!int;\r\n auto C = readarray!int;\r\n\r\n auto Z = new int[L + 1];\r\n Z[] = INF;\r\n Z[1] = 0;\r\n for (int m = 1; m <= L; m++) {\r\n for (int x = 1; x <= m; x++) {\r\n int n = m + m / x;\r\n if (n > L) continue;\r\n Z[n] = min(Z[n], Z[m] + 1);\r\n }\r\n }\r\n\r\n int M = 0; {\r\n foreach (z; Z) {\r\n if (z == INF) continue;\r\n M = max(M, z);\r\n }\r\n }\r\n\r\n int X = N * M;\r\n auto f = new int[][](N + 1, X + 1);\r\n f[0][0] = 0;\r\n for (int k = 0; k < N; k++) {\r\n for (int p = 0; p <= X; p++) {\r\n f[k + 1][p] = max(f[k + 1][p], f[k][p]);\r\n if (p + Z[B[k]] <= X) {\r\n f[k + 1][p + Z[B[k]]] = max(f[k + 1][p + Z[B[k]]], f[k][p] + C[k]);\r\n }\r\n }\r\n }\r\n int ans = f[N][min(K, X)];\r\n writeln(ans);\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": "// cheese-cracker [2022-01-31]\n\nlong[][] dp;\nint[] ks;\nint[] dp2;\nlong[] cs;\n\nlong go(int ix, int cap){\n if(ix < 0){ return 0; }\n\n if(dp[ix][cap] != -1){\n return dp[ix][cap];\n }\n\n long res = go(ix-1, cap);\n if(cap >= ks[ix]){\n long take = go(ix - 1, cap - ks[ix]) + cs[ix];\n res = max(res, take);\n }\n dp[ix][cap] = res;\n return res;\n}\n\n\n\nvoid preprocess(){\n dp2[1] = 0;\n for(int k = 1; k <= 1000; ++k){\n for(int x = 1; x < 1002; ++x){\n if(k + k/x < 1002){\n dp2[k + k/x] = min(dp2[k] + 1, dp2[k + k/x]);\n }\n }\n }\n}\n\n\nvoid solve(){\n cs = [];\n ks = [];\n auto n = scan!int;\n long k = scan;\n auto bs = scanArray;\n cs = scanArray;\n int mcap = min(22005, k.to!int);\n dp = new long[][](n, mcap+1);\n\n for(int i = 0; i < n; ++i){\n int cnt = dp2[bs[i].to!int];\n /* show(cnt); */\n ks ~= cnt;\n }\n show(ks);\n for(int i = 0; i < n; ++i){ dp[i][] = -1; }\n\n writeln(go(n-1, mcap));\n}\n\nvoid main(){\n long tests = scan; // Toggle!\n dp2 = new int[](1005);\n dp2[] = 1005;\n preprocess;\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": "// cheese-cracker [2022-01-31]\n\nlong[][] dp;\nint[] ks;\nlong[] cs;\n\nlong go(int ix, int cap){\n if(ix < 0){ return 0; }\n\n if(dp[ix][cap] != -1){\n return dp[ix][cap];\n }\n\n long res = go(ix-1, cap);\n if(cap >= ks[ix]){\n long take = go(ix - 1, cap - ks[ix]) + cs[ix];\n res = max(res, take);\n }\n dp[ix][cap] = res;\n return res;\n}\n\n\nvoid solve(){\n cs = [];\n ks = [];\n auto n = scan!int;\n long k = scan;\n auto bs = scanArray;\n cs = scanArray;\n int mcap = min(22005, k.to!int);\n dp = new long[][](n, mcap+1);\n\n for(int i = 0; i < n; ++i){\n int cnt = 0;\n long num = bs[i];\n while(num > 1){\n num >>= 1;\n ++cnt;\n }\n num = 1L << cnt;\n long till = num;\n while(num != bs[i]){\n long diff = bs[i] - num;\n long take = 1;\n for(long x = 1; 2*x <= till; ++x){\n if(num / x <= diff){\n take = max(num / x, take);\n }\n }\n num += take;\n ++cnt;\n }\n ks ~= cnt;\n }\n show(ks);\n for(int i = 0; i < n; ++i){ dp[i][] = -1; }\n\n writeln(go(n-1, mcap));\n /* show(dp); */\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"}, {"source_code": "// cheese-cracker [2022-01-31]\n\nlong[][] dp;\nint[] ks;\nlong[] cs;\n\nlong go(int ix, int cap){\n if(ix < 0){ return 0; }\n\n if(dp[ix][cap] != -1){\n return dp[ix][cap];\n }\n\n long res = go(ix-1, cap);\n if(cap >= ks[ix]){\n long take = go(ix - 1, cap - ks[ix]) + cs[ix];\n res = max(res, take);\n }\n dp[ix][cap] = res;\n return res;\n}\n\n\nvoid solve(){\n auto n = scan!int;\n long k = scan;\n auto bs = scanArray;\n cs = [];\n cs = scanArray;\n\n ks = [];\n for(int i = 0; i < n; ++i){\n int cnt = 0;\n long num = bs[i];\n while(num > 1){\n num >>= 1;\n ++cnt;\n }\n long tim = -1;\n num = bs[i];\n while(num > 0){\n tim += (num & 1);\n num >>= 1;\n }\n cnt += tim;\n ks ~= cnt;\n }\n show(ks);\n int mcap = min(22005, k.to!int);\n dp = new long[][](n+1, mcap+1);\n for(int i = 0; i <= n; ++i){ dp[i][] = -1; }\n\n writeln(go(n-1, mcap));\n /* show(dp); */\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"}, {"source_code": "// cheese-cracker [2022-01-31]\n\nlong[][] dp;\nint[] ks;\nlong[] cs;\n\nlong go(int ix, int cap){\n if(ix < 0){ return 0; }\n\n if(dp[ix][cap] != -1){\n return dp[ix][cap];\n }\n\n long res = go(ix-1, cap);\n if(cap >= ks[ix]){\n long take = go(ix - 1, cap - ks[ix]) + cs[ix];\n res = max(res, take);\n }\n dp[ix][cap] = res;\n return res;\n}\n\n\nvoid solve(){\n auto n = scan!int;\n long k = scan;\n auto bs = scanArray;\n cs = [];\n cs = scanArray;\n\n ks = [];\n for(int i = 0; i < n; ++i){\n int cnt = 0;\n long num = bs[i];\n while(num > 1){\n num >>= 1;\n ++cnt;\n }\n long tim = -1;\n num = bs[i];\n while(num > 0){\n tim += (num & 1);\n num >>= 1;\n }\n cnt += max(tim, 0);\n ks ~= cnt;\n }\n show(ks);\n int mcap = min(10005, k.to!int);\n dp = new long[][](n+1, mcap+1);\n for(int i = 0; i <= n; ++i){ dp[i][] = -1; }\n\n writeln(go(n-1, mcap));\n /* show(dp); */\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"}, {"source_code": "// cheese-cracker [2022-01-31]\n\nlong[][] dp;\nint[] ks;\nlong[] cs;\n\nlong go(int ix, int cap){\n if(ix < 0){ return 0; }\n\n if(dp[ix][cap] != -1){\n return dp[ix][cap];\n }\n\n long res = go(ix-1, cap);\n if(cap >= ks[ix]){\n long take = go(ix - 1, cap - ks[ix]) + cs[ix];\n res = max(res, take);\n }\n dp[ix][cap] = res;\n return res;\n}\n\n\nvoid solve(){\n auto n = scan!int;\n long k = scan;\n auto bs = scanArray;\n cs = [];\n cs = scanArray;\n\n ks = [];\n for(int i = 0; i < n; ++i){\n int cnt = 0;\n long num = bs[i];\n while(num > 1){\n num >>= 1;\n ++cnt;\n }\n long tim = -1;\n num = bs[i];\n while(num > 0){\n tim += (num & 1);\n num >>= 1;\n }\n show(bs[i], \" \", tim);\n cnt += max(tim, 0);\n ks ~= cnt;\n }\n show(ks);\n int mcap = min(2005, k.to!int);\n dp = new long[][](n+1, mcap+1);\n for(int i = 0; i <= n; ++i){ dp[i][] = -1; }\n\n writeln(go(n-1, mcap));\n /* show(dp); */\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"}, {"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<<28;\r\n\r\nvoid solve() {\r\n enum int L = 1000;\r\n int N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto B = readarray!int;\r\n auto C = readarray!int;\r\n\r\n auto Z = new int[L + 1];\r\n Z[] = INF;\r\n Z[1] = 0;\r\n for (int m = 1; m <= L; m++) {\r\n for (int x = 1; x <= m; x++) {\r\n int n = m + m / x;\r\n if (n > L) continue;\r\n Z[n] = min(Z[n], Z[m] + 1);\r\n }\r\n }\r\n\r\n int M = 0; {\r\n foreach (z; Z) {\r\n if (z == INF) continue;\r\n M = max(M, z);\r\n }\r\n }\r\n\r\n int X = N * M;\r\n auto f = new int[][](N + 1, X + 1);\r\n f[0][0] = 0;\r\n for (int k = 0; k < N; k++) {\r\n for (int p = 0; p < X; p++) {\r\n f[k + 1][p] = max(f[k + 1][p], f[k][p]);\r\n if (p + Z[B[k]] <= X) {\r\n f[k + 1][p + Z[B[k]]] = max(f[k + 1][p + Z[B[k]]], f[k][p] + C[k]);\r\n }\r\n }\r\n }\r\n int ans = f[N][min(K, X)];\r\n writeln(ans);\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.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<<28;\r\n\r\nvoid solve() {\r\n enum int L = 1000;\r\n int N, K; readf(\"%d %d\\n\", &N, &K);\r\n auto B = readarray!int;\r\n auto C = readarray!int;\r\n\r\n auto Z = new int[L + 1];\r\n Z[] = INF;\r\n Z[1] = 0;\r\n for (int m = 1; m <= L; m++) {\r\n for (int x = 1; x <= m; x++) {\r\n int n = m + m / x;\r\n if (n > L) continue;\r\n Z[n] = min(Z[n], Z[m] + 1);\r\n }\r\n }\r\n\r\n int M = 0; {\r\n foreach (z; Z) {\r\n if (z == INF) continue;\r\n M = max(M, z);\r\n }\r\n }\r\n\r\n int X = M * M;\r\n auto f = new int[][](N + 1, X + 1);\r\n f[0][0] = 0;\r\n for (int k = 0; k < N; k++) {\r\n for (int p = 0; p < X; p++) {\r\n f[k + 1][p] = max(f[k + 1][p], f[k][p]);\r\n if (p + Z[B[k]] <= X) {\r\n f[k + 1][p + Z[B[k]]] = max(f[k + 1][p + Z[B[k]]], f[k][p] + C[k]);\r\n }\r\n }\r\n }\r\n int ans = f[N][min(K, X)];\r\n writeln(ans);\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": "c4929ec631caae439ccb9bc6882ed816"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1472/problem/A\n// math\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;\nwhile(t--) {\n long w, h, n;\n readf(\"%s %s %s\\n\", &w, &h, &n);\n\n int x = 1;\n while(w % 2 == 0) {\n w /= 2;\n x *= 2;\n }\n\n int y = 1;\n while(h % 2 == 0) {\n h /= 2;\n y *= 2;\n }\n\n if(x*y >= n)\n \"Yes\".writeln;\n else\n \"No\".writeln;\n}\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 a = readln.splitter.map !(to !(int)).array;\r\n\t\tint res = 1;\r\n\t\tforeach (j; 0..2)\r\n\t\t{\r\n\t\t\twhile (a[j] % 2 == 0)\r\n\t\t\t{\r\n\t\t\t\ta[j] /= 2;\r\n\t\t\t\tres *= 2;\r\n\t\t\t}\r\n\t\t}\r\n\t\twriteln (res >= a[2] ? \"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 long[](t);\r\n\tforeach (ti; 0..t)\r\n\t{\r\n\t\tauto w = RD;\r\n\t\tauto h = RD;\r\n\t\tauto n = RD;\r\n\r\n\t\tlong x = 1, y = 1;\r\n\t\twhile (w % 2 == 0)\r\n\t\t{\r\n\t\t\tx *= 2;\r\n\t\t\tw /= 2;\r\n\t\t}\r\n\t\twhile (h % 2 == 0)\r\n\t\t{\r\n\t\t\ty *= 2;\r\n\t\t\th /= 2;\r\n\t\t}\r\n\r\n\t\tans[ti] = x*y >= 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": "a8201326dda46542b23dc4e528d413eb"} {"source_code": "import std.stdio;\nimport std.math;\nimport std.array;\nimport std.algorithm;\n\nunittest{\n assert(solve(2,[0,4,5,1,0]) == 1, \"Teste 1\");\n assert(solve(4,[0,1,2,3,4,5]) == 0, \"Teste 2\");\n assert(solve(5,[0,0,0,0,0,0]) == 2, \"Teste 3\");\n}\n\nulong solve(ulong k, ulong[] l){\n ulong max = 5 - k;\n ulong cnt = 0;\n foreach(x;l){\n if (x <= max){\n cnt++;\n }\n }\n debug(1) writeln(cnt/3);\n return cnt/3;\n}\n\nvoid main(){\n size_t n;\n ulong k;\n readf(\"%s %s \",&n,&k);\n\n ulong[] l = new ulong[n];\n for(size_t i = 0; i < n; i++){\n ulong t;\n readf(\"%s \",&t);\n l[i] = t;\n }\n writeln(solve(k,l));\n // auto s = r.map!\"to!string(a)\".array;\n}\n", "positive_code": [{"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, k;\n\tscanf(\"%d %d\", &n, &k);\n\tint eligible_members = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tint a;\n\t\tscanf(\"%d\", &a);\n\t\teligible_members += (a + k <= 5 ? 1 : 0); \n\t}\n\twrite (eligible_members / 3);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "fbde1e2ee02055592ff72fb04366812b"} {"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 int[] a = stdin.readln.chop.split.map!(to!int).array;\n int[] b = stdin.readln.chop.split.map!(to!int).array;\n a.sort!\"a > b\";\n b.sort!\"a > b\";\n int ai = 0, bi = 0;\n int x = n;\n while (ai < n && bi < m) {\n if (a[ai] <= b[bi]) {\n x--;\n ai++;\n bi++;\n } else {\n ai++;\n }\n }\n x.writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.math;\n\nvoid main()\n{\n\tint n, m;\n\tint[] a, b;\n\tscanf(\"%d %d\", &n, &m);\n\ta.length = n;\n\tb.length = m;\n\tforeach (i; 0 .. n) scanf(\"%d\", &a[i]);\n\tforeach (i; 0 .. m) scanf(\"%d\", &b[i]);\n\tint result;\n\twhile (b.length) {\n\t\tif (a.length == 0) break;\n\t\tif (b[0] < a[0]) {\n\t\t\tb = b[1..$];\n\t\t} else {\n\t\t\ta = a[1..$];\n\t\t\tb = b[1..$];\n\t\t}\n\t}\n\twriteln(a.length);\n}"}], "negative_code": [], "src_uid": "bf0422de4347a308d68a52421fbad0f3"} {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\n\nchar[] s;\n\nvoid main() {\n s = readln.chomp.to!(char[]);\n\n debug {\n writeln(\"s:\", s);\n }\n\n int n = s.length.to!int;\n\n int[] acnt = new int[](26);\n\n foreach (ch ; s) {\n acnt[ch - 'a']++;\n }\n\n debug {\n writeln(\"acnt:\", acnt);\n }\n\n auto u = new char[](n);\n int ui = 0;\n\n auto st = new Stack!char(n + 10);\n\n while (ui < n) {\n if (s.empty) {\n while (!st.empty) {\n u[ui++] = st.top.to!char;\n st.pop;\n }\n break;\n }\n if (st.empty) {\n st.push(s.front.to!char);\n acnt[s.front - 'a']--;\n s.popFront;\n }\n else {\n debug {\n writeln(st.top, \" \", (st.top - 'a').to!int);\n writeln(acnt[0 .. (st.top - 'a').to!int]);\n }\n if (acnt[0 .. (st.top - 'a').to!int].sum > 0) {\n st.push(s.front.to!char);\n acnt[s.front - 'a']--;\n s.popFront;\n }\n else {\n u[ui++] = st.top;\n //acnt[(st.top - 'a').to!int]--;\n st.pop;\n }\n }\n\n debug {\n //writeln(\"s:\", s);\n writeln(\"acnt:\", acnt);\n }\n }\n\n writeln(u);\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\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, std.typecons;\n\nchar[] s;\n\nvoid main() {\n s = readln.chomp.to!(char[]);\n\n int n = s.length.to!int;\n\n auto t = Stack!(char)(n + 10);\n auto u = new char[](n);\n\n auto cnt = new int[](26);\n\n foreach (ch ; s) {\n cnt[ch - 'a']++;\n }\n\n int ui;\n\n while (!s.empty) {\n if (t.empty) {\n t.push(s.front.to!char);\n cnt[s.front - 'a']--;\n s.popFront;\n }\n else {\n if (cnt[0 .. (t.top - 'a')].sum > 0) {\n t.push(s.front.to!char);\n cnt[s.front - 'a']--;\n s.popFront;\n }\n else {\n u[ui++] = t.top;\n t.pop;\n }\n }\n }\n\n while (!t.empty) {\n u[ui++] = t.top;\n t.pop;\n }\n\n writeln(u);\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\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": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\n\ndchar[] s;\n\nvoid main() {\n s = readln.chomp.to!(dchar[]);\n\n debug {\n writeln(\"s:\", s);\n }\n\n int n = s.length.to!int;\n\n int[] acnt = new int[](26);\n\n foreach (ch ; s) {\n acnt[ch - 'a']++;\n }\n\n debug {\n writeln(\"acnt:\", acnt);\n }\n\n auto u = new dchar[](n);\n int ui = 0;\n\n auto st = new Stack!dchar(n + 10);\n\n while (ui < n) {\n if (s.empty) {\n while (!st.empty) {\n u[ui++] = st.top.to!dchar;\n st.pop;\n }\n break;\n }\n if (st.empty) {\n st.push(s.front.to!dchar);\n s.popFront;\n }\n else {\n if (acnt[0 .. (st.top - 'a').to!int].sum > 0) {\n st.push(s.front.to!dchar);\n acnt[s.front - 'a']--;\n s.popFront;\n }\n else {\n u[ui++] = st.top;\n st.pop;\n }\n }\n\n debug {\n writeln(\"s:\", s);\n }\n }\n\n writeln(u);\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\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}"}], "src_uid": "e758ae072b8aed53038e4593a720276d"} {"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 M = readInt();\n auto L = new int[N];\n auto R = new int[N];\n foreach (i; 0 .. N) {\n L[i] = readInt() - 1;\n R[i] = readInt();\n }\n \n auto as = new int[M];\n foreach (i; 0 .. N) {\n ++as[L[i]];\n if (R[i] < M) {\n --as[R[i]];\n }\n }\n foreach (j; 1 .. M) {\n as[j] += as[j - 1];\n }\n debug {\n writeln(\"as = \", as);\n }\n \n int[] doIt() {\n auto dp = new int[M];\n int[] lis;\n foreach (j; 0 .. M) {\n const pos = lis.upperBound(as[j]);\n if (pos == lis.length) {\n lis ~= as[j];\n } else {\n lis[pos] = as[j];\n }\n dp[j] = pos + 1;\n }\n debug {\n writeln(as, \": \", dp);\n }\n return dp;\n }\n \n auto dpL = doIt();\n as.reverse;\n auto dpR = doIt();\n as.reverse;\n dpR.reverse;\n int ans;\n foreach (j; 0 .. M) {\n chmax(ans, dpL[j] + dpR[j] - 1);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nint [] fun (int [] a)\n{\n\tauto p = new int [a.length + 1];\n\tp[] = int.max;\n\tp[0] = int.min;\n\tint [] res;\n\tforeach (c; a)\n\t{\n\t\tint lo = 0;\n\t\tint hi = p.length.to !(int) - 1;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tint me = (lo + hi) / 2;\n\t\t\tif (p[me] <= c)\n\t\t\t{\n\t\t\t\tlo = me + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t}\n\t\tp[lo] = c;\n\t\tres ~= lo;\n\t}\n\tdebug {writeln (a); writeln (p); writeln (res);}\n\treturn res;\n}\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 + 2];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x, y;\n\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\tv[x] += 1;\n\t\t\tv[y + 1] -= 1;\n\t\t}\n\t\tforeach (j; 0..m + 1)\n\t\t{\n\t\t\tv[j + 1] += v[j];\n\t\t}\n\t\tv = v[1..$ - 1];\n\n\t\tauto x = fun (v);\n\t\treverse (v);\n\t\tauto y = fun (v);\n\t\treverse (y);\n\t\tint res = 0;\n\t\tforeach (i; 0..x.length)\n\t\t{\n\t\t\tres = max (res, x[i] + y[i] - 1);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nint fun (int [] a)\n{\n\tauto p = new int [a.length + 1];\n\tp[] = int.max;\n\tp[0] = int.min;\n\tint res = 0;\n\tforeach (c; a)\n\t{\n\t\tint lo = 0;\n\t\tint hi = p.length.to !(int) - 1;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tint me = (lo + hi) / 2;\n\t\t\tif (p[me] <= c)\n\t\t\t{\n\t\t\t\tlo = me + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t}\n\t\tp[lo] = c;\n\t\tres = max (res, lo);\n\t}\n\tdebug {writeln (a); writeln (p);}\n\treturn res;\n}\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 + 2];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x, y;\n\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\tv[x] += 1;\n\t\t\tv[y + 1] -= 1;\n\t\t}\n\t\tforeach (j; 0..m + 1)\n\t\t{\n\t\t\tv[j + 1] += v[j];\n\t\t}\n\t\tv = v.filter !(x => x > 0).array;\n\n\t\tint res = 0;\n\t\tres = max (res, fun (v));\n\t\treverse (v);\n\t\tres = max (res, fun (v));\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nint [] fun (int [] a)\n{\n\tauto p = new int [a.length + 1];\n\tp[] = int.max;\n\tp[0] = int.min;\n\tint [] res;\n\tforeach (c; a)\n\t{\n\t\tint lo = 0;\n\t\tint hi = p.length.to !(int) - 1;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tint me = (lo + hi) / 2;\n\t\t\tif (p[me] <= c)\n\t\t\t{\n\t\t\t\tlo = me + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t}\n\t\tp[lo] = c;\n\t\tres ~= lo;\n\t}\n\tdebug {writeln (a); writeln (p); writeln (res);}\n\treturn res;\n}\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 + 2];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x, y;\n\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\tv[x] += 1;\n\t\t\tv[y + 1] -= 1;\n\t\t}\n\t\tforeach (j; 0..m + 1)\n\t\t{\n\t\t\tv[j + 1] += v[j];\n\t\t}\n\t\tv = v.filter !(x => x > 0).array;\n\n\t\tauto x = fun (v);\n\t\treverse (v);\n\t\tauto y = fun (v);\n\t\treverse (y);\n\t\tint res = 0;\n\t\tforeach (i; 0..x.length)\n\t\t{\n\t\t\tres = max (res, x[i] + y[i] - 1);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nint fun (int [] a)\n{\n\tauto p = new int [a.length];\n\tp[] = int.max;\n\tp[0] = int.min;\n\tint res = 0;\n\tforeach (c; a[1..$ - 1])\n\t{\n\t\tint lo = 0;\n\t\tint hi = a.length.to !(int) - 1;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tint me = (lo + hi) / 2;\n\t\t\tif (p[me] <= c)\n\t\t\t{\n\t\t\t\tlo = me + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t}\n\t\tp[lo] = c;\n\t\tres = max (res, lo);\n\t}\n\tdebug {writeln (a); writeln (p);}\n\treturn res;\n}\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 + 2];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint x, y;\n\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\tv[x] += 1;\n\t\t\tv[y + 1] -= 1;\n\t\t}\n\t\tforeach (j; 0..m + 1)\n\t\t{\n\t\t\tv[j + 1] += v[j];\n\t\t}\n\n\t\tint res = 0;\n\t\tres = max (res, fun (v));\n\t\treverse (v);\n\t\tres = max (res, fun (v));\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "ce8350be138ce2061349d7f9224a5aaf"} {"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;\n\nimmutable int MOD = 998244353;\n\nlong addmod(long a, long b) {\n long c = a + b;\n if (c > MOD) c -= MOD;\n return c;\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 debug { arr.writeln; }\n \n auto binom = new long[][] (n+1, n+1);\n \n binom[0][0] = 1;\n foreach (nn; 1 .. n+1) {\n binom[nn][0] = 1;\n foreach (kk; 1 .. nn+1) {\n binom[nn][kk] = addmod(binom[nn-1][kk], binom[nn-1][kk-1]);\n }\n }\n \n debug { binom.writeln; }\n \n auto dp = new long[] (n+1);\n dp.fill(0);\n dp[n] = 1;\n \n long ans = 0;\n foreach_reverse (i; 0 .. n) {\n if (arr[i] <= 0) continue;\n \n auto k = arr[i] + 1;\n foreach (j; i + k-1 .. n) {\n auto opts = binom[j - i][k - 1];\n dp[i] = dp[i].addmod(opts * dp[j+1] % MOD);\n \n debug { writeln(i, ' ', j, ' ', opts, ' ', dp[j+1]); }\n }\n \n ans = ans.addmod(dp[i]);\n \n debug { writeln(i, ' ', dp[i]); }\n }\n \n ans.writeln;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint saiki(int idx, int n, int[] a, int[] dp, int[][] c)\n{\n if (dp[idx] != -1)\n {\n return dp[idx];\n }\n if (idx == n)\n {\n dp[idx] = 1;\n return 1;\n }\n if (a[idx] <= 0 || a[idx] > n - idx - 1)\n {\n dp[idx] = 0;\n return 0;\n }\n static const int mod = 998244353;\n auto res = 0;\n foreach (i; idx + a[idx] + 1 .. n + 1)\n {\n auto ret = saiki(i, n, a, dp, c);\n res += (cast(long)c[i - idx - 1][a[idx]] * ret) % mod;\n res %= mod;\n }\n dp[idx] = res;\n return res;\n}\n\nvoid solve(int[] a, int n)\n{\n static const int mod = 998244353;\n auto c = new int[][](n + 1, n + 1);\n foreach (i; 0 .. n + 1)\n {\n fill(c[i], 0);\n }\n foreach (i; 0 .. n + 1)\n {\n c[i][0] = 1;\n }\n foreach (i; 1 .. n + 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 dp = new int[n + 1];\n fill(dp, -1);\n auto res = 0;\n foreach (i; 0 .. n)\n {\n auto ret = saiki(i, n, a, dp, c);\n res = (res + ret) % mod;\n }\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;\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\nenum mod = 998244353;\nalias M = Mod!(long, mod);\nM[2000] fact;\nM bin(int n, int k)\n{\n if (k > n) return M(0);\n return fact[n] * (fact[n - k] * fact[k])^^-1;\n}\n\nvoid main(string[] args)\n{\n fact[0] = M(1);\n foreach(i; 1 .. fact.length)\n fact[i] = M(i) * fact[i - 1];\n\n auto n = next!int;\n auto a = next!int(n);\n debug writeln(\"got \", a);\n auto noStartingIn = new M[](n);\n foreach_reverse(start; 0 .. n)\n {\n debug writeln(\"doing from start = \", start);\n if (a[start] <= 0) continue;\n noStartingIn[start] = bin(n - 1 - start, a[start]);\n foreach(otherStart; start + 1 .. n)\n\t{\n\t noStartingIn[start] += bin(otherStart - start - 1, a[start]) * noStartingIn[otherStart];\n\t}\n }\n noStartingIn.sum.writeln;\n return;\n}\n\nauto noDigs(long num)\n{\n auto res = int(0);\n while(num)\n {\n num /= 10;\n res++;\n }\n return res;\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 this(Mod!(T, mod) other)\n {\n _rep = other._rep;\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 if (exp == -1) exp = mod - 2;\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.string;\nimport std.algorithm;\n\nint saiki(int idx, int n, int[] a, int[] dp, int[][] c)\n{\n if (dp[idx] != -1)\n {\n return dp[idx];\n }\n if (idx == n)\n {\n dp[idx] = 1;\n return 1;\n }\n if (a[idx] < 0 || a[idx] > n - idx - 1)\n {\n dp[idx] = 0;\n return 0;\n }\n static const int mod = 998244353;\n auto res = 0;\n foreach (i; idx + a[idx] + 1 .. n + 1)\n {\n auto ret = saiki(i, n, a, dp, c);\n res += (cast(long)c[i - idx - 1][a[idx]] * ret) % mod;\n res %= mod;\n }\n dp[idx] = res;\n return res;\n}\n\nvoid solve(int[] a, int n)\n{\n static const int mod = 998244353;\n auto c = new int[][](n + 1, n + 1);\n foreach (i; 0 .. n + 1)\n {\n fill(c[i], 0);\n }\n foreach (i; 0 .. n + 1)\n {\n c[i][0] = 1;\n }\n foreach (i; 1 .. n + 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 dp = new int[n + 1];\n fill(dp, -1);\n auto res = 0;\n foreach (i; 0 .. n)\n {\n auto ret = saiki(i, n, a, dp, c);\n res = (res + ret) % mod;\n }\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.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\nimmutable int MOD = 998244353;\n\nlong addmod(long a, long b) {\n long c = a + b;\n if (c > MOD) c -= MOD;\n return c;\n}\n\nvoid main()\n{\n \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n auto binom = new long[][] (n+1, n+1);\n \n binom[0][0] = 1;\n foreach (nn; 1..n+1) {\n foreach (kk; 0..n+1) {\n binom[nn][kk] = (binom[nn-1][kk] + (kk > 0 ? binom[nn-1][kk-1] : 0)) % MOD;\n }\n }\n \n debug { binom.writeln; }\n \n auto dp = new long[] (n+1);\n dp[n] = 0;\n \n foreach_reverse (i; 0 .. n) {\n auto k = arr[i];\n if (k < 1) continue;\n \n foreach (j; i + k .. n) {\n auto opts = k == 1 ? 1L : binom[j - 1 - i][k - 2];\n dp[i] = addmod(dp[i], addmod(opts, opts * dp[j+1] % MOD));\n \n debug { writeln(i, ' ', j, ' ', opts, ' ', dp[j+1]); }\n }\n \n debug { writeln(i, ' ', dp[i]); }\n }\n \n auto ans = dp.fold!((a, b) => addmod(a, b));\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;\nimport std.range.interfaces;\n\nimmutable int MOD = 998244353;\n\nlong addmod(long a, long b) {\n long c = a + b;\n if (c > MOD) c -= MOD;\n return c;\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 debug { arr.writeln; }\n \n auto binom = new long[][] (n+1, n+1);\n \n binom[0][0] = 1;\n foreach (nn; 1 .. n+1) {\n foreach (kk; 0 .. nn+1) {\n binom[nn][kk] = addmod(binom[nn-1][kk], kk > 0 ? binom[nn-1][kk-1] : 0L);\n }\n }\n \n debug { binom.writeln; }\n \n auto dp = new long[] (n+1);\n dp.fill(0);\n \n foreach_reverse (i; 0 .. n) {\n if (arr[i] <= 0) continue;\n \n auto k = arr[i] + 1;\n foreach (j; i + k-1 .. n) {\n auto opts = binom[j-1 - i][k - 2];\n dp[i] = dp[i].addmod(opts * addmod(dp[j+1], 1) % MOD);\n \n debug { writeln(i, ' ', j, ' ', opts, ' ', dp[j+1]); }\n }\n \n dp[i] = dp[i].addmod(dp[i+1]);\n \n debug { writeln(i, ' ', dp[i]); }\n }\n \n dp[0].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;\nimport std.range.interfaces;\n\nimmutable int MOD = 998244353;\n\nlong addmod(long a, long b) {\n long c = a + b;\n if (c > MOD) c -= MOD;\n return c;\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 debug { arr.writeln; }\n \n auto binom = new long[][] (n+1, n+1);\n \n binom[0][0] = 1;\n foreach (nn; 1 .. n+1) {\n foreach (kk; 0 .. nn+1) {\n binom[nn][kk] = addmod(binom[nn-1][kk], kk > 0 ? binom[nn-1][kk-1] : 0L);\n }\n }\n \n debug { binom.writeln; }\n \n auto dp = new long[] (n+1);\n dp.fill(0);\n \n foreach_reverse (i; 0 .. n) {\n if (arr[i] <= 0) continue;\n \n auto k = arr[i] + 1;\n foreach (j; i + k .. n) {\n auto opts = binom[j - i][k - 1];\n dp[i] = dp[i].addmod(opts * addmod(dp[j+1], 1) % MOD);\n \n debug { writeln(i, ' ', j, ' ', opts, ' ', dp[j+1]); }\n }\n \n dp[i] = dp[i].addmod(dp[i+1]);\n \n debug { writeln(i, ' ', dp[i]); }\n }\n \n dp[0].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;\nimport std.range.interfaces;\n\nimmutable int MOD = 998244353;\n\nlong addmod(long a, long b) {\n long c = a + b;\n if (c > MOD) c -= MOD;\n return c;\n}\n\nvoid main()\n{\n \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n auto binom = new long[][] (n+1, n+1);\n \n binom[0][0] = 1;\n foreach (nn; 1..n+1) {\n foreach (kk; 0..n+1) {\n binom[nn][kk] = addmod(binom[nn-1][kk], kk > 0 ? binom[nn-1][kk-1] : 0L);\n }\n }\n \n debug { binom.writeln; }\n \n auto dp = new long[] (n+1);\n dp[n] = 0;\n \n foreach_reverse (i; 0 .. n) {\n auto k = arr[i] + 1;\n if (k < 2) continue;\n \n foreach (j; i + k-1 .. n) {\n auto opts = binom[j-1 - i][k - 2];\n dp[i] = dp[i].addmod(opts * addmod(dp[j+1], 1) % MOD);\n \n debug { writeln(i, ' ', j, ' ', opts, ' ', dp[j+1]); }\n }\n \n dp[i] = dp[i].addmod(dp[i+1]);\n \n debug { writeln(i, ' ', dp[i]); }\n }\n \n dp[0].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;\nimport std.range.interfaces;\n\nimmutable int MOD = 998244353;\n\nlong addmod(long a, long b) {\n long c = a + b;\n if (c > MOD) c -= MOD;\n return c;\n}\n\nvoid main()\n{\n \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n auto binom = new long[][] (n+1, n+1);\n \n binom[0][0] = 1;\n foreach (nn; 1..n+1) {\n foreach (kk; 0..n+1) {\n binom[nn][kk] = addmod(binom[nn-1][kk], kk > 0 ? binom[nn-1][kk-1] : 0L);\n }\n }\n \n debug { binom.writeln; }\n \n auto dp = new long[] (n+1);\n dp[n] = 0;\n \n foreach_reverse (i; 0 .. n) {\n auto k = arr[i];\n if (k < 1) continue;\n \n foreach (j; i + k .. n) {\n auto opts = k == 1 ? 1L : binom[j - 1 - i][k - 2];\n dp[i] = addmod(dp[i], addmod(opts, opts * dp[j+1] % MOD));\n \n debug { writeln(i, ' ', j, ' ', opts, ' ', dp[j+1]); }\n }\n \n dp[i] += dp[i+1];\n \n debug { writeln(i, ' ', dp[i]); }\n }\n \n dp[0].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;\nimport std.range.interfaces;\n\nimmutable int MOD = 998244353;\n\nlong addmod(long a, long b) {\n long c = a + b;\n if (c > MOD) c -= MOD;\n return c;\n}\n\nvoid main()\n{\n \n int n;\n readf(\"%s\", &n);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n auto binom = new long[][] (n+1, n+1);\n \n binom[0][0] = 1;\n foreach (nn; 1..n+1) {\n foreach (kk; 0..n+1) {\n binom[nn][kk] = addmod(binom[nn-1][kk], kk > 0 ? binom[nn-1][kk-1] : 0L);\n }\n }\n \n debug { binom.writeln; }\n \n auto dp = new long[] (n+1);\n dp[n] = 0;\n \n foreach_reverse (i; 0 .. n) {\n auto k = arr[i];\n if (k < 1) continue;\n \n foreach (j; i + k .. n) {\n auto opts = k == 1 ? 1L : binom[j - 1 - i][k - 2];\n dp[i] = dp[i].addmod(opts * addmod(dp[j+1], 1) % MOD);\n \n debug { writeln(i, ' ', j, ' ', opts, ' ', dp[j+1]); }\n }\n \n dp[i] = dp[i].addmod(dp[i+1]);\n \n debug { writeln(i, ' ', dp[i]); }\n }\n \n dp[0].writeln;\n}"}], "src_uid": "e82b6958c45ff4b2c269cebe043d49de"} {"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 q; get(q);\n while(q--)\n {\n long[] a = new long[3]; get(a);\n auto sa = sort(a);\n auto res = 2 * (a[2] - a[0]);\n if (a[2] - a[0] <= 1)\n\twr(0);\n else\n\twr(res - 4);\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 q = RD!int;\n\tauto ans = new int[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tauto c = RD!int;\n\t\tif (max(a, b, c) - min(a, b, c) <= 2)\n\t\t\tcontinue;\n\t\tauto x = max(a, b, c) - min(a, b, c) - 2;\n\t\tans[i] = x * 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\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 T = readln.chomp.to!int;\n while (T--) {\n auto s = readln.split.map!(to!long);\n auto N = s[0];\n auto M = s[1];\n auto K = s[2];\n long ans = 1L << 59;\n foreach (i; -1..2) foreach (j; -1..2) foreach (k; -1..2) {\n auto a = N + i;\n auto b = M + j;\n auto c = K + k;\n ans = min(ans, abs(a - b) + abs(b - c) + abs(c - a));\n }\n ans.writeln;\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;\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 q = rint;\n\tforeach(_; 0 .. q){\n\t\tlong a = rlong, b = rlong, c = rlong;\n\t\tlong ans = (a + b + c) * 100;\n\t\tforeach(i; [a - 1, a, a + 1]) foreach(j; [b - 1, b, b + 1]) foreach(k; [c - 1, c, c + 1]){\n\t\t\tans.chmin(abs(i - j) + abs(j - k) + abs(k - i));\n\t\t}\n\t\tans.writeln;\n\t}\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 q = rint;\n\tforeach(_; 0 .. q){\n\t\tint a = rint, b = rint, c = rint;\n\t\tint ans = a + b + c;\n\t\tforeach(i; [a - 1, a, a + 1]) foreach(j; [b - 1, b, b + 1]) foreach(k; [c - 1, c, c + 1]){\n\t\t\tans.chmin(abs(i - j) + abs(j - k) + abs(k - i));\n\t\t}\n\t\tans.writeln;\n\t}\n}"}], "src_uid": "18f2e54e4147e8887da737d5b6639473"} {"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 K = s[1];\n auto S = readln.chomp;\n\n auto cnt = new int[](26);\n foreach (i; 0..N) cnt[S[i]-'A'] += 1;\n\n int ans = 1 << 29;\n foreach (i; 0..K) ans = min(ans, cnt[i]);\n\n writeln(ans * K);\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, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto s = readln.chomp;\n auto cnt = new int[k];\n foreach (e; s) ++cnt[e-'A'];\n \n auto ans = k * cnt.minElement;\n \n ans.writeln;\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, k; rd(n, k);\n auto s=readln.chomp.to!(char[]);\n\n int[char] freq;\n foreach(c; s){\n if(c in freq) freq[c]++;\n else freq[c]=1;\n }\n\n int mn=10^^9;\n for(char c='A'; c<'A'+k; c++){\n if(c in freq) mn=min(mn, freq[c]);\n else mn=min(mn, 0);\n }\n writeln(mn*k);\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": "d9d5db63b1e48214d02abe9977709384"} {"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\ta.group.map !(q{a[1]}).maxElement.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);\r\n while (T--) {\r\n int N; get(N);\r\n int last, c, max_c;\r\n foreach (a; readln.split.to!(int[])) {\r\n if (last != a) {\r\n max_c = max(max_c, c);\r\n c = 0;\r\n }\r\n last = a;\r\n ++c;\r\n }\r\n writeln(max(max_c, c));\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 ll eq = 1, maxeq = 1;\n for(int i = 1; i < n; ++i){\n if(arr[i] == arr[i-1]){\n ++eq;\n }else{\n maxeq = max(eq, maxeq);\n eq = 1;\n }\n }\n maxeq = max(maxeq, eq);\n writeln(maxeq);\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 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(-1);\r\n\r\n\t\tauto cnt = new int[](n);\r\n\t\tforeach (e; a)\r\n\t\t\t++cnt[e];\r\n\t\tans[ti] = cnt.maxElement;\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": "6d4744d7356e709f73891270becd14e3"} {"source_code": "import std.stdio;\n\nint n, m;\nchar[600][600] a;\nint[600][600] visited;\n\nvoid dfs(int x1, int y1) {\n\n\tvisited[x1][y1]++;\n\n\tif (visited[x1][y1] >= 3 || x1 > n || x1 < 1 || y1 > m || y1 < 1)\n\t\treturn;\n\n\tdfs(x1 + 1, y1);\n\tdfs(x1 - 1, y1);\n\tdfs(x1, y1 + 1);\n\tdfs(x1, y1 - 1);\n}\n\nvoid main() {\n\n\treadf(\" %s %s\", &n, &m);\n\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\treadf(\" %c \", &a[i][j]);\n\t\t\tif (a[i][j] == '.') {\n\t\t\t\tvisited[i][j] = 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tvisited[i][j] = 2;\n\t\t\t}\n\t\t}\n\t}\n\n\tint x1, y1, x2, y2;\n\n\treadf(\" %s %s %s %s\", &x1, &y1, &x2, &y2);\n\n\tvisited[x1][y1] = 1;\n\n\tdfs(x1, y1);\n\t\n\tdebug writeln(\"test\");\n\n\twriteln(visited[x2][y2] >= 3 ? \"YES\" : \"NO\");\n}", "positive_code": [{"source_code": "import std.stdio;\n\nint n, m;\nchar[600][600] a;\nint[600][600] visited;\n\nvoid dfs(int x1, int y1) {\n\n\tvisited[x1][y1]++;\n\n\tif (visited[x1][y1] >= 3 || x1 > n || x1 < 1 || y1 > m || y1 < 1)\n\t\treturn;\n\n\tdfs(x1 + 1, y1);\n\tdfs(x1 - 1, y1);\n\tdfs(x1, y1 + 1);\n\tdfs(x1, y1 - 1);\n}\n\nvoid main() {\n\n\treadf(\" %s %s\", &n, &m);\n\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. m + 1) {\n\t\t\treadf(\" %c \", &a[i][j]);\n\t\t\tif (a[i][j] == '.') {\n\t\t\t\tvisited[i][j] = 1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tvisited[i][j] = 2;\n\t\t\t}\n\t\t}\n\t}\n\n\tint x1, y1, x2, y2;\n\n\treadf(\" %s %s %s %s\", &x1, &y1, &x2, &y2);\n\n\tvisited[x1][y1] = 1;\n\n\tdfs(x1, y1);\n\n\twriteln(visited[x2][y2] >= 3 ? \"YES\" : \"NO\");\n}"}], "negative_code": [], "src_uid": "afac59c927522fb223f59c36184229e2"} {"source_code": "import std.stdio;\n\nlong mulmod (long a, long b, long m)\n{\n\tlong res = 0;\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres += a;\n\t\t\tif (res >= m)\n\t\t\t{\n\t\t\t\tres -= m;\n\t\t\t}\n\t\t}\n\t\ta <<= 1;\n\t\tif (a >= m)\n\t\t{\n\t\t\ta -= m;\n\t\t}\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint tests;\n\treadf (\" %s\", &tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tlong p, q, b;\n\t\treadf (\" %s %s %s\", &p, &q, &b);\n\t\timmutable int steps = 6;\n\t\tb %= q;\n\t\tforeach (step; 0..steps)\n\t\t{\n\t\t\tb = mulmod (b, b, q);\n\t\t}\n\t\tp %= q;\n\t\tp = mulmod (p, b, q);\n\t\twriteln (p == 0 ? \"Finite\" : \"Infinite\");\n\t}\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\nT gcd(T) (T a, T b) pure nothrow @nogc {\n if (a < b) {\n swap (a, b);\n }\n while (b) {\n T c = a % b; a = b; b = c;\n }\n return a;\n}\n\nvoid main() {\n int nt;\n readf (\" %d\", &nt);\n foreach (t; 0 .. nt) {\n long p, q, b;\n readf (\" %d %d %d\", &p, &q, &b);\n long g = gcd (p, q);\n q /= g;\n while (true) {\n debug stderr.writefln (\"q = %d b = %d\", q, b);\n g = gcd (q, b);\n if (g == 1) break;\n while (true) {\n long r = q / g;\n if (r * g != q) break;\n q = r;\n }\n }\n writeln (q == 1 ? \"Finite\" : \"Infinite\");\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nlong mulmod (long a, long b, long m)\n{\n\tlong res = 0;\n\twhile (b)\n\t{\n\t\ta <<= 1;\n\t\tif (a >= m)\n\t\t{\n\t\t\ta -= m;\n\t\t}\n\t\tif (b & 1)\n\t\t{\n\t\t\tres += a;\n\t\t\tif (res >= m)\n\t\t\t{\n\t\t\t\tres -= m;\n\t\t\t}\n\t\t}\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint tests;\n\treadf (\" %s\", &tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tlong p, q, b;\n\t\treadf (\" %s %s %s\", &p, &q, &b);\n\t\timmutable int steps = 6;\n\t\tb %= q;\n\t\tforeach (step; 0..steps)\n\t\t{\n\t\t\tb = mulmod (b, b, q);\n\t\t}\n\t\tp %= q;\n\t\tp = mulmod (p, b, q);\n\t\twriteln (p == 0 ? \"Finite\" : \"Infinite\");\n\t}\n}\n"}], "src_uid": "1b8c94f278ffbdf5b7fc38b3976252b6"} {"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 auto grp = S.group.array;\n bool ans = true;\n ans = ans && (grp.length == 3);\n ans = ans && (grp[0][0] == 'a');\n ans = ans && (grp[1][0] == 'b');\n ans = ans && (grp[2][0] == 'c');\n ans = ans && (grp[2][1] == grp[0][1] || grp[2][1] == grp[1][1]);\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\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, std.regex;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n string s;\n sc.read(s);\n auto r = regex(r\"^a+b+c+$\");\n if (!matchFirst(s, r)) {\n writeln(\"NO\");\n } else {\n if (s.count('a') != s.count('c') && s.count('b') != s.count('c')) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n }\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*/"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\nimport std.regex;\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 string s; readV(s);\n\n auto m = s.matchFirst(r\"^(a+)(b+)(c+)$\");\n writeln(m && (m[1].length == m[3].length || m[2].length == m[3].length) ? \"YES\" : \"NO\");\n}\n"}], "negative_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, std.regex;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n string s;\n sc.read(s);\n auto r = regex(r\"a+b+c+\");\n if (!matchFirst(s, r)) {\n writeln(\"NO\");\n } else {\n if (s.count('a') != s.count('c') && s.count('b') != s.count('c')) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n }\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"}], "src_uid": "6581dbaff7eb52b63ccfe9c0c4117c09"} {"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 if (iota(0, n).map!(i => pmod(a.at(i) + i, n)).array.sort.uniq.array.length == n)\n writeln(\"YES\");\n else\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", "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;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\ta[] += n.iota.array[];\n\t\ta[] = ((a[] % n) + n) % n;\n\t\tsort (a);\n\t\twriteln (equal (a, n.iota) ? \"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 long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n auto rs = new long[N];\n foreach (i; 0 .. N) {\n rs[i] = ((i + A[i]) % N + N) % N;\n }\n rs.sort;\n \n bool ans = true;\n foreach (i; 0 .. N) {\n ans = ans && (rs[i] == i);\n }\n writeln(ans ? \"YES\" : \"NO\");\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 moved = iota(0, n).map!(i => pmod(a.at(i) + i, n)).array;\n auto movedSet = redBlackTree!long();\n foreach(m; moved)\n movedSet.insert(m);\n if (movedSet.length == n)\n writeln(\"YES\");\n else\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) { 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\n\t\tauto used = new bool[](n);\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto p = (i+a[i]+n);\n\t\t\tp += (abs(p/n)+1)*n;\n\t\t\tp %= n;\n\t\t\tif (used[cast(int)p])\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tused[cast(int)p] = true;\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\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 if (iota(0, n).map!(i => pmod(a.at(i) + i, n)).uniq.array.length == n)\n writeln(\"YES\");\n else\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"}], "src_uid": "2173310623173d761b6039f0e5e661a8"} {"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, m; get(n, m);\n auto trips = new int[n + 1];\n int k = 0;\n foreach(i; 2 .. n + 1)\n trips[i] = trips[i - 1] + cast(int)(i - 1) / 2,\n k = cast(int)(k == 0? (trips[i] > m? i - 1 : 0) : k);\n int remainingLength = n - k - 1;\n int border = 2*k + 1 - 2*(m - trips[k]);\n int startValue = max(2*border, remainingLength - 1);\n int jump = border + 1;\n ans(m > trips[n]? [-1]:\n m == trips[n]? iota(1, 1 + n).array:\n m == 0? iota(n - 1, 2*n - 1).array:\n chain(iota(1, 1 + k),\n\t [border],\n\t iota(0, remainingLength).map!(i => startValue + jump * i))\n .array);\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}\n\nint main()\n{\n int n, m;\n get(n, m);\n int[] trips = new int[n + 1];\n trips[1] = 0;\n foreach(i; iota(2, 1 + n))\n trips[i] = trips[i - 1] + (i - 1) / 2;\n if (m > trips[n])\n ans(-1);\n if (m == trips[n])\n ans(iota(1, 1 + n).array);\n if (m == 0)\n ans(iota(n - 1, 2*n - 1).array);\n size_t k = 0;\n foreach(i, t; trips)\n if (t > m)\n\t{\n\t k = i - 1;\n\t break;\n\t}\n auto remainingLength = n - k - 1;\n auto border = 2*k + 1 - 2*(m - trips[k]);\n auto startValue = max(2*border, remainingLength - 1);\n auto jump = border + 1;\n ans(chain(iota(1, 1 + k).array,\n\t [border],\n\t iota(0, remainingLength).map!(i => startValue + jump * i))\n .array);\n assert(0);\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 /*\n debug {\n enum lim = 16;\n auto anss = new int[][][][](lim + 1, lim^^2 + 1);\n foreach (p; 0 .. 1 << lim) {\n const n = popcnt(p);\n int m;\n foreach (a; 1 .. lim + 1) foreach (b; a + 1 .. lim - a + 1) {\n if ((p & 1 << (a - 1)) && (p & 1 << (b - 1)) && (p & 1 << (a + b - 1))) {\n ++m;\n }\n }\n anss[n][m] ~= iota(1, lim + 1).filter!(a => (p & 1 << (a - 1))).array;\n }\n foreach (n; 0 .. lim + 1) {\n foreach (m; 0 .. n^^2 + 1) {\n writeln(n, \" \", m, \": \", anss[n][m]);\n }\n }\n }\n */\n \n try {\n for (; ; ) {\n const N = readInt();\n const M = readInt();\n \n int[] ans;\n foreach (x; 1 .. N + 1) {\n // x, ..., x + N\n int all;\n foreach (i; 0 .. N + 1) {\n // 0 <= i < j <= N, (x + i) + (x + j) <= x + N\n const lb = i + 1;\n const ub = N - x - i;\n if (lb <= ub) {\n all += (ub - lb + 1);\n }\n }\n foreach (y; 0 .. N + 1) {\n // x, ..., x + y - 1, x + y + 1, ..., x + N\n int num = all;\n /*\n 0 <= i < j <= y - 1, (x + i) + (x + j) = x + y\n 0 <= i < -i - x + y <= y - 1\n */\n {\n const lb = max(0, -x - 1);\n const ub = ((-x + y - 1) - (((-x + y - 1)) & 1)) / 2;\n if (lb <= ub) {\n num -= (ub - lb + 1);\n }\n }\n // 0 <= i <= N, (x + y) + (x + i) <= x + N\n {\n const lb = 0;\n const ub = min(N, N - x - y);\n if (lb <= ub) {\n num -= (ub - lb + 1);\n }\n }\n // (x + y) + (x + y) <= x + N\n if ((x + y) + (x + y) <= x + N) {\n num += 1;\n }\n debug {\n // writeln(x, \" \", y, \": \", num);\n }\n if (num == M) {\n ans = iota(x, x + y).array ~ iota(x + y + 1, x + N + 1).array;\n goto found;\n }\n }\n }\n writeln(\"-1\");\n continue;\n found:\n assert(ans.length == N);\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(ans[i]);\n }\n writeln();\n \n debug {\n bool[int] app;\n foreach (i; 0 .. N) {\n app[ans[i]] = true;\n }\n int cnt;\n foreach (i; 0 .. N) foreach (j; i + 1 .. N) {\n if ((ans[i] + ans[j]) in app) {\n ++cnt;\n }\n }\n assert(cnt == M);\n }\n }\n } catch (EOFException e) {\n }\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\nint main()\n{\n int n, m;\n get(n, m);\n int[] trips = new int[n + 1];\n trips[1] = 0;\n foreach(i; iota(2, 1 + n))\n trips[i] = trips[i - 1] + (i - 1) / 2;\n if (m > trips[n])\n ans(-1);\n if (m == trips[n])\n ans(iota(1, 1 + n).array);\n if (m == 0)\n ans(iota(n - 1, 2*n - 1).array);\n uint k = 0;\n foreach(i, t; trips)\n if (t > m)\n\t k = i - 1;\n auto remainingLength = n - k - 1;\n auto startValue = max(2*k + 3 - (m - trips[k]), remainingLength - 1);\n ans(chain(iota(1, 1 + k).array,\n\t [2 * k + 1 - 2*(m - trips[k])],\n\t iota(startValue, startValue + remainingLength))\n .array);\n assert(0);\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\nint main()\n{\n int n, m;\n get(n, m);\n int[] trips = new int[n + 1];\n trips[1] = 0;\n foreach(i; iota(2, 1 + n))\n trips[i] = trips[i - 1] + (i - 1) / 2;\n if (m > trips[n])\n ans(-1);\n if (m == trips[n])\n ans(iota(1, 1 + n).array);\n if (m == 0)\n ans(iota(n - 1, 2*n - 1).array);\n size_t k = 0;\n foreach(i, t; trips)\n if (t > m)\n\t{\n\t k = i - 1;\n\t break;\n\t}\n auto remainingLength = n - k - 1;\n auto border = 2*k + 1 - 2*(m - trips[k]);\n auto startValue = max(2*border, remainingLength - 1);\n ans(chain(iota(1, 1 + k).array,\n\t [border],\n\t iota(startValue, startValue + remainingLength))\n .array);\n assert(0);\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\nint main()\n{\n int n, m;\n get(n, m);\n int[] trips = new int[n + 1];\n trips[1] = 0;\n foreach(i; iota(2, 1 + n))\n trips[i] = trips[i - 1] + (i - 1) / 2;\n if (m > trips[n])\n ans(-1);\n if (m == trips[n])\n ans(iota(1, 1 + n).array);\n if (m == 0)\n ans(iota(n - 1, 2*n - 1));\n uint k = 0;\n foreach(i, t; trips)\n if (t > m)\n\t k = i - 1;\n auto remainingLength = n - k - 1;\n auto startValue = max(2*k + 3 - (m - trips[k]), remainingLength - 1);\n ans(chain(iota(1, 1 + k).array,\n\t [2 * k + 1 - 2*(m - trips[k])],\n\t iota(startValue, startValue + remainingLength))\n .array);\n assert(0);\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\nint main()\n{\n int n, m;\n get(n, m);\n int[] trips = new int[n + 1];\n trips[1] = 0;\n foreach(i; iota(2, 1 + n))\n trips[i] = trips[i - 1] + (i - 1) / 2;\n if (m > trips[n])\n ans(-1);\n if (m == trips[n])\n ans(iota(1, 1 + n).array);\n if (m == 0)\n ans(iota(n - 1, 2*n - 1));\n uint k = 0;\n foreach(i, t; trips)\n if (t > m)\n\t k = i - 1;\n wr(\"k\", k);\n auto remainingLength = n - k - 1;\n auto startValue = max(2*k + 3 - (m - trips[k]), remainingLength - 1);\n ans(chain(iota(1, 1 + k).array,\n\t [2 * k + 1 - 2*(m - trips[k])],\n\t iota(startValue, startValue + remainingLength))\n .array);\n assert(0);\n}\n"}], "src_uid": "b8c440664f8073d3e273878b0ca1e810"} {"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 lo = int.max;\n\t\tint hi = 0;\n\t\tbool ok = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tlo = min (lo, a[i] - hi);\n\t\t\thi = max (hi, a[i] - lo);\n\t\t\tok &= (lo >= 0 && lo + hi == a[i]);\n\t\t\tdebug {writeln (lo, \" \", hi, \" \", ok);}\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 a = RDA;\n\n\t\tlong x = a[0];\n\t\tlong y;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tx.chmin(a[i]);\n\t\t\tauto rem = a[i] - x;\n\t\t\tauto d = rem - y;\n\t\t\tif (d < 0)\n\t\t\t{\n\t\t\t\tx += d;\n\t\t\t}\n\t\t\tif (x < 0) break;\n\t\t\ta[i] -= x;\n\t\t\ty = a[i];\n\t\t}\n\t\tx = a[$-1];\n\t\ty = 0;\n\t\tforeach_reverse (i; 0..n)\n\t\t{\n\t\t\tx.chmin(a[i]);\n\t\t\tauto rem = a[i] - x;\n\t\t\tauto d = rem - y;\n\t\t\tif (d < 0)\n\t\t\t{\n\t\t\t\tx += d;\n\t\t\t}\n\t\t\tif (x < 0) break;\n\t\t\ta[i] -= x;\n\t\t\ty = a[i];\n\t\t}\n\t\tauto s = a.sum;\n\t\tans[ti] = s == 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, 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 auto ds = new long[N + 1];\n ds[0] = A[0] - 0;\n foreach (i; 1 .. N) {\n ds[i] = A[i] - A[i - 1];\n }\n ds[N] = 0 - A[N - 1];\n debug {\n writeln(\"ds = \", ds);\n }\n \n long posi, nega;\n foreach (i; 1 .. N) {\n if (ds[i] > 0) posi += ds[i];\n if (ds[i] < 0) nega += ds[i];\n }\n \n const ans = (ds[0] >= -nega && -ds[N] >= posi);\n writeln(ans ? \"YES\" : \"NO\");\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\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 = new int [n];\n\t\tforeach (k; 0..2)\n\t\t{\n\t\t\tint lo = int.max;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tlo = min (lo, a[i]);\n\t\t\t\tb[i] += lo;\n\t\t\t}\n\t\t\treverse (a);\n\t\t\treverse (b);\n\t\t}\n\t\twriteln (n.iota.all !(i => a[i] <= b[i]) ? \"YES\" : \"NO\");\n\t}\n}\n"}], "src_uid": "6e6356adb23da0dfa38834a0e157524c"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.utf;\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\n\t\tchar [] [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= readln.strip.dup;\n\t\t}\n\t\t\n\t\tint res = 0;\n\t\tbool [string] vis;\n\t\tforeach (ref line; s)\n\t\t{\n\t\t\tif (line.idup in vis)\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t\tline[0] = \"0123456789\".byChar.find !(c =>\n\t\t\t\t s.all !(other => other[0] != c)).front;\n\t\t\t}\n\t\t\tvis[line.idup] = true;\n\t\t}\n\t\twriteln (res);\n\t\tforeach (ref line; s)\n\t\t{\n\t\t\twriteln (line);\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 string[][](t);\n\tauto cnt = new int[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tint[string] set;\n\t\tauto str = new string[](n);\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tauto p = RD!string;\n\t\t\tstr[j] = p;\n\t\t\t++set[p];\n\t\t}\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (set[str[j]] == 1)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t--set[str[j]];\n\t\t\t++cnt[i];\n\t\t\t(){\n\t\t\tforeach (k; 0..4)\n\t\t\t{\n\t\t\t\tforeach (num; 0..10)\n\t\t\t\t{\n\t\t\t\t\tauto tmp = str[j].dup;\n\t\t\t\t\ttmp[k] = num.to!string[0];\n\t\t\t\t\tif (set.get(tmp.idup, 0) == 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tstr[j] = tmp.idup;\n\t\t\t\t\t\t++set[str[j]];\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\tans[i].length = n;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tans[i][j] = str[j];\n\t\t}\n\t}\n\t\n\tforeach (i; 0..t)\n\t{\n\t\twriteln(cnt[i]);\n\t\tforeach (e; ans[i])\n\t\t\twriteln(e);\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\tint t = rint;\n\tforeach(_; 0 .. t){\n\t\tint n = rint;\n\t\tstring[] ps = rtypes!string(n);\n\t\tstring[] qs = new string[](n);\n\t\tA: foreach(i; 0 .. n){\n\t\t\tforeach(j; 0 .. n) if(ps[i] == qs[j]) continue A;\n\t\t\tqs[i] = ps[i];\n\t\t}\n\t\tstring m = \"1234567890\";\n\t\tforeach(i; 0 .. n){\n\t\t\tif(qs[i] != \"\") continue;\n\t\t\tstring p = ps[i];\n\t\t\twhile(1){\n\t\t\t\tbool f = 0;\n\t\t\t\tforeach(j; 0 .. n) if(p == qs[j]) f = 1;\n\t\t\t\tif(f) p = p[0 .. 3] ~ m[p[3] - '0'];\n\t\t\t\telse break;\n\t\t\t}\n\t\t\tqs[i] = p;\n\t\t}\n\t\tint cnt;\n\t\tforeach(i; 0 .. n) if(ps[i] != qs[i]) cnt += 1;\n\t\tcnt.writeln;\n\t\tforeach(q; qs) q.writeln;\n\t}\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 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\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\tint res = 0;\n\t\tbool [string] vis;\n\t\tforeach (ref line; s)\n\t\t{\n\t\t\tif (line.idup in vis)\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tint d = line[0] - '0';\n\t\t\t\t\td = (d + 1) % 10;\n\t\t\t\t\tline[0] = cast (char) (d + '0');\n\t\t\t\t}\n\t\t\t\twhile (line in vis);\n\t\t\t}\n\t\t\tvis[line.idup] = true;\n\t\t}\n\t\twriteln (res);\n\t\tforeach (ref line; s)\n\t\t{\n\t\t\twriteln (line);\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;\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\tint n = rint;\n\t\tstring[] ps = rtypes!string(n);\n\t\tstring[] qs;\n\t\tint[string] px;\n\t\tbool[string] qset;\n\t\tint cnt = 0;\n\t\tforeach(int i, p; ps) if(p !in px) px[p] = i;\n\t\tforeach(int i, p; ps){\n\t\t\tif(px[p] != i){\n\t\t\t\tcnt += 1;\n\t\t\t\tchar[] q = p.to!(char[]);\n\t\t\t\twhile(q.to!string in qset) q[3] = '0' + (q[3] - '0' + 1) % 10;\n\t\t\t\tqset[q.to!string] = 1;\n\t\t\t\tqs ~= q.to!string;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tqset[p] = 1;\n\t\t\t\tqs ~= p;\n\t\t\t}\n\t\t}\n\t\tcnt.writeln;\n\t\tforeach(q; qs) q.writeln;\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\tint t = rint;\n\tforeach(_; 0 .. t){\n\t\tint n = rint;\n\t\tstring[] ps = rtypes!string(n);\n\t\tstring[] qs;\n\t\tbool[string] qset;\n\t\tint cnt = 0;\n\t\tforeach(p; ps){\n\t\t\tchar[] q = p.to!(char[]);\n\t\t\tif(q.to!string in qset) cnt += 1;\n\t\t\twhile(q.to!string in qset) q[3] = '0' + (q[3] - '0' + 1) % 10;\n\t\t\tqset[q.to!string] = 1;\n\t\t\tqs ~= q.to!string;\n\t\t}\n\t\tcnt.writeln;\n\t\tforeach(q; qs) q.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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 string[][](t);\n\tauto cnt = new int[](t);\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tint[string] set;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tauto p = RD!string;\n\t\t\tbool ok = true;\n\t\t\twhile (set.get(p, -1) >= 0)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tp = ((p.to!int+1) % 10000).to!string;\n\t\t\t}\n\t\t\tset[p] = j;\n\t\t\tif (!ok)\n\t\t\t\t++cnt[i];\n\t\t}\n\t\tans[i].length = n;\n\t\tforeach (key; set.keys)\n\t\t{\n\t\t\tans[i][set[key]] = key;\n\t\t}\n\t}\n\t\n\tforeach (i; 0..t)\n\t{\n\t\twriteln(cnt[i]);\n\t\tforeach (e; ans[i])\n\t\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "1d2ba15a7f2958bb79ccc7b2a2a1545b"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport core.memory;\nimport std.array : uninitializedArray;\n\nimmutable long inf = 2 * cast(long) 1e18 + 5;\n\nstruct line\n{\n long a, b;\n long val(long x)\n {\n return a * x + b;\n }\n}\n\nclass convex_hull\n{\n line[] d;\n size_t ptr = 0;\n bool check(in line i, in line j, in line k)\n {\n return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);\n }\n\n ref line opIndex(size_t x)\n {\n return d[x];\n }\n\n void opOpAssign(string op)(line x)\n {\n if (op == \"~\")\n {\n if (d.length && d[$ - 1].a == x.a)\n {\n x.b = max(x.b, d[$ - 1].b);\n --d.length;\n }\n d ~= x;\n while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))\n {\n d[$ - 2] = d[$ - 1];\n --d.length;\n }\n }\n }\n\n long query(long x)\n {\n if (ptr == d.length)\n return -inf;\n while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))\n ++ptr;\n return d[ptr].val(x);\n }\n}\n\nclass IT\n{\n convex_hull[] T;\n this(int size = 0)\n {\n T = new convex_hull[4 * size];\n foreach (ref t; T)\n t = new convex_hull;\n }\n\n void up(int v, int l, int r, int i, int j, in line val)\n {\n if (l > j || r < i)\n return;\n if (i <= l && r <= j)\n {\n T[v] ~= val;\n return;\n }\n immutable int mid = (l + r) / 2;\n up(2 * v, l, mid, i, j, val);\n up(2 * v + 1, mid + 1, r, i, j, val);\n }\n\n long get(int v, int l, int r, int pos, in long x)\n {\n if (l > pos || r < pos)\n return -inf;\n if (l == r)\n return T[v].query(x);\n immutable int mid = (l + r) / 2;\n return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,\n r, pos, x));\n }\n}\n\nIT T;\n\nalias Query = Tuple!(int, \"x\", int, \"st\", int, \"ed\", line, \"a\", int, \"typ\");\n\nQuery[] Q, Add, Ask;\nlong[] ans;\n\nint N;\n\nvoid main()\n{\n readf(\"%d\\n\", &N);\n Q = uninitializedArray!(Query[])(N);\n T = new IT(N);\n ans = uninitializedArray!(long[])(N);\n foreach (i; 0 .. N)\n {\n auto q = &Q[i];\n readf(\"%d \", &q.typ);\n if (q.typ == 1)\n {\n readf(\"%d %d\\n\", &q.a.a, &q.a.b);\n q.st = i + 1;\n q.ed = N;\n }\n else if (q.typ == 2)\n {\n readf(\"%d\\n\", &q.x);\n Q[q.x - 1].ed = i + 1;\n }\n else\n {\n readf(\"%d\\n\", &q.x);\n q.st = i + 1;\n Ask ~= *q;\n }\n }\n foreach (ref q; Q)\n if (q.typ == 1)\n Add ~= q;\n sort!`a.a.a < b.a.a`(Add);\n foreach (ref q; Add)\n T.up(1, 1, N, q.st, q.ed, q.a);\n sort!`a.x < b.x`(Ask);\n foreach (ref q; Ask)\n ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);\n foreach (i; 0 .. N)\n if (Q[i].typ == 3)\n {\n if (ans[i] == -inf)\n writef(\"EMPTY SET\\n\");\n else\n writef(\"%d\\n\", ans[i]);\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport core.memory;\nimport std.array : uninitializedArray;\n\nimmutable long inf = 2 * cast(long) 1e18 + 5;\n\nstruct line\n{\n long a, b;\n long val(long x)\n {\n return a * x + b;\n }\n}\n\nclass convex_hull\n{\n line[] d;\n size_t ptr = 0;\n bool check(in line i, in line j, in line k)\n {\n return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);\n }\n\n ref line opIndex(size_t x)\n {\n return d[x];\n }\n\n void opOpAssign(string op)(line x)\n {\n if (op == \"~\")\n {\n if (d.length && d[$ - 1].a == x.a)\n {\n x.b = max(x.b, d[$ - 1].b);\n --d.length;\n }\n d ~= x;\n while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))\n {\n d[$ - 2] = d[$ - 1];\n --d.length;\n }\n }\n }\n\n long query(long x)\n {\n if (ptr == d.length)\n return -inf;\n while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))\n ++ptr;\n return d[ptr].val(x);\n }\n}\n\nclass IT\n{\n convex_hull[] T;\n this(int size = 0)\n {\n T = new convex_hull[4 * size];\n foreach (i; 0..4 * size)\n\t\t\t\t\t\tT[i] = new convex_hull;\n }\n\n void up(int v, int l, int r, int i, int j, in line val)\n {\n if (l > j || r < i)\n return;\n if (i <= l && r <= j)\n {\n T[v] ~= val;\n return;\n }\n immutable int mid = (l + r) / 2;\n up(2 * v, l, mid, i, j, val);\n up(2 * v + 1, mid + 1, r, i, j, val);\n }\n\n long get(int v, int l, int r, int pos, in long x)\n {\n if (l > pos || r < pos)\n return -inf;\n if (l == r)\n return T[v].query(x);\n immutable int mid = (l + r) / 2;\n return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,\n r, pos, x));\n }\n}\n\nIT T;\n\nalias Query = Tuple!(int, \"x\", int, \"st\", int, \"ed\", line, \"a\", int, \"typ\");\n\nQuery[] Q, Add, Ask;\nlong[] ans;\n\nint N;\n\nvoid main()\n{\n readf(\"%d\\n\", &N);\n Q = uninitializedArray!(Query[])(N);\n T = new IT(N);\n ans = uninitializedArray!(long[])(N);\n foreach (i; 0 .. N)\n {\n auto q = &Q[i];\n readf(\"%d \", &q.typ);\n if (q.typ == 1)\n {\n readf(\"%d %d\\n\", &q.a.a, &q.a.b);\n q.st = i + 1;\n q.ed = N;\n }\n else if (q.typ == 2)\n {\n readf(\"%d\\n\", &q.x);\n Q[q.x - 1].ed = i + 1;\n }\n else\n {\n readf(\"%d\\n\", &q.x);\n q.st = i + 1;\n Ask ~= *q;\n }\n }\n for (int i = 0; i < N; ++i)\n if (Q[i].typ == 1)\n Add ~= Q[i];\n sort!`a.a.a < b.a.a`(Add);\n for (int i = 0; i < Add.length; ++i)\n T.up(1, 1, N, Add[i].st, Add[i].ed, Add[i].a);\n sort!`a.x < b.x`(Ask);\n for (int i = 0; i < Ask.length; ++i)\n\t\t\t\tans[Ask[i].st - 1] = T.get(1, 1, N, Ask[i].st, Ask[i].x);\n foreach (i; 0 .. N)\n if (Q[i].typ == 3)\n {\n if (ans[i] == -inf)\n writef(\"EMPTY SET\\n\");\n else\n writef(\"%d\\n\", ans[i]);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nimmutable long inf = 2 * cast(long) 1e18 + 5;\n\nstruct line\n{\n long a, b;\n long val(long x)\n {\n return a * x + b;\n }\n}\n\nclass convex_hull\n{\n line[] d;\n size_t ptr = 0;\n bool check(in line i, in line j, in line k)\n {\n return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);\n }\n\n ref line opIndex(size_t x)\n {\n return d[x];\n }\n\n void opOpAssign(string op)(line x)\n {\n if (op == \"~\")\n {\n if (d.length && d[$ - 1].a == x.a)\n {\n x.b = max(x.b, d[$ - 1].b);\n --d.length;\n }\n d ~= x;\n while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))\n {\n d[$ - 2] = d[$ - 1];\n --d.length;\n }\n }\n }\n\n long query(long x)\n {\n if (ptr == d.length)\n return -inf;\n while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))\n ++ptr;\n return d[ptr].val(x);\n }\n}\n\nclass IT\n{\n convex_hull[] T;\n this(int size = 0)\n {\n T = new convex_hull[4 * size];\n foreach (ref t; T)\n t = new convex_hull;\n }\n\n void up(int v, int l, int r, int i, int j, in line val)\n {\n if (l > j || r < i)\n return;\n if (i <= l && r <= j)\n {\n T[v] ~= val;\n return;\n }\n immutable int mid = (l + r) / 2;\n up(2 * v, l, mid, i, j, val);\n up(2 * v + 1, mid + 1, r, i, j, val);\n }\n\n long get(int v, int l, int r, int pos, in long x)\n {\n if (l > pos || r < pos)\n return -inf;\n if (l == r)\n return T[v].query(x);\n immutable int mid = (l + r) / 2;\n return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,\n r, pos, x));\n }\n}\n\nIT T;\n\nstruct Query\n{\n int typ, x, st, ed;\n line a;\n}\n\nQuery[] Q, Add, Ask;\nlong[] ans;\n\nint N;\n\nvoid main()\n{\n readf(\"%d\\n\", &N);\n Q = new Query[N];\n T = new IT(N);\n ans = new long[N];\n foreach (i; 0 .. N)\n {\n auto q = &Q[i];\n readf(\"%d \", &q.typ);\n if (q.typ == 1)\n {\n readf(\"%d %d\\n\", &q.a.a, &q.a.b);\n q.st = i + 1;\n q.ed = N;\n }\n else if (q.typ == 2)\n {\n readf(\"%d\\n\", &q.x);\n Q[q.x - 1].ed = i + 1;\n }\n else\n {\n readf(\"%d\\n\", &q.x);\n q.st = i + 1;\n Ask ~= *q;\n }\n }\n foreach (ref q; Q)\n if (q.typ == 1)\n Add ~= q;\n sort!`a.a.a < b.a.a`(Add);\n foreach (ref q; Add)\n T.up(1, 1, N, q.st, q.ed, q.a);\n sort!`a.x < b.x`(Ask);\n foreach (ref q; Ask)\n ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);\n foreach (i; 0 .. N)\n if (Q[i].typ == 3)\n {\n if (ans[i] == -inf)\n writeln(\"EMPTY SET\");\n else\n writeln(ans[i]);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nimmutable long inf = 2 * cast(long) 1e18 + 5;\n\nstruct line\n{\n long a, b;\n long val(long x)\n {\n return a * x + b;\n }\n}\n\nclass convex_hull\n{\n line[] d;\n size_t ptr = 0;\n bool check(in line i, in line j, in line k)\n {\n return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);\n }\n\n ref line opIndex(size_t x)\n {\n return d[x];\n }\n\n void opOpAssign(string op)(line x)\n {\n if (op == \"~\")\n {\n if (d.length && d[$ - 1].a == x.a)\n {\n x.b = max(x.b, d[$ - 1].b);\n --d.length;\n }\n d ~= x;\n while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))\n {\n d[$ - 2] = d[$ - 1];\n --d.length;\n }\n }\n }\n\n long query(long x)\n {\n if (ptr == d.length)\n return -inf;\n while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))\n ++ptr;\n return d[ptr].val(x);\n }\n}\n\nclass IT\n{\n convex_hull[] T;\n this(int size = 0)\n {\n T = new convex_hull[4 * size];\n foreach (ref t; T)\n t = new convex_hull;\n }\n\n void up(int v, int l, int r, int i, int j, in line val)\n {\n if (l > j || r < i)\n return;\n if (i <= l && r <= j)\n {\n T[v] ~= val;\n return;\n }\n immutable int mid = (l + r) / 2;\n up(2 * v, l, mid, i, j, val);\n up(2 * v + 1, mid + 1, r, i, j, val);\n }\n\n long get(int v, int l, int r, int pos, in long x)\n {\n if (l > pos || r < pos)\n return -inf;\n if (l == r)\n return T[v].query(x);\n immutable int mid = (l + r) / 2;\n return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,\n r, pos, x));\n }\n}\n\nIT T;\n\nstruct Query\n{\n int typ, x, st, ed;\n line a;\n}\n\nQuery[] Q, Add, Ask;\nlong[] ans;\n\nint N;\n\nvoid main()\n{\n readf(\"%d\\n\", &N);\n Q = new Query[N];\n T = new IT(N);\n ans = new long[N];\n foreach (i; 0 .. N)\n {\n auto q = &Q[i];\n readf(\"%d \", &q.typ);\n if (q.typ == 1)\n {\n readf(\"%d %d\\n\", &q.a.a, &q.a.b);\n q.st = i + 1;\n q.ed = N;\n }\n else if (q.typ == 2)\n {\n readf(\"%d\\n\", &q.x);\n Q[q.x - 1].ed = i + 1;\n }\n else\n {\n readf(\"%d\\n\", &q.x);\n q.st = i + 1;\n Ask ~= *q;\n }\n }\n foreach (ref q; Q)\n if (q.typ == 1)\n Add ~= q;\n sort!`a.a.a < b.a.a`(Add);\n foreach (ref q; Add)\n T.up(1, 1, N, q.st, q.ed, q.a);\n sort!`a.x < b.x`(Ask);\n foreach (ref q; Ask)\n ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);\n foreach (i; 0 .. N)\n if (Q[i].typ == 3)\n {\n if (ans[i] == -inf)\n writef(\"EMPTY SET\\n\");\n else\n writef(\"%d\\n\", ans[i]);\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport core.memory;\nimport std.container.array : Array;\n\nimmutable long inf = 2 * cast(long) 1e18 + 5;\n\nstruct line\n{\n long a, b;\n long val(long x)\n {\n return a * x + b;\n }\n}\n\nclass convex_hull\n{\n line[] d;\n size_t ptr = 0;\n bool check(in line i, in line j, in line k)\n {\n return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);\n }\n\n ref line opIndex(size_t x)\n {\n return d[x];\n }\n\n void opOpAssign(string op)(line x)\n {\n if (op == \"~\")\n {\n if (d.length && d[$ - 1].a == x.a)\n {\n x.b = max(x.b, d[$ - 1].b);\n --d.length;\n }\n d ~= x;\n while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))\n {\n d[$ - 2] = d[$ - 1];\n --d.length;\n }\n }\n }\n\n long query(long x)\n {\n if (ptr == d.length)\n return -inf;\n while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))\n ++ptr;\n return d[ptr].val(x);\n }\n}\n\nclass IT\n{\n convex_hull[] T;\n this(int size = 0)\n {\n T = new convex_hull[4 * size];\n foreach (ref t; T)\n t = new convex_hull;\n }\n\n void up(int v, int l, int r, int i, int j, in line val)\n {\n if (l > j || r < i)\n return;\n if (i <= l && r <= j)\n {\n T[v] ~= val;\n return;\n }\n immutable int mid = (l + r) / 2;\n up(2 * v, l, mid, i, j, val);\n up(2 * v + 1, mid + 1, r, i, j, val);\n }\n\n long get(int v, int l, int r, int pos, in long x)\n {\n if (l > pos || r < pos)\n return -inf;\n if (l == r)\n return T[v].query(x);\n immutable int mid = (l + r) / 2;\n return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,\n r, pos, x));\n }\n}\n\nIT T;\n\nalias Query = Tuple!(int, \"x\", int, \"st\", int, \"ed\", line, \"a\", int, \"typ\");\n\nQuery[] Q, Add, Ask;\nlong[] ans;\n\nint N;\n\nvoid main()\n{\n readf(\"%d\\n\", &N);\n Q = new Query[N];\n T = new IT(N);\n ans = new long[N];\n foreach (i; 0 .. N)\n {\n auto q = &Q[i];\n readf(\"%d \", &q.typ);\n if (q.typ == 1)\n {\n readf(\"%d %d\\n\", &q.a.a, &q.a.b);\n q.st = i + 1;\n q.ed = N;\n }\n else if (q.typ == 2)\n {\n readf(\"%d\\n\", &q.x);\n Q[q.x - 1].ed = i + 1;\n }\n else\n {\n readf(\"%d\\n\", &q.x);\n q.st = i + 1;\n Ask ~= *q;\n }\n }\n foreach (ref q; Q)\n if (q.typ == 1)\n Add ~= q;\n sort!`a.a.a < b.a.a`(Add);\n foreach (ref q; Add)\n T.up(1, 1, N, q.st, q.ed, q.a);\n sort!`a.x < b.x`(Ask);\n foreach (ref q; Ask)\n ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);\n foreach (i; 0 .. N)\n if (Q[i].typ == 3)\n {\n if (ans[i] == -inf)\n writef(\"EMPTY SET\\n\");\n else\n writef(\"%d\\n\", ans[i]);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\n\nimmutable long inf = 2 * cast(long) 1e18 + 5;\n\nstruct line\n{\n long a, b;\n long val(long x)\n {\n return a * x + b;\n }\n}\n\nclass convex_hull\n{\n line[] d;\n size_t ptr = 0;\n bool check(in line i, in line j, in line k)\n {\n return (k.b - i.b) * 1.0L / (i.a - k.a) < (j.b - i.b) * 1.0L / (i.a - j.a);\n }\n\n ref line opIndex(size_t x)\n {\n return d[x];\n }\n\n void opOpAssign(string op)(line x)\n {\n if (op == \"~\")\n {\n if (d.length && d[$ - 1].a == x.a)\n {\n x.b = max(x.b, d[$ - 1].b);\n --d.length;\n }\n d ~= x;\n while (d.length > 2 && check(d[$ - 3], d[$ - 2], d[$ - 1]))\n {\n writeln(d.length);\n d[$ - 2] = d[$ - 1];\n --d.length;\n }\n }\n }\n\n long query(long x)\n {\n if (ptr == d.length)\n return -inf;\n while (ptr + 1 < d.length && d[ptr].val(x) < d[ptr + 1].val(x))\n ++ptr;\n return d[ptr].val(x);\n }\n}\n\nclass IT\n{\n convex_hull[] T;\n this(int size = 0)\n {\n T = new convex_hull[4 * size];\n foreach (ref t; T)\n t = new convex_hull;\n }\n\n void up(int v, int l, int r, int i, int j, in line val)\n {\n if (l > j || r < i)\n return;\n if (i <= l && r <= j)\n {\n T[v] ~= val;\n return;\n }\n immutable int mid = (l + r) / 2;\n up(2 * v, l, mid, i, j, val);\n up(2 * v + 1, mid + 1, r, i, j, val);\n }\n\n long get(int v, int l, int r, int pos, in long x)\n {\n if (l > pos || r < pos)\n return -inf;\n if (l == r)\n return T[v].query(x);\n immutable int mid = (l + r) / 2;\n return max(T[v].query(x), get(2 * v, l, mid, pos, x), get(2 * v + 1, mid + 1,\n r, pos, x));\n }\n}\n\nIT T;\n\nstruct Query\n{\n int typ, x, st, ed;\n line a;\n}\n\nQuery[] Q, Add, Ask;\nlong[] ans;\n\nint N;\n\nvoid main()\n{\n readf(\"%d\\n\", &N);\n Q = new Query[N];\n T = new IT(N);\n ans = new long[N];\n foreach (i; 0 .. N)\n {\n auto q = &Q[i];\n readf(\"%d \", &q.typ);\n if (q.typ == 1)\n {\n readf(\"%d %d\\n\", &q.a.a, &q.a.b);\n q.st = i + 1;\n q.ed = N;\n }\n else if (q.typ == 2)\n {\n readf(\"%d\\n\", &q.x);\n Q[q.x - 1].ed = i + 1;\n }\n else\n {\n readf(\"%d\\n\", &q.x);\n q.st = i + 1;\n Ask ~= *q;\n }\n }\n foreach (ref q; Q)\n if (q.typ == 1)\n Add ~= q;\n sort!`a.a.a < b.a.a`(Add);\n foreach (ref q; Add)\n T.up(1, 1, N, q.st, q.ed, q.a);\n sort!`a.x < b.x`(Ask);\n foreach (ref q; Ask)\n ans[q.st - 1] = T.get(1, 1, N, q.st, q.x);\n foreach (i; 0 .. N)\n if (Q[i].typ == 3)\n {\n if (ans[i] == -inf)\n writeln(\"EMPTY SET\");\n else\n writeln(ans[i]);\n }\n}\n"}], "src_uid": "56127b122f24083304a75ece4f9f7310"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 b = RDA;\n\tauto a = new long[](n);\n\tauto c = new long[](n);\n\tlong last;\n\tforeach (i; 0..n)\n\t{\n\t\ta[i] = b[i] + last;\n\t\tlast.chmax(a[i]);\n\t\tif (a[i] < 0)\n\t\t{\n\t\t\tc[i] = abs(a[i]);\n\t\t\tlast += c[i];\n\t\t}\n\t}\n\tlong add;\n\tforeach_reverse (i; 0..n)\n\t{\n\t\ta[i] += add;\n\t\tif (c[i] > 0)\n\t\t{\n\t\t\tadd = c[i];\n\t\t}\n\t}\n\n\ta.map!(to!string).join(\" \").writeln;\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 b = readln.splitter.map !(to !(long)).array;\n\t\tlong m = 0;\n\t\tlong [] a;\n\t\tforeach (ref c; b)\n\t\t{\n\t\t\ta ~= c + m;\n\t\t\tm = max (m, a.back);\n\t\t}\n\t\twritefln !(\"%(%s %)\") (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(); } 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[] bs = scan!long(n);\n\n long x = 0;\n long[] as;\n foreach(i; 0 .. n){\n as ~= x + bs[i];\n x.raiseTo(as[i]);\n }\n as.unsplit.print;\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 B = new long[N];\n foreach (i; 0 .. N) {\n B[i] = readLong();\n }\n \n auto as = new long[N];\n auto xs = new long[N + 1];\n xs[0] = 0;\n foreach (i; 0 .. N) {\n // b = a - x\n as[i] = B[i] + xs[i];\n xs[i + 1] = max(xs[i], as[i]);\n }\n foreach (i; 0 .. N) {\n if (i > 0) write(\" \");\n write(as[i]);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "e22b10cdc33a165fbd73b45dc5fbedce"} {"source_code": "import std.algorithm;\nimport std.stdio;\n\nimmutable int MAX_C = 10_005;\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\tint res = MAX_C * MAX_C;\n\t\tforeach (i; 1..min (MAX_C, n))\n\t\t{\n\t\t\tint add = i;\n\t\t\tadd *= add;\n\t\t\tint cur = 0;\n\t\t\tforeach (j; 1..n)\n\t\t\t{\n\t\t\t\tcur += a[j];\n\t\t\t\tif (j > i)\n\t\t\t\t{\n\t\t\t\t\tcur -= a[j - i];\n\t\t\t\t}\n\t\t\t\tif (-MAX_C <= cur && cur <= MAX_C)\n\t\t\t\t{\n\t\t\t\t\tres = min (res, cur * cur + add);\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, std.math, std.stdio;\nvoid main () {\n\tint n;\n\treadf (\" %s\", &n);\n\tauto a = new int [n];\n\tforeach (ref x; a) readf (\" %s\", &x);\n\tlong r = long.max;\n\tforeach (i; 1..1111) {\n\t\tlong c = 0;\n\t\tforeach (j; 1..n) {\n\t\t\tc += a[j];\n\t\t\tif (j > i) c -= a[j - i];\n\t\t\tr = min (r, c * c + i * i);\n\t\t}\n\t}\n\twriteln (r);\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\nint MAX_C = 10_005;\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\tint res = MAX_C;\n\t\tforeach (i; 1..min (MAX_C, n))\n\t\t{\n\t\t\tint add = i;\n\t\t\tadd *= add;\n\t\t\tint cur = 0;\n\t\t\tforeach (j; 1..n)\n\t\t\t{\n\t\t\t\tcur += a[j];\n\t\t\t\tif (j > i)\n\t\t\t\t{\n\t\t\t\t\tcur -= a[j - i];\n\t\t\t\t}\n\t\t\t\tif (cur <= MAX_C)\n\t\t\t\t{\n\t\t\t\t\tres = min (res, cur * cur + add);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "74da42a1627e4a00fbaae91c75140287"} {"source_code": "import std.stdio;\nint main()\n{\n\tfloat a=0;\n\treadf(\" %f\", &a);\n\tfloat sum=0;\n\tfor (int i=0; i a + b) / cast(double) arr.length);\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.regex;\nimport std.algorithm.iteration;\nimport std.array;\n\nvoid main()\n{\n stdin.readln;\n auto ps = stdin.readln.strip.split(regex(` +`)).map!(to!double)\n .map!\"a/100\".array;\n writef(\"%.9f\",ps.sum/ps.length*100);\n}"}], "negative_code": [], "src_uid": "580596d05a2eaa36d630d71ef1055c43"} {"source_code": "import std.stdio, std.range, std.algorithm, std.conv, std.typecons, std.container, std.string, std.math;\n\nvoid main() {\n int n = readln.strip.to!int;\n int[] a = readln.strip.split.map!(to!int).array;\n writeln(abs(a[0]-a[1]), \" \", abs(a[0]-a[n-1]));\n foreach (i; 1..n-1) {\n auto mn = min(abs(a[i]-a[i-1]), abs(a[i]-a[i+1]));\n auto mx = max(abs(a[i]-a[0]), abs(a[i]-a[n-1]));\n writeln(mn, \" \", mx);\n }\n writeln(abs(a[n-1]-a[n-2]), \" \", abs(a[0]-a[n-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 writeln(a[1] - a[0], ' ', a[n - 1] - a[0]);\n foreach (i; 1..n-1) {\n writeln(min(a[i] - a[i - 1], a[i + 1] - a[i]), ' ',\n max(a[i] - a[0], a[n - 1] - a[i]));\n }\n writeln(a[n - 1] - a[n - 2], ' ', a[n - 1] - a[0]);\n}\n"}], "negative_code": [], "src_uid": "55383f13c8d097408b0ccf5653c4563d"} {"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 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 auto f = new long[](N);\n auto g = new long[](N);\n auto h = new long[](N);\n auto k = new long[](N);\n\n void dfs1(int n, int p) {\n foreach (m; G[n]) {\n if (m == p) continue;\n dfs1(m, n);\n g[n] += g[m] + A[m];\n f[n] += f[m] + g[m] + A[m];\n }\n }\n\n void dfs2(int n, int p) {\n if (p == -1) {\n h[n] = f[n];\n k[n] = g[n];\n } else {\n /*\n long fp = h[p] - f[n] - g[n] - A[n];\n long gp = k[p] - g[n] - A[n];\n h[n] = fp + gp + A[p];\n k[n] = gp + A[p];\n */\n h[n] = h[p] + k[p] + A[p] - (A[n] + g[n]) * 2;\n k[n] = k[p] + A[p] - A[n];\n }\n foreach (m; G[n]) if (m != p) dfs2(m, n);\n }\n\n dfs1(0, -1);\n dfs2(0, -1);\n h.reduce!max.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.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 adjlist = new int[][](n);\n foreach(i; 0 .. n - 1)\n {\n auto u = next!int - 1;\n auto v = next!int - 1;\n adjlist[u] ~= v;\n adjlist[v] ~= u;\n }\n auto aSum = new long[](n);\n auto treeCost = new long[](n);\n void dfs1(int v, int p)\n {\n aSum[v] = a[v];\n treeCost[v] = 0;\n foreach(w; adjlist[v])\n if (w != p)\n\t{\n\t dfs1(w, v);\n\t treeCost[v] += treeCost[w] + aSum[w];\n\t aSum[v] += aSum[w];\n\t}\n }\n dfs1(0, -1);\n long maxCost = long.min;\n void dfs2(int v, int p, long parentCost)\n {\n auto cost = treeCost[v] + parentCost;\n maxCost = max(maxCost, cost);\n foreach(w; adjlist[v])\n if (w != p)\n\t{\n\t dfs2(w, v, cost - treeCost[w] - aSum[w] + aSum[0] - aSum[w]);\n\t}\n }\n dfs2(0, -1, 0);\n maxCost.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": [], "src_uid": "0ed34310c59e3946b1c55b2618218120"} {"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\n__gshared int [] [] a;\n__gshared int [] p;\n__gshared bool [] b;\n__gshared int n;\n\nbool find_pair (int c)\n{\n\tif (b[c])\n\t{\n\t\treturn false;\n\t}\n\tb[c] = true;\n\tforeach_reverse (d; a[c])\n\t{\n\t\tif (!b[d])\n\t\t{\n\t\t\tif (p[d] == NA || find_pair (p[d]))\n\t\t\t{\n\t\t\t\tdebug {writeln (c, '-', d);}\n\t\t\t\tp[d] = c;\n\t\t\t\tp[c] = d;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nbool find_pair2 (int c)\n{\n// /*\n\tif (c < n / 2)\n\t{\n\t\treturn find_pair (c);\n\t}\n// */\n\tif (b[c])\n\t{\n\t\treturn false;\n\t}\n\tb[c] = true;\n\tif (a[c].length == 0)\n\t{\n\t\treturn false;\n\t}\n/*\n\tforeach_reverse (d; a[c])\n\t{\n\t\tif (!b[d])\n\t\t{\n\t\t\tif (p[d] == NA || find_pair2 (p[d]))\n\t\t\t{\n\t\t\t\tdebug {writeln (c, '-', d);}\n\t\t\t\tp[d] = c;\n\t\t\t\tp[c] = d;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n*/\n\tforeach_reverse (d; a[a[c][$ - 1]])\n\t{\n\t\tif (!b[d])\n\t\t{\n\t\t\tif (p[d] == NA || find_pair2 (p[d]))\n\t\t\t{\n\t\t\t\tdebug {writeln (c, '-', d);}\n\t\t\t\tp[d] = c;\n\t\t\t\tp[c] = d;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (a[c].length <= 1)\n\t{\n\t\treturn false;\n\t}\n\tforeach_reverse (d; a[a[c][0]])\n\t{\n\t\tif (!b[d])\n\t\t{\n\t\t\tif (p[d] == NA || find_pair2 (p[d]))\n\t\t\t{\n\t\t\t\tdebug {writeln (c, '-', d);}\n\t\t\t\tp[d] = c;\n\t\t\t\tp[c] = d;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false;\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tn++;\n\t\ta = new int [] [n];\n\t\tforeach (c; 2..n)\n\t\t{\n\t\t\tfor (int d = c * 2; d < n; d += c)\n\t\t\t{\n\t\t\t\ta[c] ~= d;\n\t\t\t\ta[d] ~= c;\n\t\t\t}\n\t\t}\n\n\t\tlong res = 0;\n\t\tp = new int [n];\n\t\tp[] = NA;\n\t\tb = new bool [n];\n\t\tforeach_reverse (c; 2..n)\n\t\t{\n\t\t\tif (p[c] == NA)\n\t\t\t{\n\t\t\t\tif (find_pair (c))\n\t\t\t\t{\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tb[] = false;\n\t\t\t\t\tif (find_pair (c))\n\t\t\t\t\t{\n\t\t\t\t\t\tres++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (p);}\n\t\t\t}\n\t\t}\n\n\t\tversion (DEBUG)\n\t\t{\n\t\t\tint num = 0;\n\t\t\tforeach (c; 2..n)\n\t\t\t{\n\t\t\t\tif (a[c].length > 0 && p[c] == NA)\n\t\t\t\t{\n\t\t\t\t\tnum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteln (\"!\", num);\n\t\t}\n\n\t\tb[] = false;\n\t\tforeach_reverse (c; 2..n)\n\t\t{\n\t\t\tif (p[c] == NA)\n\t\t\t{\n\t\t\t\tif (find_pair2 (c))\n\t\t\t\t{\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n/*\n\t\t\t\t\tb[] = false;\n\t\t\t\t\tif (find_pair2 (c))\n\t\t\t\t\t{\n\t\t\t\t\t\tres++;\n\t\t\t\t\t}\n*/\n\t\t\t\t}\n\t\t\t\tdebug {writeln (p);}\n\t\t\t}\n\t\t}\n\n\t\tversion (DEBUG)\n\t\t{\n\t\t\tnum = 0;\n\t\t\tforeach (c; 2..n)\n\t\t\t{\n\t\t\t\tif (a[c].length > 0 && p[c] == NA)\n\t\t\t\t{\n\t\t\t\t\tnum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteln (\"!\", num);\n\t\t}\n\n\t\tforeach_reverse (c; 2..n)\n\t\t{\n\t\t\tif (p[c] == NA)\n\t\t\t{\n\t\t\t\tb[] = false;\n\t\t\t\tif (find_pair2 (c))\n\t\t\t\t{\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t\tdebug {writeln (p);}\n\t\t\t}\n\t\t}\n\n\t\tversion (DEBUG)\n\t\t{\n\t\t\tnum = 0;\n\t\t\tforeach (c; 2..n)\n\t\t\t{\n\t\t\t\tif (a[c].length > 0 && p[c] == NA)\n\t\t\t\t{\n\t\t\t\t\tnum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteln (\"!\", num);\n\t\t}\n\n\t\twriteln (res);\n\t\tforeach (c; 2..n)\n\t\t{\n\t\t\tif (p[c] > c)\n\t\t\t{\n\t\t\t\twriteln (c, ' ', p[c]);\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.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\nimmutable LIM = 100005;\n\nint N;\n\nvoid main(string[] args) {\n\tbool[] isnp = new bool[LIM];\n\tfor (int i = 2; i * i < LIM; ++i) if (!isnp[i]) for (int j = i * i; j < LIM; j += i) isnp[j] = true;\n\t\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\t\n\t\tPair!(int, int)[] ans;\n\t\tbool[] used = new bool[N + 1];\n\t\tfor (int d = N; d >= 2; --d) if (!isnp[d]) {\n\t\t\tint[] xs;\n\t\t\tfor (int x = d; x <= N; x += d) if (!used[x]) {\n\t\t\t\txs ~= x;\n\t\t\t}\n\t\t\tif (xs.length >= 2 && xs[1] == d * 2) {\n\t\t\t\tswap(xs[0], xs[1]);\n\t\t\t}\n\t\t\tfor (int j = xs.length % 2; j < xs.length; j += 2) {\n\t\t\t\tans ~= pair(xs[j], xs[j + 1]);\n\t\t\t\tused[xs[j]] = true;\n\t\t\t\tused[xs[j + 1]] = true;\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(ans.length);\n\t\tforeach (p; ans) {\n\t\t\twriteln(p.x, \" \", p.y);\n\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.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\n__gshared int [] [] a;\n__gshared int [] p;\n__gshared bool [] b;\n__gshared int n;\n\nbool find_pair (int c)\n{\n\tif (b[c])\n\t{\n\t\treturn false;\n\t}\n\tb[c] = true;\n\tforeach_reverse (d; a[c])\n\t{\n\t\tif (!b[d])\n\t\t{\n\t\t\tif (p[d] == NA || find_pair (p[d]))\n\t\t\t{\n\t\t\t\tdebug {writeln (c, '-', d);}\n\t\t\t\tp[d] = c;\n\t\t\t\tp[c] = d;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tn++;\n\t\ta = new int [] [n];\n\t\tforeach (c; 2..n)\n\t\t{\n\t\t\tfor (int d = c * 2; d < n; d += c)\n\t\t\t{\n\t\t\t\ta[c] ~= d;\n\t\t\t\ta[d] ~= c;\n\t\t\t}\n\t\t}\n\n\t\tlong res = 0;\n\t\tp = new int [n];\n\t\tp[] = NA;\n\t\tb = new bool [n];\n\t\tforeach_reverse (c; 2..n)\n\t\t{\n\t\t\tif (p[c] == NA)\n\t\t\t{\n\t\t\t\tif (find_pair (c))\n\t\t\t\t{\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tb[] = false;\n\t\t\t\t\tif (find_pair (c))\n\t\t\t\t\t{\n\t\t\t\t\t\tres++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (p);}\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t\tforeach (c; 2..n)\n\t\t{\n\t\t\tif (p[c] > c)\n\t\t\t{\n\t\t\t\twriteln (c, ' ', p[c]);\n\t\t\t}\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\nimmutable int NA = -1;\n\n__gshared int [] [] a;\n__gshared int [] p;\n__gshared bool [] b;\n__gshared int n;\n\nbool find_pair (int c)\n{\n\tif (b[c])\n\t{\n\t\treturn false;\n\t}\n\tb[c] = true;\n\tforeach_reverse (d; a[c])\n\t{\n\t\tif (!b[d])\n\t\t{\n\t\t\tif (p[d] == NA || find_pair (p[d]))\n\t\t\t{\n\t\t\t\tdebug {writeln (c, '-', d);}\n\t\t\t\tp[d] = c;\n\t\t\t\tp[c] = d;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid main ()\n{\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tn++;\n\t\ta = new int [] [n];\n\t\tforeach (c; 2..n)\n\t\t{\n\t\t\tfor (int d = c * 2; d < n; d += c)\n\t\t\t{\n\t\t\t\ta[c] ~= d;\n\t\t\t\ta[d] ~= c;\n\t\t\t}\n\t\t}\n\n\t\tlong res = 0;\n\t\tp = new int [n];\n\t\tp[] = NA;\n\t\tb = new bool [n];\n\t\tforeach_reverse (c; 2..n / 2 + 1)\n\t\t{\n\t\t\tif (p[c] == NA)\n\t\t\t{\n\t\t\t\tif (find_pair (c))\n\t\t\t\t{\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tb[] = false;\n\t\t\t\t\tif (find_pair (c))\n\t\t\t\t\t{\n\t\t\t\t\t\tres++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdebug {writeln (p);}\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t\tforeach (c; 2..n)\n\t\t{\n\t\t\tif (p[c] > c)\n\t\t\t{\n\t\t\t\twriteln (c, ' ', p[c]);\n\t\t\t}\n\t\t}\n\t}\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;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\t\n\t\tPair!(int, int)[] ans;\n\t\tbool[] used = new bool[N + 1];\n\t\tfor (int d = N; d >= 2; --d) {\n\t\t\tint[] xs;\n\t\t\tfor (int i = d; i <= N; i += d) if (!used[i]) {\n\t\t\t\txs ~= i;\n\t\t\t}\n\t\t\tif (xs.length > 1 && xs.length % 2 != 0) {\n\t\t\t\tswap(xs[0], xs[1]);\n\t\t\t}\n\t\t\tfor (int j = xs.length % 2; j < xs.length; j += 2) {\n\t\t\t\tans ~= pair(xs[j], xs[j + 1]);\n\t\t\t\tused[xs[j]] = true;\n\t\t\t\tused[xs[j + 1]] = true;\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(ans.length);\n\t\tforeach (p; ans) {\n\t\t\twriteln(p.x, \" \", p.y);\n\t\t}\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.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;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\t\n\t\tPair!(int, int)[] ans;\n\t\tbool[] used = new bool[N + 1];\n\t\tfor (int d = N; d >= 2; --d) {\n\t\t\tint[] xs;\n\t\t\tfor (int i = d; i <= N; i += d) if (!used[i]) {\n\t\t\t\txs ~= i;\n\t\t\t}\n\t\t\tif (xs.length >= 2 && xs[1] == d * 2) {\n\t\t\t\tswap(xs[0], xs[1]);\n\t\t\t}\n\t\t\tfor (int j = xs.length % 2; j < xs.length; j += 2) {\n\t\t\t\tans ~= pair(xs[j], xs[j + 1]);\n\t\t\t\tused[xs[j]] = true;\n\t\t\t\tused[xs[j + 1]] = true;\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(ans.length);\n\t\tforeach (p; ans) {\n\t\t\twriteln(p.x, \" \", p.y);\n\t\t}\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "src_uid": "72d70a1c2e579bf81954ff932a9bc16e"} {"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 x1, y1, x2, y2;\n readf(\"%s %s %s %s\", &x1, &y1, &x2, &y2);\n readln;\n \n auto n = x2 - x1;\n auto m = y2 - y1;\n \n if (n > m) { swap(n, m); }\n \n long sm (int k) {\n return (1 + k).to!long * k / 2;\n }\n \n long ans = 1 + sm(n) * 2 + n.to!long * (m - 1 - n);\n \n ans.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\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint row1, col1, row2, col2;\n\t\treadf !(\" %s %s %s %s\") (row1, col1, row2, col2);\n\t\twriteln ((row2 - row1) * 1L * (col2 - col1) + 1);\n\t}\n}\n"}], "negative_code": [], "src_uid": "1b13c9d9fa0c5a44d035bcf6d70e1a60"} {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, m;\n rd(n, m);\n auto a = new int[][](n, m);\n foreach (i; 0 .. n) {\n a[i] = readln.split.to!(int[]);\n }\n auto b = new int[][](n, m);\n foreach (i; 0 .. n) {\n b[i] = readln.split.to!(int[]);\n }\n\n if (n < 2 || m < 2) {\n bool all = true;\n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n all &= a[i][j] == b[i][j];\n }\n }\n writeln(all ? \"Yes\" : \"No\");\n return;\n }\n foreach (i; 0 .. (n - 1)) {\n foreach (j; 0 .. (m - 1)) {\n if (a[i][j] != b[i][j]) {\n a[i][j] ^= 1;\n a[i + 1][j] ^= 1;\n a[i][j + 1] ^= 1;\n a[i + 1][j + 1] ^= 1;\n }\n }\n }\n bool all = true;\n foreach (i; 0 .. n) {\n foreach (j; 0 .. m) {\n all &= a[i][j] == b[i][j];\n }\n }\n writeln(all ? \"Yes\" : \"No\");\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\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\treadln;\n\n\t\tint [] [] a;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta ~= readln.splitter.map !(to !(int)).array;\n\t\t}\n\n\t\tint [] [] b;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tb ~= readln.splitter.map !(to !(int)).array;\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ta[i][] ^= b[i][];\n\t\t}\n\n\t\tauto u = new int [n];\n\t\tauto v = new int [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\tu[i] += a[i][j];\n\t\t\t\tv[j] += a[i][j];\n\t\t\t}\n\t\t}\n\n\t\tbool ok = true;\n\t\tok &= u.all !(x => x % 2 == 0);\n\t\tok &= v.all !(x => x % 2 == 0);\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\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\nbool check (int[][] a, int[][] b, int h, int w) {\n auto r = new int[h];\n foreach (i; 0 .. h) {\n int t;\n foreach (j; 0 .. w) {\n t += a[i][j] ^ b[i][j];\n }\n if (t & 1) return false;\n }\n foreach (j; 0 .. w) {\n int t;\n foreach (i; 0 .. h) {\n t += a[i][j] ^ b[i][j];\n }\n if (t & 1) return false;\n }\n return true;\n}\n\nvoid main() {\n auto r = new InputReader;\n immutable h = r.next!uint;\n immutable w = r.next!uint;\n auto a = uninitializedArray!(int[][]) (h, w);\n auto b = uninitializedArray!(int[][]) (h, w);\n foreach (i; 0 .. h) foreach (j; 0 .. w) a[i][j] = r.next!uint;\n foreach (i; 0 .. h) foreach (j; 0 .. w) b[i][j] = r.next!uint;\n writeln (check (a, b, h, w) ? \"Yes\" : \"No\");\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\nint M, N;\nint[][] A, B;\n\nvoid main() {\n try {\n for (; ; ) {\n M = readInt();\n N = readInt();\n A = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n A[x][y] = readInt();\n }\n B = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n B[x][y] = readInt();\n }\n \n auto a = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n a[x][y] = A[x][y];\n }\n foreach (x; 0 .. M - 1) foreach (y; 0 .. N - 1) {\n if (a[x][y] != B[x][y]) {\n a[x][y] ^= 1;\n a[x][y + 1] ^= 1;\n a[x + 1][y] ^= 1;\n a[x + 1][y + 1] ^= 1;\n }\n }\n bool ans = true;\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n ans = ans && (a[x][y] == B[x][y]);\n }\n writeln(ans ? \"Yes\" : \"No\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "068e6bbfe590f4485528e85fa991ff24"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tbool mode;\n\t\tans[ti] = true;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (!mode)\n\t\t\t{\n\t\t\t\tif (a[i] < i)\n\t\t\t\t\tmode = true;\n\t\t\t}\n\t\t\tif (mode)\n\t\t\t{\n\t\t\t\ta[i].chmin(a[i-1]-1);\n\t\t\t\tif (a[i] < 0)\n\t\t\t\t\tans[ti] = false;\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.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 long readLong() {\n import std.conv : to;\n\n return readToken.to!long;\n }\n\n string[] tokens;\n}\n\nbool solve(int n, int[] a) {\n bool ok = true;\n bool[] prefixOK = new bool[n];\n\n for (int i = 0; i < n; ++i) {\n ok &= a[i] >= i;\n prefixOK[i] = ok;\n }\n ok = true;\n for (int i = n; i--;) {\n ok &= a[i] >= n - 1 - i;\n if (prefixOK[i] && ok) {\n return true;\n }\n }\n return false;\n}\n\nvoid main() {\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = io.readInt();\n }\n writeln(solve(n, a) ? \"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\nvoid main()\n{\n auto t = next!long;\n foreach(tc; 0 .. t)\n {\n auto n = next!long;\n auto a = new long[n.ind];\n read(a);\n auto inc = long(0);\n for(inc = 0; inc < n && a.at(inc) >= inc; inc++)\n {}\n if (inc == n)\n {\n writeln(\"Yes\");\n continue;\n }\n auto dec = long(0);\n for(dec = n - 1; dec >= 0 && a.at(dec) >= (n - 1 - dec); dec--)\n {}\n if (dec == -1)\n {\n writeln(\"Yes\");\n continue;\n }\n if (tc == 6)\n logSym!(n, a, inc, dec);\n if (dec >= inc)\n {\n writeln(\"No\");\n }\n else\n {\n if (inc == dec + 1 && inc == n - 1 - dec)\n {\n writeln(\"No\");\n }\n else\n {\n writeln(\"Yes\");\n }\n }\n }\n}\n"}], "negative_code": [], "src_uid": "b9d5e58459baf2a2c294225b73b7229b"} {"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 logLimit = 21;\nimmutable int limit = 1 << logLimit;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tint h, c, t;\n\t\treadf !(\" %s %s %s\") (h, c, t);\n\t\tint res = 1;\n\n\t\tlong fun (int x)\n\t\t{\n\t\t\tauto y = x / 2;\n\t\t\tauto z = x - y;\n\t\t\tauto num = c * 1L * y + h * 1L * z;\n\t\t\treturn num;\n\t\t}\n\n\t\tvoid go (int x)\n\t\t{\n\t\t\tauto prev = fun (res);\n\t\t\tauto next = fun (x);\n\t\t\tif (abs (prev - t * 1L * res) * x >\n\t\t\t abs (next - t * 1L * x) * res)\n\t\t\t{\n\t\t\t\tres = x;\n\t\t\t}\n\t\t}\n\n\t\tgo (2);\n\n\t\tint lo = 2;\n\t\tint hi = limit;\n\t\tforeach (step; 0..logLimit)\n\t\t{\n\t\t\tauto me = (lo + hi) / 2;\n\t\t\tauto cur = me * 2 + 1;\n\t\t\tif (fun (cur) > t * 1L * cur)\n\t\t\t{\n\t\t\t\tlo = me + 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = me;\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; lo - 1..lo + 2)\n\t\t{\n\t\t\tgo (2 * i + 1);\n\t\t}\n\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, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nint isz(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\ndouble dist(ll treq, ll cups, ll c, ll h){\n ll haf = (cups - 1) / 2;\n double val = c*haf + h*(haf + 1);\n val /= cups;\n return abs(val - treq);\n}\n\n\nvoid play(){\n ll h, c, treq;\n h = rd; c = rd; treq = rd;\n /* double mid = (h + c) / 2.0; */\n\n if(treq >= h || h == c){\n writeln(1); return;\n }if(2*treq <= h + c){\n writeln(2); return;\n }\n\n // Multiple of (H - C)\n /* double temptake = (treq - c) / (h - c); */\n /*\n */\n ll num = (h - c);\n ll den = (2*treq - h - c);\n\n ll res = num / den;\n if(res % 2 == 0) ++res;\n if(dist(treq, res, c, h) > dist(treq, res - 2, c, h)){\n res -= 2;\n }else if (dist(treq, res, c, h) > dist(treq, res+2, c, h)){\n res += 2;\n }\n writeln(res);\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) { 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 h = RD;\n\t\tauto c = RD;\n\t\tauto tt = RD;\n\n\t\tbool f(long x)\n\t\t{\n\t\t\treturn h*x + c*(x-1) > tt*(x*2-1);\n\t\t}\n\t\tauto r = binarySearch!(f)(0L, int.max);\n\n\t\tif (r == 0)\n\t\t{\n\t\t\tif (abs((tt - h)*2) < abs(tt*2 - (h+c)))\n\t\t\t\tans[ti] = 1;\n\t\t\telse\n\t\t\t\tans[ti] = 2;\n\t\t}\n\t\telse if (r == int.max-1)\n\t\t{\n\t\t\tans[ti] = 2;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto d1 = cast(double)(h*r + c*(r-1))/(r*2-1) - tt;\n\t\t\tauto d2 = cast(double)(h*(r+1) + c*r)/(r*2+1) - tt;\n\t\t\tdebug writeln(\"r:\", r, \" h*(r+1):\", h*(r+1), \" c*r:\", c*r, \" d1:\", d1, \" d2:\", d2);\n\t\t\tif (abs(d1) <= abs(d2))\n\t\t\t\tans[ti] = r*2 - 1;\n\t\t\telse\n\t\t\t\tans[ti] = r*2 + 1;\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": "// 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 isz(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\ndouble[] ratios;\nvoid preprocess(){\n foreach(i; 0..100000){\n ratios ~= (i + 1) / (2*i + 1);\n }\n}\n\n\nvoid play(){\n ll h, c, treq;\n h = rd; c = rd; treq = rd;\n double mid = (h + c) / 2.0;\n\n if(treq == h || h == c){\n writeln(1); return;\n }if(treq <= mid){\n writeln(2); return;\n }\n\n // Multiple of (H - C)\n /* double temptake = (treq - c) / (h - c); */\n /*\n ll lo = 0; ll hi = 100_000;\n while(hi - lo > 1){\n ll midd = (lo + hi)/2;\n if(ratios[midd] < temptake){\n hi = midd;\n }else{\n lo = midd;\n }\n }\n if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){\n lo = hi;\n }\n */\n double num = (h - c);\n double den = (2*treq - h - c);\n debug writeln(num , \" \", den);\n double margin = num / den;\n debug writeln(margin);\n ll res = to!ll(margin);\n if(res % 2 == 0) ++res;\n if(abs(margin - res - 2) < abs(margin - res)){\n res -= 2;\n }\n writeln(res);\n}\n\nint main(){\n ll t = 1;\n /* preprocess(); */\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, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nint isz(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\ndouble[] ratios;\nvoid preprocess(){\n foreach(i; 0..100000){\n ratios ~= (i + 1) / (2*i + 1);\n }\n}\n\n\nvoid play(){\n ll h, c, treq;\n h = rd; c = rd; treq = rd;\n double mid = (h + c) / 2.0;\n\n if(treq == h || h == c){\n writeln(1); return;\n }if(treq <= mid){\n writeln(2); return;\n }\n\n // Multiple of (H - C)\n /* double temptake = (treq - c) / (h - c); */\n /*\n ll lo = 0; ll hi = 100_000;\n while(hi - lo > 1){\n ll midd = (lo + hi)/2;\n if(ratios[midd] < temptake){\n hi = midd;\n }else{\n lo = midd;\n }\n }\n if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){\n lo = hi;\n }\n */\n double num = (h - c);\n double den = (treq - mid);\n debug writeln(num , \" \", den);\n double margin = num / (2.0 * den);\n debug writeln(margin);\n ll res = to!ll(margin);\n if(res % 2 == 0) ++res;\n writeln(res);\n}\n\nint main(){\n ll t = 1;\n /* preprocess(); */\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, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nint isz(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\ndouble[] ratios;\nvoid preprocess(){\n foreach(i; 0..100000){\n ratios ~= (i + 1) / (2*i + 1);\n }\n}\n\n\nvoid play(){\n ll h, c, treq;\n h = rd; c = rd; treq = rd;\n double mid = (h + c) / 2.0;\n\n if(treq >= h || h == c){\n writeln(1); return;\n }if(treq <= mid){\n writeln(2); return;\n }\n\n // Multiple of (H - C)\n /* double temptake = (treq - c) / (h - c); */\n /*\n */\n ll num = (h - c);\n ll den = (2*treq - h - c);\n debug writeln(num , \" \", den);\n\n ll lo = 0; ll hi = 100_000;\n while(hi - lo > 1){\n ll midd = (lo + hi)/2;\n ll midval = 2*midd + 1;\n if(den * midval > num){\n hi = midd;\n }else{\n lo = midd;\n }\n }\n ll midval = 2 * lo + 1;\n debug writeln(midval);\n if(abs(den * midval - num) > abs(den * (midval + 2) - num)){\n midval += 2;\n }\n\n /* double margin = num / den; */\n /* debug writeln(margin); */\n /* ll res = to!ll(margin); */\n /* if(res % 2 == 0) ++res; */\n /* if(abs(margin - res + 2) < abs(margin - res)){ */\n /* res -= 2; */\n /* }else if (abs(margin - res - 2) < abs(margin - res)){ */\n /* res += 2; */\n /* } */\n /* writeln(res); */\n writeln(midval);\n}\n\nint main(){\n ll t = 1;\n /* preprocess(); */\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, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;\n\nalias ll = long;\nint isz(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\ndouble[] ratios;\nvoid preprocess(){\n foreach(i; 0..100000){\n ratios ~= (i + 1) / (2*i + 1);\n }\n}\n\n\nvoid play(){\n ll h, c, treq;\n h = rd; c = rd; treq = rd;\n double mid = (h + c) / 2.0;\n\n if(treq == h || h == c){\n writeln(1); return;\n }if(treq <= mid){\n writeln(2); return;\n }\n\n // Multiple of (H - C)\n /* double temptake = (treq - c) / (h - c); */\n /*\n ll lo = 0; ll hi = 100_000;\n while(hi - lo > 1){\n ll midd = (lo + hi)/2;\n if(ratios[midd] < temptake){\n hi = midd;\n }else{\n lo = midd;\n }\n }\n if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){\n lo = hi;\n }\n */\n double num = (h - c);\n double den = (2*treq - h - c);\n debug writeln(num , \" \", den);\n double margin = num / den;\n debug writeln(margin);\n ll res = to!ll(margin);\n if(res % 2 == 0) ++res;\n if(abs(margin - res + 2) < abs(margin - res)){\n res -= 2;\n }else if (abs(margin - res - 2) < abs(margin - res)){\n res += 2;\n }\n writeln(res);\n}\n\nint main(){\n ll t = 1;\n /* preprocess(); */\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) { 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 h = RD;\n\t\tauto c = RD;\n\t\tauto tt = RD;\n\n\t\tbool f(long x)\n\t\t{\n\t\t\treturn h*x + c*(x-1) > tt*(x*2-1);\n\t\t}\n\t\tauto r = binarySearch!(f)(0L, int.max);\n\n\t\tif (r == 0)\n\t\t{\n\t\t\tans[ti] = 1;\n\t\t}\n\t\telse if (r == int.max-1)\n\t\t{\n\t\t\tans[ti] = 2;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto d1 = h*r + c*(r-1) - tt*2;\n\t\t\tauto d2 = (h+1)*r + c*r - tt*2;\n\t\t\tif (d1 <= d2)\n\t\t\t\tans[ti] = r*2 + 1;\n\t\t\telse\n\t\t\t\tans[ti] = (r+1)*2 + 1;\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, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 h = RD;\n\t\tauto c = RD;\n\t\tauto tt = RD;\n\n\t\tbool f(long x)\n\t\t{\n\t\t\treturn h*x + c*(x-1) > tt*(x*2-1);\n\t\t}\n\t\tauto r = binarySearch!(f)(0L, int.max);\n\n\t\tif (r == 0)\n\t\t{\n\t\t\tans[ti] = 1;\n\t\t}\n\t\telse if (r == int.max-1)\n\t\t{\n\t\t\tans[ti] = 2;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tauto d1 = h*r + c*(r-1) - tt*2;\n\t\t\tauto d2 = h*(r+1) + c*r - tt*2;\n\t\t\tif (d1 <= d2)\n\t\t\t\tans[ti] = r*2 + 1;\n\t\t\telse\n\t\t\t\tans[ti] = (r+1)*2 + 1;\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "ca157773d06c7d192589218e2aad6431"} {"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 k = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tif (k == 0)\r\n\t\t\tans[ti] = true;\r\n\t\telse if (n <= k*2)\r\n\t\t\tcontinue;\r\n\t\telse\r\n\t\t{\r\n\t\t\tint l, r = n-1;\r\n\t\t\tint cnt;\r\n\t\t\twhile (l < r)\r\n\t\t\t{\r\n\t\t\t\tif (s[l] != s[r])\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t++l; --r;\r\n\t\t\t\t++cnt;\r\n\t\t\t}\r\n\t\t\tans[ti] = cnt >= k;\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}", "positive_code": [{"source_code": "// Vicfred\r\n// https://codeforces.com/contest/1496/problem/A\r\n// string manipulation\r\nimport std.algorithm;\r\nimport std.stdio;\r\nimport std.conv;\r\nimport std.string;\r\n\r\nvoid main() {\r\n long t;\r\n readf(\"%s\\n\", &t);\r\n\r\n uint n, k;\r\n string s;\r\n while(t--) {\r\n readf(\"%s %s\\n\", &n, &k);\r\n readf(\"%s\\n\", &s);\r\n\r\n string S = s[0..k];\r\n\r\n if(k > (n-1)/2)\r\n writeln(\"NO\");\r\n else if(k == 0 || s[0..k] == s[$-k..$].dup.reverse) {\r\n \"YES\".writeln;\r\n } else {\r\n \"NO\".writeln;\r\n }\r\n }\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 int k = scan!int;\n dchar[] arr = scan!(dchar[]);\n bool f = 1;\n for(int i = 0; i < k; ++i){\n if(arr[i] != arr[n - i - 1]){\n f = 0; break;\n }\n }\n if((n % 2 == 0 && k == n/2) || !f){\n writeln(\"NO\");\n }else{\n writeln(\"YES\");\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": "// Vicfred\n// https://codeforces.com/contest/1496/problem/A\n// string manipulation\nimport std.algorithm;\nimport std.stdio;\nimport std.conv;\nimport std.string;\nimport core.stdc.string : strlen;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\n uint n, k;\n string s;\nwhile(t--) {\n readf(\"%s %s\\n\", &n, &k);\n readf(\"%s\\n\", &s);\n\n if(k == 0) {\n \"YES\".writeln;\n continue;\n }\n\n if(2*k == n) {\n \"NO\".writeln;\n continue;\n }\n\n if(s[0..k] == s[$-k..$].dup.reverse) {\n \"YES\".writeln;\n } else {\n \"NO\".writeln;\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\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 k = RD!int;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tif (k == 0)\r\n\t\t\tans[ti] = true;\r\n\t\telse if (n <= k*2)\r\n\t\t\tcontinue;\r\n\t\telse\r\n\t\t{\r\n\t\t\tint l, r = n-1;\r\n\t\t\tbool ok = true;\r\n\t\t\twhile (l < r)\r\n\t\t\t{\r\n\t\t\t\tif (s[l] != s[r])\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\t++l; --r;\r\n\t\t\t}\r\n\t\t\tans[ti] = 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}"}], "src_uid": "6fbf41dc32d1c28351d78a9ec5fc0026"} {"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 S = readln.chomp;\n auto D = S.map!(c => c == 'D').sum;\n auto R = N - D;\n auto dead = new bool[](N);\n\n int can_kill_D, can_kill_R;\n\n while (D > 0 && R > 0) {\n foreach (i, c; enumerate(S)) {\n if (dead[i])\n continue;\n if (c == 'D' && can_kill_D > 0) {\n D--;\n can_kill_D--;\n dead[i] = true;\n }\n else if (c == 'D') {\n can_kill_R++;\n }\n else if (c == 'R' && can_kill_R > 0) {\n R--;\n can_kill_R--;\n dead[i] = true;\n }\n else if (c == 'R') {\n can_kill_D++;\n }\n }\n }\n\n writeln(D > 0 ? \"D\" : \"R\");\n\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;\nchar[200_001][2] s;\n\nvoid main() {\n while (read(&n)) {\n auto s2 = s[0][ ];\n readln(s2);\n int cur = 0;\n int dcount, rcount;\n int delta = 0;\n do {\n int nextN = 0;\n dcount = rcount = 0;\n foreach (i; 0 .. n)\n if (s[cur][i] == 'D') {\n if (delta++ >= 0) {\n s[!cur][nextN++] = 'D';\n dcount++;\n }\n } else\n if (delta-- <= 0) {\n s[!cur][nextN++] = 'R';\n rcount++;\n }\n cur = !cur;\n n = nextN;\n } while (dcount && rcount);\n if (dcount)\n write(\"D\\n\");\n else\n write(\"R\\n\");\n }\n}\n"}], "negative_code": [], "src_uid": "cc50eef15726d429cfc2e76f0aa8cd19"} {"source_code": "import std.stdio;\n\nbool is_prime (int n)\n{\n\tfor (int i = 2; i * i <= n; i++)\n\t{\n\t\tif (n % i == 0)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nvoid main ()\n{\n\tint n;\nmain_loop:\t\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tfor (int k = 4; k <= n - 4; k++)\n\t\t{\n\t\t\tif (!is_prime (k) && !is_prime (n - k))\n\t\t\t{\n\t\t\t\twriteln (k, ' ', n - k);\n\t\t\t\tcontinue main_loop;\n\t\t\t}\n\t\t}\n\t\tassert (false);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\nint main()\n{\n\tdebug\n\t{\n\t\tfreopen(\".input\",\"r\",stdin);\n\t\tfreopen(\".output\",\"w\",stdout);\n\t}\n\t\n\t//int n = to!(int)(readln()[0..$-1]);\n\tint n;\n\treadf(\"%s\",&n);\n\t\n\tfor(int i=4;i<=n-4;i++)\n\t{\n\t\tbool nt = false;\n\t\t\n\t\tfor(int j=2;j 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;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\t\n\t\tbool[] isnp = new bool[N + 1];\n\t\tforeach (i; 2 .. isnp.length) if (!isnp[i]) for (int j = i * i; j < isnp.length; j += i) isnp[j] = true;\n\t\t\n\t\tfor (int x = 2; x <= N - 2; ++x) {\n\t\t\tconst y = N - x;\n\t\t\tif (isnp[x] && isnp[y]) {\n\t\t\t\twriteln(x, \" \", y);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport core.stdc.stdio;\nimport std.bigint;\nimport std.format;\nimport std.math;\n\nstring readline()\n{\n\tstring result = readln();\n\tif (result[result.length - 1] == '\\n') result.length--;\n\treturn result;\n}\n\nbool isPrime(long x)\n{\n\tforeach (long i; 2..(x/2 + 1))\n\t{\n\t\tif (x % i == 0)\n\t\t\treturn false;\n\t}\n\treturn true;\n}\n\nint main(string[] argv)\n{\n\tlong n;\n\tscanf(\"%d\", &n);\n\tlong x, y;\n\tx = n / 2;\n\ty = n / 2;\n\tif (x + y != n) y++;\n\tforeach (long i; 0..x)\n\t{\n\t\tif (!isPrime(x - i) && !isPrime(y + i))\n\t\t{\n\t\t\tprintf(\"%d \", x - i);\n\t\t\tprintf(\"%d\", y + i);\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport core.stdc.stdio;\nimport std.bigint;\nimport std.format;\nimport std.math;\n\nstring readline()\n{\n\tstring result = readln();\n\tif (result[result.length - 1] == '\\n') result.length--;\n\treturn result;\n}\n\nbool isPrime(long x)\n{\n\tforeach (long i; 2..(x/2))\n\t{\n\t\tif (x % i == 0)\n\t\t\treturn false;\n\t}\n\treturn true;\n}\n\nint main(string[] argv)\n{\n\tlong n;\n\tscanf(\"%d\", &n);\n\tlong x, y;\n\tx = n / 2;\n\ty = n / 2;\n\tif (x + y != n) y++;\n\tforeach (long i; 0..x)\n\t{\n\t\tx -= i;\n\t\ty += i;\n\t\tif (!isPrime(x) && !isPrime(y))\n\t\t{\n\t\t\tprintf(\"%d \", x);\n\t\t\tprintf(\"%d\", y);\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport core.stdc.stdio;\nimport std.bigint;\nimport std.format;\nimport std.math;\n\nstring readline()\n{\n\tstring result = readln();\n\tif (result[result.length - 1] == '\\n') result.length--;\n\treturn result;\n}\n\nbool isPrime(long x)\n{\n\tforeach (long i; 2..(x/2 + 1))\n\t{\n\t\tif (x % i == 0)\n\t\t\treturn false;\n\t}\n\treturn true;\n}\n\nint main(string[] argv)\n{\n\tlong n;\n\tscanf(\"%d\", &n);\n\tlong x, y;\n\tx = n / 2;\n\ty = n / 2;\n\tif (x + y != n) y++;\n\tforeach (long i; 0..x)\n\t{\n\t\tx -= 1;\n\t\ty += 1;\n\t\tif (!isPrime(x) && !isPrime(y))\n\t\t{\n\t\t\tprintf(\"%d \", x);\n\t\t\tprintf(\"%d\", y);\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 0;\n}\n"}], "src_uid": "3ea971165088fae130d866180c6c868b"} {"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n return writeln((readInt!int + readInt!int*0 + readInt!int)&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", "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 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\n\t\tauto tot = a + b*2 + c*3;\n\t\tauto half = tot / 2;\n\t\tdebug writeln(half);\n\t\thalf -= min(c, half / 3) * 3;\n\t\tdebug writeln(half);\n\t\thalf -= min(b, half / 2) * 2;\n\t\tdebug writeln(half);\n\t\thalf -= min(a, half);\n\t\tdebug writeln(half);\n\t\tans[ti] = half * 2 + tot % 2;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n return writeln((readInt!int + readInt!int + readInt!int)&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"}], "src_uid": "4322861935ca727b0de8556849bc5982"} {"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\") long[] b;\n\n void solve(long tc = -1)\n {\n logSym!this;\n auto oa = a.fold!min(long.max);\n auto ob = b.fold!min(long.max);\n auto res = long(0);\n foreach(i; 0 .. n)\n {\n auto opa = a.at(i) - oa;\n auto opb = b.at(i) - ob;\n auto common = min(opa, opb);\n logSym!(opa, opb, common);\n res += opa + opb - common;\n }\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)\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 w)\n {\n static foreach(fieldName; FieldNameTuple!W)\n {\n with(w)\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", "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\t\tauto b = RDA;\n\n\t\tlong min_a = long.max;\n\t\tlong min_b = long.max;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tmin_a.chmin(a[i]);\n\t\t\tmin_b.chmin(b[i]);\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto da = a[i] - min_a;\n\t\t\tauto db = b[i] - min_b;\n\t\t\tans[ti] += max(da, db);\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;\nimport std.algorithm : map, min, minElement, sum;\nimport std.range : zip;\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!long);\n auto b = readln.strip.split.map!(to!long);\n\n auto mina = a.minElement;\n auto minb = b.minElement;\n\n auto c = zip(a, b)\n .map!(a => (a[0] - mina) + (a[1] - minb) - min(a[0] - mina, a[1] - minb))\n .sum;\n\n writefln(\"%d\", c);\n }\n}"}], "negative_code": [], "src_uid": "35368cefc5ce46a9f41a15734826a151"} {"source_code": "// Code By H~$~C\n\nmodule main;\n\nimport core.stdc.stdlib, core.stdc.string;\nimport std.stdio, std.array, std.string, std.math, std.uni;\nimport std.algorithm, std.range, std.random, std.container;\nimport std.conv, std.typecons, std.functional;\n\nimmutable Maxn = 200005;\n\nstruct node {\n this()() {\n mn = lnf;\n tag = 0;\n }\n this()(in node x) { *this = x; }\n long mn, tag;\n void apply(int l, int r, long x) {\n mn += x, tag += x;\n }\n}\nvoid pullup(ref node a, in node b, in node c) {\n a.mn = min(b.mn, c.mn);\n}\nstruct segment_tree {\n int N;\n node[] tr;\n private void pushup(int p) {\n pullup(tr[p], tr[p * 2], tr[p * 2 + 1]);\n }\n private void modify_(T...)(int p, int l, int r, int L, int R, T args) {\n if (L == l && r == R) return tr[p].apply(l, r, args);\n pushdown(p, l, r);\n int mid = (l + r) >> 1;\n if (R <= mid) modify_(p * 2, l, mid, L, R, args);\n else if (L > mid) modify_(p * 2 + 1, mid + 1, r, L, R, args);\n else {\n modify_(p * 2, l, mid, L, mid, args);\n modify_(p * 2 + 1, mid + 1, r, mid + 1, R, args);\n }\n pushup(p);\n }\n private node query_(int p, int l, int r, int L, int R) {\n if (L == l && r == R) return tr[p];\n pushdown(p, l, r);\n int mid = (l + r) >> 1;\n if (R <= mid) return query_(p * 2, l, mid, L, R);\n if (L > mid) return query_(p * 2 + 1, mid + 1, r, L, R);\n node left = query_(p * 2, l, mid, L, mid);\n node right = query_(p * 2 + 1, mid + 1, r, mid + 1, R);\n node ans; pullup(ans, left, right); return ans;\n }\n public void build(T...)(int len, T args) {\n N = len;\n tr.length = (N + 1) << 2;\n build(1, 1, N, args);\n }\n public void modify(T...)(int L, int R, T args) {\n if (L > R) return ;\n modify_(1, 1, N, L, R, args);\n }\n public node query(int L, int R) {\n if (L > R) return node();\n return query_(1, 1, N, L, R);\n }\n private void pushdown(int p, int l, int r) {\n int mid = (l + r) >> 1;\n if (tr[p].tag != 0) {\n tr[p * 2].apply(l, mid, tr[p].tag);\n tr[p * 2 + 1].apply(mid + 1, r, tr[p].tag);\n tr[p].tag = 0;\n }\n }\n private void build(int p, int l, int r, in long[] args) {\n if (l == r) {\n tr[p].apply(l, r, args[l]);\n return ;\n }\n int mid = (l + r) >> 1;\n build(p * 2, l, mid, args);\n build(p * 2 + 1, mid + 1, r, args);\n pushup(p);\n }\n}\nsegment_tree sgt;\n\nvoid solve(in int testcase) {\n int n; n.read;\n long[Maxn] arr;\n arr[1 .. n + 1] = readarray!long;\n sgt.build(n, arr);\n int q; q.read;\n while (q--) {\n int[] fuck = readarray!int.map!(a => a + 1).array;\n if (fuck.length == 2) {\n int l = fuck[0], r = fuck[1];\n if (l <= r) sgt.query(l, r).mn.writeln;\n else min(sgt.query(1, r).mn, sgt.query(l, n).mn).writeln;\n }\n else {\n int l = fuck[0], r = fuck[1];\n int x = fuck[2] - 1;\n if (l <= r) sgt.modify(l, r, x);\n else sgt.modify(1, r, x), sgt.modify(l, n, x);\n }\n }\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", "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; }\n/*******************************It's a Me, Mario!*******************************************/\n\n\nll[] arr, segtree, delta;\nconst ll LMAX = to!ll(1e15);\n\nll build(int v, ll l, ll r){\n if(l == r){ return (segtree[v] = arr[to!int(l)]); }\n\n ll midd = (l + r)/2;\n return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));\n}\n\nvoid apply(int v){\n segtree[2*v] += delta[v];\n segtree[2*v+1] += delta[v];\n delta[2*v] += delta[v];\n delta[2*v+1] += delta[v];\n delta[v] = 0;\n}\n\nll query(int v, ll l, ll r, ll L, ll R){\n if(L > R){ return LMAX; }\n if(L <= l && r <= R){\n return segtree[v];\n }\n apply(v);\n ll midd = (l + r)/2;\n ll lq = query(2*v, l, midd, L, min(midd, R)); \n ll hq = query(2*v + 1, midd+1, r, max(midd+1, L), R);\n /* debug writeln(lq, \" \", hq); */\n return min(lq, hq);\n}\n\n\nvoid update(int v, ll l, ll r, ll L, ll R, ll incr){\n if(L > R || l > R || r < L || l > r){ return; }\n if(L <= l && r <= R){\n segtree[v] += incr;\n delta[v] += incr;\n return;\n }\n /* writeln(v, \" \", l, \" \", r, \" \", L, \" \", R); */\n apply(v);\n ll midd = (l + r)/2;\n update(2*v, l, midd, L, R, incr); \n update(2*v+1, midd+1, r, L, R, incr);\n\n // Note: Even if we HAVE to take Min of Segtree Values NOT update return values. \n // Since it may not update and return INF\n segtree[v] = min(segtree[2*v], segtree[2*v+1]);\n}\n\n\nvoid play(){\n int n, m;\n n = rd!int;\n segtree.length = 4*n+1;\n delta.length = 4*n+1;\n arr = rdarr;\n build(1, 0, n-1);\n m = rd!int;\n while(m--){\n ll[] reds = rdarr;\n ll l = reds[0], r = reds[1];\n if(reds.length == 3){\n if(l > r){\n update(1, 0, n-1, l, n-1, reds[2]);\n update(1, 0, n-1, 0, r, reds[2]);\n }else{\n update(1, 0, n-1, l, r, reds[2]);\n }\n }else{\n ll res;\n if(l > r){\n res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));\n }else{\n res = query(1, 0, n-1, l, r);\n }\n writeln(res);\n }\n /* debug{ writeln(segtree);} */\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; }\n/*******************************It's a Me, Mario!*******************************************/\n\nll[] arr, segtree, delta;\n\nll build(int v, ll l, ll r){\n if(l == r){ return (segtree[v] = arr[to!int(l)]); }\n\n ll midd = (l + r)/2;\n return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));\n}\n\nll query(int v, ll l, ll r, ll L, ll R){\n if(l > r || r < L || l > R){ return to!ll(1e8); }\n if(L <= l && r <= R){\n return segtree[v];\n }\n if(delta[v]) apply(v);\n ll midd = (l + r)/2;\n return min(query(2*v, l, midd, L, R), query(2*v + 1, midd+1, r, L, R));\n}\n\nvoid apply(int v){\n segtree[2*v] += delta[v];\n segtree[2*v+1] += delta[v];\n delta[2*v] = (delta[2*v+1] = delta[v]);\n delta[v] = 0;\n}\n\nll update(int v, ll l, ll r, ll L, ll R, ll incr){\n if(l > r || r < L || l > R){ return to!ll(1e8); }\n if(L <= l && r <= R){\n segtree[v] += incr;\n delta[v] += incr;\n return segtree[v];\n }\n if(delta[v]) apply(v);\n ll midd = (l + r)/2;\n return segtree[v] = min(update(2*v, l, midd, L, R, incr), update(2*v+1, midd+1, r, L, R, incr));\n}\n\n\nvoid play(){\n int n, m;\n n = rd!int;\n segtree.length = 4*n+1;\n delta.length = 4*n+1;\n arr = rdarr;\n build(1, 0, n-1);\n m = rd!int;\n while(m--){\n ll[] reds = rdarr;\n ll l = reds[0], r = reds[1];\n if(reds.length == 3){\n if(l > r){\n update(1, 0, n-1, l, n-1, reds[2]); \n update(1, 0, n-1, 0, r, reds[2]);\n }else{\n update(1, 0, n-1, l, r, reds[2]);\n }\n }else{\n ll res;\n if(l > r){\n res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));\n }else{\n res = query(1, 0, n-1, l, r);\n }\n writeln(res);\n }\n debug{ writeln(segtree);}\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; }\n/*******************************It's a Me, Mario!*******************************************/\n\nll[] arr, segtree, delta;\nconst ll LMAX = to!ll(1e12);\n\nll build(int v, ll l, ll r){\n if(l == r){ return (segtree[v] = arr[to!int(l)]); }\n\n ll midd = (l + r)/2;\n return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));\n}\n\nll query(int v, ll l, ll r, ll L, ll R){\n if(l > r || r < L || l > R){ return LMAX; }\n if(L <= l && r <= R){\n return segtree[v];\n }\n if(delta[v]) apply(v);\n ll midd = (l + r)/2;\n return min(query(2*v, l, midd, L, R), query(2*v + 1, midd+1, r, L, R));\n}\n\nvoid apply(int v){\n segtree[2*v] += delta[v];\n segtree[2*v+1] += delta[v];\n delta[2*v] = (delta[2*v+1] = delta[v]);\n delta[v] = 0;\n}\n\nll update(int v, ll l, ll r, ll L, ll R, ll incr){\n if(l > r || r < L || l > R){ return LMAX; }\n if(L <= l && r <= R){\n segtree[v] += incr;\n delta[v] += incr;\n return segtree[v];\n }\n if(delta[v]) apply(v);\n ll midd = (l + r)/2;\n return segtree[v] = min(update(2*v, l, midd, L, R, incr), update(2*v+1, midd+1, r, L, R, incr));\n}\n\n\nvoid play(){\n int n, m;\n n = rd!int;\n segtree.length = 4*n+1;\n delta.length = 4*n+1;\n arr = rdarr;\n build(1, 0, n-1);\n m = rd!int;\n while(m--){\n ll[] reds = rdarr;\n ll l = reds[0], r = reds[1];\n if(reds.length == 3){\n if(l > r){\n update(1, 0, n-1, l, n-1, reds[2]); \n update(1, 0, n-1, 0, r, reds[2]);\n }else{\n update(1, 0, n-1, l, r, reds[2]);\n }\n }else{\n ll res;\n if(l > r){\n res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));\n }else{\n res = query(1, 0, n-1, l, r);\n }\n writeln(res);\n }\n debug{ writeln(segtree);}\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": "// Code By H~$~C\n\nmodule main;\n\nimport core.stdc.stdlib, core.stdc.string;\nimport std.stdio, std.array, std.string, std.math, std.uni;\nimport std.algorithm, std.range, std.random, std.container;\nimport std.conv, std.typecons, std.functional;\n\nimmutable Maxn = 200005;\n\nstruct node {\n this()() {\n mn = lnf;\n tag = 0;\n }\n this()(in node x) { *this = x; }\n long mn, tag;\n void apply(int l, int r, long x) {\n mn += x, tag += x;\n }\n}\nvoid pullup(ref node a, in node b, in node c) {\n a.mn = min(b.mn, c.mn);\n}\nstruct segment_tree {\n int N;\n node[] tr;\n private void pushup(int p) {\n pullup(tr[p], tr[p * 2], tr[p * 2 + 1]);\n }\n private void modify_(T...)(int p, int l, int r, int L, int R, T args) {\n if (L == l && r == R) return tr[p].apply(l, r, args);\n pushdown(p, l, r);\n int mid = (l + r) >> 1;\n if (R <= mid) modify_(p * 2, l, mid, L, R, args);\n else if (L > mid) modify_(p * 2 + 1, mid + 1, r, L, r, args);\n else {\n modify_(p * 2, l, mid, L, mid, args);\n modify_(p * 2 + 1, mid + 1, r, mid + 1, R, args);\n }\n pushup(p);\n }\n private node query_(int p, int l, int r, int L, int R) {\n if (L == l && r == R) return tr[p];\n pushdown(p, l, r);\n int mid = (l + r) >> 1;\n if (R <= mid) return query_(p * 2, l, mid, L, R);\n if (L > mid) return query_(p * 2 + 1, mid + 1, r, L, R);\n node left = query_(p * 2, l, mid, L, mid);\n node right = query_(p * 2 + 1, mid + 1, r, mid + 1, R);\n node ans; pullup(ans, left, right); return ans;\n }\n public void build(T...)(int len, T args) {\n N = len;\n tr.length = (N + 1) << 2;\n build(1, 1, N, args);\n }\n public void modify(T...)(int L, int R, T args) {\n if (L > R) return ;\n modify_(1, 1, N, L, R, args);\n }\n public node query(int L, int R) {\n if (L > R) return node();\n return query_(1, 1, N, L, R);\n }\n private void pushdown(int p, int l, int r) {\n int mid = (l + r) >> 1;\n if (tr[p].tag != 0) {\n tr[p * 2].apply(l, mid, tr[p].tag);\n tr[p * 2 + 1].apply(mid + 1, r, tr[p].tag);\n tr[p].tag = 0;\n }\n }\n private void build(int p, int l, int r, in long[] args) {\n if (l == r) {\n tr[p].apply(l, r, args[l]);\n return ;\n }\n int mid = (l + r) >> 1;\n build(p * 2, l, mid, args);\n build(p * 2 + 1, mid + 1, r, args);\n pushup(p);\n }\n}\nsegment_tree sgt;\n\nvoid solve(in int testcase) {\n int n; n.read;\n long[Maxn] arr;\n arr[1 .. n + 1] = readarray!long;\n sgt.build(n, arr);\n int q; q.read;\n while (q--) {\n int[] fuck = readarray!int.map!(a => a + 1).array;\n if (fuck.length == 2) {\n int l = fuck[0], r = fuck[1];\n if (l <= r) sgt.query(l, r).mn.writeln;\n else min(sgt.query(1, r).mn, sgt.query(l, n).mn).writeln;\n }\n else {\n int l = fuck[0], r = fuck[1];\n int x = fuck[2] - 1;\n if (l <= r) sgt.modify(l, r, x);\n else sgt.modify(1, r, x), sgt.modify(l, n, x);\n }\n }\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"}], "src_uid": "29cb3c45e1004b78d65ddd1a5242dd9e"} {"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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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\tstring sh=\"aeiouy\";\n\twhile(input(&n))\n\t{\n\t\tauto p=arread!int;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tauto s=readln;\n\t\t\tauto k=s.count!q{a=='a' || a=='e' || a=='i' || a=='o' || a=='u' || a=='y'};\n\t\t\tif(k!=p[i]){writeln(\"NO\");return;}\n\t\t}\n\t\twriteln(\"YES\");\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\tbool ok = true;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tauto s = readln.strip;\n\t\t\tauto t = s.count !(x => \"aeiouy\".canFind (x));\n\t\t\tok &= (c == t);\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\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 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]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\tstring sh=\"aeiouy\";\n\twhile(input(&n))\n\t{\n\t\tauto p=arread!int;\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tauto s=readln;\n\t\t\tauto k=s.count!q{a=='a' || a=='e' || a=='i' || a=='o' || a=='u' || a=='y'};\n\t\t\tif(k 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto c = new int [limit];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\tforeach (i; 0..limit)\n\t\t\t{\n\t\t\t\tif (x & (1 << i))\n\t\t\t\t{\n\t\t\t\t\tc[i] += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint res = -1;\n\t\tint pos = -1;\n\t\tforeach (j, x; a)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..limit)\n\t\t\t{\n\t\t\t\tif (x & (1 << i))\n\t\t\t\t{\n\t\t\t\t\tif (c[i] == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tcur |= 1 << i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (res < cur)\n\t\t\t{\n\t\t\t\tres = cur;\n\t\t\t\tpos = j.to !(int);\n\t\t\t}\n\t\t}\n\n\t\twrite (a[pos]);\n\t\twritefln (\"%( %s%)\", chain (a[0..pos], a[pos + 1..$]));\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 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[] cnt = new int[](30);\n\tforeach(a; as){\n\t\tforeach(i; 0 .. 30){\n\t\t\tlong m = 1L << i;\n\t\t\tif(m & a) cnt[i] += 1;\n\t\t}\n\t}\n\n\tint maxi = -1;\n\tforeach(i; 0 .. 30) if(cnt[i] == 1) maxi = i;\n\n\tlong[] ans;\n\tif(maxi >= 0){\n\t\tforeach(a; as){\n\t\t\tlong m = 1L << maxi;\n\t\t\tif(m & a) ans ~= a;\n\t\t}\n\t\tforeach(a; as) if(a != ans[0]) ans ~= a;\n\t}\n\telse ans = as;\n\n\tans.map!(to!string).array.join(\" \").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\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 ls = new long[N + 1];\n foreach (i; 0 .. N) {\n ls[i + 1] = ls[i] | A[i];\n }\n auto rs = new long[N + 1];\n foreach_reverse (i; 0 .. N) {\n rs[i] = A[i] | rs[i + 1];\n }\n \n long ans = -1;\n int im = -1;\n foreach (i; 0 .. N) {\n if (chmax(ans, A[i] & ~ls[i] & ~rs[i + 1])) {\n im = i;\n }\n }\n debug {\n writeln(ans, \" \", im);\n }\n auto as = A.dup;\n swap(as[0], as[im]);\n foreach (j; 0 .. N) {\n if (j > 0) write(\" \");\n write(as[j]);\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}, {"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 import std.algorithm : swap;\n\n IO io;\n int n = io.readInt;\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = io.readInt;\n }\n int m = 0;\n for (int k = 30; k >= 0; --k) {\n int found = -1;\n for (int i = m; i < n; ++i) {\n if (a[i] >> k & 1) {\n if (found == -1) {\n found = i;\n }\n else {\n found = n;\n }\n }\n }\n if (m <= found && found < n) {\n swap(a[m++], a[found]);\n }\n }\n for (int i = 0; i < n; ++i) {\n writeln(a[i]);\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)\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 foreach(i; 0 .. times)\n {\n static if (is(typeof(f(i))))\n {\n f(i);\n }\n else\n {\n f();\n }\n }\n}\n\nvoid main()\n{\n static assert(uint.max >= 1_000_000_000);\n auto n = next!uint;\n auto a = makeSlice(n, next!uint);\n foreach_reverse(i; 0 .. 31)\n {\n auto has = a.filter!(ai => (ai & (1 << i)) != 0).array;\n if (has.length == 1)\n {\n auto initial = has[0];\n write(initial, \" \");\n a.filter!(ai => ai != initial).each!(ai => write(ai, \" \"));\n writeln;\n return;\n }\n }\n a.each!(ai => write(ai, \" \"));\n 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 a = RDA!int;\n\tint pos = -1;\n\tforeach_reverse (i; 0..32)\n\t{\n\t\tauto bit = 1L << i;\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tif (a[j] & bit)\n\t\t\t{\n\t\t\t\tif (pos == -1)\n\t\t\t\t\tpos = j;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpos = -1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (pos != -1)\n\t\t\tbreak;\n\t}\n\t\n\tif (pos == -1)\n\t\ta.map!(to!string).join(\" \").writeln;\n\telse\n\t{\n\t\tint[] ans;\n\t\tans ~= a[pos];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (i == pos) continue;\n\t\t\tans ~= a[i];\n\t\t}\n\t\tans.map!(to!string).join(\" \").writeln;\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "14fd47f6f0fcbdb16dbd73dcca8a782f"} {"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 int n = r.next!uint ();\n const int m = r.next!uint ();\n writeln ((n % m) == 0 ? \"YES\" : \"NO\");\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 a = scan!int, b = scan!int;\n if(a % b == 0) \"YES\".print;\n else \"NO\".print;\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 m = RD!int;\n\t\tans[ti] = n % m == 0;\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\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 m = RD!int;\n\t\tans[ti] = m * 2 == n;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "6b37fc623110e49a5e311a2d186aae46"} {"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 S = readToken();\n const N = cast(int)(S.length);\n \n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = \"bw\".indexOf(S[i]) ^ (i & 1);\n }\n debug {\n writeln(\"A = \", A);\n }\n \n int ans;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && A[i] == A[j]; ++j) {}\n chmax(ans, j - i);\n }\n \n int head, tail;\n foreach (i; 0 .. N) {\n if (A[0] == A[i]) {\n ++head;\n } else {\n break;\n }\n }\n foreach_reverse (i; 0 .. N) {\n if (A[i] == A[N - 1]) {\n ++tail;\n } else {\n break;\n }\n }\n foreach (k; 1 .. N) {\n // S[k .. N] ~ S[0 .. k]\n if (A[N - 1] == (A[0] ^ (N & 1))) {\n chmax(ans, min(tail, N - k) + min(head, k));\n }\n }\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\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto n = s.length.to !(int);\n\t\ts ~= s;\n\t\tint res = 1;\n\t\tint cur = 1;\n\t\tforeach (i; 1..n * 2)\n\t\t{\n\t\t\tif (s[i - 1] != s[i])\n\t\t\t{\n\t\t\t\tcur += 1;\n\t\t\t\tres = max (res, cur);\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\tres = min (res, n);\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;\n\nimmutable long MOD = 998244353;\n\nvoid main() {\n auto S = readln.chomp;\n auto N = S.length.to!int;\n S ~= S;\n char prev = S[0];\n int tmp = 0;\n int ans = 0;\n\n foreach (i; 0..2*N) {\n if (S[i] == prev) {\n tmp = 1;\n } else {\n tmp += 1;\n }\n ans = max(ans, tmp);\n prev = S[i];\n }\n\n ans = min(ans, 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 auto s = readln.chomp;\n s = s ~ s;\n \n int ans = 1, cur = 1;\n foreach (a, b; lockstep(s, s.dropOne)) {\n if (a != b) {\n ++cur;\n ans = max(ans, cur);\n } else {\n cur = 1;\n }\n }\n \n ans = min(ans, s.length / 2);\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.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 s = s ~ s;\n \n int ans = 1, cur = 1;\n foreach (a, b; lockstep(s, s.dropOne)) {\n if (a != b) {\n ++cur;\n } else {\n ans = max(ans, cur);\n cur = 1;\n }\n }\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 auto s = readln.chomp;\n s = s ~ s;\n \n int ans = 1, cur = 1;\n foreach (a, b; lockstep(s, s.dropOne)) {\n if (a != b) {\n ++cur;\n ans = max(ans, cur);\n } else {\n cur = 1;\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.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 N = cast(int)(S.length);\n \n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = \"bw\".indexOf(S[i]) ^ (i & 1);\n }\n debug {\n writeln(\"A = \", A);\n }\n \n int ans;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && A[i] == A[j]; ++j) {}\n chmax(ans, j - i);\n }\n \n int head, tail;\n foreach (i; 0 .. N) {\n if (A[0] == A[i]) {\n ++head;\n } else {\n break;\n }\n }\n foreach_reverse (i; 0 .. N) {\n if (A[i] == A[N - 1]) {\n ++tail;\n } else {\n break;\n }\n }\n foreach (k; 1 .. N) {\n // S[k .. N] ~ S[0 .. k]\n if ((A[N - 1] ^ ((N - 1) & 1)) == (A[0] ^ (N & 1))) {\n chmax(ans, min(tail, N - k) + min(head, k));\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "313b16ba918fbb96a2b103128e0153c6"} {"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 = [1, 2, 3].replicate(n);\n Tuple!(int, int)[] ans;\n foreach (k ; 0 .. n) {\n int i = k * 3;\n int j = (n * 3 - k * 3) - 1;\n if (i >= j)\n break;\n ans ~= tuple(i + 1, j + 1);\n swap(a[i], a[j]);\n }\n// writeln(a);\n writeln(ans.length);\n foreach (x ; ans)\n writefln(\"%d %d\", x[0], x[1]);\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 writeln(n / 2 + n % 2);\r\n if (n == 1)\r\n writeln(\"1 2\");\r\n else {\r\n foreach(i; 0 .. n / 2) {\r\n writeln(i * 3 + 1, \" \", (3*n - 1 - 3*i));\r\n }\r\n if (n % 2)\r\n writeln(3*(n/2) + 1,\" \",3*(n/2) + 2);\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"}], "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 writeln(n / 2 + n % 2);\r\n if (n == 1)\r\n writeln(\"1 2\");\r\n else {\r\n foreach(i; 0 .. n / 2) {\r\n writeln(i * 3 + 1, \" \", (3*n - 1 - 3*i));\r\n if (n % 2)\r\n writeln(3*(n/2) + 1,\" \",3*(n/2) + 2);\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"}, {"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 writeln(n / 2 + n % 2);\r\n if (n == 1)\r\n writeln(\"1 2\");\r\n else {\r\n foreach(i; 0 .. n / 2) {\r\n writeln(i * 3 + 1, \" \", (3*n - 1 - 3*i));\r\n if (n % 2)\r\n writeln(3*(n/2) ,\" \",3*(n/2) + 1);\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"}, {"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 == 1) {\r\n writeln(1);\r\n writeln(1,\" \", 2);\r\n }\r\n else {\r\n writeln(n / 2 + n % 2);\r\n foreach(i; 0 .. n / 2) {\r\n writeln(i * 6 + 1 + 1, \" \", i * 6 + 3 + 1);\r\n if (n % 2)\r\n writeln(3*n - 2 + 1,\" \", 3*n - 1 + 1);\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"}, {"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 == 1) {\r\n writeln(1);\r\n writeln(1,\" \", 2);\r\n }\r\n else {\r\n writeln(n / 2 + n % 2);\r\n foreach(i; 0 .. n / 2) {\r\n writeln(i * 6 + 1, \" \", i * 6 + 3);\r\n if (n % 2)\r\n writeln(3*n - 2,\" \", 3*n -1);\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"}, {"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 = [1, 2, 3].replicate(n);\n int i = 0, j = cast(int)(a.length - 1);\n Tuple!(int, int)[] ans;\n while (true) {\n while (i < a.length && a[i] == 2)\n i++;\n while (j >= 0 && a[j] != 2)\n j--;\n if (i >= a.length || j >= a.length || i >= j)\n break;\n swap(a[i], a[j]);\n ans ~= tuple(i + 1, j + 1);\n }\n writeln(ans.length);\n foreach (x ; ans)\n writefln(\"%d %d\", x[0], x[1]);\n }\n}\n"}], "src_uid": "aeea2ca73f1b5c5b86fb508afcbec68a"} {"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\nint[] solve(int n)\n{\n for (int a = 2; a * a < n; ++a)\n {\n if (n % a == 0)\n {\n for (int b = a + 1; b * b < n / a; ++b)\n {\n if (n / a % b == 0)\n {\n return [a, b, n / a / b];\n }\n }\n }\n }\n return null;\n}\n\nvoid main()\n{\n int T = readInt;\n while (T--)\n {\n auto res = solve(readInt);\n if (res)\n {\n writeln(\"YES\");\n writeln(res[0], \" \", res[1], \" \", res[2]);\n }\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;\nimport std.typecons;\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\tfor (int a = 2; a * a * a <= n; a++) if (n % a == 0)\n\t\t{\n\t\t\tint m = n / a;\n\t\t\tfor (int b = a + 1; b * b < m; b++) if (m % b == 0)\n\t\t\t{\n\t\t\t\tint c = m / b;\n\t\t\t\twriteln (\"YES\");\n\t\t\t\twriteln (a, \" \", b, \" \", c);\n\t\t\t\tcontinue multitest_loop;\n\t\t\t}\n\t\t}\n\t\twriteln (\"NO\");\n\t}\n}\n"}, {"source_code": "\nimport 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\nvoid main()\n{\n int t;\n read(t);\n testCase:foreach(tc; 0 .. t)\n {\n long n;\n read(n);\n long[] divs = null;\n for(long d = 2; d * d <= n; d++)\n {\n if (n % d == 0)\n {\n n /= d;\n divs ~= d;\n break;\n }\n }\n if (divs is null)\n {\n writeln(\"NO\");\n continue testCase;\n }\n for(long d = 2; d * d <= n; d++)\n if (n % d == 0 && d != divs[0] && n/d != divs[0] && n/d != d)\n {\n writeln(\"YES\");\n writeln(divs[0], \" \", d, \" \", n/d);\n continue testCase;\n }\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 = 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\tfor (long i = 2; i*i <= n; ++i)\n\t\t{\n\t\t\tif (n % i != 0) continue;\n\t\t\t\n\t\t\tauto x = n / i;\n\t\t\tfor (long j = 2; j*j <= x; ++j)\n\t\t\t{\n\t\t\t\tif (x % j != 0) continue;\n\n\t\t\t\tauto k = x / j;\n\t\t\t\tif (i == j || i == k || j == k) continue;\n\t\t\t\tans[ti] = [i, j, k];\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\twriteln(e[0], \" \", e[1], \" \", e[2]);\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "0f7ceecdffe11f45d0c1d618ef3c6469"} {"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\tint m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\treadln;\n\t\tint [string] mask;\n\t\tstring [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= readln.strip;\n\t\t\tmask[s.back] |= 1;\n\t\t}\n\t\tstring [] t;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tt ~= readln.strip;\n\t\t\tmask[t.back] |= 2;\n\t\t}\n\t\tauto d = new string [] [4];\n\t\tforeach (key, value; mask)\n\t\t{\n\t\t\td[value] ~= key;\n\t\t}\n\t\tforeach (i; 0..n + m + 1)\n\t\t{\n\t\t\tif (!d[3].empty)\n\t\t\t{\n\t\t\t\td[3].popFront ();\n\t\t\t}\n\t\t\telse if (!d[1 + (i & 1)].empty)\n\t\t\t{\n\t\t\t\td[1 + (i & 1)].popFront ();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twriteln ((i & 1) ? \"YES\" : \"NO\");\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\n\nimmutable string no = \"NO\",yes = \"YES\";\nvoid main(string[] args) \n{\n int n = 0;\n int m = 1;\n scanf(\"%d %d\", &n, &m);\n\n if(n>m)\n {\n writeln(yes);\n return;\n }\n else if(m>n)\n {\n writeln(no);\n return;\n }\n readln;\n int [string] a;\n int [string] b;\n string s;\n for(int i=0; iab)\n writeln(yes);\n else if(ab>as)\n writeln(no);\n else if(ab==as && as%2==1)\n writeln(yes);\n else\n writeln(no);\n}"}], "negative_code": [], "src_uid": "4b352854008a9378551db60b76d33cfa"} {"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;\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\t/*int n;\n\tloop:while(read(&n))\n\t{\n\n\t}*/\n\tauto a=new string[3];\n\tforeach(i;0..3)\n\t{\n\t\tauto s=readln.strip;\n\t\tforeach(c;s)\n\t\t{\n\t\t\tif(c!=';' && c!='-' && c!='_')a[i]~=toLower(c);\n\t\t}\n\t}\n\tauto p=[0,1,2];\n\tint n;\n\tread(&n);\ngo:foreach(i;0..n)\n\t{\n\t\tauto s=readln.strip;\n\t\tstring r;\n\t\tforeach(c;s)\n\t\t{\n\t\t\tif(c!=';' && c!='-' && c!='_')r~=toLower(c);\n\t\t}\n\t\tdo{\n\t\t\tif((a[p[0]]~a[p[1]]~a[p[2]])==r)\n\t\t\t{\n\t\t\t\twriteln(\"ACC\");\n\t\t\t\tp=[0,1,2];\n\t\t\t\tcontinue go;\n\t\t\t}\n\t\t}while(nextPermutation(p));\n\t\twriteln(\"WA\");\n\t}\n\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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 string[3];\n\tforeach(i;0..3)\n\t{\n\t\ta[i]=readln.split(regex(\"[-_;\\n]+\")).join.toLower;\n\t}\n\tauto p=[0,1,2];\n\tint n;\n\tread(&n);\ngo:foreach(i;0..n)\n\t{\n\t\tauto s=readln.split(regex(\"[-_;\\n]+\")).join.toLower;\n\t\tdo{\n\t\t\tif((a[p[0]]~a[p[1]]~a[p[2]])==s)\n\t\t\t{\n\t\t\t\twriteln(\"ACC\");\n\t\t\t\tp=[0,1,2];\n\t\t\t\tcontinue go;\n\t\t\t}\n\t\t}while(nextPermutation(p));\n\t\twriteln(\"WA\");\n\t}\n\t\n}"}], "negative_code": [], "src_uid": "95ccc87fe9e431f9c6eeffeaf049f797"} {"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\n int p;\n foreach (i; 0..K) {\n if (i != K-1 && i > 0 && i < N-1 && as[i] > as[i-1] && as[i] > as[i+1]) ++p;\n }\n int max_p = p, min_l = 1;\n foreach (i; 1..N-K+1) {\n auto j = i+K-1;\n if (as[j-1] > as[j-2] && as[j-1] > as[j]) ++p;\n if (as[i] > as[i-1] && as[i] > as[i+1]) --p;\n if (p > max_p) {\n max_p = p;\n min_l = i+1;\n }\n }\n writeln(max_p+1, \" \", min_l);\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\n\t\tauto p = new bool[](n);\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\tp[i] = true;\n\t\t}\n\n\t\tauto b = new long[](n-k+1);\n\t\tforeach (i; 1..k-1)\n\t\t{\n\t\t\tif (p[i])\n\t\t\t\t++b[0]; \n\t\t}\n\t\tforeach (i; 1..n-k+1)\n\t\t{\n\t\t\tb[i] = b[i-1];\n\t\t\tif (p[i])\n\t\t\t\t--b[i];\n\t\t\tif (p[i+k-2])\n\t\t\t\t++b[i];\n\t\t}\n\n\t\tlong best = long.min;\n\t\tforeach (i; 0..b.length)\n\t\t{\n\t\t\tif (b[i] > best)\n\t\t\t{\n\t\t\t\tbest = b[i];\n\t\t\t\tans[ti] = [best+1, i+1];\n\t\t\t}\n\t\t}\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": "//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 int n = r.next!uint;\n const int k = r.next!uint;\n auto a = r.nextA!uint (n);\n auto b = new int[n];\n foreach (i; 1 .. n - 1) {\n if (a[i] > a[i-1] && a[i] > a[i+1]) {\n b[i] = 1;\n }\n }\n foreach (i; 1 .. n) {\n b[i] += b[i-1];\n }\n int res = -1, peaks = int.min;\n foreach (j; k .. n + 1) {\n int i = j - k;\n //[i, j)\n int t = b[j - 2] - b[i];\n if (peaks < t) {\n res = i;\n peaks = t;\n }\n }\n ++res;\n ++peaks;\n writeln (peaks, ' ', res);\n }\n}\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 nk = readln.split.to!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n auto as = readln.split.to!(int[]);\n\n int p;\n foreach (i; 0..K) {\n if (i != K-1 && i > 0 && i < N-1 && as[i] > as[i-1] && as[i] > as[i+1]) ++p;\n }\n int max_p = p, min_l = 1;\n foreach (i; 1..N-K+1) {\n auto j = i+K-1;\n if (j <= N-1 && j-1 > 0 && as[j-1] > as[j-2] && as[j-1] > as[j]) ++p;\n if (i-1 > 0 && as[i-1] > as[i-2] && as[i-1] > as[i]) --p;\n if (p > max_p) {\n max_p = p;\n min_l = i+1;\n }\n }\n writeln(max_p+1, \" \", min_l);\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 auto as = readln.split.to!(int[]);\n\n int p;\n foreach (i; 0..K) {\n if (i != K-1 && i > 0 && i < N-1 && as[i] > as[i-1] && as[i] > as[i+1]) ++p;\n }\n int max_p = p, min_l = 1;\n foreach (i; 1..N-K) {\n auto j = i+K-1;\n if (j <= N-1 && j-1 > 0 && as[j-1] > as[j-2] && as[j-1] > as[j]) ++p;\n if (i-1 > 0 && as[i-1] > as[i-2] && as[i-1] > as[i]) --p;\n if (p > max_p) {\n max_p = p;\n min_l = i+1;\n }\n }\n writeln(p+1, \" \", min_l);\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 auto as = readln.split.to!(int[]);\n\n int p;\n foreach (i; 0..K) {\n if (i != K-1 && i > 0 && i < N-1 && as[i] > as[i-1] && as[i] > as[i+1]) ++p;\n }\n int max_p = p, min_l = 1;\n foreach (i; 1..N-K+1) {\n auto j = i+K-1;\n if (j <= N-1 && j-1 > 0 && as[j-1] > as[j-2] && as[j-1] > as[j]) ++p;\n if (i-1 > 0 && as[i-1] > as[i-2] && as[i-1] > as[i]) --p;\n if (p > max_p) {\n max_p = p;\n min_l = i+1;\n }\n }\n writeln(p+1, \" \", min_l);\n }\n}"}], "src_uid": "8e182e0acb621c86901fb94b56ff991e"} {"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.sort();\n\n auto primes = new bool[](10^^3);\n int[] pr;\n fill(primes, true);\n primes[0] = primes[1] = false;\n for (int i = 2; i * i <= 10^^5; i++) {\n if (!primes[i])\n continue;\n pr ~= i;\n for (int j = i + i; j * j <= 10^^5; j += i) {\n primes[j] = false;\n }\n }\n\n auto cnt = new int[](10^^5+1);\n foreach (a; A) {\n foreach (p; pr) {\n if (p > a)\n break;\n if (a % p == 0) {\n cnt[p] += 1;\n while (a % p == 0) {\n a /= p;\n }\n }\n }\n if (a > 1)\n cnt[a] += 1;\n }\n\n auto ans = cnt.reduce!(max);\n writeln(max(ans, 1));\n\n}\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=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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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;\n\tloop:while(read(&n))\n\t{\n\t\tauto m=new int[100500];\n\t\tauto a=arread!int;\n\t\tforeach(i;a)m[i]++;\n\t\tint ans;\n\t\tforeach(i;2..10^^5)\n\t\t{\n\t\t\tint k=0;\n\t\t\tfor(int j=i;j<=10^^5;j+=i)k+=m[j];\n\t\t\tans=max(ans,k);\n\t\t}\n\t\twriteln(max(ans,1));\n\t}\n}"}, {"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 maxS = 100_005;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tint [maxS] h;\n\t\tforeach (c; readln.split.map !(to !(int)))\n\t\t{\n\t\t\th[c] += 1;\n\t\t}\n\t\tint [maxS] p;\n\t\tforeach (d; 2..maxS)\n\t\t{\n\t\t\tfor (int c = d; c < maxS; c += d)\n\t\t\t{\n\t\t\t\tp[d] += h[c];\n\t\t\t}\n\t\t}\n\n\t\tint res = 1;\n\t\tforeach (c; 2..maxS)\n\t\t{\n\t\t\tres = max (res, p[c]);\n\t\t}\n\t\twriteln (res);\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;\n\nvoid main() {\n int n;\n scan(n);\n auto s = readln.split.to!(int[]);\n\n auto ps = sieveEratos(10^^5 + 1);\n\n debug {\n writeln(ps[0 .. 30]);\n }\n\n auto b = new int[](10^^5 + 1);\n\n foreach (si ; s) {\n b[si]++;\n }\n\n int ans;\n\n foreach (p ; ps) {\n int cnt;\n\n for (int q = p; q < 10^^5 + 1; q += p) {\n cnt += b[q];\n }\n\n ans = max(ans, cnt);\n }\n\n if (ans == 0) ans = 1;\n\n writeln(ans);\n}\n\nint[] sieveEratos(int N) {\n auto s = new bool[](N);\n s[] = 1;\n s[0] = s[1] = 0;\n\n for (int p = 2; p*p < N; p++) {\n if (s[p]) {\n for (int q = p*p; q < N; q += p) {\n s[q] = 0;\n }\n }\n }\n\n return iota(N).filter!(i => s[i]).array;\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 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;\nint[100_001] counts;\n\nvoid main() {\n while (read(&n)) {\n memset(counts.ptr, 0x00, counts.sizeof);\n foreach (i; 0 .. n) {\n int x;\n read(&x);\n if (!(x & 0x1)) {\n counts[2]++;\n while (x && !(x & 0x1))\n x >>= 1;\n }\n int cur = 3;\n while (cur * cur <= x) {\n if (!(x % cur)) {\n counts[cur]++;\n while (!(x % cur))\n x /= cur;\n }\n cur += 2;\n }\n counts[x]++;\n }\n writeln(max(maxPos(counts[2 .. $])[0], 1));\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 auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array.sort();\n\n auto primes = new bool[](10^^3);\n fill(primes, true);\n primes[0] = primes[1] = false;\n for (int i = 2; i * i <= 10^^5; i++) {\n if (!primes[i])\n continue;\n for (int j = i + i; j * j <= 10^^5; j += i) {\n primes[j] = false;\n }\n }\n\n auto cnt = new int[](10^^3);\n for (int i = 2; i * i <= 10^^5; i++) {\n if (!primes[i])\n continue;\n foreach (a; A) {\n if (a % i == 0)\n cnt[i] += 1;\n }\n }\n\n cnt.reduce!(max).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 N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array.sort();\n\n auto primes = new bool[](10^^3);\n int[] pr;\n fill(primes, true);\n primes[0] = primes[1] = false;\n for (int i = 2; i * i <= 10^^5; i++) {\n if (!primes[i])\n continue;\n pr ~= i;\n for (int j = i + i; j * j <= 10^^5; j += i) {\n primes[j] = false;\n }\n }\n\n auto cnt = new int[](10^^5+1);\n foreach (a; A) {\n foreach (p; pr) {\n if (p > a)\n break;\n while (a % p == 0) {\n a /= p;\n cnt[p] += 1;\n }\n }\n if (a > 1)\n cnt[a] += 1;\n }\n \n auto ans = cnt.reduce!(max);\n writeln(max(ans, 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 N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array.sort();\n\n auto primes = new bool[](10^^3);\n fill(primes, true);\n primes[0] = primes[1] = false;\n for (int i = 2; i * i <= 10^^5; i++) {\n if (!primes[i])\n continue;\n for (int j = i + i; j * j <= 10^^5; j += i) {\n primes[j] = false;\n }\n }\n\n auto cnt = new int[](10^^3);\n for (int i = 2; i * i <= 10^^5; i++) {\n if (!primes[i])\n continue;\n foreach (a; A) {\n if (a % i == 0)\n cnt[i] += 1;\n }\n }\n\n auto ans = cnt.reduce!(max);\n writeln(max(ans, 1));\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\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;\nint[100_001] counts;\n\nvoid factorize(int x) {\n if (!(x & 0x1)) {\n counts[2]++;\n while (x && !(x & 0x1))\n x >>= 1;\n }\n int cur = 3;\n while (cur * cur <= x) {\n if (!(x % cur)) {\n counts[cur]++;\n while (!(x % cur))\n x /= cur;\n }\n cur += 2;\n }\n counts[x]++;\n}\n\nvoid main() {\n while (read(&n)) {\n memset(counts.ptr, 0x00, counts.sizeof);\n foreach (i; 0 .. n) {\n int x;\n read(&x);\n factorize(x);\n }\n writeln(maxPos(counts[2 .. $])[0]);\n }\n}\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.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;\n\tloop:while(read(&n))\n\t{\n\t\tauto m=new int[100500];\n\t\tauto a=arread!int;\n\t\tforeach(i;a)m[i]++;\n\t\tint ans;\n\t\tforeach(i;2..10^^5)\n\t\t{\n\t\t\tint k=0;\n\t\t\tfor(int j=i;j<=10^^5;j+=i)k+=m[j];\n\t\t\tans=max(ans,k);\n\t\t}\n\t\twriteln(ans);\n\t}\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\nvoid main() {\n int n;\n scan(n);\n auto s = readln.split.to!(int[]);\n\n auto ps = sieveEratos(10^^5 + 1);\n\n debug {\n writeln(ps[0 .. 30]);\n }\n\n auto b = new int[](10^^5 + 1);\n\n foreach (si ; s) {\n b[si]++;\n }\n\n int ans;\n\n foreach (p ; ps) {\n int cnt;\n\n for (int q = p; q < 10^^5 + 1; q += p) {\n cnt += b[q];\n }\n\n ans = max(ans, cnt);\n }\n\n writeln(ans);\n}\n\nint[] sieveEratos(int N) {\n auto s = new bool[](N);\n s[] = 1;\n s[0] = s[1] = 0;\n\n for (int p = 2; p*p < N; p++) {\n if (s[p]) {\n for (int q = p*p; q < N; q += p) {\n s[q] = 0;\n }\n }\n }\n\n return iota(N).filter!(i => s[i]).array;\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.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 auto s = readln.split.to!(int[]);\n\n auto ps = sieveEratos(10^^5 + 1);\n\n auto b = new bool[](10^^5 + 1);\n\n foreach (si ; s) {\n b[si] = 1;\n }\n\n int ans;\n\n foreach (p ; ps) {\n int cnt;\n\n for (int q = p; q < 10^^5 + 1; q += p) {\n if (b[q]) cnt++;\n }\n\n ans = max(ans, cnt);\n }\n\n writeln(ans);\n}\n\nint[] sieveEratos(int N) {\n auto s = new bool[](N);\n s[] = 1;\n s[0] = s[1] = 0;\n\n for (int p = 2; p*p < N; p++) {\n if (s[p]) {\n for (int q = p*p; q < N; q += p) {\n s[q] = 0;\n }\n }\n }\n\n return iota(N).filter!(i => s[i]).array;\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": "eea7860e6bbbe5f399b9123ebd663e3e"} {"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 t = next!int;\n foreach(tc; 0 .. t)\n {\n auto a = next!long;\n auto b = next!long;\n auto c = next!long;\n auto maxside = max(a, b, c);\n writeln(maxside);\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\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tuint a, b, c;\n\t\treadf !(\" %s %s %s\") (a, b, c);\n\t\twriteln (a + b + c - 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\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 a = RD;\n\t\tauto b = RD;\n\t\tauto c = RD;\n\t\tbool[long] set;\n\t\tset[a] = true;\n\t\tset[b] = true;\n\t\tset[c] = true;\n\n\t\tauto arr = [a, b, c];\n\t\tarr.sort();\n\t\tauto rem = arr[2] - (arr[0]+arr[1]) + 1;\n\n\t\tauto l = max(1, rem);\n\t\tforeach (long i; l..l+10)\n\t\t{\n\t\t\tif (set.get(i, false) == false)\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\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"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"}], "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(min(a, b, c));\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\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 c = RD;\n\t\tbool[long] set;\n\t\tset[a] = true;\n\t\tset[b] = true;\n\t\tset[c] = true;\n\n\t\tforeach (i; 1..10)\n\t\t{\n\t\t\tif (set.get(i, false) == false)\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\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "40d679f53417ba058144c745e7a2c76d"} {"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 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 \n bool ok = true;\n for (int i = 0, j = n-1; i < j; ++i, --j) {\n auto dist = abs(s[i] - s[j]);\n ok &= dist == 0 || dist == 2;\n }\n \n writeln(ok ? \"YES\" : \"NO\");\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\nint[] a;\nbool pos(int i,int j){\n int x=a[i],y=a[j];\n if(x==y) return true;\n if((x<26 && y>1 && x+1==y-1)\n ||(x>1 && y<26 && x-1==y+1))\n return true;\n return false;\n}\nvoid main(){ \n int t=readln.chomp.to!int,n;\n bool ans;\n while(t--){\n n=readln.chomp.to!int;\n a=readln.strip\n .map!(to!int)\n .map!\"a-96\"\n .array;\n ans=true;\n foreach(i;0..n/2){\n if(!pos(i,n-i-1)){\n ans=false;\n break;\n }\n }\n if(ans)\n writeln(\"YES\");\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 t=readln.chomp.to!int,n;\n bool ans;\n while(t--){\n n=readln.chomp.to!int;\n auto a=readln.strip\n .map!(to!int)\n .map!\"a-96\"\n .array;\n ans=true;\n foreach(i;0..n/2){\n int d=abs(a[i]-a[n-i-1]);\n if(d==1||d>2){\n ans=false;\n break;\n }\n }\n if(ans)\n writeln(\"YES\");\n else\n writeln(\"NO\");\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, std.bitmanip;\n\nvoid main() {\n auto T = readln.chomp.to!int;\n while (T--) solve;\n}\n\nvoid solve() {\n auto N = readln.chomp.to!int;\n auto S = readln.chomp;\n bool ok = true;\n\n foreach (i; 0..N/2) {\n char x = S[i];\n char y = S[N-i-1];\n if (x != y && abs(x - y) != 2) ok = false;\n }\n\n writeln(ok ? \"YES\" : \"NO\");\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 s = readln.chomp;\n \n bool ok = true;\n for (int i = 0, j = n-1; i < j; ++i, --j) {\n auto dist = abs(s[i] - s[j]);\n ok &= dist == 0 || dist == 2;\n }\n \n writeln(ok ? \"YES\" : \"NO\");\n }\n}"}], "negative_code": [], "src_uid": "cc4cdcd162a83189c7b31a68412f3fe7"} {"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, K; long P; scanf(\"%d %d %d %d\\n\", &N, &M, &K, &P);\n long[][] F = new long[][N];\n foreach (i; 0 .. N) {\n F[i] = readln.chomp.split(\" \").map!(to!long).array;\n }\n long[] SR = new long[N],\n SC = new long[M];\n foreach (i; 0 .. N) {\n foreach (j; 0 .. M) {\n SR[i] += F[i][j];\n SC[j] += F[i][j];\n }\n }\n SR = SR.sort.array;\n SC = SC.sort.array;\n\n long DR = 0, DC = 0;\n\n BinaryHeap!(Array!long, \"a < b\") PQ;\n foreach (r; SR) PQ.insert(r);\n long[] R = new long[K + 1];\n R[0] = 0;\n foreach (i; 1 .. K + 1) {\n long r = PQ.front;\n R[i] = R[i - 1] + r;\n PQ.removeFront;\n PQ.insert(r - P * M);\n }\n\n PQ.clear;\n foreach (c; SC) PQ.insert(c);\n long[] C = new long[K + 1];\n C[0] = 0;\n foreach (i; 1 .. K + 1) {\n long c = PQ.front;\n C[i] = C[i - 1] + c;\n PQ.removeFront;\n PQ.insert(c - P * N);\n }\n\n /*\n writeln(R);\n writeln(C);\n */\n\n long Ans = long.min;\n\n foreach (long i; 0 .. K + 1) {\n Ans = max(Ans, R[cast(uint)i] + C[K - cast(uint)i] - (i * (cast(long)K - i) * P));\n }\n writeln(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, 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 M, N, K;\nlong P;\nlong[][] A;\n\nlong[] solve(long[] xs, long dec) {\n\tauto q = heapify(xs);\n\tlong[] ret = new long[K + 1];\n\tforeach (k; 0 .. K) {\n\t\tconst now = q.front;\n\t\tq.removeFront;\n\t\tret[k + 1] = ret[k] + now;\n\t\tq.insert(now - dec);\n\t}\n\treturn ret;\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tK = readInt;\n\t\tP = readLong;\n\t\tA = new long[][](M, N);\n\t\tforeach (x; 0 .. M) foreach (y; 0 .. N) {\n\t\t\tA[x][y] = readLong;\n\t\t}\n\t\t\n\t\tlong[] bs = new long[M];\n\t\tlong[] cs = new long[N];\n\t\tforeach (x; 0 .. M) foreach (y; 0 .. N) {\n\t\t\tbs[x] += A[x][y];\n\t\t\tcs[y] += A[x][y];\n\t\t}\n\t\t\n\t\tlong[] fbs = solve(bs, P * N);\n\t\tlong[] fcs = solve(cs, P * M);\n// writeln(fbs);\n// writeln(fcs);\n\t\tlong ans = long.min;\n\t\tforeach (k; 0 .. K + 1) {\n\t\t\tchmax(ans, fbs[k] + fcs[K - k] - P * k * (K - k));\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 \nvoid main() {\n int N, M, K; long P; scanf(\"%d %d %d %d\\n\", &N, &M, &K, &P);\n long[][] F = new long[][N];\n foreach (i; 0 .. N) {\n F[i] = readln.chomp.split(\" \").map!(to!long).array;\n }\n long[] SR = new long[N],\n SC = new long[M];\n foreach (i; 0 .. N) {\n foreach (j; 0 .. M) {\n SR[i] += F[i][j];\n SC[j] += F[i][j];\n }\n }\n SR = SR.sort.array;\n SC = SC.sort.array;\n\n long DR = 0, DC = 0;\n\n BinaryHeap!(Array!long, \"a < b\") PQ;\n foreach (r; SR) PQ.insert(r);\n long[] R = new long[K + 1];\n R[0] = 0;\n foreach (i; 1 .. K + 1) {\n long r = PQ.front;\n R[i] = R[i - 1] + r;\n PQ.removeFront;\n PQ.insert(r - P * M);\n }\n\n PQ.clear;\n foreach (c; SC) PQ.insert(c);\n long[] C = new long[K + 1];\n C[0] = 0;\n foreach (i; 1 .. K + 1) {\n long c = PQ.front;\n C[i] = C[i - 1] + c;\n PQ.removeFront;\n PQ.insert(c - P * N);\n }\n\n /*\n writeln(R);\n writeln(C);\n */\n\n long Ans = 0;\n\n foreach (i; 0 .. K + 1) {\n Ans = max(Ans, R[i] + C[K - i] - (i * (K - i) * P));\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 \nvoid main() {\n int N, M, K, P; scanf(\"%d %d %d %d\\n\", &N, &M, &K, &P);\n int[][] F = new int[][N];\n foreach (i; 0 .. N) {\n F[i] = readln.chomp.split(\" \").map!(to!int).array;\n }\n long[] SR = new long[N],\n SC = new long[M];\n foreach (i; 0 .. N) {\n foreach (j; 0 .. M) {\n SR[i] += F[i][j];\n SC[j] += F[i][j];\n }\n }\n SR = SR.sort.array;\n SC = SC.sort.array;\n\n struct V {\n int type; // row or column? 1 => row, 2 => column\n long value;\n }\n long DR = 0, DC = 0;\n bool comp(in V a, in V b) {\n long A = a.value - (a.type == 1 ? DR : DC),\n B = b.value - (b.type == 1 ? DR : DC);\n return A < B;\n }\n\n BinaryHeap!(Array!V, comp) PQ;\n foreach (r; SR) PQ.insert(V(1, r));\n foreach (c; SC) PQ.insert(V(2, c));\n\n long Calc(in V a) {\n return a.value - (a.type == 1 ? DR : DC);\n }\n\n long Ans = 0;\n while (K--) {\n V v = PQ.front;\n (v.type == 1 ? DC : DR) += P;\n PQ.insert(V(v.type, v.value - P * (v.type == 1 ? M : N)));\n Ans += Calc(PQ.front);\n PQ.removeFront;\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 \nvoid main() {\n int N, M, K, P; scanf(\"%d %d %d %d\\n\", &N, &M, &K, &P);\n int[][] F = new int[][N];\n foreach (i; 0 .. N) {\n F[i] = readln.chomp.split(\" \").map!(to!int).array;\n }\n long[] SR = new long[N],\n SC = new long[M];\n foreach (i; 0 .. N) {\n foreach (j; 0 .. M) {\n SR[i] += F[i][j];\n SC[j] += F[i][j];\n }\n }\n SR = SR.sort.array;\n SC = SC.sort.array;\n\n long DR = 0, DC = 0;\n\n BinaryHeap!(Array!long, \"a < b\") PQ;\n foreach (r; SR) PQ.insert(r);\n long[] R = new long[K + 1];\n R[0] = 0;\n foreach (i; 1 .. K + 1) {\n long r = PQ.front;\n R[i] = R[i - 1] + r;\n PQ.removeFront;\n PQ.insert(r - P * M);\n }\n\n PQ.clear;\n foreach (c; SC) PQ.insert(c);\n long[] C = new long[K + 1];\n C[0] = 0;\n foreach (i; 1 .. K + 1) {\n long c = PQ.front;\n C[i] = C[i - 1] + c;\n PQ.removeFront;\n PQ.insert(c - P * N);\n }\n\n /*\n writeln(R);\n writeln(C);\n */\n\n long Ans = 0;\n\n foreach (i; 0 .. K + 1) {\n Ans = max(Ans, R[i] + C[K - i] - (i * (K - i) * P));\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 \nvoid main() {\n int N, M, K; long P; scanf(\"%d %d %d %d\\n\", &N, &M, &K, &P);\n long[][] F = new long[][N];\n foreach (i; 0 .. N) {\n F[i] = readln.chomp.split(\" \").map!(to!long).array;\n }\n long[] SR = new long[N],\n SC = new long[M];\n foreach (i; 0 .. N) {\n foreach (j; 0 .. M) {\n SR[i] += F[i][j];\n SC[j] += F[i][j];\n }\n }\n SR = SR.sort.array;\n SC = SC.sort.array;\n\n long DR = 0, DC = 0;\n\n BinaryHeap!(Array!long, \"a < b\") PQ;\n foreach (r; SR) PQ.insert(r);\n long[] R = new long[K + 1];\n R[0] = 0;\n foreach (i; 1 .. K + 1) {\n long r = PQ.front;\n R[i] = R[i - 1] + r;\n PQ.removeFront;\n PQ.insert(r - P * M);\n }\n\n PQ.clear;\n foreach (c; SC) PQ.insert(c);\n long[] C = new long[K + 1];\n C[0] = 0;\n foreach (i; 1 .. K + 1) {\n long c = PQ.front;\n C[i] = C[i - 1] + c;\n PQ.removeFront;\n PQ.insert(c - P * N);\n }\n\n /*\n writeln(R);\n writeln(C);\n */\n\n long Ans = 0;\n\n foreach (long i; 0 .. K + 1) {\n Ans = max(Ans, R[cast(uint)i] + C[K - cast(uint)i] - (i * (cast(long)K - i) * P));\n }\n writeln(Ans);\n}\n"}], "src_uid": "8a905ae55ac9364a9ed2807f06a05ff0"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint gcd(int a, int b)\n{\n if (b == 0) return a;\n return gcd(b, a % b);\n}\n\nvoid solve(int[] a)\n{\n auto n = cast(int)a.length;\n int c = 0;\n foreach (i; 0 .. n)\n {\n if (a[i] == 1) ++ c;\n }\n if (c > 0)\n {\n writeln(n - c);\n return;\n }\n int ans = int.max;\n foreach (i; 0 .. n)\n {\n auto g = a[i];\n foreach (j; i + 1 .. n)\n {\n if (j - i + n - 1 >= ans) break;\n g = gcd(g, a[j]);\n if (g == 1)\n {\n ans = min(ans, j - i + n - 1);\n break;\n }\n }\n }\n if (ans == int.max) ans = -1;\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": "// 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.numeric : gcd;\n\nvoid main()\n{\n auto n = readln.chomp.to!int;\n auto xs = readln.chomp.split.to!(int[]);\n \n auto p = xs[0];\n auto e = 0;\n foreach (x; xs)\n {\n p = gcd(p, x);\n if (x == 1)\n {\n e++;\n }\n }\n if (p != 1)\n {\n writeln(-1);\n return;\n }\n if (e > 0)\n {\n writeln(n-e);\n return;\n }\n auto ans = n * 10;\n void dfs(uint i, int c)\n {\n if (c >= ans)\n {\n return;\n }\n if (i > 0)\n {\n auto g = gcd(xs[i], xs[i-1]);\n if (g == 1)\n {\n ans = c;\n return;\n }\n if (xs[i] != g)\n {\n auto t1 = xs[i]; xs[i] = g; dfs(i, c + 1); xs[i] = t1;\n }\n if (xs[i-1] != g)\n {\n auto t2 = xs[i-1]; xs[i-1] = g; dfs(i-1, c+1); xs[i-1] = t2;\n }\n }\n if (i+1 < n)\n {\n auto g = gcd(xs[i], xs[i+1]);\n if (g == 1)\n {\n ans = c;\n return;\n }\n if (xs[i] != g)\n {\n auto t1 = xs[i]; xs[i] = g; dfs(i, c+1); xs[i] = t1;\n }\n if (xs[i+1] != g)\n {\n auto t2 = xs[i+1]; xs[i+1] = g; dfs(i+1, c+1); xs[i+1] = t2;\n }\n }\n }\n foreach (i, _ ; xs)\n {\n dfs(i, 0);\n }\n ans += n;\n writeln(ans);\n}"}, {"source_code": "/+ dub.sdl:\n name \"A\"\n dependency \"dcomp\" version=\">=0.7.4\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\nimport std.numeric : gcd;\n// import dcomp.foundation, dcomp.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n int n;\n sc.read(n);\n long[] a;\n sc.read(a);\n int zc = a.count(1).to!int;\n if (zc) {\n writeln(n - zc);\n return 0; \n }\n int ans = 10000;\n foreach (l; 0..n) {\n long g = 0;\n foreach (r; l+1..n+1) {\n g = gcd(g, a[r-1]);\n if (g == 1) {\n ans = min(ans, 2*(r-l-1) + l + (n-r));\n }\n }\n }\n if (ans == 10000) ans = -1;\n writeln(ans);\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}\n\nimport core.bitop : popcnt;\nstatic if (!__traits(compiles, popcnt(ulong.max))) {\n public import core.bitop : popcnt;\n int popcnt(ulong v) {\n return popcnt(cast(uint)(v)) + popcnt(cast(uint)(v>>32));\n }\n}\n\nbool poppar(ulong v) {\n v^=v>>1;\n v^=v>>2;\n v&=0x1111111111111111UL;\n v*=0x1111111111111111UL;\n return ((v>>60) & 1) != 0;\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"}, {"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\tauto a = readln.splitter.map !(to !(int)).array;\n\n\t\tint c = a.count (1);\n\t\tif (c > 0)\n\t\t{\n\t\t\twriteln (n - c);\n\t\t\tcontinue;\n\t\t}\n\n\t\tint d = n;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tint v = a[i];\n\t\t\tfor (int j = i + 1; j < n; j++)\n\t\t\t{\n\t\t\t\tv = gcd (v, a[j]);\n\t\t\t\tif (v == 1)\n\t\t\t\t{\n\t\t\t\t\td = min (d, j - i);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (d < n)\n\t\t{\n\t\t\twriteln (d + n - 1);\n\t\t\tcontinue;\n\t\t}\n\n\t\twriteln (-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 N = readInt();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n int ans = int.max;\n \n const cnt1 = cast(int)(A.count(1));\n if (cnt1 >= 1) {\n chmin(ans, N - cnt1);\n }\n \n foreach (i; 0 .. N) {\n long g = 0;\n foreach (j; i .. N) {\n g = gcd(g, A[j]);\n if (g == 1) {\n chmin(ans, (j - i) + (N - 1));\n break;\n }\n }\n }\n writeln((ans >= int.max) ? -1 : ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "c489061d9e8587d2e85cad0e2f23f3fb"} {"source_code": "import std.stdio;\nimport std.string;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint[] m = new int[a];\n\tfor (int i=0; imax)\n\t\t{\n\t\t\tmax=m[i];\n\t\t}\n\t}\n\tfor (int i=0; i 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\tlog(\"as:\", as);\n\n\t\tlong u;\n\t\tforeach(a; as) u += a;\n\n\t\tlong v;\n\t\tforeach(a; as) v ^= (a * 2);\n\t\t\n\t\tlog(\"u:\", u, \"v:\", v);\n\t\t\n\t\tlong[] ans;\n\n\t\t{\n\t\t\tlong tmp = 1;\n\t\t\twhile(tmp <= u || tmp <= v) tmp *= 2;\n\t\t\tif(u % 2 == 1 && tmp % 2 == 0) tmp += 1;\n\t\t\tif(u % 2 == 0 && tmp % 2 == 1) tmp -= 1;\n\t\t\tlog(\"tmp:\", tmp);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tlog(\"ans:\", ans, \"u:\", u, \"v:\", v);\n\t\t}\n\n\t\tif(u < v){\n\t\t\tlog(\"u < v\");\n\t\t\tlong tmp = (v - u) / 2;\n\t\t\tlog(\"tmp:\", tmp);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tlog(\"ans:\", ans, \"u:\", u, \"v:\", v);\n\t\t}\n\n\t\tans.length.writeln;\n\t\tans.map!(to!string).array.join(\" \").writeln;\n\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; }\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 (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto a = RDA;\n\t\tauto x = a.sum;\n\t\tif (x % 2 == 1)\n\t\t{\n\t\t\ta ~= 1;\n\t\t\tx += 1;\n\t\t\tans[ti] ~= 1;\n\t\t}\n\t\tlong y;\n\t\tforeach (i; 0..a.length)\n\t\t{\n\t\t\ty ^= a[i];\n\t\t}\n\t\tdebug writeln(\"x:\", x, \" y:\", y);\n\t\tlong tmp;\n\t\tforeach (i; 1..64)\n\t\t{\n\t\t\tauto bit = 1L << i;\n\t\t\tif (((x >> i) & 1) == ((y >> (i-1)) & 1))\n\t\t\t\tcontinue;\n\t\t\ttmp += bit;\n\t\t\tx += bit;\n\t\t\ty ^= bit;\n\t\t}\n\t\tans[ti] ~= tmp;\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}\n"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm : map, sum, fold;\nimport std.string : strip, split;\nimport std.conv : to;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n foreach (i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n auto a = readln.strip.split.map!(to!ulong);\n\n // append at most 3 elements so that s = 2*x (= x<<1)\n auto s = a.sum;\n auto x = a.fold!\"a ^ b\"(0uL);\n\n writefln(\"2\\n%d %d\", x, s+x);\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 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 !(long)).array;\n\t\tauto totalSum = a.reduce !(q{a + b});\n\t\tauto totalXor = a.reduce !(q{a ^ b});\n\n\t\ta ~= totalXor;\n\t\ttotalSum += totalXor;\n\t\ttotalXor ^= totalXor;\n\n\t\ta ~= totalSum;\n\t\ttotalXor ^= totalSum;\n\t\ttotalSum += totalSum;\n\n\t\twriteln (2, \" \", a[$ - 2], \" \", a[$ - 1]);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm : map, sum, fold;\nimport std.string : strip, split;\nimport std.conv : to;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n foreach (i; 0..t) {\n int n;\n readf!\"%d\\n\"(n);\n auto a = readln.strip.split.map!(to!int);\n\n // append at most 3 elements so that s = 2*x (= x<<1)\n auto s = a.sum;\n auto x = a.fold!\"a ^ b\"(0);\n\n writefln(\"2\\n%d %d\", x, s+x);\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\t\tlog(\"as:\", as);\n\n\t\tlong u;\n\t\tforeach(a; as) u += a;\n\n\t\tlong v;\n\t\tforeach(a; as) v ^= (a * 2);\n\t\t\n\t\tlog(\"u:\", u, \"v:\", v);\n\t\t\n\t\tlong[] ans;\n\n\t\t{\n\t\t\tlong tmp = 1;\n\t\t\twhile(tmp <= u || tmp <= v) tmp *= 2;\n\t\t\tif(u % 2 && tmp > 1) tmp += 1;\n\t\t\tlog(\"tmp:\", tmp);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tlog(\"ans:\", ans, \"u:\", u, \"v:\", v);\n\t\t}\n\n\t\tif(u < v){\n\t\t\tlog(\"u < v\");\n\t\t\tlong tmp = (v - u) / 2;\n\t\t\tlog(\"tmp:\", tmp);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tlog(\"ans:\", ans, \"u:\", u, \"v:\", v);\n\t\t}\n\n\t\tans.length.writeln;\n\t\tans.map!(to!string).array.join(\" \").writeln;\n\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\tforeach(_; 0 .. rint){\n\t\tint n = rint;\n\t\tlong[] as = rlong(n);\n\t\tlog(\"as:\", as);\n\n\t\tlong u;\n\t\tforeach(a; as) u += a;\n\n\t\tlong v;\n\t\tforeach(a; as) v ^= (a * 2);\n\t\t\n\t\tlog(\"u:\", u, \"v:\", v);\n\t\t\n\t\tlong[] ans;\n\t\tif(u > v){\n\t\t\tlog(\"u > v\");\n\t\t\tlong tmp = 1;\n\t\t\twhile(tmp <= u) tmp *= 2;\n\t\t\tif(u % 2) tmp += 1;\n\t\t\tlog(\"tmp:\", tmp);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tlog(\"ans:\", ans, \"u:\", u, \"v:\", v);\n\t\t}\n\t\tif(u < v){\n\t\t\tlog(\"u < v\");\n\t\t\tlong tmp = (v - u) / 2;\n\t\t\tlog(\"tmp:\", tmp);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tans ~= tmp, u += tmp, v ^= (tmp * 2);\n\t\t\tlog(\"ans:\", ans, \"u:\", u, \"v:\", v);\n\t\t}\n\n\t\tans.length.writeln;\n\t\tans.map!(to!string).array.join(\" \").writeln;\n\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 long[][](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\tif (x % 2 == 1)\n\t\t{\n\t\t\ta ~= 1;\n\t\t\tx += 1;\n\t\t\tans[ti] ~= 1;\n\t\t}\n\t\tlong y;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ty ^= a[i];\n\t\t}\n\t\tlong tmp;\n\t\tforeach (i; 1..64)\n\t\t{\n\t\t\tauto bit = 1L << i;\n\t\t\tif (((x >> i) & 1) == ((y >> (i-1)) & 1))\n\t\t\t\tcontinue;\n\t\t\ttmp += bit;\n\t\t\tx += bit;\n\t\t\ty ^= bit;\n\t\t}\n\t\tans[ti] ~= tmp;\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}\n"}], "src_uid": "cced3c3d3f1a63e81e36c94fc2ce9379"} {"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\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 auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1] - 1;\r\n G[p] ~= i;\r\n }\r\n\r\n auto IDX = new int[N];\r\n auto RIDX = new int[N];\r\n auto R = new int[N]; // R[i] = r means [i, r] is the all node of the subtree whose root is i\r\n auto D = new int[N];\r\n void dfs(int v, ref int i, int d) {\r\n IDX[v] = i;\r\n RIDX[i] = v;\r\n D[i] = d;\r\n int orgi = i;\r\n foreach (u; G[v]) {\r\n i++;\r\n dfs(u, i, d+1);\r\n }\r\n R[orgi] = i;\r\n }\r\n {\r\n int i = 0;\r\n dfs(0, i, 0);\r\n }\r\n\r\n auto M = iota(N).array.sort!((i, j) => D[i] > D[j]).array;\r\n auto T = RootedTree(G, 0);\r\n bool C(int h) {\r\n int k = 0;\r\n auto used = RSQ!int(new int[N]);\r\n foreach (j; M) {\r\n if (D[j] <= h) break;\r\n if (used.query(j, j+1) >= 1) continue;\r\n k++;\r\n if (k > K) return false;\r\n int p = T.kth_ancestor(RIDX[j], h - 1);\r\n int i = IDX[p];\r\n if (R[i] + 1 - i > N - K + k) return true;\r\n used.add(i, R[i]+1, 1);\r\n }\r\n return true;\r\n }\r\n int lb = 0, ub = D.reduce!max;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\r\n}\r\n\r\nstruct LazySegmentTree(T, F) {\r\n int n;\r\n T[] dat;\r\n F[] laz; // composition of all uniformly applied `F`s\r\n this(int n_) {\r\n n = 1;\r\n while (n < n_) n *= 2;\r\n dat = new T[2*n-1];\r\n dat[] = T.unit;\r\n laz = new F[2*n-1];\r\n laz[] = F.id;\r\n }\r\n this(T[] xs) {\r\n this(cast(int)(xs.length));\r\n for (int i = 0; i < xs.length; i++) { this.dat[this.n - 1 + i] = xs[i]; }\r\n for (int k = this.n-2; k >= 0; k--) { this.dat[k] = T.binop(this.dat[2*k+1], this.dat[2*k+2]); }\r\n }\r\n void push(int k) {\r\n if (laz[k] == F.id) return;\r\n if (k < n - 1) {\r\n laz[k*2+1] = F.composite(laz[k], laz[k*2+1]);\r\n laz[k*2+2] = F.composite(laz[k], laz[k*2+2]);\r\n }\r\n dat[k] = laz[k](dat[k]);\r\n laz[k] = F.id;\r\n }\r\n // apply `f` to range [a, b). i.e. x[a] <- f(x[a]), ..., x[b-1] <- f(x[b-1])\r\n void apply(int a, int b, F f) { apply(a, b, f, 0, 0, n); }\r\n void apply(int a, int b, F f, int k, int l, int r) {\r\n push(k);\r\n if (a <= l && r <= b) {\r\n laz[k] = F.composite(f, laz[k]);\r\n push(k); // we need this line to update `dat[k]`. because (*) below uses `dat[k]` after this function call returns.\r\n } else if (l < b && a < r) {\r\n apply(a, b, f, k*2+1, l, (l+r)/2);\r\n apply(a, b, f, k*2+2, (l+r)/2, r);\r\n dat[k] = T.binop(dat[k*2+1], dat[k*2+2]); // (*)\r\n }\r\n }\r\n // return x[a] + x[a+1] + ... + x[b-1] (here '+' corresponds to `T.binop`)\r\n T query(int a, int b) { return query(a, b, 0, 0, n); }\r\n T query(int a, int b, int k, int l, int r) {\r\n push(k);\r\n if (b <= l || r <= a) return T.unit;\r\n else if (a <= l && r <= b) return dat[k];\r\n else {\r\n auto lres = query(a, b, k*2+1, l, (l+r)/2);\r\n auto rres = query(a, b, k*2+2, (l+r)/2, r);\r\n return T.binop(lres, rres);\r\n }\r\n }\r\n // for debugging. apply all propagated function to leaves.\r\n void push_all() {\r\n for (int k = 0; k < n-1; k++) push(k);\r\n }\r\n}\r\n\r\nstruct RSQ(Integer) {\r\n struct T {\r\n Integer x;\r\n Integer len;\r\n static T binop(T a, T b) { return T(a.x + b.x, a.len + b.len); }\r\n enum T unit = T(0, 0);\r\n }\r\n struct F {\r\n Integer x;\r\n this(Integer x) { this.x = x; }\r\n T opCall(T t) { return T(x * t.len + t.x, t.len); }\r\n static F composite(F f, F g) { return F(f.x + g.x); }\r\n enum F id = F(0);\r\n }\r\n LazySegmentTree!(T, F) lst;\r\n this(int n_) { lst = LazySegmentTree!(T, F)(n_); }\r\n this(Integer[] xs) {\r\n lst = LazySegmentTree!(T, F)(xs.map!((x) => T(x, 1)).array);\r\n }\r\n void add(int a, int b, Integer x) {\r\n lst.apply(a, b, F(x));\r\n }\r\n Integer query(int a, int b) {\r\n return lst.query(a, b).x;\r\n }\r\n}\r\n\r\nstruct RootedTree {\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 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 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 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 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< D[i] > D[j]).array;\r\n bool C(int h) {\r\n auto used = new bool[N];\r\n Array!int path;\r\n void fillused(int v) {\r\n if (used[v]) return;\r\n used[v] = true;\r\n foreach (u; G[v]) {\r\n fillused(u);\r\n }\r\n }\r\n int k = 0;\r\n auto anc = new int[N]; anc[] = -1;\r\n void dfs(int v) {\r\n path ~= v;\r\n int n = path.length;\r\n if (n - h >= 0) {\r\n anc[v] = path[n - h];\r\n }\r\n foreach (u; G[v]) {\r\n dfs(u);\r\n }\r\n path.removeBack;\r\n }\r\n dfs(0);\r\n foreach (j; M) {\r\n if (used[j]) continue;\r\n if (D[j] <= h) break;\r\n k++;\r\n fillused(anc[j]);\r\n }\r\n return k <= K;\r\n }\r\n \r\n int lb = 0, ub = D.reduce!max;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\r\n\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\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 auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1] - 1;\r\n G[p] ~= i;\r\n }\r\n\r\n auto IDX = new int[N];\r\n auto RIDX = new int[N];\r\n auto R = new int[N]; // R[i] = r means [i, r] is the all node of the subtree whose root is i\r\n auto D = new int[N];\r\n void dfs(int v, ref int i, int d) {\r\n IDX[v] = i;\r\n RIDX[i] = v;\r\n D[i] = d;\r\n int orgi = i;\r\n foreach (u; G[v]) {\r\n i++;\r\n dfs(u, i, d+1);\r\n }\r\n R[orgi] = i;\r\n }\r\n {\r\n int i = 0;\r\n dfs(0, i, 0);\r\n }\r\n\r\n auto M = iota(N).array.sort!((i, j) => D[i] > D[j]).array;\r\n auto T = RootedTree(G, 0);\r\n bool C(int h) {\r\n int k = 0;\r\n auto used = RSQ!int(new int[N]);\r\n foreach (j; M) {\r\n if (D[j] <= h) break;\r\n if (used.query(j, j+1) >= 1) continue;\r\n k++;\r\n if (k > K) return false;\r\n int p = T.kth_ancestor(RIDX[j], h - 1);\r\n int i = IDX[p];\r\n if (R[i] + 1 - i > N - K) return true;\r\n used.add(i, R[i]+1, 1);\r\n }\r\n return true;\r\n }\r\n int lb = 0, ub = D.reduce!max;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\r\n}\r\n\r\nstruct LazySegmentTree(T, F) {\r\n int n;\r\n T[] dat;\r\n F[] laz; // composition of all uniformly applied `F`s\r\n this(int n_) {\r\n n = 1;\r\n while (n < n_) n *= 2;\r\n dat = new T[2*n-1];\r\n dat[] = T.unit;\r\n laz = new F[2*n-1];\r\n laz[] = F.id;\r\n }\r\n this(T[] xs) {\r\n this(cast(int)(xs.length));\r\n for (int i = 0; i < xs.length; i++) { this.dat[this.n - 1 + i] = xs[i]; }\r\n for (int k = this.n-2; k >= 0; k--) { this.dat[k] = T.binop(this.dat[2*k+1], this.dat[2*k+2]); }\r\n }\r\n void push(int k) {\r\n if (laz[k] == F.id) return;\r\n if (k < n - 1) {\r\n laz[k*2+1] = F.composite(laz[k], laz[k*2+1]);\r\n laz[k*2+2] = F.composite(laz[k], laz[k*2+2]);\r\n }\r\n dat[k] = laz[k](dat[k]);\r\n laz[k] = F.id;\r\n }\r\n // apply `f` to range [a, b). i.e. x[a] <- f(x[a]), ..., x[b-1] <- f(x[b-1])\r\n void apply(int a, int b, F f) { apply(a, b, f, 0, 0, n); }\r\n void apply(int a, int b, F f, int k, int l, int r) {\r\n push(k);\r\n if (a <= l && r <= b) {\r\n laz[k] = F.composite(f, laz[k]);\r\n push(k); // we need this line to update `dat[k]`. because (*) below uses `dat[k]` after this function call returns.\r\n } else if (l < b && a < r) {\r\n apply(a, b, f, k*2+1, l, (l+r)/2);\r\n apply(a, b, f, k*2+2, (l+r)/2, r);\r\n dat[k] = T.binop(dat[k*2+1], dat[k*2+2]); // (*)\r\n }\r\n }\r\n // return x[a] + x[a+1] + ... + x[b-1] (here '+' corresponds to `T.binop`)\r\n T query(int a, int b) { return query(a, b, 0, 0, n); }\r\n T query(int a, int b, int k, int l, int r) {\r\n push(k);\r\n if (b <= l || r <= a) return T.unit;\r\n else if (a <= l && r <= b) return dat[k];\r\n else {\r\n auto lres = query(a, b, k*2+1, l, (l+r)/2);\r\n auto rres = query(a, b, k*2+2, (l+r)/2, r);\r\n return T.binop(lres, rres);\r\n }\r\n }\r\n // for debugging. apply all propagated function to leaves.\r\n void push_all() {\r\n for (int k = 0; k < n-1; k++) push(k);\r\n }\r\n}\r\n\r\nstruct RSQ(Integer) {\r\n struct T {\r\n Integer x;\r\n Integer len;\r\n static T binop(T a, T b) { return T(a.x + b.x, a.len + b.len); }\r\n enum T unit = T(0, 0);\r\n }\r\n struct F {\r\n Integer x;\r\n this(Integer x) { this.x = x; }\r\n T opCall(T t) { return T(x * t.len + t.x, t.len); }\r\n static F composite(F f, F g) { return F(f.x + g.x); }\r\n enum F id = F(0);\r\n }\r\n LazySegmentTree!(T, F) lst;\r\n this(int n_) { lst = LazySegmentTree!(T, F)(n_); }\r\n this(Integer[] xs) {\r\n lst = LazySegmentTree!(T, F)(xs.map!((x) => T(x, 1)).array);\r\n }\r\n void add(int a, int b, Integer x) {\r\n lst.apply(a, b, F(x));\r\n }\r\n Integer query(int a, int b) {\r\n return lst.query(a, b).x;\r\n }\r\n}\r\n\r\nstruct RootedTree {\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 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 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 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 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< D[i] > D[j]).array;\r\n auto T = RootedTree(G, 0);\r\n bool C(int h) {\r\n int k = 0;\r\n auto used = RSQ(N);\r\n foreach (j; M) {\r\n if (D[j] <= h) break;\r\n int p = T.kth_ancestor(RIDX[j], h - 1);\r\n int i = IDX[p];\r\n if (used.query(i, j+1) >= 1) continue;\r\n if (D[j] > h) {\r\n k++;\r\n if (k > K) return false;\r\n used.update(i, used.query(i,i+1) + 1);\r\n used.update(R[i]+1, used.query(R[i]+1,R[i]+2)-1);\r\n }\r\n }\r\n return true;\r\n }\r\n int lb = 0, ub = D.reduce!max;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\r\n}\r\n\r\nstruct RootedTree {\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 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 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 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 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< 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\nenum int INF = 1<<28;\r\nalias RSQ = SegmentTree!(int, 0, (a, b) => a + b);\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\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 auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1] - 1;\r\n G[p] ~= i;\r\n }\r\n\r\n auto IDX = new int[N];\r\n auto RIDX = new int[N];\r\n auto R = new int[N]; // R[i] = r means [i, r] is the all node of the subtree whose root is i\r\n auto D = new int[N];\r\n void dfs(int v, ref int i, int d) {\r\n IDX[v] = i;\r\n RIDX[i] = v;\r\n D[i] = d;\r\n int orgi = i;\r\n foreach (u; G[v]) {\r\n i++;\r\n dfs(u, i, d+1);\r\n }\r\n R[orgi] = i;\r\n }\r\n {\r\n int i = 0;\r\n dfs(0, i, 0);\r\n }\r\n\r\n auto M = iota(N).array.sort!((i, j) => D[i] > D[j]).array;\r\n auto T = RootedTree(G, 0);\r\n bool C(int h) {\r\n int k = 0;\r\n auto used = RSQ(N);\r\n foreach (j; M) {\r\n if (D[j] <= h) break;\r\n int p = T.kth_ancestor(RIDX[j], h - 1);\r\n int i = IDX[p];\r\n if (used.query(0, j+1) >= 1) continue;\r\n if (D[j] > h) {\r\n k++;\r\n if (k > K) return false;\r\n used.update(i, used.query(i,i+1) + 1);\r\n used.update(R[i]+1, used.query(R[i]+1,R[i]+2)-1);\r\n }\r\n }\r\n return true;\r\n }\r\n int lb = 0, ub = D.reduce!max;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\r\n}\r\n\r\nstruct RootedTree {\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 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 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 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 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< 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\nenum int INF = 1<<28;\r\nalias RSQ = SegmentTree!(int, 0, (a, b) => a + b);\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\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 auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1] - 1;\r\n G[p] ~= i;\r\n }\r\n\r\n auto IDX = new int[N];\r\n auto RIDX = new int[N];\r\n auto R = new int[N]; // R[i] = r means [i, r] is the all node of the subtree whose root is i\r\n auto D = new int[N];\r\n void dfs(int v, ref int i, int d) {\r\n IDX[v] = i;\r\n RIDX[i] = v;\r\n D[i] = d;\r\n int orgi = i;\r\n foreach (u; G[v]) {\r\n i++;\r\n dfs(u, i, d+1);\r\n }\r\n R[orgi] = i;\r\n }\r\n {\r\n int i = 0;\r\n dfs(0, i, 0);\r\n }\r\n\r\n auto M = iota(N).array.sort!((i, j) => D[i] > D[j]).array;\r\n auto T = RootedTree(G, 0);\r\n bool C(int h) {\r\n int k = 0;\r\n auto used = RSQ(N);\r\n foreach (j; M) {\r\n if (D[j] <= h) break;\r\n int p = T.kth_ancestor(RIDX[j], h - 1);\r\n int i = IDX[p];\r\n if (used.query(0, j+1) >= 1) continue;\r\n if (D[j] > h) {\r\n k++;\r\n if (k > K) return false;\r\n used.update(i, 1);\r\n used.update(R[i]+1, -1);\r\n }\r\n }\r\n return true;\r\n }\r\n int lb = 0, ub = D.reduce!max;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\r\n}\r\n\r\nstruct RootedTree {\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 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 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 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 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< 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\nenum int INF = 1<<28;\r\nalias RSQ = SegmentTree!(int, 0, (a, b) => a + b);\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\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 auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1] - 1;\r\n G[p] ~= i;\r\n }\r\n\r\n auto IDX = new int[N];\r\n auto RIDX = new int[N];\r\n auto R = new int[N]; // R[i] = r means [i, r] is the all node of the subtree whose root is i\r\n auto D = new int[N];\r\n void dfs(int v, ref int i, int d) {\r\n IDX[v] = i;\r\n RIDX[i] = v;\r\n D[i] = d;\r\n int orgi = i;\r\n foreach (u; G[v]) {\r\n i++;\r\n dfs(u, i, d+1);\r\n }\r\n R[orgi] = i;\r\n }\r\n {\r\n int i = 0;\r\n dfs(0, i, 0);\r\n }\r\n\r\n auto M = iota(N).array.sort!((i, j) => D[i] > D[j]).array;\r\n auto T = RootedTree(G, 0);\r\n bool C(int h) {\r\n int k = 0;\r\n auto used = RMQ(N);\r\n foreach (j; M) {\r\n if (D[j] <= h) break;\r\n int p = T.kth_ancestor(RIDX[j], h - 1);\r\n int i = IDX[p];\r\n if (used.query(i, j+1) >= 1) continue;\r\n if (D[j] > h) {\r\n k++;\r\n if (k > K) return false;\r\n used.update(i, 1);\r\n }\r\n }\r\n return true;\r\n }\r\n int lb = 0, ub = D.reduce!max;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\r\n}\r\n\r\nstruct LazySegmentTree(T, F) {\r\n int n;\r\n T[] dat;\r\n F[] laz; // composition of all uniformly applied `F`s\r\n this(int n_) {\r\n n = 1;\r\n while (n < n_) n *= 2;\r\n dat = new T[2*n-1];\r\n dat[] = T.unit;\r\n laz = new F[2*n-1];\r\n laz[] = F.id;\r\n }\r\n this(T[] xs) {\r\n this(cast(int)(xs.length));\r\n for (int i = 0; i < xs.length; i++) { this.dat[this.n - 1 + i] = xs[i]; }\r\n for (int k = this.n-2; k >= 0; k--) { this.dat[k] = T.binop(this.dat[2*k+1], this.dat[2*k+2]); }\r\n }\r\n void push(int k) {\r\n if (laz[k] == F.id) return;\r\n if (k < n - 1) {\r\n laz[k*2+1] = F.composite(laz[k], laz[k*2+1]);\r\n laz[k*2+2] = F.composite(laz[k], laz[k*2+2]);\r\n }\r\n dat[k] = laz[k](dat[k]);\r\n laz[k] = F.id;\r\n }\r\n // apply `f` to range [a, b). i.e. x[a] <- f(x[a]), ..., x[b-1] <- f(x[b-1])\r\n void apply(int a, int b, F f) { apply(a, b, f, 0, 0, n); }\r\n void apply(int a, int b, F f, int k, int l, int r) {\r\n push(k);\r\n if (a <= l && r <= b) {\r\n laz[k] = F.composite(f, laz[k]);\r\n push(k); // we need this line to update `dat[k]`. because (*) below uses `dat[k]` after this function call returns.\r\n } else if (l < b && a < r) {\r\n apply(a, b, f, k*2+1, l, (l+r)/2);\r\n apply(a, b, f, k*2+2, (l+r)/2, r);\r\n dat[k] = T.binop(dat[k*2+1], dat[k*2+2]); // (*)\r\n }\r\n }\r\n // return x[a] + x[a+1] + ... + x[b-1] (here '+' corresponds to `T.binop`)\r\n T query(int a, int b) { return query(a, b, 0, 0, n); }\r\n T query(int a, int b, int k, int l, int r) {\r\n push(k);\r\n if (b <= l || r <= a) return T.unit;\r\n else if (a <= l && r <= b) return dat[k];\r\n else {\r\n auto lres = query(a, b, k*2+1, l, (l+r)/2);\r\n auto rres = query(a, b, k*2+2, (l+r)/2, r);\r\n return T.binop(lres, rres);\r\n }\r\n }\r\n // for debugging. apply all propagated function to leaves.\r\n void push_all() {\r\n for (int k = 0; k < n-1; k++) push(k);\r\n }\r\n}\r\n\r\nstruct RSQ(Integer) {\r\n struct T {\r\n Integer x;\r\n Integer len;\r\n static T binop(T a, T b) { return T(a.x + b.x, a.len + b.len); }\r\n enum T unit = T(0, 0);\r\n }\r\n struct F {\r\n Integer x;\r\n this(Integer x) { this.x = x; }\r\n T opCall(T t) { return T(x * t.len + t.x, t.len); }\r\n static F composite(F f, F g) { return F(f.x + g.x); }\r\n enum F id = F(0);\r\n }\r\n LazySegmentTree!(T, F) lst;\r\n this(int n_) { lst = LazySegmentTree!(T, F)(n_); }\r\n this(Integer[] xs) {\r\n lst = LazySegmentTree!(T, F)(xs.map!((x) => T(x, 1)).array);\r\n }\r\n void add(int a, int b, Integer x) {\r\n lst.apply(a, b, F(x));\r\n }\r\n Integer query(int a, int b) {\r\n return lst.query(a, b).x;\r\n }\r\n}\r\n\r\nstruct RootedTree {\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 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 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 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 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< 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\nenum int INF = 1<<28;\r\nalias RMQ = SegmentTree!(int, -INF, (a, b) => max(a, b));\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, K; readf(\"%d %d\\n\", &N, &K);\r\n auto P = readarray!int;\r\n auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1] - 1;\r\n G[p] ~= i;\r\n }\r\n\r\n auto IDX = new int[N];\r\n auto R = new int[N]; // R[i] = r means [i, r) is the all node of the subtree whose root is i\r\n auto D = new int[N];\r\n void dfs(int v, ref int i, int d) {\r\n IDX[v] = i;\r\n D[i] = d;\r\n int orgi = i;\r\n foreach (u; G[v]) {\r\n i++;\r\n dfs(u, i, d+1);\r\n }\r\n R[orgi] = i;\r\n }\r\n {\r\n int i = 0;\r\n dfs(0, i, 0);\r\n }\r\n\r\n auto M = iota(N).array.sort!((i, j) => D[i] > D[j]).array;\r\n bool C(int h) {\r\n auto used = new bool[N];\r\n int k = 0;\r\n foreach (j; M) {\r\n if (used[j]) continue;\r\n if (D[j] > h) {\r\n k++;\r\n int i = j;\r\n while (true) {\r\n if (D[i] == D[j] - h + 1) break;\r\n i--;\r\n }\r\n for (int l = i; l < R[i]; l++) {\r\n used[l] = true;\r\n }\r\n }\r\n }\r\n return k <= K;\r\n }\r\n int lb = 0, ub = N;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\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, K; readf(\"%d %d\\n\", &N, &K);\r\n auto P = readarray!int;\r\n auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1] - 1;\r\n G[p] ~= i;\r\n }\r\n\r\n auto IDX = new int[N];\r\n auto R = new int[N]; // R[i] = r means [i, r) is the all node of the subtree whose root is i\r\n auto D = new int[N];\r\n void dfs(int v, ref int i, int d) {\r\n IDX[v] = i;\r\n D[i] = d;\r\n int orgi = i;\r\n foreach (u; G[v]) {\r\n i++;\r\n dfs(u, i, d+1);\r\n }\r\n R[orgi] = i;\r\n }\r\n {\r\n int i = 0;\r\n dfs(0, i, 0);\r\n }\r\n\r\n auto M = iota(N).array.sort!((i, j) => D[i] > D[j]).array;\r\n bool C(int h) {\r\n auto used = new bool[N];\r\n int k = 0;\r\n foreach (j; M) {\r\n if (used[j]) continue;\r\n if (D[j] > h) {\r\n k++;\r\n int i = j;\r\n while (true) {\r\n used[i] = true;\r\n if (D[i] == D[j] - h + 1) break;\r\n i--;\r\n }\r\n }\r\n }\r\n return k <= K;\r\n }\r\n int lb = 0, ub = N;\r\n while (lb + 1 < ub) {\r\n int mid = (lb + ub) / 2;\r\n (C(mid) ? ub : lb) = mid;\r\n }\r\n writeln(ub);\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, K; readf(\"%d %d\\n\", &N, &K);\r\n auto P = readarray!int;\r\n auto G = new int[][N];\r\n for (int i = 1; i < N; i++) {\r\n int p = P[i-1] - 1;\r\n G[p] ~= i;\r\n }\r\n BinaryHeap!(Array!int) Q;\r\n void dfs(int v, int d) {\r\n if (G[v].empty) {\r\n Q.insert(d);\r\n } else {\r\n foreach (u; G[v]) {\r\n dfs(u, d+1);\r\n }\r\n }\r\n }\r\n dfs(0, 0);\r\n\r\n for (int k = 0; k < K; k++) {\r\n auto c = Q.front; Q.removeFront;\r\n int a = c / 2;\r\n int b = c - a;\r\n Q.insert(a);\r\n Q.insert(b);\r\n }\r\n writeln(Q.reduce!max);\r\n}\r\n"}], "src_uid": "f260d0885319a146904b43f89e253f0c"} {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array, std.container;\n\nvoid u(int[] a) {\n writef(\"%d\", a.length);\n foreach (x; a) {\n writef(\" %d\", x);\n }\n writeln;\n}\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n auto a = stdin.readln.split.map!(to!int).array;\n auto ns = a.partition3(0);\n if (ns[2].length == 0) {\n ns[2] ~= ns[0][$ - 2 .. $];\n ns[0] = ns[0][0 .. $ - 2];\n }\n if (ns[0].length % 2 == 0) {\n ns[1] ~= ns[0][$ - 1];\n ns[0] = ns[0][0 .. $ - 1];\n }\n u(ns[0]);\n u(ns[2]);\n u(ns[1]);\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\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;\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 x = array (filter !(\"a < 0\") (a));\n\t\tauto y = array (filter !(\"a > 0\") (a));\n\t\tauto z = array (filter !(\"a == 0\") (a));\n\t\tif (y.length == 0)\n\t\t{\n\t\t\tassert (x.length >= 3);\n\t\t\ty ~= x[0..2];\n\t\t\tx = x[2..$];\n\t\t}\n\t\tif (x.length % 2 == 0)\n\t\t{\n\t\t\tz ~= x[0..1];\n\t\t\tx = x[1..$];\n\t\t}\n\t\twritefln (\"%s %(%s %)\", x.length, x);\n\t\twritefln (\"%s %(%s %)\", y.length, y);\n\t\twritefln (\"%s %(%s %)\", z.length, z);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array, std.container;\n\nvoid u(Array!int a) {\n writef(\"%d\", a.length);\n foreach (x; a) {\n writef(\" %d\", x);\n }\n writeln;\n}\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n auto a = stdin.readln.split.map!(to!int);\n bool f = true;\n Array!int e, o, z;\n foreach (x; a) {\n if (x == 0) {\n z.insert(x);\n } else if (f && x % 2 != 0) {\n o.insert(x);\n f = false;\n } else {\n e.insert(x);\n }\n }\n u(o);\n u(e);\n u(z);\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array, std.container;\n\nvoid u(int[] a) {\n writef(\"%d\", a.length);\n foreach (x; a) {\n writef(\" %d\", x);\n }\n writeln;\n}\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n auto a = stdin.readln.split.map!(to!int).array;\n auto ns = a.partition3(0);\n if (ns[2].length == 0) {\n ns[2] ~= ns[0][$ - 2 .. $];\n ns[0] = ns[0][0 .. $ - 2];\n }\n if (ns[0].length % 2 == 0) {\n ns[1] ~= ns[0][$ - 1];\n ns[0] ~= ns[0][0 .. $ - 1];\n }\n u(ns[0]);\n u(ns[2]);\n u(ns[1]);\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array, std.container;\n\nvoid u(int[] a) {\n writef(\"%d\", a.length);\n foreach (x; a) {\n writef(\" %d\", x);\n }\n writeln;\n}\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n auto a = stdin.readln.split.map!(to!int).array;\n auto ns = a.partition3(0);\n if (ns[2].length == 0) {\n ns[2] ~= ns[0][$ - 2 .. $];\n ns[0] = ns[0][0 .. $ - 2];\n }\n if (ns[0].length % 2 == 0) {\n ns[1] ~= ns[0][$ - 1];\n ns[0] ~= ns[0][0 .. $ - 1];\n }\n foreach (x; ns) {\n u(x);\n }\n}\n"}, {"source_code": "import std.algorithm;\nimport std.container;\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;\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 x = array (filter !(\"a < 0\") (a));\n\t\tauto y = array (filter !(\"a > 0\") (a));\n\t\tauto z = array (filter !(\"a == 0\") (a));\n\t\tif (y.length == 0)\n\t\t{\n\t\t\tassert (x.length >= 3);\n\t\t\ty ~= x[0..2];\n\t\t\tx = x[2..$];\n\t\t}\n\t\twritefln (\"%s %(%s %)\", x.length, x);\n\t\twritefln (\"%s %(%s %)\", y.length, y);\n\t\twritefln (\"%s %(%s %)\", z.length, z);\n\t}\n}\n"}], "src_uid": "03cf2cc26c84aab685ee78a1d6318b30"} {"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 cnt = new int[10 ^^ 5 + 1];\n cnt[] = 0;\n arr.each!(x => ++cnt[x]);\n auto vals = cnt.count!(x => x > 0);\n \n bool[10 ^^ 5 + 1] done;\n done[] = false;\n long ans = 0;\n foreach (e; arr) {\n cnt[e] -= 1;\n if (cnt[e] == 0) --vals;\n \n if (done[e]) continue;\n \n ans += vals;\n done[e] = true;\n }\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 readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int [int] cnt;\n arr.each!(x => ++cnt[x]);\n \n int [int] done;\n long ans = 0;\n foreach (e; arr) {\n cnt[e] -= 1;\n if (cnt[e] == 0) cnt.remove(e);\n \n if (e in done) continue;\n \n ans += cnt.length;\n done[e] = true;\n }\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 readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int [int] cnt;\n arr.each!(x => ++cnt[x]);\n \n bool[10 ^^ 5 + 1] done;\n done[] = false;\n long ans = 0;\n foreach (e; arr) {\n cnt[e] -= 1;\n if (cnt[e] == 0) cnt.remove(e);\n \n if (done[e]) continue;\n \n ans += cnt.length;\n done[e] = true;\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "4671380d70876044e0ec7a9cab5e25ae"} {"source_code": "module main;\n\nimport std.stdio : readln, writeln, write, writefln, writef;\nimport std.conv : to;\nimport std.array : split, replace;\nimport std.string : strip;\nimport std.algorithm : max, min, map, reduce, sort, reverse;\nimport std.functional : memoize;\n\nversion = B;\n\nversion (A)\n{\n void main()\n {\n auto sequence = read_one!string();\n auto instructions = read_one!string();\n size_t position = 0;\n foreach (instruction; instructions)\n {\n if (sequence[position] == instruction)\n {\n position += 1;\n }\n }\n writeln(position + 1);\n }\n}\nversion (B)\n{\n T abs(T)(T x)\n {\n if (x < 0) return -x; return x;\n }\n void main()\n {\n auto n = read_one!int();\n auto heights = new int[n+1];\n foreach (i; 1..n+1)\n {\n heights[i] = read_one!int();\n }\n auto answer = n * 2 - 1;\n foreach (i; 0..n)\n {\n answer += abs(heights[i] - heights[i+1]);\n }\n writeln(answer);\n // walks: heights[0] + (heights[i] - heights[i-1]).map!abs.sum\n // jumps: n-1\n // eats: n\n }\n}\nversion (C)\n{\n void main()\n {\n auto n = read_one!int();\n }\n}\nversion (D)\n{\n void main()\n {\n auto n = read_one!int();\n }\n}\nversion (E)\n{\n void main()\n {\n }\n}\n\nT read_one(T)()\n{\n return readln().strip().to!T();\n}\n \nT[] read_some(T)()\n{\n T[] ret;\n foreach (e; readln().strip().split())\n {\n ret ~= e.to!T();\n }\n return ret;\n}\n\nT[m] read_fixed(int m, T)()\n{\n T[m] ret;\n foreach (i, e; readln().strip().split())\n {\n ret[i] = e.to!T();\n }\n return ret;\n}\n", "positive_code": [{"source_code": "import std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nprivate const JUMP_TIME = 1;\nprivate const EAT_TIME = 1;\n\nvoid main() {\n\tauto\n\t\ttrees_count = read(),\n\t\tposition = read(),\n\t\ttime = position + EAT_TIME;\n\n\tforeach (i; 1 .. trees_count) {\n\t\tauto tree = read();\n\n\t\ttime += abs(position - tree) + EAT_TIME + JUMP_TIME;\n\t\t\n\t\tposition = tree;\n\t}\n\n\tstdout.write(time);\n}\n\nint read() {\n\treturn to!int(strip(stdin.readln()));\n}"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\nimport std.math;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] h = new int[n];\n for (int i = 0; i < n; i++) {\n readf(\"%d\\n\", &h[i]);\n }\n int t = 0;\n int c = 0;\n for (int i = 0; i < n; i++) {\n t += abs(h[i] - c);\n c = h[i];\n }\n t += n;\n t += n - 1;\n writeln(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;\n\nimmutable int MAX = 10^^6;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto pos = readln.chomp.to!int;\n long ans = pos + 1;\n foreach (_; 0..N-1) {\n auto H = readln.chomp.to!int;\n auto npos = min(pos, H);\n ans += pos - npos + 1 + H - npos + 1;\n pos = H;\n }\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;\nint readint() { return readln.chomp.to!int; }\nint[] readints() { return readln.split.to!(int[]); }\n\nvoid main() {\n int n = readint();\n int[] hs;\n foreach(i; 0..n) hs ~= readint();\n\n int t, ph;\n foreach (i, h ; hs) {\n t += h - ph;\n t++;\n if (i != n-1) {\n t += max(0, h - hs[i+1]);\n ph = min(h, hs[i+1]);\n t++;\n }\n }\n\n writeln(t);\n string _ = readln;\n}"}], "negative_code": [{"source_code": "import std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nprivate const JUMP_TIME = 1;\nprivate const EAT_TIME = 1;\n\nvoid main() {\n\tauto\n\t\ttrees_count = read(),\n\t\tposition = read(),\n\t\ttime = position + EAT_TIME;\n\n\tforeach (i; 1 .. trees_count) {\n\t\tauto tree = read();\n\n\t\ttime += abs(position - tree) + EAT_TIME + JUMP_TIME;\n\t}\n\n\tstdout.write(time);\n}\n\nint read() {\n\treturn to!int(strip(stdin.readln()));\n}"}], "src_uid": "a20ca4b053ba71f6b2dc05749287e0a4"} {"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 K = s[1];\n auto P = s[2];\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array;\n A.sort();\n B.sort();\n\n long hi = 2 * 10^^ 9 + 1;\n long lo = -1;\n\n while (hi - lo > 1) {\n long mid = (hi + lo) / 2;\n int p = -1;\n foreach (i; 0..N) {\n p++;\n while (p < K && abs(A[i] - B[p]) + abs(B[p] - P) > mid) p++;\n }\n if (p < K) hi = mid;\n else lo = mid;\n }\n\n hi.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, k, p;\n readf(\"%s %s %s\", &n, &k, &p);\n readln;\n \n auto rd = () => readln.chomp.split.map!(to!int).array.sort().array;\n \n auto a = rd();\n auto b = rd();\n \n bool isOk(int m) {\n debug { m.writeln; }\n \n bool chk(int m, int[] a, int[] b) {\n auto toTake = (true).repeat(b.length).array;\n foreach (el; a) {\n bool found = false;\n foreach (i, ky; b) {\n if (!toTake[i]) { continue; }\n \n if (abs(el - ky) + abs(ky - p) > m) { continue; }\n \n toTake[i] = false;\n found = true;\n break;\n }\n \n if (!found) { return false; }\n }\n \n return true;\n }\n \n return chk(m, a, b) || chk(m, a.retro().array, b.retro().array);\n }\n \n int le = 0, r = 10 ^^ 9 * 2;\n while (le < r) {\n int m = le + (r - le) / 2;\n \n if (isOk(m)) r = m;\n else le = m+1;\n }\n \n le.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, k, p;\n readf(\"%s %s %s\", &n, &k, &p);\n readln;\n \n auto rd = () => readln.chomp.split.map!(to!int).array.sort().array;\n \n auto a = rd();\n auto b = rd();\n \n bool isOk(int m) {\n debug { m.writeln; }\n \n bool chk(int m, int[] a, int[] b) {\n auto toTake = (true).repeat(b.length).array;\n foreach (el; a) {\n bool found = false;\n foreach (i, ky; b) {\n if (!toTake[i]) { continue; }\n \n if (abs(el - ky) + abs(ky - p) > m) { continue; }\n \n toTake[i] = false;\n found = true;\n break;\n }\n \n if (!found) { return false; }\n }\n \n return true;\n }\n \n return chk(m, a, b) || chk(m, a.retro().array, b.retro().array) \n || chk(m, a.retro().array, b) || chk(m, a, b.retro().array);\n }\n \n int le = 0, r = 10 ^^ 9 * 2;\n while (le < r) {\n int m = le + (r - le) / 2;\n \n if (isOk(m)) r = m;\n else le = m+1;\n }\n \n le.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 P = readLong();\n auto A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n auto B = new long[K];\n foreach (j; 0 .. K) {\n B[j] = readLong();\n }\n A.sort;\n B.sort;\n \n long ans = long.max;\n foreach (j0; 0 .. K - N + 1) {\n long mx;\n foreach (i; 0 .. N) {\n chmax(mx, abs(A[i] - B[j0 + i]) + abs(B[j0 + i] - P));\n }\n chmin(ans, mx);\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, core.stdc.stdio;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto P = s[2];\n auto A = readln.split.map!(to!long).array;\n auto B = readln.split.map!(to!long).array;\n A.sort();\n B.sort();\n\n long hi = 2 * 10^^ 9 + 1;\n long lo = -1;\n\n while (hi - lo > 1) {\n long mid = (hi + lo) / 2;\n int p = 0;\n foreach (i; 0..N) {\n while (p < K && abs(A[i] - B[p]) + abs(B[p] - P) > mid) p++;\n }\n if (p < K) hi = mid;\n else lo = mid;\n }\n\n hi.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, k, p;\n readf(\"%s %s %s\", &n, &k, &p);\n readln;\n \n auto rd = () => readln.chomp.split.map!(to!int).array.sort().array;\n \n auto a = rd();\n auto b = rd();\n \n bool isOk(int m) {\n debug { m.writeln; }\n \n bool chk(int m, int[] a, int[] b) {\n auto toTake = (true).repeat(b.length).array;\n foreach (el; a) {\n bool found = false;\n foreach (i, ky; b) {\n if (!toTake[i]) { continue; }\n \n if (abs(el - ky) + abs(ky - p) > m) { continue; }\n \n toTake[i] = false;\n found = true;\n break;\n }\n \n if (!found) { return false; }\n }\n \n return true;\n }\n \n return chk(m, a, b) || chk(m, a.retro().array, b.retro().array) \n || chk(m, a.retro().array, b) || chk(m, a, b.retro().array);\n }\n \n int le = 1, r = 10 ^^ 9 * 2;\n while (le < r) {\n int m = le + (r - le) / 2;\n \n if (isOk(m)) r = m;\n else le = m+1;\n }\n \n le.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, k, p;\n readf(\"%s %s %s\", &n, &k, &p);\n readln;\n \n auto rd = () => readln.chomp.split.map!(to!int).array.sort().array;\n \n auto a = rd();\n auto b = rd();\n \n bool isOk(int m) {\n debug { m.writeln; }\n \n bool chk(int m, int[] a, int[] b) {\n auto toTake = (true).repeat(b.length).array;\n foreach (el; a) {\n bool found = false;\n foreach (i, ky; b) {\n if (!toTake[i]) { continue; }\n \n if (abs(el - ky) + abs(ky - p) > m) { continue; }\n \n toTake[i] = false;\n found = true;\n break;\n }\n \n if (!found) { return false; }\n }\n \n return true;\n }\n \n return chk(m, a, b) || chk(m, a.retro().array, b.retro().array) || chk(m, a.retro().array, b);\n }\n \n int le = 1, r = 10 ^^ 9 * 2;\n while (le < r) {\n int m = le + (r - le) / 2;\n \n if (isOk(m)) r = m;\n else le = m+1;\n }\n \n le.writeln;\n}"}], "src_uid": "c045163f2539a117c5160eaedc2dab3e"} {"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 alias ln = int;\n ln n; get(n);\n ln sn = n * n;\n ln[] sets = new ln[n];\n ln curr = 0;\n for(ln i = 1; i <= n; i++)\n {\n ln fd = 2 * (n - i) + 1;\n ln ld = 2 * i - 1;\n ln tn = 0;\n for(ln q = i; q <= sn;)\n\t{\n\t write(q, \" \");\n\t if (tn)\n\t q += ld;\n\t else\n\t q += fd;\n\t tn ^= 1;\n\t}\n 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.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\tauto ans = new long[][](n);\n\tforeach (i; 0..n*n)\n\t{\n\t\tauto pos = i % n;\n\t\tif ((i / n) % 2 == 1)\n\t\t{\n\t\t\tpos = n - pos - 1;\n\t\t}\n\t\tans[pos] ~= i+1;\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": "d5ae278ad52a4ab55d732b27a91c2620"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length < b.length)\n return true;\n else if(a.length == b.length)\n return a < b;\n else\n return false;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n for(char e = 'a'; e <= 'z'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n", "positive_code": [{"source_code": "import std.container;\r\nimport std.stdio;\r\nimport std.conv;\r\n\r\nvoid main() {\r\n int t;\r\n readf(\"%s\\n\", &t);\r\n\r\n while(t--) {\r\n int n;\r\n readf(\"%s\\n\", &n);\r\n string s;\r\n readf(\"%s\\n\", &s);\r\n auto rbt = new RedBlackTree!(string);\r\n\r\n for(int k = 1; k <= 3; ++k)\r\n for(int i = 0; i <= n-k; ++i)\r\n rbt.insert(s[i..i+k]);\r\n \r\n string abc = \"abcdefghijklmnopqrstuvwxyz\";\r\n auto q = DList!string();\r\n for(char c = 'a'; c <= 'z'; ++c) {\r\n q.insert(c.to!string);\r\n }\r\n\r\n while(!q.empty) {\r\n auto p = q.front();\r\n q.removeFront();\r\n if(!(p in rbt)) {\r\n p.writeln;\r\n break;\r\n }\r\n foreach(char l; abc)\r\n q.insertBack(p ~ l);\r\n }\r\n }\r\n}\r\n\r\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\ndchar[] getStr(ll num){\n dchar[] res;\n while(num > 0){\n num -= 1;\n ll cr = (num % 26);\n if(cr >= 0){\n res ~= to!dchar(cr + 'a');\n }\n num /= 26;\n }\n res.reverse;\n return res;\n}\n\nint makeNum(dchar[] w, int st, int end){\n int res = 0;\n for(int i = st; i <= end; ++i){\n dchar cr = w[i];\n res *= 26;\n res += (cr - 'a' + 1);\n }\n return res;\n}\n\nvoid theCode(){\n ll n = scan;\n auto word = scan!(dchar[]);\n auto freq = new ll[](2000);\n for(int j = 0; j < 3; ++j){\n for(int i = 0; i < n - j; ++i){\n int num = makeNum(word, i, i+j);\n if(num < 2000){\n ++freq[num];\n }\n }\n }\n for(int i = 1; i < 2000; ++i){\n if(!freq[i]){\n writeln(getStr(i));\n return;\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"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length == b.length)\n return a < b;\n return a.length < b.length;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n for(char e = 'a'; e <= 'e'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(!canFind(s, item)) {\n item.writeln;\n break;\n }\n }\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length == b.length)\n return a < b;\n return a.length < b.length;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n for(char e = 'a'; e <= 'e'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(canFind(s, item))\n continue;\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length == b.length)\n return a < b;\n return a.length < b.length;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n for(char e = 'a'; e <= 'e'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\n int n;\n string s;\nwhile(t--) {\n readf(\"%s\\n\", &n);\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length == b.length)\n return a < b;\n return a.length < b.length;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n for(char e = 'a'; e <= 'e'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length == b.length)\n return a < b;\n return a.length < b.length;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n for(char e = 'a'; e <= 'z'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length < b.length)\n return true;\n return a < b;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi,false);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n for(char e = 'a'; e <= 'z'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\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 s = readln.strip;\n bool[] one = new bool[](26 + 1);\n bool[] two = new bool[](26 * 26 + 1);\n bool[] three = new bool[](26 * 26 * 26 + 1);\n foreach (i ; 0 .. s.length) {\n one[s[i] - 'a'] = true;\n if (i + 1 < s.length)\n two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;\n if (i + 2 < s.length)\n three[(s[i] - 'a') * 26 * 26 + (s[i + 1] - 'a') * 26 + (s[i + 2] - 'a')] = true;\n }\n long x1 = one.countUntil(false);\n long x2 = two.countUntil(false);\n long x3 = three.countUntil(false);\n auto result1 = ['a'];\n auto result2 = ['a', 'a'];\n auto result3 = ['a', 'a', 'a'];\n if (x1 < 26) {\n result1[0] += x1;\n writefln(\"%s\", result1.idup);\n } else if (x2 < 26 * 26) {\n result2[0] += x2 / 26;\n result2[1] += x2 % 26;\n writefln(\"%s\", result2.idup);\n } else {\n result3[0] += x3 / (26 * 26);\n result3[1] += (x3 / 26) % 26;\n result3[2] += x3 % 26;\n writefln(\"%s\", result3.idup);\n }\n }\n}\n"}, {"source_code": "import std.container;\r\nimport std.stdio;\r\nimport std.conv;\r\n\r\nvoid main() {\r\n int t;\r\n readf(\"%s\\n\", &t);\r\n\r\n while(t--) {\r\n int n;\r\n readf(\"%s\\n\", &n);\r\n string s;\r\n readf(\"%s\\n\", &s);\r\n auto rbt = new RedBlackTree!string;\r\n\r\n for(int k = 1; k <= 3; ++k)\r\n for(int i = 0; i <= n-k; ++i)\r\n rbt.insert(s[i..i+k]);\r\n \r\n string abc = \"abcdefghijklmnopqrstuvwxyz\";\r\n auto q = DList!string();\r\n for(char c = 'a'; c <= 'z'; ++c) {\r\n q.insert(c.to!string);\r\n }\r\n\r\n while(!q.empty) {\r\n auto p = q.front();\r\n q.removeFront();\r\n if(!(p in rbt)) {\r\n p.writeln;\r\n break;\r\n }\r\n foreach(char l; abc)\r\n q.insertBack(p ~ l);\r\n }\r\n }\r\n}\r\n\r\n"}], "negative_code": [{"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length < b.length)\n return true;\n else if(a.length == b.length)\n return a < b;\n else\n return false;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n /*\n for(char e = 'a'; e <= 'z'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n */\n }\n }\n\n rbtree.insert(\"aaa\");\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length < b.length)\n return true;\n else if(a.length == b.length)\n return a < b;\n else\n return false;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n /*\n for(char e = 'a'; e <= 'z'; ++e) {\n string three = [c, d, e];\n rbtree.insert(three);\n }\n */\n }\n }\n\n rbtree.insert(\"aaa\");\n rbtree.writeln;\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length < b.length)\n return true;\n return a < b;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n }\n }\n rbtree.insert(\"aaa\");\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "// Vicfred\n// https://codeforces.com/contest/1536/problem/B\n// brute force, constructive\nimport std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.stdio;\n\nbool lexi(string a, string b) {\n if(a.length < b.length)\n return true;\n return a < b;\n}\n\nvoid main() {\n auto rbtree = new RedBlackTree!(string,lexi);\n for(char c = 'a'; c <= 'z'; ++c) {\n string one = [c];\n rbtree.insert(one);\n for(char d = 'a'; d <= 'z'; ++d) {\n string two = [c, d];\n rbtree.insert(two);\n }\n }\n\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int n;\n readf(\"%s\\n\", &n);\n string s;\n readf(\"%s\\n\", &s);\n\n foreach(item; rbtree) {\n if(count(s, item) > 0) {\n continue;\n }\n item.writeln;\n break;\n }\n}\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\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 s = readln.strip;\n bool[] one = new bool[](26 + 1);\n bool[] two = new bool[](26 * 26 + 1);\n bool[] three = new bool[](26 * 26 * 26 + 1);\n foreach (i ; 0 .. s.length) {\n one[s[i] - 'a'] = true;\n if (i + 1 < s.length)\n two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;\n if (i + 2 < s.length)\n three[(s[i] - 'a') * 26 * 26 + (s[i + 1] - 'a') * 26 + (s[i + 2] - 'a')] = true;\n }\n long x1 = one.countUntil(false);\n long x2 = two.countUntil(false);\n long x3 = three.countUntil(false);\n auto result1 = ['a'];\n auto result2 = ['a', 'a'];\n auto result3 = ['a', 'a', 'a'];\n if (x1 < 26) {\n result1[0] += x1;\n writefln(\"%s\", result1.idup);\n } else if (x2 < 26 * 26) {\n result2[0] += x2 / 26;\n result2[1] += x2 % 26;\n writefln(\"%s\", result2.idup);\n } else {\n result3[0] += x2 / (26 * 26);\n result3[1] += (x2 / 26) % 26;\n result3[2] += x2 % 26;\n writefln(\"%s\", result3.idup);\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\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 s = readln.strip;\n bool[] one = new bool[](26 + 1);\n bool[] two = new bool[](26 * 26 + 1);\n foreach (i ; 0 .. s.length) {\n one[s[i] - 'a'] = true;\n if (i + 1 < s.length)\n two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;\n }\n long x1 = one.countUntil(false);\n long x2 = two.countUntil(false);\n auto result1 = ['a'];\n auto result2 = ['a', 'a'];\n if (x1 < 26) {\n result1[0] += x1;\n writefln(\"%s\", result1.idup);\n } else {\n result2[0] += x2 / 26;\n result2[1] += x2 % 26;\n writefln(\"%s\", result2.idup);\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\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 s = readln.strip;\n bool[] one = new bool[](26);\n bool[] two = new bool[](26 * 26);\n foreach (i ; 0 .. s.length) {\n one[s[i] - 'a'] = true;\n if (i + 1 < s.length)\n two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;\n }\n long x1 = one.countUntil(false);\n long x2 = two.countUntil(false);\n auto result1 = ['a'];\n auto result2 = ['a', 'a'];\n if (x1 < one.length) {\n result1[0] += x1;\n writefln(\"%s\", result1.idup);\n } else {\n result2[0] += x2 / 26;\n result2[1] += x2 % 26;\n writefln(\"%s\", result2.idup);\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\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 s = readln.strip;\n bool[] one = new bool[](26);\n bool[] two = new bool[](26 * 26);\n foreach (i ; 0 .. s.length) {\n one[s[i] - 'a'] = true;\n if (i + 1 < s.length)\n two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;\n }\n long x1 = one.countUntil(false);\n long x2 = two.countUntil(false);\n auto result1 = ['a'];\n auto result2 = ['a', 'a'];\n if (x1 < one.length) {\n result1[0] += x1;\n writefln(\"%s\", result1.to!string);\n } else {\n result2[0] += x2 / 26;\n result2[1] += x2 % 26;\n writefln(\"%s\", result2.to!string);\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\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 s = readln.strip;\n bool[] one = new bool[](26);\n bool[] two = new bool[](26 * 26);\n foreach (i ; 0 .. s.length) {\n one[s[i] - 'a'] = true;\n if (i + 1 < s.length)\n two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;\n }\n long x1 = one.countUntil(false);\n long x2 = two.countUntil(false);\n auto result1 = ['a'];\n auto result2 = ['a', 'a'];\n if (x1 < one.length) {\n result1[0] += x1;\n writefln(\"%s\", result1);\n } else {\n result2[0] += x2 / 26;\n result2[1] += x2 % 26;\n writefln(\"%s\", result2);\n }\n }\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;\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 s = readln.strip;\n bool[] one = new bool[](26);\n bool[] two = new bool[](26 * 26);\n foreach (i ; 0 .. s.length) {\n one[s[i] - 'a'] = true;\n if (i + 1 < s.length)\n two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;\n }\n long x1 = one.countUntil(false);\n long x2 = two.countUntil(false);\n char[1] result1 = \"a\";\n char[2] result2 = \"aa\";\n if (x1 < one.length) {\n result1[0] += x1;\n writefln(\"%s\", result1);\n } else {\n result2[0] += x2 / 26;\n result2[1] += x2 % 26;\n writefln(\"%s\", result2);\n }\n }\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\ndchar[] getStr(ll num){\n dchar[] res;\n while(num > 0){\n ll cr = (num % 26) - 1;\n if(cr >= 0){\n res ~= to!dchar(cr + 'a');\n }\n num /= 26;\n }\n res.reverse;\n return res;\n}\n\nint makeNum(dchar[] w, int st, int end){\n int res = 0;\n for(int i = st; i <= end; ++i){\n dchar cr = w[i];\n res *= 26;\n res += (cr - 'a' + 1);\n }\n return res;\n}\n\nvoid theCode(){\n ll n = scan;\n auto word = scan!(dchar[]);\n auto freq = new ll[](2000);\n for(int j = 0; j < 3; ++j){\n for(int i = 0; i < n - j; ++i){\n int num = makeNum(word, i, i+j);\n if(num < 2000){\n ++freq[num];\n }\n }\n }\n for(int i = 1; i < 2000; ++i){\n if(!freq[i]){\n writeln(getStr(i));\n return;\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"}], "src_uid": "83a665723ca4e40c78fca20057a0dc99"} {"source_code": "// Taken from https://codeforces.com/contest/1760/submission/182072909\n// and rewritten a bit to get rid of C/C++ style scanf/printf and\n// imperative loops\n\nimport std;\n\nvoid main()\n{\n foreach (t ; readln.strip.to!int.iota) {\n int m = 0, M = 0, n = readln.strip.to!int;\n\n // calculate 'm' and 'M' in a single pass while reading the array\n auto a = readln.splitter.map!((x) { auto k = x.to!int;\n if (k > M) {\n m = M;\n M = k;\n } else if (k > m) {\n m = k;\n }\n return k; }).array;\n\n a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!\"%(%s %)\";\n }\n}\n", "positive_code": [{"source_code": "// Taken from https://codeforces.com/contest/1760/submission/182072909\n// and rewritten a bit to get rid of C/C++ style scanf/printf and\n// imperative loops. Allocate the array on stack. Bring back printf.\n\nimport std;\n\nvoid main()\n{\n int[200000] arr = void;\n foreach (t ; readln.strip.to!int.iota) {\n int m = 0, M = 0, n = readln.strip.to!int;\n auto a = arr[0 .. n];\n\n // calculate 'm' and 'M' in a single pass while reading the array\n readln.splitter.map!((x) { auto k = x.to!int;\n if (k > M) {\n m = M;\n M = k;\n } else if (k > m) {\n m = k;\n }\n return k; }).copy(a);\n\n foreach (k ; a)\n printf(\"%d \", (k == M) ? (k - m) : (k - M));\n printf(\"\\n\");\n }\n}\n"}, {"source_code": "// Taken from https://codeforces.com/contest/1760/submission/182072909\n// and rewritten a bit to get rid of C/C++ style scanf/printf and\n// imperative loops. Allocate the array on stack.\n\nimport std;\n\nvoid main()\n{\n int[200000] arr = void;\n foreach (t ; readln.strip.to!int.iota) {\n int m = 0, M = 0, n = readln.strip.to!int;\n auto a = arr[0 .. n];\n\n // calculate 'm' and 'M' in a single pass while reading the array\n readln.splitter.map!((x) { auto k = x.to!int;\n if (k > M) {\n m = M;\n M = k;\n } else if (k > m) {\n m = k;\n }\n return k; }).copy(a);\n a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!\"%(%s %)\";\n }\n}\n"}, {"source_code": "import std;\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 auto seg = a.Segtree!(int, (x, y) => max(x, y), () => 0);\n n.iota.map!(i => a[i] - max(seg.prod(0, i), seg.prod(i + 1, n)))\n .writefln!\"%(%s %)\";\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": "// Taken from https://codeforces.com/contest/1760/submission/182072909\n// and rewritten a bit to get rid of C/C++ style scanf/printf and\n// imperative loops. Also added \".take(n)\"\n\nimport std;\n\nvoid main()\n{\n foreach (t ; readln.strip.to!int.iota) {\n int m = 0, M = 0, n = readln.strip.to!int;\n\n // calculate 'm' and 'M' in a single pass while reading the array\n auto a = readln.splitter.map!((x) { auto k = x.to!int;\n if (k > M) {\n m = M;\n M = k;\n } else if (k > m) {\n m = k;\n }\n return k; }).take(n).array;\n\n a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!\"%(%s %)\";\n }\n}\n"}, {"source_code": "import std;\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 auto seg = a.Segtree!(int, (x, y) => max(x, y), () => 0);\n int[] ans;\n foreach (i ; 0 .. a.length.to!int) {\n int best = max(seg.prod(0, i), seg.prod(i + 1, n));\n ans ~= a[i] - best;\n }\n writefln(\"%(%s %)\", 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.stdio;\r\nimport std.algorithm;\r\nimport std.math;\r\nimport std.conv;\r\n//import std.numeric;\r\n//import std.range;\r\nimport std.array;\r\n//import std.bigint;\r\nimport std.string;\r\n\r\nvoid sol(){\r\n\r\n int n, k, m=0, M=0;\r\n int[200000] arr;\r\n\r\n scanf(\"%d\",&n);\r\n \r\n foreach(i; 0..n){\r\n scanf(\"%d \",&k);\r\n arr[i] = k;\r\n\r\n if(k>M){\r\n m=M;\r\n M=k;\r\n }\r\n else if(k>m){\r\n m=k;\r\n }\r\n }\r\n\r\n foreach(i; 0..n){\r\n k = arr[i];\r\n if (k==M){\r\n printf(\"%d \", k-m);\r\n }\r\n else{\r\n printf(\"%d \", k-M);\r\n }\r\n }\r\n printf(\"\\n\");\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.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 (_; 0..t)\r\n {\r\n auto n = readln().strip().to!int;\r\n auto s = readln().strip().split().map!(e=>e.to!int).array;\r\n auto sorted = s.dup;\r\n sorted.sort;\r\n\r\n foreach (e; s)\r\n {\r\n if (e == sorted[$-1])\r\n {\r\n writef(\"%d \", e - sorted[$-2]);\r\n }\r\n else\r\n {\r\n writef(\"%d \", e - sorted[$-1]);\r\n }\r\n }\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio;\r\nimport std.algorithm;\r\nimport std.math;\r\nimport std.conv;\r\n//import std.numeric;\r\n//import std.range;\r\nimport std.array;\r\n//import std.bigint;\r\nimport std.string;\r\n\r\nvoid sol(){\r\n\r\n int n, k, m=0, M=0;\r\n int[200000] arr;\r\n\r\n scanf(\"%d\",&n);\r\n \r\n foreach(i; 0..n){\r\n scanf(\"%d \",&k);\r\n arr[i] = k;\r\n\r\n if(k>M){\r\n M=k;\r\n }\r\n else if(k>m){\r\n m=k;\r\n }\r\n }\r\n\r\n foreach(i; 0..n){\r\n k = arr[i];\r\n if (k==M){\r\n printf(\"%d \", k-m);\r\n }\r\n else{\r\n printf(\"%d \", k-M);\r\n }\r\n }\r\n printf(\"\\n\");\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}"}], "src_uid": "7965b6ce237b02617b55dc175ffa0451"} {"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 n = read.to!long;\n\tlong m = read.to!long;\n\t\n\tNode[] nodes;\n\tforeach(i; 0 .. n) nodes ~= new Node(i, 0);\n\t\n\tforeach(nd; nodes){\n\t\tnd.group = new Group(nd);\n\t}\n\t\n\tEdge[] edges;\n\tforeach(i; 0 .. m){\n\t\tlong k = read.to!long;\n\t\tif(k > 0){\n\t\t\tint a = read.to!int - 1;\n\t\t\tforeach(j; 1 .. k){\n\t\t\t\tint b = read.to!int - 1;\n\t\t\t\tedges ~= new Edge(nodes[a], nodes[b], 1);\n\t\t\t}\n\t\t}\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) ans ~= nd.group.nodes.length;\n\t\n\tans.map!(to!string).join(\" \").writeln;\n\t\n}\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}\n}\n\nclass Group{\n\tlong value;\n\tlong pendingEdgeCount;\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(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.pendingEdgeCount += gp.pendingEdgeCount;\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.random;\nimport std.datetime.systime : Clock;\n\nclass DisjointSet {\n private:\n int [] p, h;\n int n;\n public:\n this (int _n) {\n n = _n;\n p = iota (0, n).array;\n h = new int[n];\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 } else if (h[i] > h[j]) {\n p[j] = i;\n } else {\n p[i] = j;\n ++h[j];\n }\n }\n }\n int biggest_set_size () pure {\n auto c = new int[n];\n foreach (i; 0 .. n) {\n ++c[findSet (i)];\n }\n return c.reduce! (max);\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\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!uint, m = r.next!uint;\n auto ds = new DisjointSet (n);\n foreach (group; 0 .. m) {\n immutable k = r.next!uint;\n auto x = r.nextA!uint (k);\n foreach (i; 1 .. k) {\n ds.merge (x[i] - 1, x[i-1] - 1);\n }\n }\n auto c = new int[n];\n foreach (i; 0 .. n) {\n ++c[ds.findSet (i)];\n }\n int[] res;\n res.reserve (n);\n foreach (i; 0 .. n) {\n res ~= c[ds.findSet (i)];\n }\n writefln (\"%(%s %)\", res);\n}\n\n"}, {"source_code": "module _;\nvoid main() {\n\timport std.stdio;\n\timport std.algorithm;\n\timport std.array, std.range;\n\tint n,m;\n\tint[] pa, h, sz;\n\treadf(\"%s %s \", &n, &m);\n\tpa = iota(n).array;\n\th = new int[n];\n\tsz = new int[n];\n\th[] = 1;\n\tsz[] = 1;\n\n\tint getpa(int a) {\n\t\tif (pa[a] == a) {\n\t\t\treturn a;\n\t\t}\n\t\tpa[a] = getpa(pa[a]);\n\t\treturn pa[a];\n\t}\n\tvoid merge(int a, int b) {\n\t\tint paa = getpa(a), pab = getpa(b);\n\t\tif (paa == pab) {\n\t\t\treturn;\n\t\t}\n\t\tif (h[paa] > h[pab]) {\n\t\t\tpa[pab] = paa;\n\t\t\tsz[paa] += sz[pab];\n\t\t} else {\n\t\t\tpa[paa] = pab;\n\t\t\tsz[pab] += sz[paa];\n\t\t\tif (h[paa] == h[pab]) {\n\t\t\t\th[pab]++;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach(i; 0..m) {\n\t\tint k;\n\t\treadf(\"%s \", &k);\n\t\tif (k) {\n\t\t\tint mem0;\n\t\t\treadf(\"%s \", &mem0);\n\t\t\tforeach(j; 1..k) {\n\t\t\t\tint mem;\n\t\t\t\treadf(\"%s \", &mem);\n\t\t\t\tmerge(mem-1, mem0-1);\n\t\t\t}\n\t\t}\n\t}\n\tforeach(i; 0..n) {\n\t\twritef(\"%s \", sz[getpa(i)]);\n\t}\n\twriteln;\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 uf = new UnionFind(N);\n foreach (_; 0..M) {\n auto A = readln.split.map!(to!int).array;\n foreach (i; 2..A.length.to!int) {\n uf.unite(A[1]-1, A[i]-1);\n }\n }\n N.iota.map!(i => -uf.table[uf.find(i)]).map!(to!string).join(\" \").writeln;\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}"}], "negative_code": [{"source_code": "module _;\nvoid main() {\n\timport std.stdio;\n\timport std.algorithm;\n\timport std.array, std.range;\n\tint n,m;\n\tint[] pa, h, sz;\n\treadf(\"%s %s \", &n, &m);\n\tpa = iota(n).array;\n\th = new int[n];\n\tsz = new int[n];\n\th[] = 1;\n\tsz[] = 1;\n\n\tint getpa(int a) {\n\t\tif (pa[a] == a) {\n\t\t\treturn a;\n\t\t}\n\t\tpa[a] = getpa(pa[a]);\n\t\treturn pa[a];\n\t}\n\tvoid merge(int a, int b) {\n\t\tint paa = getpa(a), pab = getpa(b);\n\t\tif (h[paa] > h[pab]) {\n\t\t\tpa[pab] = paa;\n\t\t\tsz[paa] += sz[pab];\n\t\t} else {\n\t\t\tpa[paa] = pab;\n\t\t\tsz[pab] += sz[paa];\n\t\t\tif (h[paa] == h[pab]) {\n\t\t\t\th[pab]++;\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach(i; 0..m) {\n\t\tint k;\n\t\treadf(\"%s \", &k);\n\t\tint mem0;\n\t\tif (k) {\n\t\t\treadf(\"%s \", &mem0);\n\t\t\tforeach(j; 1..k) {\n\t\t\t\tint mem;\n\t\t\t\treadf(\"%s \", &mem);\n\t\t\t\tmerge(mem-1, mem0-1);\n\t\t\t}\n\t\t}\n\t}\n\tforeach(i; 0..n) {\n\t\twritef(\"%s \", sz[getpa(i)]);\n\t}\n\twriteln;\n}\n"}], "src_uid": "a7e75ff150d300b2a8494dca076a3075"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1421/problem/A\n//\nimport std.stdio;\n\nvoid main() {\n long t;\n readf(\"%s\\n\", &t);\n\n long a, b;\n while(t--) {\n readf(\"%s %s\\n\", &a, &b);\n\n long bits = 0L;\n\n for(int i = 0; i < 32; i++)\n if(a&(1<= 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 a = RD!int;\n\t\tauto b = RD!int;\n\n\t\tauto x = a & b;\n\t\tans[ti] = (a ^ x) + (b ^ x);\n\t}\n\t\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "4be3698735278f29b307a7060eb69693"} {"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 h1, a1, c1;\n int h2, a2;\n\n scan(h1, a1, c1);\n scan(h2, a2);\n\n auto cmd = [\"STRIKE\", \"HEAL\"];\n\n auto ans = new string[](0);\n\n while (h2 > 0) {\n if (h2 > a1 && h1 <= a2) {\n ans ~= cmd[1];\n h1 += c1;\n }\n else {\n ans ~= cmd[0];\n h2 -= a1;\n }\n\n h1 -= a2;\n }\n\n writeln(ans.length);\n foreach (ai ; ans) {\n writeln(ai);\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\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 h1, a1, c1;\n\tread(h1, a1, c1);\n\tint h2, a2;\n\tread(h2, a2);\n\tstring[] ans;\n\twhile (h2 > 0)\n\t{\n\t\tif (a1 >= h2)\n\t\t{\n\t\t\tans ~= \"STRIKE\";\n\t\t\tbreak;\n\t\t}\n\t\telse if (a2 >= h1)\n\t\t{\n\t\t\tans ~= \"HEAL\";\n\t\t\th1 += c1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans ~= \"STRIKE\";\n\t\t\th2 -= a1;\n\t\t}\n\t\th1 -= a2;\n\t}\n\twriteln(ans.length);\n\tforeach (s; ans)\n\t{\n\t\twriteln(s);\n\t}\n}\n"}], "negative_code": [], "src_uid": "d497431eb37fafdf211309da8740ece6"} {"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 int lastOdd = 1;\r\n int lastEven = 0;\r\n foreach(a; A) {\r\n if (a % 2 == 0) {\r\n if (lastOdd > a) return YESNO[false];\r\n lastOdd = a;\r\n } else {\r\n if (lastEven > a) return YESNO[false];\r\n lastEven = a;\r\n }\r\n }\r\n \r\n return YESNO[true];\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>>\".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.stdio, std.string, std.conv;\r\nimport std.algorithm.iteration;\r\nimport std.algorithm.searching;\r\nimport std.algorithm.mutation;\r\nimport std.range;\r\nimport std.typecons;\r\nvoid solution(ref File input, ref File output) {\r\n auto t = input.readln.chomp.to!int;\r\n while (t-- > 0) {\r\n auto _ = input.readln;\r\n auto source = input.readln.chomp\r\n .split(' ')\r\n .map!(to!int);\r\n int max_e = -1, max_o = -1;\r\n foreach(item; source)\r\n {\r\n if (item % 2) {\r\n if (max_o > item)\r\n {\r\n output.writeln(\"No\");\r\n goto end;\r\n } else\r\n {\r\n max_o = item;\r\n }\r\n\r\n } else\r\n {\r\n if (max_e > item)\r\n {\r\n output.writeln(\"No\");\r\n goto end;\r\n } else\r\n {\r\n max_e = item;\r\n }\r\n\r\n }\r\n }\r\n output.writeln(\"Yes\");\r\n end:\r\n }\r\n}\r\nvoid main()\r\n{\r\n File input, output;\r\n debug(1) {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n solution(input, output);\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\r\nimport std.algorithm.iteration;\r\nimport std.algorithm.searching;\r\nimport std.algorithm.mutation;\r\nimport std.range;\r\nimport std.typecons;\r\nvoid solution(ref File input, ref File output) {\r\n auto t = input.readln.chomp.to!int;\r\n while (t-- > 0) {\r\n auto _ = input.readln;\r\n auto source = input.readln.chomp\r\n .split(' ')\r\n .map!(to!int);\r\n int max_e = -1, max_o = -1;\r\n foreach(item; source)\r\n {\r\n if (item % 2) {\r\n if (max_o > item)\r\n {\r\n output.writeln(\"No\");\r\n goto end;\r\n }\r\n if (max_o == -1)\r\n {\r\n max_o = item;\r\n }\r\n\r\n } else\r\n {\r\n if (max_e > item)\r\n {\r\n output.writeln(\"No\");\r\n goto end;\r\n }\r\n if (max_e == -1)\r\n {\r\n max_e = item;\r\n }\r\n\r\n }\r\n }\r\n output.writeln(\"Yes\");\r\n end:\r\n }\r\n}\r\nvoid main()\r\n{\r\n File input, output;\r\n debug(1) {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n solution(input, output);\r\n}\r\n"}], "src_uid": "a97e70ad20a337d12dcf79089c16c9f0"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 abc = RDA;\n\t\tabc.sort!\"a > b\"();\n\t\tforeach (ref e; abc)\n\t\t{\n\t\t\tif (e != 0)\n\t\t\t{\n\t\t\t\t++ans[ti];\n\t\t\t\t--e;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..2)\n\t\t{\n\t\t\tforeach (j; i+1..3)\n\t\t\t{\n\t\t\t\tif (abc[i] != 0 && abc[j] != 0)\n\t\t\t\t{\n\t\t\t\t\t++ans[ti];\n\t\t\t\t\t--abc[i];\n\t\t\t\t\t--abc[j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (abc[0] != 0 && abc[1] != 0 && abc[2] != 0)\n\t\t\t++ans[ti];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}", "positive_code": [{"source_code": "module main;\n\nimport 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 core.bitop : popcnt;\n import std.algorithm : max;\n\n IO io;\n int T = io.readInt;\n while (T--) {\n int[3] count;\n for (int i = 0; i < 3; ++i) {\n count[i] = io.readInt;\n }\n int result = 0;\n for (int mask = 0; mask < 1 << 8; mask += 2) {\n bool ok = true;\n for (int i = 0; i < 3; ++i) {\n int c = count[i];\n for (int s = 0; s < 8; ++s) {\n if ((s >> i & 1) && (mask >> s & 1)) {\n c--;\n }\n }\n ok &= c >= 0;\n }\n if (ok) {\n result = max(result, popcnt(mask));\n }\n }\n writeln(result);\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.range;\nimport std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, std.random, core.bitop;\n\nenum inf = 1_001_001_001;\nenum infl = 1_001_001_001_001_001_001L;\n\n\nvoid main() {\n int t;\n scan(t);\n\n while (t--) {\n int a, b, c;\n scan(a, b, c);\n auto ans = solve(a, b, c);\n writeln(ans);\n }\n}\n\nint solve(int a, int b, int c) {\n int res;\n\n foreach (comb ; 0 .. 1 << (1 << 3)) {\n auto x = new int[](3);\n\n foreach (i ; 0 .. 1 << 3) if (comb & 1 << i) {\n foreach (j ; 0 .. 3) if (i & 1 << j) {\n x[j]++;\n }\n }\n\n if (x[0] <= a && x[1] <= b && x[2] <= c) {\n chmax(res, comb.popcnt);\n }\n }\n\n res--;\n\n return res;\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\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\nbool chmin(T, U...)(ref T x, U args) {\n bool isChanged;\n\n foreach (arg; args) {\n if (x > arg) {\n x = arg;\n isChanged = true;\n }\n }\n\n return isChanged;\n}\n\nbool chmax(T, U...)(ref T x, U args) {\n bool isChanged;\n\n foreach (arg; args) {\n if (x < arg) {\n x = arg;\n isChanged = true;\n }\n }\n\n return isChanged;\n}\n"}], "negative_code": [], "src_uid": "98a8fc06e8265bbf9c16ee3c7b9d0223"} {"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 \n long ans = 1;\n if (A % B != 0) {\n chmax(ans, A);\n }\n \n long[] ps;\n long b = B;\n for (long p = 2; p^^2 <= b; ++p) {\n if (b % p == 0) {\n do {\n b /= p;\n } while (b % p == 0);\n ps ~= p;\n }\n }\n if (b > 1) {\n ps ~= b;\n }\n \n foreach (p; ps) {\n long a = A;\n for (; a % B == 0; a /= p) {}\n chmax(ans, a);\n }\n \n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "// a \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\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 \n long ans = 1;\n if (A % B != 0) {\n chmax(ans, A);\n }\n \n long[] ps;\n long b = B;\n for (long p = 2; p^^2 <= b; ++p) {\n if (b % p == 0) {\n do {\n b /= p;\n } while (b % p == 0);\n ps ~= p;\n }\n }\n if (b > 1) {\n ps ~= b;\n }\n \n foreach (p; ps) {\n long a = A;\n for (; a % B == 0; a /= p) {}\n chmax(ans, a);\n }\n \n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nll[] primes;\n\nvoid play(){\n ll p, q;\n p = rd; q = rd;\n ll P = p, Q = q;\n\n // Base\n if(p % q != 0){\n writeln(p);\n return;\n }\n\n // Prime Factorize\n ll[] pfact;\n int[] cntp;\n foreach(prime; primes){\n int isin = 0;\n while(q % prime == 0 && q > 1){\n q /= prime;\n ++isin;\n }\n if(isin){\n pfact ~= prime;\n cntp ~= isin;\n }\n }\n if(q != 1){ pfact ~= q; cntp ~= 1; }\n show(pfact);\n\n ll mindiv = -1;\n foreach(i; 0.. pfact.length){\n ll prime = pfact[i];\n ll k = 1;\n while(p % prime == 0 && p > 1){\n p /= prime;\n k *= prime;\n }\n foreach(j; 1..cntp[i]){\n k /= prime;\n }\n show(k);\n if(mindiv == -1){\n mindiv = k;\n }else{\n mindiv = min(mindiv, k);\n }\n show(mindiv);\n }\n writeln(P/mindiv);\n}\n\nint main(){\n // Sieve\n const int SZ = 100000;\n ll[SZ+1] notprime;\n foreach(p; 2..1000){\n if(!notprime[p]){\n for(int div = p*p; div <= SZ; div += p){\n notprime[div] = 1;\n }\n }\n }\n foreach(i; 2..SZ){\n if(!notprime[i]){\n primes ~= i.to!long;\n }\n }\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"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint [] divisors (int n)\n{\n\tint [] res;\n\tfor (int d = 2; d * d <= n; d++)\n\t{\n\t\tif (n % d == 0)\n\t\t{\n\t\t\tres ~= d;\n\t\t\twhile (n % d == 0)\n\t\t\t{\n\t\t\t\tn /= d;\n\t\t\t}\n\t\t}\n\t}\n\tif (n > 1)\n\t{\n\t\tres ~= n;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\tlong p;\n\t\tint q;\n\t\treadf !(\" %s %s\") (p, q);\n\t\tauto d = divisors (q);\n\n\t\tlong res = 1;\n\n\t\tvoid recur (long cur, int i)\n\t\t{\n\t\t\tif (cur % q != 0)\n\t\t\t{\n\t\t\t\tres = max (res, cur);\n\t\t\t}\n\t\t\tif (i >= d.length)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\t\t\trecur (cur, i + 1);\n\t\t\twhile (cur % d[i] == 0)\n\t\t\t{\n\t\t\t\tcur /= d[i];\n\t\t\t\trecur (cur, i + 1);\n\t\t\t}\n\t\t}\n\n\t\trecur (p, 0);\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nll[] primes;\n\nvoid play(){\n ll p, q;\n p = rd; q = rd;\n ll P = p, Q = q;\n\n // Base\n if(p % q != 0){\n writeln(p);\n return;\n }\n\n // Prime Factorize\n ll[] pfact;\n foreach(prime; primes){\n bool isin = 0;\n while(q % prime == 0 && q > 1){\n q /= prime;\n isin = 1;\n }\n if(isin){\n pfact ~= prime;\n }\n }\n if(q != 1){ pfact ~= q; }\n show(pfact);\n\n ll mindiv = -1;\n foreach(ll prime; pfact){\n ll k = 1;\n while(p % prime == 0 && p > 1){\n p /= prime;\n k *= prime;\n }\n show(k);\n if(mindiv == -1){\n mindiv = k;\n }else{\n mindiv = min(mindiv, k);\n }\n show(mindiv);\n }\n writeln(P/mindiv);\n}\n\nint main(){\n // Sieve\n const int SZ = 100000;\n ll[SZ+1] notprime;\n foreach(p; 2..1000){\n if(!notprime[p]){\n for(int div = p*p; div <= SZ; div += p){\n notprime[div] = 1;\n }\n }\n }\n foreach(i; 2..SZ){\n if(!notprime[i]){\n primes ~= i.to!long;\n }\n }\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"}], "src_uid": "2ced6a414a9752e7c50d37e1e1c8ffd7"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.utf;\n\nauto savings (R) (R r)\n{\n\tint balance = 0;\n\tint res = 0;\n\tforeach (const ref cur; r)\n\t{\n\t\tbalance += cur ? +1 : -1;\n\t\tbalance = max (balance, 0);\n\t\tres = max (res, balance);\n\t}\n\treturn res;\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\treadln;\n\t\tauto s = readln.strip.map !(q{a == '1'}).array;\n\t\tint total = s.sum;\n\t\tint res = total;\n\t\tforeach (start; 0..k)\n\t\t{\n\t\t\tres = min (res, total -\n\t\t\t savings (s.drop (start).stride (k)));\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\nvoid main(string[] args)\n{\n auto t = next!int;\n tcl: foreach(tc; 0 .. t)\n {\n auto n = next!int;\n auto k = next!int;\n auto s = next!char(n);\n auto totalModuloCount = new int[](k);\n auto rightModuloCount = new int[](k);\n auto no1s = s.count!(c => c == '1');\n foreach(i, c; s) if (c == '1') totalModuloCount[cast(int)i % k]++;\n rightModuloCount[] = totalModuloCount[];\n auto bestEnding = new int[](n);\n auto bestEndingPerClass = new int[](k);\n debug writeln(totalModuloCount);\n bestEndingPerClass[] = 1_000_000_0;\n foreach(i; 0 .. n)\n\t{\n\t auto moduloClass = cast(int) i % k;\n\t if (s[i] == '1')\n\t {\n\t rightModuloCount[moduloClass]--;\n\t }\n\t if (i - k >= 0)\n\t {\n\t debug\n\t\t{\n\t\t if (i == 3)\n\t\t {\n\t\t writeln(\"current cost: \", - int(s[i] == '1') + int(s[i] != '1'));\n\t\t writeln(bestEnding);\n\t\t writeln(\"comparing \", totalModuloCount[moduloClass] - int(s[i] == '1') + int(s[i] != '1'),\n\t\t\t \" with \", bestEnding[i - k] - int(s[i] == '1') + int(s[i] != '1'));\n\t\t }\n\t\t}\n\t bestEnding[i] = min(totalModuloCount[moduloClass] - int(s[i] == '1') + int(s[i] != '1'),\n\t\t\t\t bestEnding[i - k] - int(s[i] == '1') + int(s[i] != '1'));\n\t }\n\t else\n\t {\n\t bestEnding[i] = totalModuloCount[moduloClass] - int(s[i] == '1') + int(s[i] != '1');\n\t }\n\t bestEndingPerClass[moduloClass] = min(bestEndingPerClass[moduloClass],\n\t\t\t\t\t\tbestEnding[i]);\n\t}\n debug writeln(bestEnding);\n debug writeln(bestEndingPerClass);\n int bestTotal = cast(int)no1s;\n foreach(cl; 0 .. k)\n\t{\n\t bestTotal = min(bestTotal, bestEndingPerClass[cl] + no1s - totalModuloCount[cl]);\n\t}\n bestTotal.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"}], "negative_code": [], "src_uid": "8b28309055f13837eb1f51422fb91029"} {"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 solve(int a, int b) {\n if (a == 0 || b == 0) return 0;\n else return max(a, b) / min(a, b) + solve(max(a, b) % min(a, b), min(a, b));\n}\nvoid main() {\n IO cin;\n int t = 1;\n t = cin.readInt;\n while (t--) {\n int a = cin.readInt;\n int b = cin.readInt;\n int count = 0;\n writeln(solve(a, b));\n } \n}", "positive_code": [{"source_code": "import std.stdio;\n\nint steps (int a, int b)\n{\n\tif (b == 0)\n\t{\n\t\treturn 0;\n\t}\n\treturn a / b + steps (b, a % b);\n}\n\nint main ()\n{\n int tests;\n readf (\" %s\", &tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint a, b;\n\t\treadf (\" %s %s\", &a, &b);\n\t\twritefln (\"%s\", steps (a, b));\n\t}\n\treturn 0;\n}\n"}], "negative_code": [], "src_uid": "5c3eb78a7e15d9afe6d745e1a77d7451"} {"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 mx = a.maxElement;\n if (mx != a[0] && mx != a[$ - 1]) {\n writeln(-1);\n continue;\n }\n if (mx == a[0])\n a = a[1 .. $];\n else\n a = a[0 .. $ - 1];\n writefln(\"%(%s %)\", [mx] ~ a.reverse);\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\tif (a.front == n || a.back == n)\r\n\t\t{\r\n\t\t\ta.retro.writefln !(\"%(%s %)\");\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": "69bbc06c385d51f78ce1f64afffb4cf1"} {"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;\nimport std.math :pow;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n\n\n int t;\n readf(\" %s\", t);\n\n\n int[][] factors = new int[] [1_000_009];\n bool[] primes = new bool [1_000_009];\n primes[] = true;\n foreach(i; 2 .. 1_000_000) {\n if (primes[i]) {\n factors[i] ~= i;\n\n for(uint j = 2*i; j <= 1_000_000; j += i) {\n primes[j] = false;\n factors[j] ~= i;\n }\n }\n }\n\n foreach(q; 0 .. t) {\n \n uint n;\n\n readf(\" %s\", n);\n\n auto d = new int [n];\n int[int] allprimes;\n\n foreach(i; 0 .. n) {\n readf(\" %s\", d[i]);\n\n\n foreach(p; factors[ d[i] ]) {\n int pow = 0;\n int t_ = d[i];\n while ( t_ % p == 0) { pow++; t_ /= p; }\n\n if (p in allprimes) {\n allprimes[p] = max( allprimes[p], pow );\n } else {\n allprimes[p] = pow;\n }\n }\n }\n\n long num_divisors = 1;\n long x =1 ;\n long sp = -1;\n foreach(k,v; allprimes) {\n // writeln(k, \" \", v);\n sp = v;\n num_divisors *= (v+1);\n if (num_divisors > n+2) break;\n x *= pow(k, v);\n }\n\n long ans = -1;\n if (num_divisors > n+2) { writeln(-1); } \n else if (d.canFind(x)) {\n foreach(k, v; allprimes) {\n auto new_num_divisors = num_divisors / (v+1) * (v+2);\n if (new_num_divisors == n+2) {\n auto newx = x * k;\n if (ans == -1) ans = newx; else ans = min(ans, newx);\n }\n }\n\n if (ans != -1) writeln(ans); else writeln(-1);\n }\n else if (n==1) {\n if (primes[d[0]]) writeln(d[0]*d[0]); else writeln(-1);\n } else if (allprimes.length == 1) {\n if (num_divisors == n + 1) {\n writeln(x*sp);\n } else {\n writeln(-1);\n }\n\n } else if (num_divisors != n+2) writeln(-1); \n else {\n writeln(x);\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.string;\n\nvoid solve() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n A.sort();\n\n long ans = -1;\n\n for (int i = 0; i <= N - i - 1; ++i) {\n if (ans == -1) {\n ans = A[i] * A[N-i-1];\n } else if (ans != A[i] * A[N-i-1]) {\n writeln(-1);\n return;\n }\n }\n\n long[] F;\n for (long i = 2; i * i <= ans; ++i) {\n if (ans % i == 0) {\n F ~= i;\n if (i * i != ans) {\n F ~= ans / i;\n }\n }\n }\n F.sort();\n\n writeln(F == A ? ans : -1);\n}\n\nvoid main() {\n auto N = readln.chomp.to!int;\n while (N--) solve;\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 t = read.to!int;\n\t\n\tforeach(q; 0 .. t){\n\t\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!();\n\t\t\n\t\tlong x = as[0] * as[$ - 1];\n\t\tint flag = 1;\n\t\t\n\t\tint k = 0;\n\t\tfor(long d = 2; d * d <= x; d ++){\n\t\t\tif(x % d == 0){\n\t\t\t\tif(as[k] == d && as[$ - 1 - k] == x / d){\n\t\t\t\t\tk += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse flag = -1;\n\t\t\t}\n\t\t} \n\t\tif(k <= n - 1 - k) flag = -1;\n\t\t\n\t\tif(flag < 0) \"-1\".writeln;\n\t\telse x.writeln;\n\t\t\n\t}\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 t = read.to!int;\n\t\n\tforeach(q; 0 .. t){\n\t\t\n\t\tint n = read.to!int;\n\t\tint[] as;\n\t\tforeach(i; 0 .. n) as ~= read.to!int;\n\t\t\n\t\tas.sort!();\n\t\t\n\t\tint x = as[0] * as[$ - 1];\n\t\tint flag = 1;\n\t\t\n\t\tint k = 0;\n\t\tfor(int d = 2; d * d <= x; d ++){\n\t\t\tif(x % d == 0){\n\t\t\t\tif(as[k] == d && as[$ - 1 - k] == x / d){\n\t\t\t\t\tk += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse flag = -1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(as[k] != d) continue;\n\t\t\t\telse flag = -1;\n\t\t\t}\n\t\t} \n\t\tif(k <= n - 1 - k) flag = -1;\n\t\t\n\t\tif(flag < 0) \"-1\".writeln;\n\t\telse x.writeln;\n\t\t\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;\nimport std.math :pow;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n\n\n int t;\n readf(\" %s\", t);\n\n\n int[][] factors = new int[] [1_000_009];\n bool[] primes = new bool [1_000_009];\n primes[] = true;\n foreach(i; 2 .. 1_000_000) {\n if (primes[i]) {\n factors[i] ~= i;\n\n for(uint j = 2*i; j <= 1_000_000; j += i) {\n primes[j] = false;\n factors[j] ~= i;\n }\n }\n }\n\n foreach(q; 0 .. t) {\n \n uint n;\n\n readf(\" %s\", n);\n\n auto d = new int [n];\n int[int] allprimes;\n\n foreach(i; 0 .. n) {\n readf(\" %s\", d[i]);\n\n\n foreach(p; factors[ d[i] ]) {\n int pow = 0;\n int t_ = d[i];\n while ( t_ % p == 0) { pow++; t_ /= p; }\n\n if (p in allprimes) {\n allprimes[p] = max( allprimes[p], pow );\n } else {\n allprimes[p] = pow;\n }\n }\n }\n\n long num_divisors = 1;\n long x =1 ;\n long sp = -1;\n foreach(k,v; allprimes) {\n // writeln(k, \" \", v);\n sp = v;\n num_divisors *= (v+1);\n if (num_divisors > n+2) break;\n x *= pow(k, v);\n }\n\n if (n==1) {\n if (primes[d[0]]) writeln(d[0]*d[0]); else writeln(-1);\n } else if (allprimes.length == 1) {\n if (num_divisors == n + 1) {\n writeln(x*sp);\n } else {\n writeln(-1);\n }\n\n\n } else if (num_divisors != n+2) writeln(-1); \n else {\n writeln(x);\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;\nimport std.math :pow;\n\nalias Tree = RBT!int;\n\nvoid main() {\n GC.disable();\n\n\n\n int t;\n readf(\" %s\", t);\n\n\n int[][] factors = new int[] [1_000_009];\n bool[] primes = new bool [1_000_009];\n primes[] = true;\n foreach(i; 2 .. 1_000_000) {\n if (primes[i]) {\n factors[i] ~= i;\n\n for(uint j = 2*i; j <= 1_000_000; j += i) {\n primes[j] = false;\n factors[j] ~= i;\n }\n }\n }\n\n foreach(q; 0 .. t) {\n \n uint n;\n\n readf(\" %s\", n);\n\n auto d = new int [n];\n int[int] allprimes;\n\n foreach(i; 0 .. n) {\n readf(\" %s\", d[i]);\n\n\n foreach(p; factors[ d[i] ]) {\n int pow = 0;\n int t_ = d[i];\n while ( t_ % p == 0) { pow++; t_ /= p; }\n\n if (p in allprimes) {\n allprimes[p] = max( allprimes[p], pow );\n } else {\n allprimes[p] = pow;\n }\n }\n }\n\n long num_divisors = 1;\n long x =1 ;\n foreach(k,v; allprimes) {\n // writeln(k, \" \", v);\n num_divisors *= (v+1);\n if (num_divisors > n+2) break;\n x *= pow(k, v);\n }\n\n if (n==1) {\n if (primes[d[0]]) writeln(d[0]*d[0]);\n else writeln(-1);\n } else\n if (num_divisors != n+2) writeln(-1); \n else {\n writeln(x);\n }\n\n }\n}\n"}], "src_uid": "fe9b1527571ea37f402512ac378dee13"} {"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// xorshift\nuint xrand() {\n static uint x = 314159265, y = 358979323, z = 846264338, w = 327950288;\n uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;\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; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1, \"modInv: gcd(a, m) != 1\");\n if (b == -1) y = -y;\n return (y < 0) ? (y + m) : y;\n }\n x -= t * y;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1, \"modInv: gcd(a, m) != 1\");\n if (a == -1) x = -x;\n return (x < 0) ? (x + m) : x;\n }\n y -= t * x;\n }\n}\n\n// (a / 2) mod m\nlong div2(long a, long m)\nin {\n assert(1 <= m && m < 1L << 62, \"div2: 1 <= m < 2^62 must hold\");\n assert(m % 2 != 0, \"div2: m must not be divisibly by 3\");\n assert(0 <= a && a < m, \"div2: 0 <= a < m must hold\");\n}\ndo {\n return (a + (a % 2) * m) / 2;\n}\n\n// (a / 3) mod m\nlong div3(long a, long m)\nin {\n assert(1 <= m && m < 1L << 61, \"div3: 1 <= m < 2^61 must hold\");\n assert(m % 3 != 0, \"div3: m must not be divisibly by 3\");\n assert(0 <= a && a < m, \"div3: 0 <= a < m must hold\");\n}\ndo {\n return (a + (((3 - a % 3) * (m % 3)) % 3) * m) / 3;\n}\n\n// Jacobi symbol (a/m)\nint jacobi(long a, long m)\nin {\n assert(m > 0, \"jacobi: m > 0 must hold\");\n assert(m & 1, \"jacobi: m must be odd\");\n}\ndo {\n import core.bitop : bsf;\n import std.algorithm.mutation : swap;\n int s = 1;\n if (a < 0) a = a % m + m;\n for (; m > 1; ) {\n a %= m;\n if (a == 0) return 0;\n const r = bsf(a);\n if ((r & 1) && ((m + 2) & 4)) s = -s;\n a >>= r;\n if (a & m & 2) s = -s;\n swap(a, m);\n }\n return s;\n}\n\n// sqrt(a) (mod p)\n// p: be prime\n// (b + sqrt(b^2 - a))^((p+1)/2) in F_p(sqrt(b^2 - a))\nlong[] modSqrt(long a, long p)\nin {\n assert(p < 1L << 31, \"modSqrt: p < 2^31 must hold\");\n assert(-p * p <= a && a <= p * p, \"modSqrt: -p^2 <= a <= p^2 must hold\");\n}\ndo {\n if (p == 2) return [a & 1];\n const j = jacobi(a, p);\n if (j == 0) return [0];\n if (j == -1) return [];\n long b, d;\n for (; ; ) {\n b = xrand() % p;\n d = (b * b - a) % p;\n if (d < 0) d += p;\n if (jacobi(d, p) == -1) break;\n }\n long[2] multiply(in long[2] x, in long[2] y) {\n return [(x[0] * y[0] + d * ((x[1] * y[1]) % p)) % p,\n (x[0] * y[1] + x[1] * y[0]) % p];\n }\n long[2] f = [b, 1], g = [1, 0];\n for (long e = (p + 1) >> 1; e; e >>= 1) {\n if (e & 1) g = multiply(g, f);\n f = multiply(f, f);\n }\n assert(g[1] == 0);\n return (g[0] < p - g[0]) ? [g[0], p - g[0]] : [p - g[0], g[0]];\n}\n\n// Roots of f0 + f1 T + T^2 in F_p[T] with multiplicity\n// p: prime\nlong[] modRoots2(long f0, long f1, long p)\nin {\n assert(2 <= p && p < 1L << 31, \"modRoots2: 2 <= p < 2^31 must hold\");\n assert(0 <= f0 && f0 < p, \"modRoots2: 0 <= f0 < p must hold\");\n assert(0 <= f1 && f1 < p, \"modRoots2: 0 <= f1 < p must hold\");\n}\ndo {\n import std.algorithm : sort;\n if (p == 2) {\n if (f0 == 0 && f1 == 0) return [0, 0];\n if (f0 == 0 && f1 == 1) return [0, 1];\n if (f0 == 1 && f1 == 0) return [1, 1];\n return [];\n } else {\n const f12 = f1.div2(p);\n auto ts = modSqrt(f12 * f12 - f0, p);\n foreach (ref t; ts) {\n if ((t -= f12) < 0) t += p;\n }\n sort(ts);\n switch (ts.length) {\n case 0: return [];\n case 1: return [ts[0], ts[0]];\n case 2: return ts;\n default: assert(false);\n }\n }\n}\n\n// Roots of f0 + f1 T + f2 T^2 + T^3 in F_p[T] with multiplicity\n// p: prime\nlong[] modRoots3(long f0, long f1, long f2, long p)\nin {\n assert(2 <= p && p <= 1_500_000_001,\n \"modRoots3: 2 <= p <= 1_500_000_001 must hold\");\n assert(0 <= f0 && f0 < p, \"modRoots3: 0 <= f0 < p must hold\");\n assert(0 <= f1 && f1 < p, \"modRoots3: 0 <= f1 < p must hold\");\n assert(0 <= f2 && f2 < p, \"modRoots3: 0 <= f2 < p must hold\");\n}\ndo {\n import std.algorithm : sort;\n if (p == 2) {\n if (f0 == 0 && f1 == 0 && f2 == 0) return [0, 0, 0];\n if (f0 == 0 && f1 == 0 && f2 == 1) return [0, 0, 1];\n if (f0 == 0 && f1 == 1 && f2 == 0) return [0, 1, 1];\n if (f0 == 1 && f1 == 1 && f2 == 1) return [1, 1, 1];\n if (f0 == 0) return [0];\n if ((f0 + f1 + f2 + 1) % 2 == 0) return [1];\n return [];\n } else if (p == 3) {\n if (f0 == 0 && f1 == 0 && f2 == 0) return [0, 0, 0];\n if (f0 == 0 && f1 == 0 && f2 == 2) return [0, 0, 1];\n if (f0 == 0 && f1 == 0 && f2 == 1) return [0, 0, 2];\n if (f0 == 0 && f1 == 1 && f2 == 1) return [0, 1, 1];\n if (f0 == 0 && f1 == 2 && f2 == 0) return [0, 1, 2];\n if (f0 == 0 && f1 == 1 && f2 == 2) return [0, 2, 2];\n if (f0 == 2 && f1 == 0 && f2 == 0) return [1, 1, 1];\n if (f0 == 1 && f1 == 2 && f2 == 2) return [1, 1, 2];\n if (f0 == 2 && f1 == 2 && f2 == 1) return [1, 2, 2];\n if (f0 == 1 && f1 == 0 && f2 == 0) return [2, 2, 2];\n if (f0 == 0) return [0];\n if ((f0 + f1 + f2 + 1) % 3 == 0) return [1];\n if ((f0 - f1 + f2 - 1) % 3 == 0) return [2];\n return [];\n } else {\n // gcd(f0 + f1 T + f2 T^2 + T^3, f1 + 2 f2 T + 3 T^2)\n // remainder: (f0 - f1 f2 / 9) + (2 f1 / 3 - 2 f2^2 / 9) T\n const f13 = f1.div3(p), f23 = f2.div3(p);\n long a0 = (f0 - f13 * f23) % p, a1 = (2 * f13 - 2 * f23 * f23) % p;\n if (a0 < 0) a0 += p;\n if (a1 < 0) a1 += p;\n if (a1 != 0) {\n if ((f13 * ((a1 * a1) % p) - 2 * f23 * ((a0 * a1) % p) + a0 * a0) % p != 0) {\n // gcd = 1\n } else {\n // gcd = a0 + a1 T\n const t2 = ((p - a0) * a1.modInv(p)) % p;\n long t1 = (-f2 - 2 * t2) % p;\n if (t1 < 0) t1 += p;\n auto ts = [t1, t2, t2];\n sort(ts);\n return ts;\n }\n } else if (a0 != 0) {\n // gcd = 1\n } else {\n // gcd = f1 + 2 f2 T + 3 T^2\n const t = (f23 != 0) ? (p - f23) : 0;\n return [t, t, t];\n }\n\n long[3] mul(in long[3] a, in long[3] b) {\n long[3] c = [a[0] * b[0], a[0] * b[1] + a[1] * b[0],\n a[0] * b[2] + a[1] * b[1] + a[2] * b[0]];\n long c3 = a[1] * b[2] + a[2] * b[1], c4 = a[2] * b[2];\n c4 %= p;\n c[1] -= f0 * c4; c[2] -= f1 * c4; c3 -= f2 * c4;\n c3 %= p;\n c[0] -= f0 * c3; c[1] -= f1 * c3; c[2] -= f2 * c3;\n if ((c[0] %= p) < 0) c[0] += p;\n if ((c[1] %= p) < 0) c[1] += p;\n if ((c[2] %= p) < 0) c[2] += p;\n return c;\n }\n\n // f: square-free\n // gcd(f, T^p - T)\n long[3] t2 = [0, 1, 0], tp = [1, 0, 0];\n for (long e = p; e; e >>= 1) {\n if (e & 1) tp = mul(tp, t2);\n t2 = mul(t2, t2);\n }\n if (--tp[1] < 0) tp[1] += p;\n if (tp[2] != 0) {\n const invTp2 = tp[2].modInv(p);\n (tp[0] *= invTp2) %= p;\n (tp[1] *= invTp2) %= p;\n long b0 = (f0 - (f2 - tp[1]) * tp[0]) % p;\n long b1 = (f1 - tp[0] - (f2 - tp[1]) * tp[1]) % p;\n if (b0 < 0) b0 += p;\n if (b1 < 0) b1 += p;\n if (b1 != 0) {\n if ((tp[0] * ((b1 * b1) % p) - tp[1] * ((b0 * b1) % p) + b0 * b0) % p != 0) {\n // gcd = 1\n return [];\n } else {\n // gcd = b0 + b1 T\n return [((p - b0) * b1.modInv(p)) % p];\n }\n } else if (b0 != 0) {\n // gcd = 1\n return [];\n } else {\n // gcd = tp[0] + tp[1] T + T^2\n assert(false);\n }\n } else if (tp[1] != 0) {\n const tp02 = (tp[0] * tp[0]) % p, tp12 = (tp[1] * tp[1]) % p;\n if ((((f0 * tp[1] - f1 * tp[0]) % p) * tp12 +\n ((f2 * tp[1] - tp[0]) % p) * tp02) % p != 0) {\n // gcd = 1\n return [];\n } else {\n // gcd = tp[0] + tp[1] T\n return [((p - tp[0]) * tp[1].modInv(p)) % p];\n }\n } else if (tp[0] != 0) {\n // gcd = 1\n return [];\n } else {\n // gcd = f0 + f1 T + f2 T^2 + T^3\n }\n\n // f: split\n for (; ; ) {\n // gcd(rand^((p-1)/2) - 1, f)\n long[3] r2 = [xrand() % p, xrand() % p, xrand() % p], rp = [1, 0, 0];\n for (long e = (p - 1) / 2; e; e >>= 1) {\n if (e & 1) rp = mul(rp, r2);\n r2 = mul(r2, r2);\n }\n if (--rp[0] < 0) rp[0] += p;\n if (rp[2] != 0) {\n const invRp2 = rp[2].modInv(p);\n (rp[0] *= invRp2) %= p;\n (rp[1] *= invRp2) %= p;\n long c0 = (f0 - (f2 - rp[1]) * rp[0]) % p;\n long c1 = (f1 - rp[0] - (f2 - rp[1]) * rp[1]) % p;\n if (c0 < 0) c0 += p;\n if (c1 < 0) c1 += p;\n if (c1 != 0) {\n if ((rp[0] * ((c1 * c1) % p) - rp[1] * ((c0 * c1) % p) + c0 * c0) % p != 0) {\n // gcd = 1\n } else {\n // gcd = c0 + c1 T\n const t = ((p - c0) * c1.modInv(p)) % p;\n auto ts = [t] ~ modRoots2((f1 + (f2 + t) * t) % p, (f2 + t) % p, p);\n sort(ts);\n return ts;\n }\n } else if (c0 != 0) {\n // gcd = 1\n } else {\n // gcd = rp[0] + rp[1] T + T^2\n auto ts = modRoots2(rp[0], rp[1], p) ~ [(rp[1] - f2 + p) % p];\n sort(ts);\n return ts;\n }\n } else if (rp[1] != 0) {\n const rp02 = (rp[0] * rp[0]) % p, rp12 = (rp[1] * rp[1]) % p;\n if ((((f0 * rp[1] - f1 * rp[0]) % p) * rp12 +\n ((f2 * rp[1] - rp[0]) % p) * rp02) % p != 0) {\n // gcd = 1\n } else {\n // gcd = rp[0] + rp[1] T\n const t = ((p - rp[0]) * rp[1].modInv(p)) % p;\n auto ts = [t] ~ modRoots2((f1 + (f2 + t) * t) % p, (f2 + t) % p, p);\n sort(ts);\n return ts;\n }\n } else if (rp[0] != 0) {\n // gcd = 1\n } else {\n // gcd = f0 + f1 T + f2 T^2 + T^3\n }\n }\n }\n}\n\n\nint N;\nlong P, K;\nlong[] A;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n P = readLong();\n K = readLong();\n A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n long[long] cnt;\n foreach (a; A) {\n ++cnt[a];\n }\n \n long ans;\n foreach (a; A) {\n /*\n (A[i] + T) (A[i]^2 + T^2) = k\n */\n const aa = (a * a) % P;\n const res = modRoots3((a * aa - K + P) % P, aa, a, P);\n debug {\n writeln(a, \": \", (a * aa - K + P) % P, \" \", aa, \" \", a, \" \", res);\n }\n foreach (t; res.uniq) {\n if (a < t) {\n if (t in cnt) {\n ans += cnt[t];\n }\n }\n }\n }\n writeln(ans);\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\nint N;\nlong P, K;\nlong[] A;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n P = readLong();\n K = readLong();\n A = new long[N];\n foreach (i; 0 .. N) {\n A[i] = readLong();\n }\n \n auto fs = new long[N];\n foreach (i; 0 .. N) {\n long a2 = (A[i] * A[i]) % P;\n fs[i] = ((a2 * a2 - K * A[i]) % P + P) % P;\n }\n fs.sort;\n \n long ans;\n for (int i = 0, j; i < N; i = j) {\n for (j = i; j < N && fs[i] == fs[j]; ++j) {}\n ans += (j - i) * (j - i - 1) / 2;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "ac4d58b5dfb61a27205a4fe2d3d5d268"} {"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\tint k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tk = min (k, n - k);\n\t\tint me = 1;\n\t\twhile (me < n * 2)\n\t\t{\n\t\t\tme <<= 1;\n\t\t}\n\t\tint hi = me << 1;\n\t\tauto t = new long [hi];\n\n\t\tvoid add (int p, long value)\n\t\t{\n\t\t\tfor (p += me; p > 0; p >>= 1)\n\t\t\t{\n\t\t\t\tt[p] += value;\n\t\t\t}\n\t\t}\n\n\t\tlong seg (int lo, int hi)\n\t\t{\n\t\t\tlong res = 0;\n\t\t\tfor (lo += me, hi += me; lo < hi; 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\tres += t[lo];\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\tres += t[hi];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tlong res = 1;\n\t\tint cur = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint next = cur + k;\n\t\t\tres += 1 + seg (cur + 1, next);\n\t\t\twrite (res, \"\\n \"[i + 1 < n]);\n\n\t\t\tif (next >= n)\n\t\t\t{\n\t\t\t\tnext -= n;\n\t\t\t}\n\t\t\tadd (cur, 1);\n\t\t\tadd (next, 1);\n\t\t\tadd (cur + n, 1);\n\t\t\tadd (next + n, 1);\n\t\t\tcur = next;\n\t\t}\n\t\tdebug {stderr.writeln (res);}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.array, std.algorithm;\nimport std.uni, std.range, std.math, std.container, std.datetime;\nimport core.bitop, std.typetuple, std.typecons;\n\nimmutable long MOD = 1_000_000_007;\nalias tie = TypeTuple;\nalias triplet = Tuple!(int, int, int);\n\nvoid main(){\n int N, K;\n readVars(N, K);\n\n K = min(K, N - K);\n\n int s, t;\n long d = 1;\n long res = 1;\n\n foreach(i ; 0 .. N){\n t = (s + K) % N;\n\n if (s < t || t == 0) {\n res += d;\n } else {\n d++;\n res += d;\n d++;\n }\n\n write(res, i != N - 1 ? ' ' : '\\n');\n\n s = t;\n }\n}\n\nclass FenwickTree(T){\nprivate:\n T[] data;\n int N;\n\npublic:\n this(T[] a){\n data = [cast(T)0] ~ a[];\n N = a.length.to!int;\n\n foreach (i ; 1 .. N + 1) {\n if (i + (i & (-i)) <= N) {\n data[i + (i & (-i))] += data[i];\n }\n }\n }\n\n void add(int i, T x) {\n i++;\n\n while (i <= N) {\n data[i] += x;\n i += i & (-i);\n }\n }\n\n T getSum(int r) {\n T res;\n\n while(r > 0){\n res += data[r];\n r -= r & (-r);\n }\n\n return res;\n }\n\n void print(){\n stderr.writefln(\"%(%s %)\", data);\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 throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.array, std.algorithm;\nimport std.uni, std.range, std.math, std.container, std.datetime;\nimport core.bitop, std.typetuple, std.typecons;\n\nimmutable long MOD = 1_000_000_007;\nalias tie = TypeTuple;\nalias triplet = Tuple!(int, int, int);\n\nvoid main(){\n int N, K;\n readVars(N, K);\n\n K = min(K, N - K);\n\n int s, t;\n\n auto a = new long[](N);\n auto ft = new FenwickTree!(long)(a);\n long res = 1;\n\n foreach(i ; 0 .. N){\n t = (s + K) % N;\n\n if(s < t){\n res += ft.getSum(t) - ft.getSum(s + 1) + 1;\n } else {\n res += ft.getSum(N) - ft.getSum(s + 1);\n res += ft.getSum(t) + 1;\n }\n\n write(res, i == N - 1 ? '\\n' : ' ');\n\n ft.add(s, 1);\n ft.add(t, 1);\n\n s = t;\n }\n\n}\n\nclass FenwickTree(T){\nprivate:\n T[] data;\n int N;\n\npublic:\n this(T[] a){\n data = [cast(T)0] ~ a[];\n N = a.length.to!int;\n\n foreach (i ; 1 .. N + 1) {\n if (i + (i & (-i)) <= N) {\n data[i + (i & (-i))] += data[i];\n }\n }\n }\n\n void add(int i, T x) {\n i++;\n\n while (i <= N) {\n data[i] += x;\n i += i & (-i);\n }\n }\n\n T getSum(int r) {\n T res;\n\n while(r > 0){\n res += data[r];\n r -= r & (-r);\n }\n\n return res;\n }\n\n void print(){\n stderr.writefln(\"%(%s %)\", data);\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 throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.array, std.algorithm;\nimport std.uni, std.range, std.math, std.container, std.datetime;\nimport core.bitop, std.typetuple, std.typecons;\n\nimmutable long MOD = 1_000_000_007;\nalias tie = TypeTuple;\nalias triplet = Tuple!(int, int, int);\n\nvoid main(){\n int N, K;\n readVars(N, K);\n\n K = min(K, N - K);\n\n int s, t;\n long d = 1;\n long res = 1;\n //auto ans = new long[](N);\n\n foreach(i ; 0 .. N){\n t = (s + K) % N;\n\n if (s < t || t == 0) {\n res += d;\n } else {\n d++;\n res += d;\n d++;\n }\n\n //ans[i] = res;\n write(res, ' ');\n\n s = t;\n }\n writeln();\n\n //writefln(\"%(%s %)\", ans);\n}\n\nclass FenwickTree(T){\nprivate:\n T[] data;\n int N;\n\npublic:\n this(T[] a){\n data = [cast(T)0] ~ a[];\n N = a.length.to!int;\n\n foreach (i ; 1 .. N + 1) {\n if (i + (i & (-i)) <= N) {\n data[i + (i & (-i))] += data[i];\n }\n }\n }\n\n void add(int i, T x) {\n i++;\n\n while (i <= N) {\n data[i] += x;\n i += i & (-i);\n }\n }\n\n T getSum(int r) {\n T res;\n\n while(r > 0){\n res += data[r];\n r -= r & (-r);\n }\n\n return res;\n }\n\n void print(){\n stderr.writefln(\"%(%s %)\", data);\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 throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.array, std.algorithm;\nimport std.uni, std.range, std.math, std.container, std.datetime;\nimport core.bitop, std.typetuple, std.typecons;\n\nimmutable long MOD = 1_000_000_007;\nalias tie = TypeTuple;\nalias triplet = Tuple!(int, int, int);\n\nvoid main(){\n int N, K;\n readVars(N, K);\n\n K = min(K, N - K);\n\n int s, t;\n long d = 1;\n long res = 1;\n auto ans = new long[](N);\n\n foreach(i ; 0 .. N){\n t = (s + K) % N;\n\n if (s < t || t == 0) {\n res += d;\n } else {\n d++;\n res += d;\n d++;\n }\n\n ans[i] = res;\n\n s = t;\n }\n\n writefln(\"%(%s %)\", ans);\n}\n\nclass FenwickTree(T){\nprivate:\n T[] data;\n int N;\n\npublic:\n this(T[] a){\n data = [cast(T)0] ~ a[];\n N = a.length.to!int;\n\n foreach (i ; 1 .. N + 1) {\n if (i + (i & (-i)) <= N) {\n data[i + (i & (-i))] += data[i];\n }\n }\n }\n\n void add(int i, T x) {\n i++;\n\n while (i <= N) {\n data[i] += x;\n i += i & (-i);\n }\n }\n\n T getSum(int r) {\n T res;\n\n while(r > 0){\n res += data[r];\n r -= r & (-r);\n }\n\n return res;\n }\n\n void print(){\n stderr.writefln(\"%(%s %)\", data);\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 throw new Exception(\"args num < input num\");\n }\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.array, std.algorithm;\nimport std.uni, std.range, std.math, std.container, std.datetime;\nimport core.bitop, std.typetuple, std.typecons;\n\nimmutable long MOD = 1_000_000_007;\nalias tie = TypeTuple;\nalias triplet = Tuple!(int, int, int);\n\nvoid main(){\n int N, K;\n readVars(N, K);\n\n K = min(K, N - K);\n\n int s, t;\n\n auto a = new long[](N);\n auto ft = new FenwickTree!(long)(a);\n auto ans = new long[](N);\n long res = 1;\n\n foreach(i ; 0 .. N){\n t = (s + K) % N;\n\n if(s < t){\n res += ft.getSum(t) - ft.getSum(s + 1) + 1;\n ans[i] = res;\n } else {\n res += ft.getSum(N) - ft.getSum(s + 1);\n res += ft.getSum(t) + 1;\n ans[i] = res;\n }\n\n ft.add(s, 1);\n ft.add(t, 1);\n\n s = t;\n }\n\n writefln(\"%(%s %)\", ans);\n}\n\nclass FenwickTree(T){\nprivate:\n T[] data;\n int N;\n\npublic:\n this(T[] a){\n data = [cast(T)0] ~ a[];\n N = a.length.to!int;\n\n foreach (i ; 1 .. N + 1) {\n if (i + (i & (-i)) <= N) {\n data[i + (i & (-i))] += data[i];\n }\n }\n }\n\n void add(int i, T x) {\n i++;\n\n while (i <= N) {\n data[i] += x;\n i += i & (-i);\n }\n }\n\n T getSum(int r) {\n T res;\n\n while(r > 0){\n res += data[r];\n r -= r & (-r);\n }\n\n return res;\n }\n\n void print(){\n stderr.writefln(\"%(%s %)\", data);\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 throw new Exception(\"args num < input num\");\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\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 FenwickTree(int n) {\n int[n] t;\n\n void init() {\n memset(t.ptr, 0x00, t.sizeof);\n }\n\n void inc(int i) {\n for (; i < n; i |= i + 1)\n t[i]++;\n }\n\n int get(int right) {\n int result = 0;\n for (; right; right &= right - 1)\n result += t[right - 1];\n return result;\n }\n}\n\nFenwickTree!1_000_000 fwt;\n\nvoid main() {\n int n, k;\n while (read(&n, &k)) {\n k = min(k, n - k);\n version (LocalProject)\n fwt.init();\n long result = 1;\n int cur = 0;\n foreach (i; 0 .. n) {\n int next = cur + k;\n int count;\n if (next <= n)\n count = fwt.get(next) - fwt.get(cur);\n else {\n next -= n;\n count = i - fwt.get(cur) + fwt.get(next);\n result--;\n }\n result += (count << 1) + 1;\n fwt.inc(cur);\n cur = next;\n write(result, ' ');\n }\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\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 FenwickTree(int n) {\n int[n] t;\n\n void init() {\n memset(t.ptr, 0x00, t.sizeof);\n }\n\n void inc(int i) {\n for (; i < n; i |= i + 1)\n t[i]++;\n }\n\n int get(int right) {\n int result = 0;\n for (; right; right &= right - 1)\n result += t[right - 1];\n return result;\n }\n}\n\nFenwickTree!1_000_000 fwt;\n\nvoid main() {\n int n, k;\n while (read(&n, &k)) {\n version (LocalProject)\n fwt.init();\n long result = 1;\n int cur = 0;\n foreach (i; 0 .. n) {\n int next = cur + k;\n int count;\n if (next <= n)\n count = fwt.get(next) - fwt.get(cur);\n else {\n next -= n;\n count = i - fwt.get(cur) + fwt.get(next);\n result--;\n }\n result += (count << 1) + 1;\n fwt.inc(cur);\n cur = next;\n write(result, ' ');\n }\n writeln();\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.array, std.algorithm;\nimport std.uni, std.range, std.math, std.container, std.datetime;\nimport core.bitop, std.typetuple, std.typecons;\n\nimmutable long MOD = 1_000_000_007;\nalias tie = TypeTuple;\nalias triplet = Tuple!(int, int, int);\n\nvoid main(){\n int N, K;\n readVars(N, K);\n\n K = min(K, N - K);\n\n int s, t;\n\n auto a = new int[](N);\n auto ft = new FenwickTree!(int)(a);\n auto ans = new int[](N);\n int res = 1;\n\n foreach(i ; 0 .. N){\n t = (s + K) % N;\n\n if(s < t){\n res += ft.getSum(t) - ft.getSum(s + 1) + 1;\n ans[i] = res;\n } else {\n res += ft.getSum(N) - ft.getSum(s + 1);\n res += ft.getSum(t) + 1;\n ans[i] = res;\n }\n\n ft.add(s, 1);\n ft.add(t, 1);\n\n s = t;\n }\n\n writefln(\"%(%s %)\", ans);\n}\n\nclass FenwickTree(T){\nprivate:\n T[] data;\n int N;\n\npublic:\n this(T[] a){\n data = [0] ~ a[];\n N = a.length.to!int;\n\n foreach (i ; 1 .. N + 1) {\n if (i + (i & (-i)) <= N) {\n data[i + (i & (-i))] += data[i];\n }\n }\n }\n\n void add(int i, T x) {\n i++;\n\n while (i <= N) {\n data[i] += x;\n i += i & (-i);\n }\n }\n\n T getSum(int r) {\n T res;\n\n while(r > 0){\n res += data[r];\n r -= r & (-r);\n }\n\n return res;\n }\n\n void print(){\n stderr.writefln(\"%(%s %)\", data);\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 throw new Exception(\"args num < input num\");\n }\n}"}], "src_uid": "fc82362dbda74396ad6db0d95a0f7acc"} {"source_code": "import std.stdio;\n\nvoid main()\n{\n\tint n, a, b;\n\n\treadf(\"%d %d %d\", &n, &a, &b);\n\n\tint oddSeats = (a * b + 1) / 2;\n\tint evenSeats = a * b - oddSeats;\n\n\tint oddMembers = (n + 1) / 2;\n\tint evenMembers = n - oddMembers;\n\n\tif (oddMembers > oddSeats || evenMembers > evenSeats) {\n\t\twritef(\"-1\\n\");\n\t}\n\telse {\n\t\tint id = 1;\n\t\tint[][] result = new int[][](a, b);\n\n\t\tfor (int i = 0; i < a; i++) {\n\t\t\tint from = 0;\n\t\t\tint delta = 1;\n\t\t\tif (i > 0 && result[i - 1][0] % 2 == id % 2) {\n\t\t\t\tfrom = b - 1;\n\t\t\t\tdelta = -1;\n\t\t\t}\n\t\t\tfor (int j = from; j != b && j != -1; j += delta) {\n\t\t\t\tif (id % 2 == 1 && oddMembers > 0) {\n\t\t\t\t\tresult[i][j] = id;\n\t\t\t\t\toddMembers--;\n\t\t\t\t\tid++;\n\t\t\t\t}\n\t\t\t\telse if (id % 2 == 0 && evenMembers > 0) {\n\t\t\t\t\tresult[i][j] = id;\n\t\t\t\t\tevenMembers--;\n\t\t\t\t\tid++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\twritef(\"%(%(%d %)\\n%)\\n\", result);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, a, b;\n\twhile (readf (\" %s %s %s\", &n, &a, &b) > 0)\n\t{\n\t\tif (n <= a * b)\n\t\t{\n\t\t\tauto s = iota (1, n + 1).array;\n\t\t\ts.length = a * b;\n\t\t\tauto t = s.chunks (b).array;\n\t\t\tif (b % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (i, ref r; t)\n\t\t\t\t{\n\t\t\t\t\tif (i % 2 == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\treverse (r);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\twritefln (\"%(%(%s %)\\n%)\", s.chunks (b));\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n\tint n, a, b;\n\n\treadf(\"%d %d %d\", &n, &a, &b);\n\n\tint oddSeats = (a * b + 1) / 2;\n\tint evenSeats = a * b - oddSeats;\n\n\tint oddMembers = (n + 1) / 2;\n\tint evenMembers = n - oddMembers;\n\n\tif (oddMembers > oddSeats || evenMembers > evenSeats) {\n\t\twritef(\"-1\\n\");\n\t}\n\telse {\n\t\tint id = 1;\n\t\tfor (int i = 0; i < a; i++) {\n\t\t\tfor (int j = 0; j < b; j++) {\n\t\t\t\tif (id % 2 == 1 && oddMembers > 0) {\n\t\t\t\t\twritef(\"%d\", id);\n\t\t\t\t\toddMembers--;\n\t\t\t\t\tid++;\n\t\t\t\t}\n\t\t\t\telse if (id % 2 == 0 && evenMembers > 0) {\n\t\t\t\t\twritef(\"%d\", id);\n\t\t\t\t\tevenMembers--;\n\t\t\t\t\tid++;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\twritef(\"0\");\n\t\t\t\t}\n\n\t\t\t\tif (j < b - 1)\n\t\t\t\t\twritef(\" \");\n\t\t\t\telse\n\t\t\t\t\twritef(\"\\n\");\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, a, b;\n\twhile (readf (\" %s %s %s\", &n, &a, &b) > 0)\n\t{\n\t\tif (n <= a * b)\n\t\t{\n\t\t\tauto s = iota (1, n + 1).array;\n\t\t\ts.length = a * b;\n\t\t\twritefln (\"%(%(%s %)\\n%)\", s.chunks (b));\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n"}], "src_uid": "6e0dafeaf85e92f959c388c72e158f68"} {"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 import std.math : abs;\n import std.algorithm : min, sort;\n\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int[] a = new int[n << 1];\n for (int i = 0; i < n << 1; ++i) {\n a[i] = io.readInt;\n }\n sort(a);\n int result = a[(n << 1) - 1] - a[0], half = n - 1;\n for (int i = 0; i < n << 1; ++i) {\n result = min(result, abs(a[i] - a[half + (half >= i)]));\n }\n writeln(result);\n }\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)\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 foreach(i; 0 .. times)\n {\n static if (is(typeof(f(i))))\n {\n f(i);\n }\n else\n {\n f();\n }\n }\n}\n\nvoid main()\n{\n testCase:foreach(tc; 0 .. next!long)\n {\n auto n = next!long;\n auto a = makeSlice(2 * n, next!long);\n sort(a);\n writeln(abs(a.at(n - 1) - a.at(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)\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 foreach(i; 0 .. times)\n {\n static if (is(typeof(f(i))))\n {\n f(i);\n }\n else\n {\n f();\n }\n }\n}\n\nvoid main()\n{\n ()\n {\n auto n = next!long;\n auto a = makeSlice(2 * n, next!long);\n sort(a);\n writeln(abs(a.at(n - 1) - a.at(n)));\n }.rep(next!long);\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 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\n\t\tans[ti] = a[$/2] - a[$/2-1];\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "adb0f6082367dc432e2e096c64f13a56"} {"source_code": "import std.algorithm;\nimport std.conv : to;\nimport std.container;\nimport std.numeric : gcd;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons : Tuple, tuple;\n\nvoid main() {\n int n, m;\n readf!\"%d %d\\n\"(n, m);\n auto s = new string[n];\n int res = 0;\n int[string] set;\n auto buf = new char[m];\n for (int i = 0; i < n; ++i) {\n s[i] = readln.chomp;\n for (int j = 0; j < i; ++j) {\n for (int k = 0; k < m; ++k) {\n buf[k] = s[i][k] == s[j][k] ? s[i][k] : 66 ^ s[i][k] ^ s[j][k];\n }\n res += set.get(cast(string) buf, 0);\n }\n set[s[i]] = 1;\n }\n writeln(res / 2);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string: chomp;\n\nenum Res { Unusable, Same, Different }\n\nvoid main() {\n int n, k;\n readf!\"%d %d\\n\"(n, k);\n\n string[] arr = new string[n];\n bool[][] pairs = new bool[][n];\n int[string] set;\n\n for(int i = 0; i < n; i++) {\n string s = readln().chomp();\n arr[i] = s;\n set[s] = i;\n\n pairs[i] = new bool[n];\n }\n\n int count = 0;\n\n for(int i = 0; i < (n - 1); i++) {\n for(int j = i + 1; j < n; j++) {\n if(pairs[i][j]) continue;\n pairs[i][j] = pairs[j][i] = true;\n string t = third(arr[i], arr[j], k);\n if(t in set) {\n count++;\n int x = set[t];\n pairs[i][x] = pairs[x][i] = true;\n pairs[j][x] = pairs[x][j] = true;\n // writeln(arr[i] ~ \" \" ~ arr[j] ~ \" \" ~ t);\n }\n }\n }\n\n writeln(count);\n}\n\nstring third(string first, string second, int k) {\n char[] res = new char[k];\n for(int i = 0; i < k; i++) {\n res[i] = thirdChar(first[i], second[i]);\n }\n\n return cast(string)res;\n}\n\nchar thirdChar(char first, char second) {\n if(first == 'S') {\n if(second == 'S') return 'S';\n if(second == 'E') return 'T';\n return 'E';\n }\n if(first == 'E') {\n if(second == 'E') return 'E';\n if(second == 'S') return 'T';\n return 'S';\n }\n if(second == 'T') return 'T';\n if(second == 'E') return 'S';\n return 'E';\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, k;\n read(n, k);\n auto cards = makeArray!string(n, next!string);\n bool[string] hasCard;\n foreach(card; cards)\n hasCard[card] = true;\n char other(char c1, char c2)\n {\n if (c1 == c2)\n return c1;\n foreach(c; \"SET\")\n if (c1 != c && c2 != c)\n return c;\n assert(0);\n }\n int cnt = 0;\n foreach(i; 0 .. n)\n foreach(j; i + 1 .. n)\n {\n char[] otherString;\n foreach(ki; 0 .. k)\n otherString ~= other(cards.at(i).at(ki), cards.at(j).at(ki));\n if (otherString in hasCard)\n {\n cnt++;\n }\n }\n writeln(cnt/3);\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 k = RD!int;\n\tauto s = new string[](n);\n\tforeach (i; 0..n)\n\t\ts[i] = RD!string;\n\n\tauto toNum = ['S':0, 'E':1, 'T':2];\n\tint[long] set;\n\tforeach (i; 0..n)\n\t{\n\t\tlong key;\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tauto num = toNum[s[i][j]];\n\t\t\tkey += num * (3^^j);\n\t\t}\n\t\t++set[key];\n\t\tdebug writeln(\"i:\", i, \" key:\", key);\n\t}\n\tdebug writeln(set);\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t{\n\t\tforeach (j; i+1..n)\n\t\t{\n\t\t\tlong key;\n\t\t\tforeach (l; 0..k)\n\t\t\t{\n\t\t\t\tif (s[i][l] == s[j][l])\n\t\t\t\t\tkey += toNum[s[i][l]] * (3^^l);\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tauto num = 3 - (toNum[s[i][l]] + toNum[s[j][l]]);\n\t\t\t\t\tkey += num * (3^^l);\n\t\t\t\t}\n\t\t\t}\n\t\t\tans += set.get(key, 0);\n\t\t\tdebug writeln(\"i:\", i, \" j:\", j, \" ans:\", ans);\n\t\t}\n\t}\n\n\twriteln(ans/3);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "ae7c80e068e267673a5f910bb0b121ec"} {"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 int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n auto ans = new int[N];\n int cnt;\n foreach (i; 0 .. N) {\n if (A[i] % 2 == 0) {\n ans[i] = A[i] / 2;\n } else {\n if (cnt++ % 2 == 0) {\n ans[i] = (A[i] + 1) / 2;\n } else {\n ans[i] = (A[i] - 1) / 2;\n }\n }\n }\n foreach (i; 0 .. N) {\n writeln(ans[i]);\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 string[] s_rd;\nT 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\tauto ans = new long[](n);\n\tint cnt;\n\tforeach (i; 0..n)\n\t{\n\t\tauto a = RD!int;\n\t\tif (a % 2 == 0)\n\t\t\tans[i] = a/2;\n\t\telse if (cnt == 0)\n\t\t{\n\t\t\tans[i] = a/2;\n\t\t\tif (a < 0)\n\t\t\t\t--ans[i];\n\t\t\t++cnt;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[i] = a/2;\n\t\t\tif (a > 0)\n\t\t\t\t++ans[i];\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}"}, {"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 (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\t\tauto b = new int [n];\n\t\tb[] = a[] / 2;\n\t\tauto delta = sum (b);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (delta > 0 && a[i] < 0 && a[i] % 2 != 0)\n\t\t\t{\n\t\t\t\tdelta -= 1;\n\t\t\t\tb[i] -= 1;\n\t\t\t}\n\t\t\tif (delta < 0 && a[i] > 0 && a[i] % 2 != 0)\n\t\t\t{\n\t\t\t\tdelta += 1;\n\t\t\t\tb[i] += 1;\n\t\t\t}\n\t\t}\n\t\tforeach (ref x; b)\n\t\t{\n\t\t\twriteln (x);\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;\n\tint[] as = rint(n);\n\t\n\tint cntpos, cntneg;\n\tforeach(a; as){\n\t\tif(a % 2 == 0) (a / 2).writeln;\n\t\telse if(a > 0){\n\t\t\tcntpos += 1;\n\t\t\tif(cntpos % 2 == 0) ((a - 1) / 2).writeln;\n\t\t\telse ((a + 1) / 2).writeln;\n\t\t}\n\t\telse{\n\t\t\tcntneg += 1;\n\t\t\tif(cntneg % 2 == 0) ((a + 1) / 2).writeln;\n\t\t\telse ((a - 1) / 2).writeln;\n\t\t}\n\t}\n\t\n}\n"}], "negative_code": [], "src_uid": "3545385c183c29f9b95aa0f02b70954f"} {"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 m = next!int;\n auto k = next!int;\n auto n = next!int;\n auto s = next!int;\n auto a = next!int(m);\n auto b = next!int(s);\n auto reqCnt = b.getCnt;\n uint[int] cnt;\n auto pendingFulfill = redBlackTree!int(b);\n int i = 0;\n while(i < m && !pendingFulfill.empty)\n {\n cnt.require(a[i], 0)++;\n if (a[i] in pendingFulfill)\n\tif (cnt[a[i]] >= reqCnt[a[i]])\n\t pendingFulfill.removeKey(a[i]);\n i++;\n }\n if (!pendingFulfill.empty) return (-1).writeln;\n i--;\n void dosol(int l, int h)\n {\n int toremove = h - l + 1 - k;\n debug writeln(\"solving with \", l, \" \", h);\n writeln(toremove + l % k + (m - h - 1) % k);\n foreach(i; 1 .. l % k + 1) write(i, \" \");\n {\n int i = l;\n while(toremove > 0)\n\t{\n\t if (a[i] !in reqCnt || cnt[a[i]] - 1 >= reqCnt[a[i]])\n\t {\n\t write(i + 1, \" \");\n\t cnt[a[i]]--;\n\t toremove--;\n\t }\n\t i++;\n\t}\n }\n foreach(i; h + 2 .. h + 2 + (m - h - 1) % k) write(i, \" \");\n writeln;\n }\n int l = 0;\n while(a[l] !in reqCnt || cnt[a[l]] - 1 >= reqCnt[a[l]])\n {\n cnt[a[l]]--;\n l++;\n }\n \n while(i < m)\n {\n debug writeln(\"trying \", l, \" \", i, \" \");\n int len = i - l + 1;\n if (len < k)\n\t{\n\t int rest = k - len;\n\t int ll = l - rest;\n\t if (ll >= 0)\n\t {\n\t auto toleft = ll / k;\n\t auto toright = (m - i - 1) / k;\n\t if (toleft + toright + 1 >= n)\n\t\t{\n\t\t return dosol(ll, i);\n\t\t}\n\t }\n\t}\n if (len >= k)\n\t{\n\t auto toleft = l / k;\n\t auto toright = (m - i - 1) / k;\n\t debug writeln(\"r = \", toright, \" l = \", toleft);\n\t if (toleft + toright + 1 >= n)\n\t {\n\t return dosol(l, i);\n\t }\n\t}\n \n i++; if (i >= m) break;\n cnt.require(a[i], 0)++;\n while(a[l] !in reqCnt || cnt[a[l]] - 1 >= reqCnt[a[l]])\n\t{\n\t cnt[a[l]]--;\n\t l++;\n\t}\n }\n return (-1).writeln;\n}\n\nauto getCnt(T)(T[] arr)\n{\n uint[T] cnt;\n foreach(a; arr) cnt.require(a, 0)++;\n return cnt;\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.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 K = readInt();\n const N = readInt();\n const S = readInt();\n auto A = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt();\n }\n auto B = new int[S];\n foreach (s; 0 .. S) {\n B[s] = readInt();\n }\n \n const lim = max(A.maxElement, B.maxElement) + 1;\n auto cnt = new int[lim];\n \n B.sort;\n const BGroup = B.group.array;\n \n const width = M - K * (N - 1);\n foreach (i; 0 .. width) {\n ++cnt[A[i]];\n }\n \n int[] ans;\n foreach (x; 0 .. N) {\n // K x to the left, K (N - 1 - x) to the right\n bool ok = true;\n foreach (g; BGroup) {\n ok = ok && (cnt[g[0]] >= g[1]);\n }\n if (ok) {\n debug {\n writeln(\"found x = \", x);\n }\n auto need = new int[lim];\n foreach (g; BGroup) {\n need[g[0]] += g[1];\n }\n foreach (i; K * x .. K * x + width) {\n if (need[A[i]] > 0) {\n --need[A[i]];\n } else {\n ans ~= i;\n }\n }\n if (ans.length >= width - K) {\n ans.length = width - K;\n }\n writeln(ans.length);\n foreach (index, i; ans) {\n if (index > 0) write(\" \");\n write(i + 1);\n }\n writeln();\n goto found;\n }\n if (x + 1 < N) {\n foreach (i; K * x .. K * (x + 1)) {\n --cnt[A[i]];\n ++cnt[A[i + width]];\n }\n }\n }\n writeln(-1);\n found:\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 M = readInt();\n const K = readInt();\n const N = readInt();\n const S = readInt();\n auto A = new int[M];\n foreach (i; 0 .. M) {\n A[i] = readInt();\n }\n auto B = new int[S];\n foreach (s; 0 .. S) {\n B[s] = readInt();\n }\n \n const lim = max(A.maxElement, B.maxElement) + 1;\n auto cnt = new int[lim];\n \n B.sort;\n const BGroup = B.group.array;\n \n const width = M - K * (N - 1);\n foreach (i; 0 .. width) {\n ++cnt[A[i]];\n }\n int[] ans;\n foreach (x; 0 .. N) {\n // K x to the left, K (N - 1 - x) to the right\n bool ok = true;\n foreach (g; BGroup) {\n ok = ok && (cnt[g[0]] >= g[1]);\n }\n if (ok) {\n debug {\n writeln(\"found x = \", x);\n }\n auto need = new int[lim];\n foreach (g; BGroup) {\n need[g[0]] += g[1];\n }\n foreach (i; K * x .. K * x + width) {\n if (need[A[i]] > 0) {\n --need[A[i]];\n } else {\n ans ~= i;\n if (ans.length >= width - K) {\n break;\n }\n }\n }\n break;\n }\n if (x + 1 < N) {\n foreach (i; K * x .. K * (x + 1)) {\n --cnt[A[i]];\n ++cnt[A[i + width]];\n }\n }\n }\n \n if (!ans.empty) {\n writeln(ans.length);\n foreach (index, i; ans) {\n if (index > 0) write(\" \");\n write(i + 1);\n }\n writeln();\n } else {\n writeln(-1);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "fdc491122e3895f1fe3fcdccf657fa26"} {"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 long readLong() {\n import std.conv : to;\n\n return readToken.to!long;\n }\n\n string[] tokens;\n}\n\nvoid main() {\n import std.algorithm : max, min;\n\n IO io;\n int T = io.readInt;\n while (T--) {\n int n = io.readInt;\n int m = io.readInt - 1;\n int k = min(m, io.readInt);\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = io.readInt();\n }\n int result = 0;\n for (int ctr = 0; ctr <= k; ++ctr) {\n int worst = cast(int) 1e9;\n for (int arb = 0; arb <= m - k; ++arb) {\n worst = min(worst, max(a[ctr + arb], a[n - 1 - (m - (ctr + arb))]));\n }\n result = max(result, worst);\n }\n writeln(result);\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 const M = readInt();\n const K = readInt();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n const int k = min(K, M - 1);\n const int l = M - 1 - k;\n \n int ans = int.min;\n foreach (x; 0 .. k + 1) {\n int mn = int.max;\n foreach (y; 0 .. l + 1) {\n chmin(mn, max(A[x + y], A[N - (k - x) - (l - y) - 1]));\n }\n chmax(ans, mn);\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\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!long;\n foreach(tc; 0 .. t)\n {\n long n, m, k;\n read(n, m, k);\n auto a = makeArray(n, next!long);\n long rem = m - 1;\n k = min(k, rem);\n long r = rem - k;\n\n long minValue(long i, long j)\n {\n if (i > j)\n swap(i, j);\n if (i == j)\n return a.at(i);\n return min(mem!minValue(i, j - 1), a.at(j));\n }\n long partAns(long i, long j)\n {\n long res = long.max;\n assert(i >= 0 && i < n && j >= 0 && j < n);\n foreach(s; 0 .. r + 1)\n {\n res = min(res, max(a.at(i + s), a.at(j + s - r)));\n }\n return res;\n }\n long ans = long.min;\n foreach(s; 0 .. k + 1)\n {\n ans = max(ans, partAns(s, s + n - 1 - k));\n }\n writeln(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; }\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 m = RD!int-1;\n\t\tauto k = RD!int;\n\t\tauto a = RDA;\n\t\t\n\t\tauto l = min(m, k);\n\t\tauto len = n - m;\n\t\tforeach (i; 0..l+1)\n\t\t{\n\t\t\tlong tmp1 = long.max;\n\t\t\tforeach (j; 0..m-l+1)\n\t\t\t{\n\t\t\t\tlong tmp2;\n\t\t\t\ttmp2.chmax(a[i+j]);\n\t\t\t\ttmp2.chmax(a[i+j+len-1]);\n\t\t\t\t//debug writeln(i, \":\", j, \" \", tmp2);\n\t\t\t\ttmp1.chmin(tmp2);\n\t\t\t}\n\t\t\tans[ti].chmax(tmp1);\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.math;\nimport std.numeric;\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, m, k;\n\t\treadf !(\" %s %s %s\") (n, m, k);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tk = min (k, m - 1);\n\n\t\tint res = int.min;\n\t\tforeach (i; 0..k + 1)\n\t\t{\n\t\t\tint cur = int.max;\n\t\t\tforeach (j; 0..m - k)\n\t\t\t{\n\t\t\t\tint temp = max (a[i + j], a[n - m + i + j]);\n\t\t\t\tcur = min (cur, temp);\n\t\t\t}\n\t\t\tres = max (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\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 tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n, m, k;\n\t\treadf !(\" %s %s %s\") (n, m, k);\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tk = min (k, m - 1);\n\n\t\tint res = int.min;\n\t\tforeach (i; 0..k + 1)\n\t\t{\n\t\t\tint cur = int.max;\n\t\t\tforeach (j; 0..m - k)\n\t\t\t{\n\t\t\t\twriteln (i, \" \", j, \" \", i + j, \" \",\n\t\t\t\t n - m - i - j);\n\t\t\t\tint temp = max (a[i + j], a[n - m + i + j]);\n\t\t\t\tcur = min (cur, temp);\n\t\t\t}\n\t\t\tres = max (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "f2f9f63a952794f27862eb24ccbdbf36"} {"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 lrx = readarray!long;\r\n auto ab = readarray!long;\r\n if (ab[0] == ab[1]) {\r\n writeln(0);\r\n return;\r\n }\r\n else if ((lrx[0] + lrx[2] > ab[1]) && (lrx[1] - lrx[2] < ab[1])) {\r\n writeln(-1);\r\n return;\r\n }\r\n else {\r\n if (abs(ab[0] - ab[1]) >= lrx[2])\r\n writeln(1);\r\n else {\r\n if (abs(ab[0] - lrx[0]) >= lrx[2])\r\n if (lrx[2] + lrx[0] <= ab[1]) { //left\r\n writeln(2);\r\n return;\r\n }\r\n if (abs(lrx[1] - ab[0]) >= lrx[2])\r\n if (lrx[1] - lrx[2] >= ab[1]) { //right\r\n writeln(2);\r\n return;\r\n }\r\n if (abs(ab[0] - lrx[0]) >= lrx[2])\r\n if (lrx[2] + lrx[0] > ab[1]) { //left\r\n writeln(3);\r\n return;\r\n }\r\n if (abs(lrx[1] - ab[0]) >= lrx[2])\r\n if (lrx[1] - lrx[2] < ab[1]) { //right\r\n writeln(3);\r\n return;\r\n }\r\n writeln(-1);\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, 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 l, r, x, a, b;\n readf!\" %d %d %d \"(l, r, x);\n readf!\" %d %d \"(a, b);\n if (a == b) {\n writeln(0);\n continue;\n }\n if (abs(a - b) >= x) {\n writeln(1);\n } else if ((abs(a - l) >= x && abs(b - l) >= x) || (abs(a - r) >= x && abs(b - r) >= x)) {\n writeln(2);\n } else if ((abs(a - l) >= x && abs(b - r) >= x) || (abs(a - r) >= x && abs(b - l) >= x)) {\n writeln(3);\n } else {\n writeln(-1);\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\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 lo, hi, x;\r\n\t\treadf !(\" %s %s %s\") (lo, hi, x);\r\n\t\tint a, b;\r\n\t\treadf !(\" %s %s\") (a, b);\r\n\r\n\t\tauto delta = abs (a - b);\r\n\t\tif (a == b)\r\n\t\t{\r\n\t\t\twriteln (0);\r\n\t\t}\r\n\t\telse if (x <= delta)\r\n\t\t{\r\n\t\t\twriteln (1);\r\n\t\t}\r\n\t\telse if (x <= hi - b && x <= hi - a)\r\n\t\t{\r\n\t\t\twriteln (2);\r\n\t\t}\r\n\t\telse if (x <= b - lo && x <= a - lo)\r\n\t\t{\r\n\t\t\twriteln (2);\r\n\t\t}\r\n\t\telse if (x <= hi - b && x <= hi - lo && x <= a - lo)\r\n\t\t{\r\n\t\t\twriteln (3);\r\n\t\t}\r\n\t\telse if (x <= b - lo && x <= hi - lo && x <= hi - a)\r\n\t\t{\r\n\t\t\twriteln (3);\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": [{"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 lrx = readarray!long;\r\n auto ab = readarray!long;\r\n if (ab[0] == ab[1]) {\r\n writeln(0);\r\n return;\r\n }\r\n else if ((lrx[0] + lrx[2] > ab[1]) && (lrx[1] - lrx[2] < ab[1])) {\r\n writeln(-1);\r\n return;\r\n }\r\n else {\r\n if (abs(ab[0] - ab[1]) >= lrx[2])\r\n writeln(1);\r\n else {\r\n if (abs(ab[0] - lrx[0]) >= lrx[2]) {\r\n if (lrx[0] + lrx[2] <= ab[1]) //left\r\n writeln(2);\r\n else\r\n writeln(3);\r\n }\r\n else if (abs(lrx[1] - ab[0]) >= lrx[2]) {\r\n if (lrx[1] - lrx[2] >= ab[1]) //right\r\n writeln(2);\r\n else\r\n writeln(3);\r\n }\r\n else \r\n writeln(-1);\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": "e3a1f53f78fcb3a551c3ae1cbeedaf15"} {"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 n = RD!int;\r\n\tauto m = RD!int;\r\n\tauto rbts = new RedBlackTree!(int, \"a > b\")[](n);\r\n\tforeach (i; 0..n)\r\n\t\trbts[i] = new RedBlackTree!(int, \"a > b\");\r\n\tforeach (i; 0..m)\r\n\t{\r\n\t\tauto u = RD!int-1;\r\n\t\tauto v = RD!int-1;\r\n\t\trbts[u].insert(v);\r\n\t\trbts[v].insert(u);\r\n\t}\r\n\tint cnt;\r\n\tforeach (i; 0..n)\r\n\t{\r\n\t\tif (rbts[i].empty) continue;\r\n\t\tif (rbts[i].front > i)\r\n\t\t\t++cnt;\r\n\t}\r\n\tauto q = RD!int;\r\n\tint[] ans;\r\n\tforeach (i; 0..q)\r\n\t{\r\n\t\tauto num = RD!int;\r\n\t\tif (num == 3)\r\n\t\t\tans ~= n - cnt;\r\n\t\telse\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\tif (u > v)\r\n\t\t\t\tswap(u, v);\r\n\t\t\tif (num == 1)\r\n\t\t\t{\r\n\t\t\t\tbool isChange;\r\n\t\t\t\tif (rbts[u].empty)\r\n\t\t\t\t\tisChange = true;\r\n\t\t\t\telse if (rbts[u].front < u)\r\n\t\t\t\t\tisChange = true;\r\n\t\t\t\tif (isChange)\r\n\t\t\t\t\t++cnt;\r\n\t\t\t\trbts[u].insert(v);\r\n\t\t\t\trbts[v].insert(u);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trbts[u].removeKey(v);\r\n\t\t\t\trbts[v].removeKey(u);\r\n\t\t\t\tif (rbts[u].front < u)\r\n\t\t\t\t\t--cnt;\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\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 bool [int] [n];\r\n\t\tint total = n;\r\n\r\n\t\tvoid addEdge ()\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\tif (u > v)\r\n\t\t\t{\r\n\t\t\t\tswap (u, v);\r\n\t\t\t}\r\n\t\t\tif (adj[u].empty)\r\n\t\t\t{\r\n\t\t\t\ttotal -= 1;\r\n\t\t\t}\r\n\t\t\tadj[u][v] = true;\r\n\t\t}\r\n\r\n\t\tvoid remEdge ()\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\tif (u > v)\r\n\t\t\t{\r\n\t\t\t\tswap (u, v);\r\n\t\t\t}\r\n\t\t\tadj[u].remove (v);\r\n\t\t\tif (adj[u].empty)\r\n\t\t\t{\r\n\t\t\t\ttotal += 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\taddEdge ();\r\n\t\t}\r\n\r\n\t\tint q;\r\n\t\treadf !(\" %s\") (q);\r\n\t\tforeach (i; 0..q)\r\n\t\t{\r\n\t\t\tint t;\r\n\t\t\treadf !(\" %s\") (t);\r\n\t\t\tif (t == 1)\r\n\t\t\t{\r\n\t\t\t\taddEdge ();\r\n\t\t\t}\r\n\t\t\telse if (t == 2)\r\n\t\t\t{\r\n\t\t\t\tremEdge ();\r\n\t\t\t}\r\n\t\t\telse if (t == 3)\r\n\t\t\t{\r\n\t\t\t\twriteln (total);\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"}, {"source_code": "import std.stdio;\nimport std.container;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\nimport std.functional;\n\nvoid main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\talias Set = RedBlackTree!(int, (a, b) => a > b);\n\tauto adj = new Set[](n);\n\tforeach(ref adji; adj) adji = new Set();\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].insert(v);\n\t\tadj[v].insert(u);\n\t}\n\tint noGood = 0;\n\tauto isGood = new bool[](n);\n\tforeach(i; 0 .. n)\n\t{\n\t\tisGood[i] = adj[i].length == 0 || adj[i].front < i;\n\t\tnoGood += isGood[i];\n\t}\n\tauto nq = readInt!int;\n\tforeach(q; 0 .. nq)\n\t{\n\t\tauto op = readInt!int;\n\t\tint v, u;\n\t\tswitch(op)\n\t\t{\n\t\t\tcase 1:\n\t\t\t\tu = readInt!int - 1;\n\t\t\t\tv = readInt!int - 1;\n\t\t\t\tauto pu = isGood[u];\n\t\t\t\tauto pv = isGood[v];\n\t\t\t\tadj[u].insert(v);\n\t\t\t\tadj[v].insert(u);\n\t\t\t\tisGood[u] = adj[u].length == 0 || adj[u].front < u;\n\t\t\t\tisGood[v] = adj[v].length == 0 || adj[v].front < v;\n\t\t\t\tnoGood += isGood[u] - pu;\n\t\t\t\tnoGood += isGood[v] - pv;\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tu = readInt!int - 1;\n\t\t\t\tv = readInt!int - 1;\n\t\t\t\tauto pu = isGood[u];\n\t\t\t\tauto pv = isGood[v];\n\t\t\t\tadj[u].removeKey(v);\n\t\t\t\tadj[v].removeKey(u);\n\t\t\t\tisGood[u] = adj[u].length == 0 || adj[u].front < u;\n\t\t\t\tisGood[v] = adj[v].length == 0 || adj[v].front < v;\n\t\t\t\tnoGood += isGood[u] - pu;\n\t\t\t\tnoGood += isGood[v] - pv;\n\t\t\t\tbreak;\n\t\t\tcase 3: \n\t\t\t\tnoGood.writeln;\n\t\t\t\tbreak;\n\t\t\tdefault: assert(0);\n\t\t}\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"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.container;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport core.stdc.stdio;\nimport std.functional;\n\nvoid main()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\talias Set = RedBlackTree!(int, (a, b) => a > b);\n\tauto adj = new Set[](n);\n\tforeach(ref adji; adj) adji = new Set();\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].insert(v);\n\t\tadj[v].insert(u);\n\t}\n\tint noGood = 0;\n\tauto isGood = new bool[](n);\n\tforeach(i; 0 .. n)\n\t{\n\t\tisGood[i] = adj[i].front < i;\n\t\tnoGood += isGood[i];\n\t}\n\tauto nq = readInt!int;\n\tforeach(q; 0 .. nq)\n\t{\n\t\tauto op = readInt!int;\n\t\tint v, u;\n\t\tswitch(op)\n\t\t{\n\t\t\tcase 1:\n\t\t\t\tu = readInt!int - 1;\n\t\t\t\tv = readInt!int - 1;\n\t\t\t\tauto pu = isGood[u];\n\t\t\t\tauto pv = isGood[v];\n\t\t\t\tadj[u].insert(v);\n\t\t\t\tadj[v].insert(u);\n\t\t\t\tisGood[u] = adj[u].front < u;\n\t\t\t\tisGood[v] = adj[v].front < v;\n\t\t\t\tnoGood += isGood[u] - pu;\n\t\t\t\tnoGood += isGood[v] - pv;\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tu = readInt!int - 1;\n\t\t\t\tv = readInt!int - 1;\n\t\t\t\tauto pu = isGood[u];\n\t\t\t\tauto pv = isGood[v];\n\t\t\t\tadj[u].removeKey(v);\n\t\t\t\tadj[v].removeKey(u);\n\t\t\t\tisGood[u] = adj[u].front < u;\n\t\t\t\tisGood[v] = adj[v].front < v;\n\t\t\t\tnoGood += isGood[u] - pu;\n\t\t\t\tnoGood += isGood[v] - pv;\n\t\t\t\tbreak;\n\t\t\tcase 3: \n\t\t\t\tnoGood.writeln;\n\t\t\t\tbreak;\n\t\t\tdefault: assert(0);\n\t\t}\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": "49009175bae8537e6d51424fab28183a"} {"source_code": "module sigod.codeforces.p291D;\n\nimport std.conv;\nimport std.stdio;\n\nvoid main()\n{\n\tint n, k;\n\tstdin.readf(\" %s %s\", &n, &k);\n\n\tstring end_line = n.to!string() ~ (n > 1 ? \" \" ~ n.to!string() : \"\");\n\n\tint[] memory = new int[n + 1];\n\tmemory[] = 1;\n\tmemory[n] = 0;\n\n\tforeach (ki; 0 .. k) {\n\t\tforeach (i; 1 .. n - 1) {\n\t\t\tif (memory[i] < n - i) {\n\t\t\t\tif (memory[i] * 2 <= n - i) {\n\t\t\t\t\tmemory[i] *= 2;\n\t\t\t\t\tstdout.write(i, \" \");\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tint index = n - (n - i - memory[i]);\n\n\t\t\t\t\tmemory[i] += memory[index];\n\t\t\t\t\tstdout.write(index, \" \");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tstdout.write(n, \" \");\n\t\t\t}\n\t\t}\n\n\t\tstdout.writeln(end_line);\n\t}\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\tauto a = new int [n];\n\t\ta[1..$] = 1;\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tint [] r;\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tr ~= min (a[j], j - a[j]);\n\t\t\t}\n\t\t\ta[] += r[];\n\t\t\tr[] = n - r[];\n\t\t\treverse (r);\n\t\t\twritefln (\"%(%s %)\", r);\n\t\t}\n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tenforce (a[j] == j);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "c8800840e52d4141acdff0420e7ec73c"} {"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, l;\n\twhile (readf (\" %s %s %s\", &n, &m, &l) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\ta = 0 ~ a ~ 0;\n\t\tint cur = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tif (a[i] > l)\n\t\t\t{\n\t\t\t\tcur += 1;\n\t\t\t\tcur -= (a[i - 1] > l);\n//\t\t\t\tcur -= (a[i + 1] > l);\n\t\t\t}\n\t\t}\n\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 == 0)\n\t\t\t{\n\t\t\t\twriteln (cur);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint p, d;\n\t\t\t\treadf (\" %s %s\", &p, &d);\n\t\t\t\tauto g = (a[p] <= l && a[p] + d > l);\n\t\t\t\ta[p] += d;\n\t\t\t\tif (g)\n\t\t\t\t{\n\t\t\t\t\tcur += 1;\n\t\t\t\t\tcur -= (a[p - 1] > l);\n\t\t\t\t\tcur -= (a[p + 1] > l);\n\t\t\t\t}\n\t \t}\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nlong[] a=new long[100002];\nvoid main()\n{\n\tint n,m,l,ans=0;\n\tscanf(\"%d%d%d\",&n,&m,&l);\n\tfor (int i=1;i<=n;++i)\n\t{\n\t\tscanf(\"%lld\",&a[i]);\n\t\tif (a[i]>l) ans+=a[i-1]<=l;\n\t}\n\tfor (int i=1;i<=m;++i)\n\t{\n\t\tint o;\n\t\tscanf(\"%d\",&o);\n\t\tif (o==0) printf(\"%d\\n\",ans);\n\t\telse\n\t\t{\n\t\t\tint p,d;\n\t\t\tscanf(\"%d%d\",&p,&d);\n\t\t\tif (a[p]<=l && a[p]+d>l) ans+=1-(a[p-1]>l)-(a[p+1]>l);\n\t\t\ta[p]+=d;\n\t\t}\n\t}\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, m, l;\n\twhile (readf (\" %s %s %s\", &n, &m, &l) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(long)).array;\n\t\ta = 0 ~ a ~ 0;\n\t\tint cur = 0;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tif (a[i] > l)\n\t\t\t{\n\t\t\t\tcur += 1;\n\t\t\t\tcur -= (a[i - 1] > l);\n\t\t\t\tcur -= (a[i + 1] > l);\n\t\t\t}\n\t\t}\n\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 == 0)\n\t\t\t{\n\t\t\t\twriteln (cur);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint p, d;\n\t\t\t\treadf (\" %s %s\", &p, &d);\n\t\t\t\tauto g = (a[p] <= l && a[p] + d > l);\n\t\t\t\ta[p] += d;\n\t\t\t\tif (g)\n\t\t\t\t{\n\t\t\t\t\tcur += 1;\n\t\t\t\t\tcur -= (a[p - 1] > l);\n\t\t\t\t\tcur -= (a[p + 1] > l);\n\t\t\t\t}\n\t \t}\n\t\t}\n\t}\n}\n"}], "src_uid": "1e17039ed5c48e5b56314a79b3811a40"} {"source_code": "import std.conv;\nimport std.math;\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n\tauto n = readln.strip.to!uint;\n\tauto v = readln.strip.splitter(' ').map!(a => a.to!int).array;\n\n\tuint res;\n\n for(int i = cast(uint)v.length - 2; i >= 0; i -= 2) {\n\t\tres += abs(v[i] - v[i + 1]);\n\t\tif(i) v[i / 2 - 1] += max(v[i], v[i + 1]);\n }\n\n\tres.write;\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\tint n;\n\treadf (\"%s \", &n);\n\tauto a = readln.split.map!(to!int).array,\n\t\tm = a.length, v = new int [m + 1];\n\tint res = 0;\n\tforeach_reverse (i; 0..m / 2) {\n\t\tint lo = v[i * 2 + 1] + a[i * 2 + 0];\n\t\tint hi = v[i * 2 + 2] + a[i * 2 + 1];\n\t\tv[i] = max (lo, hi);\n\t\tres += v[i] * 2 - lo - hi;\n\t}\n\tres.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\tauto a = readln ().split ().map !(to !(long)).array;\n\t\tauto m = a.length;\n\t\tauto v = new long [m + 1];\n\t\tlong res = 0;\n\t\tforeach_reverse (i; 0..m / 2)\n\t\t{\n\t\t\tlong lo = v[i * 2 + 1] + a[i * 2 + 0];\n\t\t\tlong hi = v[i * 2 + 2] + a[i * 2 + 1];\n\t\t\tv[i] = max (lo, hi);\n\t\t\tres += v[i] * 2 - lo - hi;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.conv;\nimport std.math;\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.bigint;\nimport std.algorithm;\n\nstruct S {\n\tuint a, b;\n\tS *left, right;\n}\n\nvoid main() {\n\tauto n = readln.strip.to!uint;\n\tauto arr = readln.strip.splitter(' ').map!(a => a.to!uint).array;\n\n\tS *create(uint idx) {\n\t\tif(idx == n) return null;\n\n\t\tauto s = new S;\n\n\t\ts.a = arr[0];\n\t\ts.b = arr[1];\n\n\t\tarr = arr[2..$];\n\n\t\ts.left = create(++idx);\n\t\ts.right = create(idx);\n\n\t\treturn s;\n\t}\n\n\tauto root = create(0);\n\n\tuint calcMax(S *s, uint n = 0) {\n\t\tif(!s)\n\t\t\treturn n;\n\t\treturn max(calcMax(s.left, n + s.a), calcMax(s.right, n + s.b));\n\t}\n\n\tauto m = calcMax(root);\n\tBigInt res;\n\n\tlong calcResults(S *s, long n = 0) {\n\t\tif(!s)\n\t\t\treturn m - n;\n\n\t\tauto v = calcResults(s.left, n + s.a);\n\t\tauto u = calcResults(s.right, n + s.b);\n\n\t\tauto k = abs(v - u);\n\t\tres += k;\n\n\t\treturn max(v, u) - k;\n\t}\n\n\tcalcResults(root);\n\tres.writeln;\n}\n"}, {"source_code": "import std.conv;\nimport std.math;\nimport std.stdio;\nimport std.range;\nimport std.string;\nimport std.algorithm;\n\nstruct S {\n\tuint a, b;\n\tS *left, right;\n}\n\nvoid main() {\n\tauto n = readln.strip.to!uint;\n\tauto arr = readln.strip.splitter(' ').map!(a => a.to!uint).array;\n\n\tS *create(uint idx) {\n\t\tif(idx == n) return null;\n\n\t\tauto s = new S;\n\n\t\ts.a = arr[0];\n\t\ts.b = arr[1];\n\n\t\tarr = arr[2..$];\n\n\t\ts.left = create(++idx);\n\t\ts.right = create(idx);\n\n\t\treturn s;\n\t}\n\n\tauto root = create(0);\n\n\tuint calcMax(S *s, uint n = 0) {\n\t\tif(!s)\n\t\t\treturn n;\n\t\treturn max(calcMax(s.left, n + s.a), calcMax(s.right, n + s.b));\n\t}\n\n\tauto m = calcMax(root);\n\tuint res;\n\n\tint calcResults(S *s, uint n = 0) {\n\t\tif(!s)\n\t\t\treturn m - n;\n\n\t\tauto v = calcResults(s.left, n + s.a);\n\t\tauto u = calcResults(s.right, n + s.b);\n\n\t\tauto k = abs(v - u);\n\t\tres += k;\n\n\t\treturn max(v, u) - k;\n\t}\n\n\tcalcResults(root);\n\tres.writeln;\n}\n"}], "src_uid": "ae61e1270eeda8c30effc9ed999bf531"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 s = RD!string;\n\t\t\n\t\tint l = -1, r;\n\t\tforeach (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 (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '1')\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 == -1)\n\t\t{\n\t\t\tans[ti] = 1 + (n-1) / (k+1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[ti] += l / (k+1);\n\t\t\tans[ti] += (n-r-1) / (k+1);\n\t\t\tint cnt;\n\t\t\tforeach (i; l..r)\n\t\t\t{\n\t\t\t\tdebug writeln(\"cnt:\", cnt, \" ans:\", ans[ti]);\n\t\t\t\tif (s[i] == '1')\n\t\t\t\t{\n\t\t\t\t\tans[ti] += (cnt-k) / (k+1);\n\t\t\t\t\tcnt = 0;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[ti] += (cnt-k) / (k+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", "positive_code": [{"source_code": "import std.stdio;\nimport std.string : strip;\nimport std.algorithm : group;\nimport std.range;\n\nvoid main()\n{\n int t;\n readf!\"%d\\n\"(t);\n\n foreach (i; 0..t) {\n int n, k;\n readf!\"%d %d\\n\"(n, k);\n auto s = readln.strip;\n auto g = s.group;\n auto ng = g.walkLength;\n auto c = 0;\n \n foreach (e; g.enumerate) {\n auto j = e.index;\n auto x = e.value;\n\n if (x[0] == '1') {\n continue;\n }\n\n if (ng == 1) {\n // only 1 group of zeros: take the left table, then (n-1) / (k+1)\n c += 1 + (n - 1) / (k + 1);\n } else if (j == 0 || j == ng - 1) {\n // if first or last group is zeros: x / (k + 1)\n c += x[1] / (k + 1);\n } else {\n // else (x - k) / (k + 1)\n c += (x[1] - k) / (k + 1);\n }\n }\n\n writeln(c);\n }\n}"}], "negative_code": [], "src_uid": "fd85ebe1dc975a71c72fac7eeb944a4a"} {"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\nlong calc(long n, long k) {\n long d = k / (n-1);\n return k + d + (k % (n-1) == 0 ? -1 : 0);\n}\n\nvoid main() {\n int t; scan(t);\n foreach (_; 0..t) {\n int n, k; scan(n, k);\n writeln(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", "positive_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 auto nk = readNums!int;\n auto skip = (nk[1]-1) / (nk[0]-1);\n\n writeln(nk[1] + skip);\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;\n\t\tauto k = RD;\n\t\t\n\t\tlong x = k;\n\t\tlong cnt;\n\t\twhile (x >= n)\n\t\t{\n\t\t\tcnt += x / n;\n\t\t\tx = (x % n) + x / n;\n\t\t}\n\t\tans[ti] = k+cnt;\n\t}\n\t\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 ip = readAs!(long[]), n = ip[0], k = ip[1];\n\n\t\tlong l = 0, r = 1L << 60;\n\t\tlong m;\n\n\t\twhile(l + 1 < r) {\n\t\t\t//debug \"%d, %d\".writefln(l, r);\n\t\t\tm = (l+r) / 2;\n\t\t\tdebug writefln(\"%d - (%d / %d) = %d, %d\", m, m, n, m - (m / n), k);\n\t\t\tif(m - (m / n) < k) {\n\t\t\t\tdebug \"ok\".writeln;\n\t\t\t\tl = m;\n\t\t\t} else r = m;\n\t\t}\n\n\t\t(l+1).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 nk = readln.split.to!(long[]);\n auto N = nk[0];\n auto K = nk[1];\n\n if (K < N) {\n writeln(K);\n continue;\n }\n\n long l = 1, r = K*2+1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n auto e = m/N;\n if (m-e >= K) {\n r = m;\n } else {\n l = m;\n }\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\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\tauto res = k * 1L * n / (n - 1) - 5;\n\t\twhile (res - res / n < k)\n\t\t{\n\t\t\tres += 1;\n\t\t}\n\t\twriteln (res);\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 nk = readln.split.to!(long[]);\n auto N = nk[0];\n auto K = nk[1];\n\n long l = 1, r = K*2+1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n auto e = m/N;\n if (m-e >= K) {\n r = m;\n } else {\n l = m;\n }\n }\n writeln(r);\n }\n}"}, {"source_code": "// Author: Ivan Kazmenko (gassa@mail.ru)\n// does not work for some inputs, for example, n = 4 and k = 2\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\tint n, k;\n\t\treadf !(\" %s %s\") (n, k);\n\t\tauto res = k * 1L * n / (n - 1) - 1;\n\t\tif (res % n == 0)\n\t\t{\n\t\t\tres += 1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "7d6f76e24fe9a352beea820ab56f03b6"} {"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 x, y; get(x, y);\r\n char[] s; get(s);\r\n int max_x, min_x, max_y, min_y;\r\n foreach (c; s) {\r\n switch (c) {\r\n case 'U': ++max_y; break;\r\n case 'D': --min_y; break;\r\n case 'R': ++max_x; break;\r\n case 'L': --min_x; break;\r\n default:\r\n }\r\n }\r\n writeln(min_x <= x && x <= max_x && min_y <= y && y <= max_y ? \"YES\" : \"NO\");\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 x = RD;\r\n\t\tauto y = RD;\r\n\t\tauto s = RD!string;\r\n\r\n\t\tlong u, d, r, l;\r\n\t\tforeach (c; s)\r\n\t\t{\r\n\t\t\tif (c == 'U')\r\n\t\t\t\t++u;\r\n\t\t\telse if (c == 'D')\r\n\t\t\t\t--d;\r\n\t\t\telse if (c == 'R')\r\n\t\t\t\t++r;\r\n\t\t\telse\r\n\t\t\t\t--l;\r\n\t\t}\r\n\t\tans[ti] = true;\r\n\t\tif (x > r || x < l)\r\n\t\t\tans[ti] = false;\r\n\t\tif (y > u || y < d)\r\n\t\t\tans[ti] = false;\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;\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\treadln;\r\n\t\tauto s = readln.strip;\r\n\t\tbool ok = true;\r\n\t\tok &= (s.count ('R').to !(int) >= +x);\r\n\t\tok &= (s.count ('L').to !(int) >= -x);\r\n\t\tok &= (s.count ('U').to !(int) >= +y);\r\n\t\tok &= (s.count ('D').to !(int) >= -y);\r\n\t\twriteln (ok ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "65a64ea63153fec4d660bad1287169d3"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nint search(long[] arr, int n, long t)\n{\n auto left = 0, right = n - 1;\n auto res = -1;\n while (left <= right)\n {\n auto mid = (left + right) >> 1;\n if (arr[mid] >= t)\n {\n right = mid - 1;\n }\n else\n {\n left = mid + 1;\n res = mid;\n }\n }\n return res + 1;\n}\n\nlong count(int[] a, int left, int right, long t)\n{\n if (left == right)\n {\n if (a[left] < t) return 1;\n return 0;\n }\n long res = 0;\n auto mid = (left + right) >> 1;\n res += count(a, left, mid, t);\n res += count(a, mid + 1, right, t);\n auto arr = new long[mid - left + 1];\n long sum = 0;\n for (int i = mid; i >= left; -- i)\n {\n sum += a[i];\n arr[mid - i] = sum;\n }\n arr.sort;\n sum = 0;\n for (int i = mid + 1; i <= right; ++ i)\n {\n sum += a[i];\n auto ret = search(arr, mid - left + 1, t - sum);\n res += ret;\n }\n return res;\n}\n\nvoid solve(int[] a, int n, long t)\n{\n auto ans = count(a, 0, n - 1, t);\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n;\n long t;\n while (readf(\"%d %d\\n\", &n, &t) == 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, n, t);\n }\n return 0;\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\nconst long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split;\n auto N = s[0].to!int;\n auto T = s[1].to!long;\n auto A = readln.split.map!(to!long).array;\n auto B = new long[](N+1);\n foreach (i; 0..N) B[i+1] = B[i] + A[i];\n\n int[long] comp;\n auto C = B.dup.sort().uniq().array;\n auto M = C.length.to!int;\n foreach (i; 0..M) comp[C[i]] = i;\n\n auto st = new SegmentTree(M);\n foreach (i; 0..N+1) st.add(comp[B[i]], 1);\n long ans = 0;\n\n foreach (i; 0..N) {\n st.add(comp[B[i]], -1);\n auto lb = C.assumeSorted.lowerBound(T + B[i]).length.to!int;\n ans += st.sum(0, lb - 1);\n }\n\n ans.writeln;\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 (pr < pl) 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"}], "negative_code": [], "src_uid": "42c4adc1c4a10cc619c05a842e186e60"} {"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\tint m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\treadln;\n\t\tauto x = readln.split;\n\t\tauto y = readln.split;\n\t\tauto q = readln.strip.to !(int);\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tauto z = readln.strip.to !(int);\n\t\t\tz -= 1;\n\t\t\twriteln (x[z % n], y[z % m]);\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; }\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 m = RD!int;\n\tstring[] s, t;\n\tforeach (i; 0..n)\n\t\ts ~= RD!string;\n\tforeach (i; 0..m)\n\t\tt ~= RD!string;\n\tauto q = RD!int;\n\tauto ans = new string[](q);\n\tforeach (qi; 0..q)\n\t{\n\t\tauto y = RD!int-1;\n\t\tans[qi] = s[y%n] ~ t[y%m];\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string : strip, split;\n\nvoid main()\n{\n int n, m, q;\n readf!\"%d %d\\n\"(n, m);\n\n auto s = readln.strip.split;\n auto t = readln.strip.split;\n readf!\"%d\\n\"(q);\n\n foreach (i; 0..q) {\n int y;\n readf!\"%d\\n\"(y);\n y--;\n\n writeln(s[y % s.length] ~ t[y % t.length]);\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, m = rint;\n\tstring[] as = rtypes!string(n);\n\tstring[] bs = rtypes!string(m);\n\n\tforeach(_; 0 .. rint){\n\t\tlong x = rlong - 1;\n\t\t(as[(x % n).to!int] ~ bs[(x % m).to!int]).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 N = readInt();\n const M = readInt();\n auto S = new string[N];\n foreach (i; 0 .. N) {\n S[i] = readToken();\n }\n auto T = new string[M];\n foreach (j; 0 .. M) {\n T[j] = readToken();\n }\n const Q = readInt();\n auto Y = new int[Q];\n foreach (q; 0 .. Q) {\n Y[q] = readInt();\n }\n \n foreach (q; 0 .. Q) {\n writeln(S[(Y[q] - 1) % N], T[(Y[q] - 1) % M]);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "efa201456f8703fcdc29230248d91c54"} {"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 = cin.read_int;\n string s = cin.read_string;\n string code = cin.read_string;\n int ans = 0;\n for (int i = 0; i < n; i++) {\n int met1 = min(s[i], code[i]) + 10 - max(s[i], code[i]);\n int met2 = abs(code[i] - s[i]);\n ans += min(met1, met2);\n }\n writeln(ans);\n } \n}", "positive_code": [{"source_code": "import std.stdio, std.range, std.conv, std.algorithm, std.array, std.string, std.ascii, std.math;\n\nvoid main() {\n\n\treadln;\n\tauto a = readln.strip, b = readln.strip;\n\n\tuint sum;\n\tforeach (i, e; a) {\n\t\tauto tmpA = e.to!int, tmpB = b[i].to!int;\n\t\tauto minA = min(tmpA, tmpB), maxB = max(tmpA, tmpB);\n\t\tauto cl = maxB - minA, tl = 10 - maxB + minA;\n\t\tif (cl < tl) {\n\t\t\tsum += cl;\n\t\t}\n\t\telse {\n\t\t\tsum += tl;\n\t\t}\n\t}\n\n\twriteln(sum);\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n; scanf(\"%d\", &n);\n\tchar[1001] ss;\n\tchar[1001] fs;\n\tscanf(\"%s\", &ss);\n\tscanf(\"%s\", &fs);\n\tint count = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tint d1 = ss[i] - fs[i]; d1 = abs(d1);\n\t\tint d2 = 10 - d1; d2 = abs(d2);\n\t\tcount += (d1 < d2 ? d1 : d2);\n\t}\n\twrite(count);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "5adb1cf0529c3d6c93c107cf72fa5e0b"} {"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!long);\n auto a = s[0];\n auto b = s[1];\n auto c = s[2];\n auto r = s[3];\n if (a > b) swap(a, b);\n auto u = c - r;\n auto v = c + r;\n if (u >= b || v <= a) {\n writeln(b - a);\n } else {\n u = max(u, a);\n v = min(v, b);\n writeln(b - a - (v - u));\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\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 auto a = r.next!int;\n auto b = r.next!int;\n if (a > b) swap (a, b);\n immutable c = r.next!int;\n immutable rd = r.next!int;\n immutable u = c - rd, v = c + rd;\n auto x = max (a, u), y = min (b, v); \n auto s = x < y ? (y - x) : 0;\n res[tid] = (b - a) - s;\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\tlong a = rlong, b = rlong, c = rlong, r = rlong;\n\t\tlong x = c - r, y = c + r;\n\t\tif(a > b){ long z = a; a = b, b = z; }\n\t\tlong ans;\n\t\tif(y <= a || b <= x) ans += b - a;\n\t\telse{\n\t\t\tif(a < x) ans += x - a;\n\t\t\tif(y < b) ans += b - y;\n\t\t}\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 t = RD!int;\n\tauto ans = new int[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto a = RD!int;\n\t\tauto b = RD!int;\n\t\tauto c = RD!int;\n\t\tauto r = RD!int;\n\t\tif (a > b)\n\t\t\tswap(a, b);\n\t\tauto x = c - r;\n\t\tauto y = c + r;\n\t\tauto len = b - a;\n\t\tif (x < a)\n\t\t\tans[ti] = max(len - max(0, y - a), 0);\n\t\telse if (y >= b)\n\t\t\tans[ti] = max(len - max(0, b - x), 0);\n\t\telse\n\t\t\tans[ti] = max(len - (y - x), 0);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "783772cb7a54bf65f648d3f8b7648263"} {"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\tlong n;\n\t\treadf !(\" %s\") (n);\n\t\tn -= 1;\n\t\tlong triple = n / 3;\n\t\tint rem = n % 3;\n\t\tint bits = 0;\n\t\twhile (triple >= 1L << bits)\n\t\t{\n\t\t\ttriple -= 1L << bits;\n\t\t\tbits += 2;\n\t\t}\n\t\tauto a = [0L, 0L, 0L];\n\t\ta[0] += (1L << bits);\n\t\ta[1] += (2L << bits);\n\t\ta[2] += (3L << bits);\n\t\tfor (int bit = 0; bit < bits; bit += 2)\n\t\t{\n\t\t\tint cur = triple & 3;\n\t\t\ta[0] += [0L, 1L, 2L, 3L][cur] << bit;\n\t\t\ta[1] += [0L, 2L, 3L, 1L][cur] << bit;\n\t\t\ta[2] += [0L, 3L, 1L, 2L][cur] << bit;\n\t\t\ttriple >>= 2;\n\t\t}\n\t\twriteln (a[rem]);\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 bool[long] app;\n foreach (i; 0 .. 100) {\n for (int a = 0; ; ++a) {\n if (a !in app) {\n for (int b = 0; ; ++b) {\n const c = a ^ b;\n if ((b !in app) && (c !in app)) {\n writefln(\"%3d %3d %3d %10b %10b %10b\", a, b, c, a, b, c);\n app[a] = app[b] = app[c] = true;\n goto found;\n }\n }\n }\n }\n found:\n }\n }\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readLong() - 1;\n long n = N / 3;\n for (int k = 0; ; ++k) {\n // a \\in [2^(2k), 2^(2k+1))\n if (n < 1L << (2 * k)) {\n debug {\n writefln(\"k = %s, n = %s\", k, n);\n }\n long a = 1L << (2 * k);\n a += n;\n long b = 1L << (2 * k + 1);\n foreach (i; 0 .. k) {\n b |= [0L, 2L, 3L, 1L][cast(int)((a >> (2 * i)) & 3)] << (2 * i);\n }\n const c = a ^ b;\n debug {\n writefln(\"%064b\", a);\n writefln(\"%064b\", b);\n writefln(\"%064b\", c);\n }\n writeln([a, b, c][cast(int)(N % 3)]);\n break;\n } else {\n n -= 1L << (2 * k);\n }\n }\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 debug {\n bool[long] app;\n foreach (i; 0 .. 100) {\n for (int a = 0; ; ++a) {\n if (a !in app) {\n for (int b = 0; ; ++b) {\n const c = a ^ b;\n if ((b !in app) && (c !in app)) {\n writefln(\"%3d %3d %3d %10b %10b %10b\", a, b, c, a, b, c);\n app[a] = app[b] = app[c] = true;\n goto found;\n }\n }\n }\n }\n found:\n }\n }\n \n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const N = readLong() - 1;\n long n = N / 3;\n for (int k = 0; ; ++k) {\n // a \\in [2^(2k), 2^(2k+1))\n if (n < 1L << (2 * k)) {\n long a = 1L << (2 * k);\n a += n;\n long b = 1L << (2 * k + 1);\n foreach (i; 0 .. k) {\n b |= [0, 2, 3, 1][cast(int)((a >> (2 * i)) & 3)] << (2 * i);\n }\n const c = a ^ b;\n writeln([a, b, c][cast(int)(N % 3)]);\n break;\n } else {\n n -= 1L << (2 * k);\n }\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "37c3725f583ca33387dfd05fe75898a9"} {"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 h, w;\n\twhile (readf (\" %s %s\", &h, &w) > 0)\n\t{\n\t\treadln;\n\t\tstring [] a;\n\t\ta ~= '#'.repeat (w + 2).array;\n\t\tforeach (row; 1..h + 1)\n\t\t{\n\t\t\ta ~= '#' ~ readln.strip ~ '#';\n\t\t}\n\t\ta ~= '#'.repeat (w + 2).array;\n\n\t\tauto frow = new int [] [] (h + 2, w + 2);\n\t\tforeach (row; 0..h + 2)\n\t\t{\n\t\t\tfrow[row][0] = 0;\n\t\t\tforeach (col; 1..w + 2)\n\t\t\t{\n\t\t\t\tfrow[row][col] = frow[row][col - 1] +\n\t\t\t\t (a[row][col - 1] == '.' &&\n\t\t\t\t a[row][col] == '.');\n\t\t\t}\n\t\t}\n\n\t\tauto fcol = new int [] [] (w + 2, h + 2);\n\t\tforeach (col; 0..w + 2)\n\t\t{\n\t\t\tfcol[col][0] = 0;\n\t\t\tforeach (row; 1..h + 2)\n\t\t\t{\n\t\t\t\tfcol[col][row] = fcol[col][row - 1] +\n\t\t\t\t (a[row - 1][col] == '.' &&\n\t\t\t\t a[row][col] == '.');\n\t\t\t}\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\tint row1, col1, row2, col2;\n\t\t\treadf (\" %s %s %s %s\", &row1, &col1, &row2, &col2);\n\t\t\tint res = 0;\n\t\t\tforeach (row; row1..row2 + 1)\n\t\t\t{\n\t\t\t\tres += frow[row][col2] - frow[row][col1];\n\t\t\t}\n\t\t\tforeach (col; col1..col2 + 1)\n\t\t\t{\n\t\t\t\tres += fcol[col][row2] - fcol[col][row1];\n\t\t\t}\n\t\t\twriteln (res);\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, core.stdc.stdio, std.bitmanip;\n\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n \n auto B = new string[](H);\n foreach (i; 0..H) B[i] = readln.chomp;\n\n auto yoko = new int[][](H+1, W+1);\n auto tate = new int[][](H+1, W+1);\n foreach (i; 0..H) {\n foreach (j; 0..W) {\n if (j < W-1 && B[i][j] == '.' && B[i][j+1] == '.')\n yoko[i+1][j+1] += 1;\n if (i < H-1 && B[i][j] == '.' && B[i+1][j] == '.')\n tate[i+1][j+1] += 1;\n }\n }\n\n foreach (i; 0..H) foreach (j; 1..W) {\n yoko[i+1][j+1] += yoko[i+1][j];\n tate[i+1][j+1] += tate[i+1][j];\n }\n foreach (j; 0..W) foreach (i; 1..H) {\n yoko[i+1][j+1] += yoko[i][j+1];\n tate[i+1][j+1] += tate[i][j+1];\n }\n\n int acm(int a, int b, int c, int d) {\n return\n yoko[c][d-1] - yoko[a-1][d-1] - yoko[c][b-1] + yoko[a-1][b-1] +\n tate[c-1][d] - tate[a-1][d] - tate[c-1][b-1] + tate[a-1][b-1];\n }\n \n auto M = readln.chomp.to!int;\n foreach (_; 0..M) {\n int ans = 0;\n s = readln.split.map!(to!int);\n writeln(acm(s[0], s[1], s[2], s[3]));\n }\n}\n"}], "negative_code": [], "src_uid": "d9fdf0827940883069bead0d00b3da53"} {"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 auto g = new int[][] (n+1);\n foreach (i; 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 depth = new int[] (n+1);\n auto sz = new int[] (n+1);\n auto parent = new int[] (n+1);\n auto isLeaf = new bool[] (n+1);\n auto gain = new int[] (n+1);\n \n void dfs(int v, int fr) {\n depth[v] = v == 1 ? 0 : depth[fr] + 1;\n sz[v] = 1;\n parent[v] = fr;\n isLeaf[v] = true;\n \n foreach (u; g[v]) {\n if (u == fr) { continue; }\n \n dfs(u, v);\n \n sz[v] += sz[u];\n isLeaf[v] = false;\n }\n \n gain[v] = depth[v] - (sz[v] - 1);\n }\n \n dfs(1, 0);\n \n auto leavesWithGain = (n+1).iota.filter!(i => isLeaf[i]).map!(i => tuple(gain[i], i));\n auto rbt = redBlackTree(leavesWithGain);\n \n auto ans = 0L;\n while (k--) {\n ans += rbt.back[0];\n auto v = rbt.back[1];\n rbt.removeBack();\n \n rbt.insert(tuple(gain[parent[v]], parent[v]));\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.container.rbtree;\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\nclass G {\n int[][] e;\n int[] d, parent, ss;\n void go (int i) {\n ss[i] = 1;\n foreach (j; e[i]) {\n if (parent[j] == -2) {\n parent[j] = i; \n d[j] = d[i] + 1;\n go (j);\n ss[i] += ss[j];\n }\n }\n }\n this (int n) {\n e = new int[][n];\n d = new int[n];\n parent = new int[n];\n ss = new int[n];\n }\n void addEdge (int i, int j) {\n e[i] ~= j;\n e[j] ~= i;\n }\n void dfs () {\n parent[] = -2;\n parent[0] = -1;\n go (0);\n }\n}\n\nalias T = Tuple!(int, int);\n\nalias RBT = RedBlackTree!(T, \"a < b\", false);\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n const k = r.next!uint;\n auto g = new G (n);\n foreach (eid; 1 .. n) {\n const i = r.next!uint - 1;\n const j = r.next!uint - 1;\n g.addEdge (i, j);\n }\n g.dfs ();\n auto x = new int[n];\n foreach (i; 0 .. n) {\n x[i] = (g.ss[i] - 1) - g.d[i];\n }\n sort (x);\n writeln (sum(x[k .. $], 0L));\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 k = RD!int;\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 cnt = new long[](n);\n\n\tlong dfs(int pos, int par, int depth)\n\t{\n\t\tcnt[pos] += depth;\n\t\tlong res = 1;\n\t\tforeach (to; edges[pos])\n\t\t{\n\t\t\tif (to == par) continue;\n\t\t\tres += dfs(to, pos, depth+1);\n\t\t}\n\t\tcnt[pos] -= res;\n\t\treturn res;\n\t}\n\tdfs(0, -1, 0);\n\n\tauto resort = new bool[](n);\n\tauto index = cnt.MAKE_IDX;\n\tforeach (i; index[0..n-k])\n\t{\n\t\tresort[i] = true;\n\t}\n\n\tlong ans;\n\tvoid dfs2(int pos, int par, int depth)\n\t{\n\t\tif (resort[pos])\n\t\t{\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == par) continue;\n\t\t\t\tdfs2(to, pos, depth+1);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans += depth;\n\t\t\tforeach (to; edges[pos])\n\t\t\t{\n\t\t\t\tif (to == par) continue;\n\t\t\t\tdfs2(to, pos, depth);\n\t\t\t}\n\t\t}\n\t}\n\tdfs2(0, -1, 0);\n\n\twriteln(ans);\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.typecons;\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 (i; 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 depth = new int[] (n+1);\n auto sz = new int[] (n+1);\n auto parent = new int[] (n+1);\n auto isLeaf = new bool[] (n+1);\n auto gain = new int[] (n+1);\n \n void dfs(int v, int fr) {\n depth[v] = v == 1 ? 0 : depth[fr] + 1;\n sz[v] = 1;\n parent[v] = fr;\n isLeaf[v] = true;\n \n foreach (u; g[v]) {\n if (u == fr) { continue; }\n \n dfs(u, v);\n \n sz[v] += sz[u];\n isLeaf[v] = false;\n }\n \n gain[v] = depth[v] - (sz[v] - 1);\n }\n \n dfs(1, 0);\n \n auto leavesWithGain = (n+1).iota.filter!(i => isLeaf[i]).map!(i => tuple(gain[i], i));\n auto rbt = redBlackTree(leavesWithGain);\n foreach (i; 1 .. n+1) {\n if (isLeaf[i]) { rbt.insert(tuple(gain[i], i)); }\n }\n \n auto ans = 0L;\n while (k--) {\n ans += rbt.back[0];\n auto v = rbt.back[1];\n rbt.removeBack();\n \n rbt.insert(tuple(gain[parent[v]], parent[v]));\n }\n \n ans.writeln;\n}"}, {"source_code": "/// https://codeforces.com/contest/1336/problem/A\nimport std.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.container;\nimport std.range : sequence, take;\n\n\nvoid main()\n{\n int n, k;\n stdin.readf!\"%d %d\\n\"(n, k);\n\n int[][] adj; adj.length = n+1;\n\n int u, v;\n for (int i=1; i ac + (n != parent? dfs(n,node,depth+1): 0))(0);\n prioriry[node] = depth - children;\n return children + 1;\n }\n dfs(0);\n\n writeln(heapify(prioriry).take(k).sum);\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, 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 f = new int [n];\n\n\t\tint recur (int v, int p, int depth)\n\t\t{\n\t\t\tint total = 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\ttotal += recur (u, v, depth + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tf[v] = depth - total;\n\t\t\treturn total + 1;\n\t\t}\n\n\t\trecur (0, -1, 0);\n\t\tsort !(q{a > b}) (f);\n\t\twriteln (sum (f[0..k], 0L));\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, K;\nint[] A, B;\n\nint[][] G;\nint[] par, dep, sz;\n\nvoid dfs(int u, int p) {\n par[u] = p;\n dep[u] = (p == -1) ? 0 : (dep[p] + 1);\n sz[u] = 1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n dfs(v, u);\n sz[u] += sz[v];\n }\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 par = new int[N];\n dep = new int[N];\n sz = new int[N];\n dfs(0, -1);\n \n auto degs = new int[N];\n foreach (u; 1 .. N) {\n ++degs[par[u]];\n }\n alias Entry = Tuple!(int, \"score\", int, \"u\");\n BinaryHeap!(Array!Entry) que;\n foreach (u; 1 .. N) {\n if (degs[u] == 0) {\n que.insert(Entry(dep[u], u));\n }\n }\n \n long ans;\n foreach (k; 0 .. K) {\n const e = que.front;\n que.removeFront;\n debug {\n writeln(\"e = \", e);\n }\n ans += e.score;\n const p = par[e.u];\n if (p != 0 && --degs[p] == 0) {\n que.insert(Entry(dep[p] - (sz[p] - 1), p));\n }\n }\n writeln(ans);\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 = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, k;\n @Dim(\"n - 1\") long[2][] edges;\n\n void solve(long tc = -1)\n {\n auto alist = makeSlice!(long[])(n);\n auto height = makeSlice!(long)(n);\n auto size = makeSlice!(long)(n);\n foreach(ref edge; edges)\n {\n edge[] -= 1;\n alist.at(edge[0]) ~= edge[1];\n alist.at(edge[1]) ~= edge[0];\n }\n void dfs(long node, long parent, long h)\n {\n height.at(node) = h;\n size.at(node) = 1;\n foreach(nei; alist.at(node))\n if (nei != parent)\n {\n dfs(nei, node, h + 1);\n size.at(node) += size.at(nei);\n }\n }\n dfs(0, -1, 0);\n long[] priol;\n foreach(node; 0 .. n)\n priol ~= height.at(node) - size.at(node) + 1;\n sort(priol);\n writeln(priol[$ - cast(size_t) k .. $].sum);\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.stdio;\nimport std.algorithm;\nimport std.container : DList;\n\n\nvoid main()\n{\n int n, k;\n stdin.readf!\"%d %d\\n\"(n, k);\n\n int[][] adj; adj.length = n+1;\n bool[] visited; visited.length = n+1;\n bool[] tourism; tourism.length = n+1;\n\n int u, v;\n for (int i=1; i adj[b].length; }\n foreach (a; adj)\n a.sort!desc;\n\n k = n - k;\n\n auto q = DList!int(1);\n while (!q.empty() && k > 0) {\n auto city = q.back(); q.removeBack();\n tourism[city] = true;\n k = k - 1;\n if (k == 0) break;\n\n foreach (neighbor; adj[city])\n if (!visited[neighbor]) {\n visited[neighbor] = true;\n q.insertFront(neighbor);\n }\n }\n\n int happiness;\n int dfs(int i, int parent) {\n int industrial;\n\n foreach (child; adj[i])\n if (child == parent)\n continue;\n else\n industrial += dfs(child, i);\n\n if (tourism[i])\n happiness += industrial;\n else\n industrial += 1;\n\n return industrial;\n }\n\n dfs(1, 0);\n writeln(happiness);\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 Heap(T) {\n private:\n T [] a;\n int [] h;\n int [] g;\n int n;\n int size;\n pure nothrow @nogc\n void heapifyFront (int k) {\n immutable he = h[k];\n int i = k;\n int j = i << 1;\n while (j <= size) {\n if (j < size && a[h[j+1]] < a[h[j]]) {\n j++;\n }\n if (a[h[j]] >= a[he]) {\n break;\n }\n h[i] = h[j];\n g[h[i]] = i;\n i = j;\n j = i << 1;\n }\n if (i != k) {\n h[i] = he;\n g[he] = i;\n }\n }\n pure nothrow @nogc\n void heapifyBack (int k) {\n immutable he = h[k];\n int i = k;\n while (i > 1) {\n int j = i >> 1;\n if (a[he] >= a[h[j]]) {\n break;\n }\n h[i] = h[j];\n g[h[i]] = i;\n i = j;\n }\n if (i != k) {\n h[i] = he;\n g[he] = i;\n }\n }\n pure nothrow @nogc\n void insert (int i) {\n h[++size] = i;\n g[i] = size;\n heapifyBack (size);\n }\n public:\n pure nothrow @nogc\n void decreaseKey (int k, T value) in {\n assert (k >= 0 && k < n);\n assert (value < a[k]);\n } body {\n a[k] = value;\n immutable pos = g[k];\n if (!pos) {\n insert (k);\n } else {\n heapifyBack (pos);\n }\n }\n pure nothrow @nogc\n void update (int k, T value) in {\n assert (k >= 0 && k < n);\n } body {\n immutable pos = g[k];\n if (!pos) {\n a[k] = value;\n insert (k);\n } else if (value < a[k]) {\n a[k] = value;\n heapifyBack (pos);\n } else if (value > a[k]) {\n a[k] = value;\n heapifyFront (pos);\n }\n }\n pure nothrow @nogc\n int extractMin () {\n assert (size > 0);\n immutable he = h[1];\n g[he] = 0;\n if (--size) {\n h[1] = h[size+1];\n g[h[1]] = 1;\n heapifyFront (1);\n }\n return he;\n }\n pure nothrow @nogc\n inout(T) opIndex (size_t index) inout {\n return a[index];\n }\n\n @property pure nothrow @nogc\n bool empty () const { return size == 0; }\n\n this (int n_, T default_value = T.init) {\n n = n_;\n size = 0;\n a = uninitializedArray! (T[]) (n);\n a[] = default_value;\n h = new int[n+1];\n g = new int[n];\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\nclass G {\n int[][] e;\n int[] d, parent;\n void go (int i) {\n foreach (j; e[i]) {\n if (parent[j] == -2) {\n parent[j] = i; \n d[j] = d[i] + 1;\n go (j);\n }\n }\n }\n this (int n) {\n e = new int[][n];\n d = new int[n];\n parent = new int[n];\n }\n void addEdge (int i, int j) {\n e[i] ~= j;\n e[j] ~= i;\n }\n void dfs () {\n parent[] = -2;\n parent[0] = -1;\n go (0);\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n const k = r.next!uint;\n auto g = new G (n);\n foreach (eid; 1 .. n) {\n const i = r.next!uint - 1;\n const j = r.next!uint - 1;\n g.addEdge (i, j);\n }\n g.dfs ();\n auto h = new Heap!int (n, int.max / 2);\n long res;\n foreach (i; 0 .. n) {\n h.decreaseKey (i, -g.d[i]);\n }\n foreach (i; 0 .. k) {\n int j = h.extractMin ();\n res -= h[j];\n int o = g.parent[j]; \n if (o >= 0) {\n int w = h[o];\n h.update (o, w + 1);\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.container.rbtree;\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\nclass G {\n int[][] e;\n int[] d, parent;\n void go (int i) {\n foreach (j; e[i]) {\n if (parent[j] == -2) {\n parent[j] = i; \n d[j] = d[i] + 1;\n go (j);\n }\n }\n }\n this (int n) {\n e = new int[][n];\n d = new int[n];\n parent = new int[n];\n }\n void addEdge (int i, int j) {\n e[i] ~= j;\n e[j] ~= i;\n }\n void dfs () {\n parent[] = -2;\n parent[0] = -1;\n go (0);\n }\n}\n\nalias T = Tuple!(int, int);\n\nalias RBT = RedBlackTree!(T, \"a < b\", false);\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n const k = r.next!uint;\n auto g = new G (n);\n foreach (eid; 1 .. n) {\n const i = r.next!uint - 1;\n const j = r.next!uint - 1;\n g.addEdge (i, j);\n }\n g.dfs ();\n auto t = new RBT();\n foreach (i; 1 .. n) if (g.e[i].length == 1) {\n t.insert (T (g.d[i], i));\n }\n long res;\n auto delta = new int[n];\n foreach (qid; 0 .. k) {\n auto q = t.back;\n debug stderr.writeln (q);\n res += q[0];\n const int j = q[1];\n int o = g.parent[j]; \n if (o >= 0) {\n delta[o] = delta[j] + 1;\n t.insert (T (g.d[o] - delta[o], o));\n }\n t.removeBack ();\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.container.rbtree;\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\nclass G {\n int[][] e;\n int[] d, parent;\n void go (int i) {\n foreach (j; e[i]) {\n if (parent[j] == -2) {\n parent[j] = i; \n d[j] = d[i] + 1;\n go (j);\n }\n }\n }\n this (int n) {\n e = new int[][n];\n d = new int[n];\n parent = new int[n];\n }\n void addEdge (int i, int j) {\n e[i] ~= j;\n e[j] ~= i;\n }\n void dfs () {\n parent[] = -2;\n parent[0] = -1;\n go (0);\n }\n}\n\nalias T = Tuple!(int, int);\n\nalias RBT = RedBlackTree!(T, \"a < b\", false);\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n const k = r.next!uint;\n auto g = new G (n);\n foreach (eid; 1 .. n) {\n const i = r.next!uint - 1;\n const j = r.next!uint - 1;\n g.addEdge (i, j);\n }\n g.dfs ();\n auto t = new RBT();\n auto intree = new bool[n];\n foreach (i; 1 .. n) if (g.e[i].length == 1) {\n t.insert (T (g.d[i], i));\n intree[i] = true;\n }\n long res;\n auto delta = new int[n];\n foreach (qid; 0 .. k) {\n auto q = t.back;\n debug stderr.writeln (q);\n res += q[0];\n const int j = q[1];\n int o = g.parent[j]; \n t.removeBack ();\n if (o > 0) {\n if (intree[o]) {\n t.removeKey (T (g.d[o] - delta[o], o));\n } else intree[o] = true;\n delta[o] += delta[j] + 1;\n t.insert (T (g.d[o] - delta[o], o));\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.container.rbtree;\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\nclass G {\n int[][] e;\n int[] d, parent;\n void go (int i) {\n foreach (j; e[i]) {\n if (parent[j] == -2) {\n parent[j] = i; \n d[j] = d[i] + 1;\n go (j);\n }\n }\n }\n this (int n) {\n e = new int[][n];\n d = new int[n];\n parent = new int[n];\n }\n void addEdge (int i, int j) {\n e[i] ~= j;\n e[j] ~= i;\n }\n void dfs () {\n parent[] = -2;\n parent[0] = -1;\n go (0);\n }\n}\n\nalias T = Tuple!(int, int);\n\nalias RBT = RedBlackTree!(T, \"a < b\", false);\n\nvoid main() {\n auto r = new InputReader ();\n const n = r.next!uint;\n const k = r.next!uint;\n auto g = new G (n);\n foreach (eid; 1 .. n) {\n const i = r.next!uint - 1;\n const j = r.next!uint - 1;\n g.addEdge (i, j);\n }\n g.dfs ();\n auto t = new RBT();\n foreach (i; 1 .. n) if (g.e[i].length == 1) {\n t.insert (T (g.d[i], i));\n }\n long res;\n auto delta = new int[n];\n foreach (qid; 0 .. k) {\n auto q = t.back;\n debug stderr.writeln (q);\n res += q[0];\n const int j = q[1];\n int o = g.parent[j]; \n if (o > 0) {\n delta[o] = delta[j] + 1;\n t.insert (T (g.d[o] - delta[o], o));\n }\n t.removeBack ();\n }\n writeln (res);\n}\n\n"}], "src_uid": "47129977694cb371c7647cfd0db63d29"} {"source_code": "import std;\r\nvoid main () {\r\n\tforeach (t; 0..readln.strip.to!int) {\r\n\t\tauto n = readln.strip.to!int;\r\n\t\t\"21\".cycle.drop (n % 3 == 1).take ((n * 2 + 1) / 3).writeln;\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\twriteln (\"21\".cycle.drop (n % 3 == 1).take ((n * 2 + 1) / 3));\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "1a5f266b49aadbeef59e19bcf5524a57"} {"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 r = RDA;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (r[i] == 2) continue;\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": "import std.stdio, std.string, std.algorithm, 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 readln();\r\n writeln(readln.split.filter!(a => a != \"2\").array.length);\r\n }\r\n}"}], "negative_code": [], "src_uid": "a063705bd0ce1e17ccaafbbfc2663d93"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid solve() {\n int n;\n readf(\" %s\", n);\n \n int A, B, C, D;\n A = D = -100000;\n B = C = 100000;\n foreach(i; 0..n) {\n int x, y;\n bool a, b, c, d;\n readf(\" %s %s %b %b %b %b\", x, y, a, b, c, d);\n // left, up, right, down\n if (!a) A = max(A, x);\n if (!b) B = min(B, y);\n if (!c) C = min(C, x);\n if (!d) D = max(D, y);\n }\n if (!(A <= C && D <= B)) writeln(0); else writeln(1, \" \", (A+C)/2, \" \", (B+D)/2);\n}\n\nvoid main() {\n int q;\n readf(\" %s\", q);\n\n foreach(i; 0..q) {\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.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!int;\n\t\tlong l = -(10^^5), t = -(10^^5), r = 10^^5, b = 10^^5; \n\t\tforeach (j; 0..n)\n\t\t{\n\t\t\tauto a = RDA;\n\t\t\tif (a[2] == 0)\n\t\t\t\tl = max(l, a[0]);\n\t\t\tif (a[3] == 0)\n\t\t\t\tb = min(b, a[1]);\n\t\t\tif (a[4] == 0)\n\t\t\t\tr = min(r, a[0]);\n\t\t\tif (a[5] == 0)\n\t\t\t\tt = max(t, a[1]);\n\t\t}\n\t\tif (l > r || t > b)\n\t\t{\n\t\t\tans[i] = [0];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tans[i] = [1, l, t];\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}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nstruct Point {\n int x;\n int y;\n}\n\nstruct Action {\n bool up;\n bool down;\n bool left;\n bool right;\n}\n\nstruct Box {\n int top;\n int bottom;\n int left;\n int right;\n\n bool valid() {\n return top >= bottom && left <= right;\n }\n}\n\nvoid solve() {\n int n;\n readf(\" %s\", n);\n\n auto p = new Point[n];\n auto a = new Action[n];\n foreach(i; 0..n) {\n readf(\" %s %s\", p[i].x, p[i].y);\n readf(\" %b %b %b %b\", a[i].left, a[i].up, a[i].right, a[i].down);\n }\n\n auto box = Box();\n box.top = int.max;\n box.bottom = int.min;\n box.left = int.min;\n box.right = int.max;\n auto inf = box;\n\n foreach(i; 0..n) {\n if (!a[i].up) {\n box.top = min(box.top, p[i].y);\n }\n if (!a[i].down) {\n box.bottom = max(box.bottom, p[i].y);\n }\n if (!a[i].left) {\n box.left = max(box.left, p[i].x);\n }\n if (!a[i].right) {\n box.right = min(box.right, p[i].x);\n }\n if (!box.valid()) {\n writeln(0);\n return;\n }\n }\n int x;\n if (box.left != inf.left) {\n x = box.left;\n } else if (box.right != inf.right) {\n x = box.right;\n } else {\n x = 0;\n }\n\n int y;\n if (box.top != inf.top) {\n y = box.top;\n } else if (box.bottom != inf.bottom){\n y = box.bottom;\n } else {\n y = 0;\n }\n writeln(1, \" \", x, \" \", y);\n}\n\nvoid main() {\n int q;\n readf(\" %s\", q);\n\n foreach(i; 0..q) {\n solve();\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main(){\n\tconst int LOWER = -100000, HIGHER = 100000;\n\tint q;\n\treadf(\" %s\", &q);\n\n\tfor(int i = 0; i < q; i++){\n\t\tint n = 0;\n\t\treadf(\" %s\", &n);\n\n\t\tint leftBound = LOWER;\n\t\tint rightBound = HIGHER;\n\t\tint bottomBound = LOWER;\n\t\tint topBound = HIGHER;\n\n\t\tfor(int j = 0; j < n; j++){\n\t\t\tint x = 0, y = 0;\n\t\t\treadf(\" %s %s\", &x, &y);\n\n\t\t\tint downI = 0, upI = 0, rightI = 0, leftI = 0;\n\t\t\treadf(\" %s %s %s %s\", &leftI, &upI, &rightI, &downI);\n\t\t\tif(downI == 0){\n\t\t\t\tbottomBound = max(bottomBound, y);\n\t\t\t}\n\t\t\tif(upI == 0){\n\t\t\t\ttopBound = min(topBound, y);\n\t\t\t}\n\t\t\tif(leftI == 0){\n\t\t\t\tleftBound = max(leftBound, x);\n\t\t\t}\n\t\t\tif(rightI == 0){\n\t\t\t\trightBound = min(rightBound, x);\n\t\t\t}\n\t\t}\n\t\tif(rightBound < leftBound || topBound < bottomBound){\n\t\t\twritef(\"0\\n\");\n\t\t}else{\n\t\t\twritef(\"1 %d %d\\n\", leftBound, bottomBound);\n\t\t}\n\t}\n\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main(){\n\tconst int LOWER = -100000, HIGHER = 100000;\n\tint q;\n\treadf(\" %s\", &q);\n\n\tfor(int i = 0; i < q; i++){\n\t\tint n = 0;\n\t\treadf(\" %s\", &n);\n\n\t\tint leftBound = LOWER;\n\t\tint rightBound = HIGHER;\n\t\tint bottomBound = LOWER;\n\t\tint topBound = HIGHER;\n\n\t\tfor(int j = 0; j < n; j++){\n\t\t\tint x = 0, y = 0;\n\t\t\treadf(\" %s %s\", &x, &y);\n\n\t\t\tint downI = 0, upI = 0, rightI = 0, leftI = 0;\n\t\t\treadf(\" %s %s %s %s\", &downI, &upI, &rightI, &leftI);\n\t\t\tif(downI == 0){\n\t\t\t\tbottomBound = max(bottomBound, y);\n\t\t\t}\n\t\t\tif(upI == 0){\n\t\t\t\ttopBound = min(topBound, y);\n\t\t\t}\n\t\t\tif(leftI == 0){\n\t\t\t\tleftBound = max(leftBound, x);\n\t\t\t}\n\t\t\tif(rightI == 0){\n\t\t\t\trightBound = min(rightBound, x);\n\t\t\t}\n\n\t\t\tif(rightBound < leftBound || topBound < bottomBound){\n\t\t\t\twrite(\"0\\n\");\n\t\t\t}else{\n\t\t\t\twrite(\"1 %d, %d\\n\", leftBound, bottomBound);\n\t\t\t}\n\t\t}\n\t}\n\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main(){\n\tconst int LOWER = -100000, HIGHER = 100000;\n\tint q;\n\treadf(\" %s\", &q);\n\n\tfor(int i = 0; i < q; i++){\n\t\tint n = 0;\n\t\treadf(\" %s\", &n);\n\n\t\tint leftBound = LOWER;\n\t\tint rightBound = HIGHER;\n\t\tint bottomBound = LOWER;\n\t\tint topBound = HIGHER;\n\n\t\tfor(int j = 0; j < n; j++){\n\t\t\tint x = 0, y = 0;\n\t\t\treadf(\" %s %s\", &x, &y);\n\n\t\t\tint downI = 0, upI = 0, rightI = 0, leftI = 0;\n\t\t\treadf(\" %s %s %s %s\", &downI, &upI, &rightI, &leftI);\n\t\t\tif(downI == 0){\n\t\t\t\tbottomBound = max(bottomBound, y);\n\t\t\t}\n\t\t\tif(upI == 0){\n\t\t\t\ttopBound = min(topBound, y);\n\t\t\t}\n\t\t\tif(leftI == 0){\n\t\t\t\tleftBound = max(leftBound, x);\n\t\t\t}\n\t\t\tif(rightI == 0){\n\t\t\t\trightBound = min(rightBound, x);\n\t\t\t}\n\t\t}\n\t\tif(rightBound < leftBound || topBound < bottomBound){\n\t\t\twritef(\"0\\n\");\n\t\t}else{\n\t\t\twritef(\"1 %d %d\\n\", leftBound, bottomBound);\n\t\t}\n\t}\n\n}"}], "src_uid": "e86ffda4e59c87acafeb3bf0aa805a52"} {"source_code": "import std;\r\n\r\nconst int N = 1_000_101;\r\n\r\nint n, c;\r\nint[N] a, ex, s;\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 scanf(\"%d %d\\n\", &n, &c);\r\n for(int i = 1;i <= c;i++) ex[i] = false;\r\n auto tmp = readln.split.to!(int[]);\r\n for(int i = 1;i <= n;i++) a[i] = tmp[i - 1], ex[a[i]] = true;\r\n for(int i = 1;i <= c;i++) s[i] = s[i - 1] + ex[i];\r\n for(int k = 1;k <= c;k++) if(!ex[k]) {\r\n for(int y = 1;k * y <= c;y++) if(ex[y]) {\r\n int l = k * y, r = min(c,(k + 1) * y - 1);\r\n if(s[r] - s[l - 1]) {\r\n printf(\"No\\n\");\r\n continue outer;\r\n }\r\n }\r\n }\r\n printf(\"Yes\\n\");\r\n }\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\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 void add(long i, Num x) { add(cast(int)i, x); }\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 Num query(long i) { return query(cast(int)i); }\r\n}\r\n\r\nvoid solve() {\r\n int N, C; readf(\"%d %d\\n\", &N, &C);\r\n auto A = readarray!int;\r\n A = A.sort.uniq.array;\r\n N = A.length;\r\n\r\n bool f() {\r\n if (A[0] != 1) return false;\r\n auto M = new bool[C+1];\r\n foreach (a; A) M[a] = true;\r\n auto R = iota(1, C+1, 1).filter!(i => !M[i]).array;\r\n auto bit = BIT!(long, 0)(C+1);\r\n foreach (long r; R) {\r\n foreach (long a; A) {\r\n if (r * a > C) break;\r\n bit.add(r*a, 1);\r\n bit.add(r*a + a, -1);\r\n }\r\n }\r\n foreach (a; A) {\r\n if (bit.query(a+1) >= 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"}, {"source_code": "import std;\r\n\r\nconst int N = 1_000_101;\r\n\r\nint n, c;\r\nint[N] a, ex, s;\r\n\r\nint read() {\r\n int x = 0, f = 1;\r\n auto ch = getchar();\r\n while(ch > '9' || ch < '0') { if(ch == '-') f = -1; ch = getchar(); }\r\n while(ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();\r\n return x * f;\r\n}\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 scanf(\"%d %d\\n\", &n, &c);\r\n for(int i = 1;i <= c;i++) ex[i] = false;\r\n for(int i = 1;i <= n;i++) a[i] = read(), ex[a[i]] = true;\r\n for(int i = 1;i <= c;i++) s[i] = s[i - 1] + ex[i];\r\n for(int k = 1;k <= c;k++) if(!ex[k]) {\r\n for(int y = 1;k * y <= c;y++) if(ex[y]) {\r\n int l = k * y, r = min(c,(k + 1) * y - 1);\r\n if(s[r] - s[l - 1]) {\r\n printf(\"No\\n\");\r\n continue outer;\r\n }\r\n }\r\n }\r\n printf(\"Yes\\n\");\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\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!(long, 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 void add(long i, Num x) { add(cast(int)i, x); }\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 Num query(long i) { return query(cast(int)i); }\r\n}\r\n\r\n/*\r\nvoid solve() {\r\n int N, C; readf(\"%d %d\\n\", &N, &C);\r\n auto A = readarray!int;\r\n A = A.sort.uniq.array;\r\n N = A.length;\r\n bool f() {\r\n if (A[0] != 1) return false;\r\n if (N == 1) return true;\r\n auto P = RSQ(C+2);\r\n P.update(A[1], 1);\r\n P.update(A[1]+A[1], -1);\r\n P.update(min(C+1, A[1] * A[1]), 1);\r\n P.update(min(C+1, A[1] * A[1] + A[1]), -1);\r\n for (int i = 2; i < N; i++) {\r\n if (P.query(0, A[i]+1) <= 0) return false;\r\n for (int j = 0; j <= i; j++) {\r\n int L = A[i] * A[j];\r\n if (L > C) break;\r\n int R = min(C + 1, L + A[j]);\r\n P.update(L, 1);\r\n P.update(R, -1);\r\n }\r\n }\r\n return true;\r\n }\r\n writeln(f() ? \"Yes\" : \"No\");\r\n}\r\n*/\r\n\r\nvoid solve() {\r\n int N, C; readf(\"%d %d\\n\", &N, &C);\r\n auto A = readarray!long;\r\n A = A.sort.uniq.array;\r\n N = A.length;\r\n\r\n bool f() {\r\n if (A[0] != 1) return false;\r\n if (N == 1) return true;\r\n auto P = BIT!(long, 0)(C+2);\r\n P.add(A[1], 1);\r\n P.add(A[1]+A[1], -1);\r\n P.add(min(C+1, A[1] * A[1]), 1);\r\n P.add(min(C+1, A[1] * A[1] + A[1]), -1);\r\n for (int i = 2; i < N; i++) {\r\n if (P.query(cast(int)(A[i]+1)) <= 0) return false;\r\n for (int j = 0; j <= i; j++) {\r\n long L = A[i] * A[j];\r\n if (L > C) break;\r\n long R = min(C + 1, L + A[j]);\r\n P.add(L, 1);\r\n P.add(R, -1);\r\n }\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"}, {"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\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!(long, 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\n/*\r\nvoid solve() {\r\n int N, C; readf(\"%d %d\\n\", &N, &C);\r\n auto A = readarray!int;\r\n A = A.sort.uniq.array;\r\n N = A.length;\r\n bool f() {\r\n if (A[0] != 1) return false;\r\n if (N == 1) return true;\r\n auto P = RSQ(C+2);\r\n P.update(A[1], 1);\r\n P.update(A[1]+A[1], -1);\r\n P.update(min(C+1, A[1] * A[1]), 1);\r\n P.update(min(C+1, A[1] * A[1] + A[1]), -1);\r\n for (int i = 2; i < N; i++) {\r\n if (P.query(0, A[i]+1) <= 0) return false;\r\n for (int j = 0; j <= i; j++) {\r\n int L = A[i] * A[j];\r\n if (L > C) break;\r\n int R = min(C + 1, L + A[j]);\r\n P.update(L, 1);\r\n P.update(R, -1);\r\n }\r\n }\r\n return true;\r\n }\r\n writeln(f() ? \"Yes\" : \"No\");\r\n}\r\n*/\r\n\r\nvoid solve() {\r\n int N, C; readf(\"%d %d\\n\", &N, &C);\r\n auto A = readarray!int;\r\n A = A.sort.uniq.array;\r\n N = A.length;\r\n\r\n bool f() {\r\n if (A[0] != 1) return false;\r\n if (N == 1) return true;\r\n auto P = BIT!(int, 0)(C+2);\r\n P.add(A[1], 1);\r\n P.add(A[1]+A[1], -1);\r\n P.add(min(C+1, A[1] * A[1]), 1);\r\n P.add(min(C+1, A[1] * A[1] + A[1]), -1);\r\n for (int i = 2; i < N; i++) {\r\n if (P.query(A[i]+1) <= 0) return false;\r\n for (int j = 0; j <= i; j++) {\r\n int L = A[i] * A[j];\r\n if (L > C) break;\r\n int R = min(C + 1, L + A[j]);\r\n P.add(L, 1);\r\n P.add(R, -1);\r\n }\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"}], "src_uid": "bda76c8ccd3ba7d073a8f923d772361c"} {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\tint n;\n\treadf (\" %s \", &n);\n\tauto a = readln.split.map !(to!int).array, t = sum (a, 0L);\n\tlong [] p;\n\tfor (long d = 2; d * d <= t; d++) {\n\t\tif (t % d < 1) {\n\t\t\tp ~= d;\n\t\t\twhile (t % d < 1) t /= d;\n\t\t}\n\t}\n\tif (t > 1) p ~= t;\n\tlong s (long d) {\n\t\tlong c, r;\n\t\tforeach (i; 0..n - 1) {\n\t\t\tc += a[i];\n\t\t\tc %= d;\n\t\t\tr += min (c, d - c);\n\t\t}\n\t\treturn r;\n\t}\n\tlong z = long.max;\n\tforeach (ref c; p) z = min (z, s (c));\n\twriteln (z < long.max ? z : -1);\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.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\tds.sort();\n\tlong[] d2s;\n\tA:\n\tforeach(d; ds){\n\t\tif(d == 1) continue;\n\t\tforeach(d2; d2s) if(d % d2 == 0) continue A;\n\t\td2s ~= d;\n\t}\n\tds = d2s;\n\tlog(\"ds:\", ds);\n\t\n\tlong ans = as.sum * n;\n\tforeach(d; ds){\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"}, {"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": "90f08c2c8f7575330639fdd158bc8e6b"} {"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[] U, V;\nint K;\nint[] P;\n\nint[][] G;\n\nvoid main() {\n try {\n for (; ; ) {\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 K = readInt();\n P = new int[K];\n foreach (k; 0 .. K) {\n P[k] = readInt() - 1;\n }\n \n G = new int[][N];\n foreach (i; 0 .. M) {\n G[V[i]] ~= i;\n }\n auto que = new int[N];\n auto dist = new int[N];\n dist[] = N;\n int qb, qe;\n dist[P[K - 1]] = 0;\n que[qe++] = P[K - 1];\n for (; qb != qe; ) {\n const u = que[qb++];\n foreach (i; G[u]) {\n const v = U[i];\n if (chmin(dist[v], dist[u] + 1)) {\n que[qe++] = v;\n }\n }\n }\n auto deg = new int[N];\n foreach (i; 0 .. M) {\n if (dist[U[i]] == 1 + dist[V[i]]) {\n ++deg[U[i]];\n }\n }\n debug {\n writeln(\"dist = \", dist);\n writeln(\"deg = \", deg);\n }\n \n int ans0, ans1;\n foreach (k; 0 .. K - 1) {\n if (dist[P[k]] == 1 + dist[P[k + 1]]) {\n if (deg[P[k]] > 1) {\n ++ans1;\n }\n } else {\n ++ans0;\n ++ans1;\n }\n }\n writeln(ans0, \" \", ans1);\n }\n } catch (EOFException e) {\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;\nimport std.container;\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(size_t 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 N = int;\n\nN n, m;\nN[][] neis;\nN[][] ineis;\nN k;\nN[] p;\nN[] dist;\nbool[] visited;\nRedBlackTree!N[] goodneis;\n\nvoid main()\n{\n get(n, m);\n neis = new N[][cast(size_t)n];\n ineis = new N[][cast(size_t)n];\n visited = new bool[cast(size_t)n];\n goodneis = new RedBlackTree!N[cast(size_t)n];\n dist = new N[cast(size_t)n];\n goodneis.each!((ref g) {g = redBlackTree!N();});\n foreach(e; 0 .. m)\n {\n N u, v; get(u, v); u--, v--;\n neis[u]~=v;\n ineis[v]~=u;\n }\n get(k);\n p = new N[cast(size_t)k]; get(p); p.each!((ref e) => e--);\n DList!N q;\n q.insertBack(p[$ - 1]);\n visited[cast(size_t)p[$ - 1]] = true;\n dist[cast(size_t)p[$-1]] = 0;\n while(!q.empty)\n {\n auto v = q.front; q.removeFront;\n foreach(u; ineis[cast(size_t)v])\n\t{\n\t if (!visited[cast(size_t)u])\n\t {\n\t dist[cast(size_t)u] = dist[cast(size_t)v] + 1;\n\t visited[cast(size_t)u] = true;\n\t q.insertBack(u);\n\t }\n\t if (dist[cast(size_t)v] + 1 == dist[cast(size_t)u])\n\t goodneis[cast(size_t)u].insert(v);\n\t}\n }\n N minr, maxr;\n foreach(i, ref v; p[0 .. $ - 1])\n {\n if (!goodneis[cast(size_t)v].equalRange(p[i + 1]).empty)\n\t{\n\t if (goodneis[cast(size_t)v].length > 1)\n\t maxr += 1;\n\t}\n else\n\t{\n\t maxr += 1;\n\t minr += 1;\n\t}\n }\n wr(minr, maxr);\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, m = scan!int;\n Node[] nodes;\n foreach(i; 0 .. n) nodes ~= new Node(i);\n\n foreach(j; 0 .. m){\n Node u = nodes[scan!int - 1], v = nodes[scan!int - 1];\n v.kids ~= u;\n }\n int k = scan!int;\n Node[] ps = scan!int(k).map!(x => nodes[x - 1]).array;\n\n Node s = ps[0], t = ps[k - 1];\n\n auto ndq = new Queue!Node;\n ndq.enq(t);\n while(! ndq.isEmpty){\n Node nd = ndq.deq;\n foreach(kd; nd.kids){\n int d = nd.depth + 1;\n if(kd.depth < 0 || d < kd.depth){\n kd.parset[nd.id] = 1;\n kd.depth = d;\n ndq.enq(kd);\n }\n else if(d == kd.depth) kd.parset[nd.id] = 1;\n else continue;\n }\n }\n\n int ansmin, ansmax;\n foreach(i; 0 .. k - 1){\n Node a = ps[i], b = ps[i + 1];\n if(b.id in a.parset){\n if(a.parset.keys.length > 1) ansmax += 1;\n }\n else ansmin += 1, ansmax += 1;\n }\n\n print(ansmin, ansmax);\n}\n\nclass Node{\n int id;\n int depth = -1;\n Node[] kids; // この点へ来れる点\n bool[int] parset; // ゴールに向かうとき次の点になりうる点\n this(int id){ this.id = id; }\n}\n\nclass Queue(T){\n\tprivate T[] xs;\n\tprivate uint i, j; // i : 次に読み出す位置 j: 次に書き込む位置\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}\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, M;\nint[] U, V;\nint K;\nint[] P;\n\nint[][] G;\n\nvoid main() {\n try {\n for (; ; ) {\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 K = readInt();\n P = new int[K];\n foreach (k; 0 .. K) {\n P[k] = readInt() - 1;\n }\n \n G = new int[][N];\n foreach (i; 0 .. M) {\n G[V[i]] ~= i;\n }\n auto que = new int[N];\n auto dist = new int[N];\n dist[] = N;\n int qb, qe;\n dist[P[K - 1]] = 0;\n que[qe++] = P[K - 1];\n for (; qb != qe; ) {\n const u = que[qb++];\n foreach (i; G[u]) {\n const v = U[i];\n if (chmin(dist[v], dist[u] + 1)) {\n que[qe++] = v;\n }\n }\n }\n auto deg = new int[N];\n foreach (i; 0 .. M) {\n if (dist[U[i]] == 1 + dist[V[i]]) {\n ++deg[U[i]];\n }\n }\n debug {\n writeln(\"dist = \", dist);\n writeln(\"deg = \", deg);\n }\n \n int ans0, ans1;\n foreach (k; 0 .. K - 1) {\n if (dist[P[k]] == 1 + dist[P[k + 1]]) {\n if (deg[P[k]] == 2) {\n ++ans1;\n }\n } else {\n ++ans0;\n ++ans1;\n }\n }\n writeln(ans0, \" \", ans1);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a"} {"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, k; readf(\"%d %d\\n\", &n, &k);\n if (n == 1) {\n writeln(k == 0 ? 1 : -1);\n return;\n }\n if (k < n / 2) {\n writeln(-1);\n return;\n }\n int x = k - n / 2 + 1;\n int[] a;\n a ~= x; a ~= 2 * x;\n int y = 2 * x + 1;\n for (int i = 1; i < n / 2; i++) {\n a ~= y; y++;\n a ~= y; y++;\n }\n if (n % 2) a ~= 1000000000;\n write(a[0]);\n foreach (i; 1 .. a.length) {\n write(' ', a[i]);\n }\n writeln;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.conv, std.array;\n\nint main() {\n int n, k;\n readf(\"%d %d\\n\", &n, &k);\n if (k 0)\n\t{\n\t\tif (n == 1)\n\t\t{\n\t\t\twriteln (k ? -1 : 1);\n\t\t}\n\t\telse if (n / 2 > k)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint [] a;\n\t\t\tforeach (i; 1..n / 2)\n\t\t\t{\n\t\t\t\ta ~= 2 * i - 1;\n\t\t\t\ta ~= 2 * i;\n\t\t\t}\n\t\t\tint d = k - n / 2 + 1;\n\t\t\tint t = 500_000_000;\n\t\t\tt /= d;\n\t\t\tt *= d;\n\t\t\ta ~= t - d;\n\t\t\ta ~= t;\n\t\t\tif (n & 1)\n\t\t\t{\n\t\t\t\ta ~= 999_999_999;\n\t\t\t}\n\t\t\twritefln (\"%(%s %)\", a);\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, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tif (n == 1)\n\t\t{\n\t\t\twriteln (k ? -1 : 1);\n\t\t}\n\t\telse if (n / 2 > k)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint [] a;\n\t\t\tforeach (i; 1..n / 2)\n\t\t\t{\n\t\t\t\ta ~= 2 * i - 1;\n\t\t\t\ta ~= 2 * i;\n\t\t\t}\n\t\t\tint d = k - n / 2 + 1;\n\t\t\tint t = 500_000_000;\n\t\t\tt /= d;\n\t\t\tt *= d;\n\t\t\ta ~= t - d;\n\t\t\ta ~= t;\n\t\t\tif (n & 1)\n\t\t\t{\n\t\t\t\ta ~= 999_999_999;\n\t\t\t}\n\t\t\twritefln (\"%(%s %)\", a);\n\t\t}\n\t}\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, k; readf(\"%d %d\\n\", &n, &k);\n if (n == 1 || k < n / 2) {\n writeln(-1); return;\n }\n int x = k - n / 2 + 1;\n int[] a;\n a ~= x; a ~= 2 * x;\n int y = 2 * x + 1;\n for (int i = 1; i < n / 2; i++) {\n a ~= y; y++;\n a ~= y; y++;\n }\n if (n % 2) a ~= 1000000000;\n write(a[0]);\n foreach (i; 1 .. a.length) {\n write(' ', a[i]);\n }\n writeln;\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.conv, std.array;\n\nint main() {\n int n, k;\n readf(\"%d %d\\n\", &n, &k);\n if (k 0)\n\t{\n\t\tif (n / 2 > k)\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint [] a;\n\t\t\tforeach (i; 1..n / 2)\n\t\t\t{\n\t\t\t\ta ~= 2 * i - 1;\n\t\t\t\ta ~= 2 * i;\n\t\t\t}\n\t\t\tint d = k - n / 2 + 1;\n\t\t\tint t = 500_000_000;\n\t\t\tt /= d;\n\t\t\tt *= d;\n\t\t\ta ~= t - d;\n\t\t\ta ~= t;\n\t\t\tif (n & 1)\n\t\t\t{\n\t\t\t\ta ~= 999_999_999;\n\t\t\t}\n\t\t\twritefln (\"%(%s %)\", a);\n\t\t}\n\t}\n}\n"}], "src_uid": "b85c8bfbe67a23a81bef755f9313115a"} {"source_code": "// https://codeforces.com/problemset/problem/1228/B\nimport std.algorithm;\nimport std.array;\nimport std.bigint;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int h, w;\n readf(\"%s %s\\n\", &h, &w);\n\n int[] r = readln.split.map!(to!int).array;\n int[] c = readln.split.map!(to!int).array;\n\n int[][] matrix;\n\n foreach(_; 0..h) {\n int[] column = new int[w];\n matrix ~= column;\n }\n\n for(int i = 0; i < h; i++) {\n for(int idx = 0; idx < r[i]; idx++) {\n matrix[i][idx] = 1;\n }\n }\n\n for(int j = 0; j < w; j++) {\n for(int idx = 0; idx < c[j]; idx++) {\n matrix[idx][j] = 1;\n }\n }\n\n // check if valid after this process\n for(int i = 0; i < h; i++) {\n int contribution = 0;\n for(int j = 0; j < w && matrix[i][j] == 1; j++) {\n contribution += 1;\n }\n if(contribution != r[i]) {\n 0.writeln;\n return;\n }\n }\n for(int j = 0; j < w; j++) {\n int contribution = 0;\n for(int i = 0; i < h && matrix[i][j] == 1; i++) {\n contribution += 1;\n }\n if(contribution != c[j]) {\n 0.writeln;\n return;\n }\n }\n\n // Count number of free cells\n int free = 0;\n for(int i = 0; i < h; i++) {\n for(int j = 0; j < w; j++) {\n if(j-1 >= r[i] && i-1 >= c[j]) {\n free += 1;\n }\n }\n }\n BigInt ans = 1;\n ((ans<> 1);\n\treturn res * res;\n }\n }\n}\nstruct StaticModularClass(T, T modulus)\n{\n alias pmod = positiveModularRepresentative;\n T representative;\n this(T representative)\n {\n this.representative = pmod(representative, 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 alias eqLowerBound = maxRepresentative;\n T minRepresentative(T lowerBound)\n {\n return lowerBound + pmod(representative - lowerBound, modulus);\n }\n bool opEquals(StaticModularClass!(T, modulus) other)\n {\n return modulus.divides(other.representative - representative);\n }\n alias eqUpperBound = minRepresentative;\n StaticModularClass!(T, modulus) opBinary(string operation)(StaticModularClass!(T, modulus) other)\n {\n static if(operation == \"+\" || operation == \"-\" || operation == \"*\")\n return StaticModularClass!(T, modulus)(mixin(q{this.representative}, operation, q{other.representative}));\n else\n static assert(false);\n }\n StaticModularClass!(T, modulus) opBinary(string operation)(long n) if (operation == \"^\")\n {\n if(n == 0)\n return StaticModularClass!(T, modulus)(1);\n if(n & 1)\n {\n\tauto partialResult = this^(n - 1);\n\treturn this * partialResult;\n }\n else\n {\n\tauto partialResult = this^(n >> 1);\n\treturn partialResult * partialResult;\n }\n }\n}\n// minimum positive representative of x modulo m.\nT positiveModularRepresentative(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 alias egcd = extendedEuclideanAlgorithm;\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}\n// solves ax = b (mod m) giving a solution as a modulus class.\nbool solveLinearCongruence(T)(T a, T b, T m, out ModularClass!T res)\n{\n alias egcd = extendedEuclideanAlgorithm;\n alias pmod = positiveModularRepresentative;\n T x, p;\n b = b.pmod(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}\nbool divides(T)(T a, T b)\n{\n return b % a == 0;\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}\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 immutable p = 1_000_000_000 + 7;\n alias mod = StaticModularClass!(long, p);\n long h, w; get(h, w);\n enum Fill\n {\n z, o, u\n }\n Fill[][] grid = new Fill[][cast(uint)h];\n foreach(ref row; grid)\n {\n row = new Fill[cast(uint)w];\n row[] = Fill.u;\n }\n auto r = new int[cast(uint)h]; get(r);\n auto c = new int[cast(uint)w]; get(c);\n for(int row = 0; row < h; row++)\n {\n for(int col = 0; col < r[row]; col++)\n\t{\n\t grid[row][col] = Fill.o;\n\t}\n if (r[row] < w)\n\t{\n\t grid[row][r[row]] = Fill.z;\n\t}\n }\n for(int col = 0; col < w; col++)\n {\n for(int row = 0; row < c[col]; row++)\n\t{\n\t if (grid[row][col] == Fill.z)\n\t ans(0);\n\t \n\t grid[row][col] = Fill.o;\n\t}\n if (c[col] < h)\n\t{\n\t int row = c[col];\n\t if (grid[row][col] == Fill.o)\n\t ans(0);\n\t grid[row][col] = Fill.z;\n\t}\n }\n int count = 0;\n foreach(row; grid)\n foreach(e; row)\n if(e == Fill.u)\n\tcount++;\n mod ans = 2;\n ans = ans ^ count;\n wr(ans.representative);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1228/B\n// math\nimport std.algorithm;\nimport std.array;\nimport std.bigint;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int mod = 1000000007;\n\n int h, w;\n readf(\"%s %s\\n\", &h, &w);\n\n int[] r = readln.split.map!(to!int).array;\n int[] c = readln.split.map!(to!int).array;\n\n int[][] matrix;\n\n foreach(_; 0..h) {\n int[] column = new int[w];\n matrix ~= column;\n }\n\n for(int i = 0; i < h; i++) {\n for(int idx = 0; idx < r[i]; idx++) {\n matrix[i][idx] = 1;\n }\n }\n\n for(int j = 0; j < w; j++) {\n for(int idx = 0; idx < c[j]; idx++) {\n matrix[idx][j] = 1;\n }\n }\n\n // check if valid after this process\n for(int i = 0; i < h; i++) {\n int contribution = 0;\n for(int j = 0; j < w && matrix[i][j] == 1; j++) {\n contribution += 1;\n }\n if(contribution != r[i]) {\n 0.writeln;\n return;\n }\n }\n for(int j = 0; j < w; j++) {\n int contribution = 0;\n for(int i = 0; i < h && matrix[i][j] == 1; i++) {\n contribution += 1;\n }\n if(contribution != c[j]) {\n 0.writeln;\n return;\n }\n }\n\n // Count number of free cells\n int free = 0;\n for(int i = 0; i < h; i++) {\n for(int j = 0; j < w; j++) {\n if(j-1 >= r[i] && i-1 >= c[j]) {\n free += 1;\n }\n }\n }\n int ans = 1;\n for(int i = 0; i < free; i++) {\n ans = (ans*2)%mod;\n }\n ans.writeln;\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/1228/B\n// math\nimport std.algorithm;\nimport std.array;\nimport std.bigint;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int mod = 10^^9+7;\n\n int h, w;\n readf(\"%s %s\\n\", &h, &w);\n\n int[] r = readln.split.map!(to!int).array;\n int[] c = readln.split.map!(to!int).array;\n\n int[][] matrix;\n\n foreach(_; 0..h) {\n int[] column = new int[w];\n matrix ~= column;\n }\n\n for(int i = 0; i < h; i++) {\n for(int idx = 0; idx < r[i]; idx++) {\n matrix[i][idx] = 1;\n }\n }\n\n for(int j = 0; j < w; j++) {\n for(int idx = 0; idx < c[j]; idx++) {\n matrix[idx][j] = 1;\n }\n }\n\n // check if valid after this process\n for(int i = 0; i < h; i++) {\n int contribution = 0;\n for(int j = 0; j < w && matrix[i][j] == 1; j++) {\n contribution += 1;\n }\n if(contribution != r[i]) {\n 0.writeln;\n return;\n }\n }\n for(int j = 0; j < w; j++) {\n int contribution = 0;\n for(int i = 0; i < h && matrix[i][j] == 1; i++) {\n contribution += 1;\n }\n if(contribution != c[j]) {\n 0.writeln;\n return;\n }\n }\n\n // Count number of free cells\n int free = 0;\n for(int i = 0; i < h; i++) {\n for(int j = 0; j < w; j++) {\n if(j-1 >= r[i] && i-1 >= c[j]) {\n free += 1;\n }\n }\n }\n int ans = 1;\n for(int i = 0; i < free; i++) {\n ans = (ans*2)%mod;\n }\n ans.writeln;\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.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int h, w;\n readf(\"%s %s\", &h, &w);\n readln;\n\n auto r = readln.chomp.split.map!(to!int).array;\n \n auto c = readln.chomp.split.map!(to!int).array;\n \n auto res = new int[][] (h, w);\n \n foreach (i, e; r) {\n foreach (j; 0 .. e) {\n res[i][j] = 2;\n }\n \n if (e < w) { res[i][e] = 1; }\n }\n \n foreach (i, e; c) {\n foreach (j; 0 .. e) {\n if (res[j][i] == 1) {\n writeln(0);\n return;\n }\n \n res[j][i] = 2;\n }\n \n if (e < h) {\n if (res[e][i] == 2) {\n writeln(0);\n return;\n }\n \n res[e][i] = 1;\n }\n }\n \n immutable int MD = 10 ^^ 9 + 7;\n \n int ans = 1;\n foreach (i; 0 .. h) {\n foreach (j; 0 .. w) {\n if (res[i][j] == 0) {\n ans = ans * 2 % MD;\n }\n }\n }\n \n ans.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; }\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 h = RD!int;\n\tauto w = RD!int;\n\tauto r = RDA!int;\n\tauto c = RDA!int;\n\tauto a = new bool[][](h+1, w+1);\n\tforeach (i; 0..h)\n\t{\n\t\ta[i][r[i]] = true;\n\t}\n\tforeach (i; 0..w)\n\t{\n\t\ta[c[i]][i] = true;\n\t}\n\tbool ok = true;\n\tforeach (y; 0..h)\n\t{\n\t\tforeach (x; 0..r[y])\n\t\t{\n\t\t\tif (a[y][x])\n\t\t\t\tok = false;\n\t\t}\n\t}\n\tforeach (x; 0..w)\n\t{\n\t\tforeach (y; 0..c[x])\n\t\t{\n\t\t\tif (a[y][x])\n\t\t\t\tok = false;\n\t\t}\n\t}\n\tif (!ok)\n\t\twriteln(0);\n\telse\n\t{\n\t\tlong cnt;\n\t\tforeach (y; 0..h)\n\t\t{\n\t\t\tforeach (x; 0..w)\n\t\t\t{\n\t\t\t\tif (x <= r[y] || y <= c[x])\n\t\t\t\t\t++cnt;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(cnt);\n\t\tcnt = h * w - cnt;\n\t\tdebug writeln(cnt);\n\t\t/*auto num = new long[](32);\n\t\tnum[0] = 2;\n\t\tforeach (i; 1..num.length)\n\t\t{\n\t\t\tnum[i] = num[i-1];\n\t\t\tnum[i].modm(2);\n\t\t}*/\n\t\tlong ans = 1;\n\t\tforeach (_; 0..cnt)\n\t\t{\n\t\t\tans.modm(2);\n\t\t}\n\t\twriteln(ans);\n\t}\n\t\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "907f7db88fb16178d6be57bea12f90a2"} {"source_code": "import std.stdio;\n\nvoid main() {\n\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tstring s, t;\n\treadf(\"%s\\n%s\\n\", &s, &t);\n\n\tint[30] a, b;\n\tint[30][30] c;\n\n\tint distHam;\n\tforeach (i, elS; s)\n\t\tif (elS != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[elS - 'a'] = i + 1;\n\t\t\tb[t[i] - 'a'] = i + 1;\n\t\t\tc[elS - 'a'][t[i] - 'a'] = i + 1;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\t\treturn;\n\t\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, '\\n', \"-1 -1\");\n}", "positive_code": [{"source_code": "import std.conv;\nimport std.stdio;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\n\tint ch;\n\twhile ((ch = getchar) != '\\n') {\n\t\tstatic uint i;\n\t\ts[i] = ch.to!char;\n\t\t++i;\n\t}\n\n\twhile ((ch = getchar) != EOF) {\n\t\tstatic uint j;\n\t\tt[j] = ch.to!char;\n\t\t++j;\n\t}\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar[200010] s, t;\n\ts = readln.strip;\n\tt = readln.strip;\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\n\tint n;\n\n\treadf(\" %s\\n\", &n);\n\n\tstring s = readln.strip;\n\tstring t = readln.strip;\n\n\tforeach (i, elS; s) {\n\t\tif (elS != t[i]) {\n\t\t\tforeach (j; i + 1 .. n) {\n\t\t\t\tif (t[i] == s[j] && s[j] != t[j]) {\n\t\t\t\t\tchar[] newS;\n\t\t\t\t\tforeach (el; s)\n\t\t\t\t\t\tnewS ~= el;\n\t\t\t\t\tnewS ~= '\\0';\n\t\t\t\t\tnewS[i] = s[j];\n\t\t\t\t\tnewS[j] = s[i];\n\t\t\t\t\tulong sum;\n\t\t\t\t\tforeach (k, elNewS; newS) {\n\t\t\t\t\t\tif (elNewS != '\\0' && elNewS != t[k])\n\t\t\t\t\t\t\t++sum;\n\t\t\t\t\t}\n\t\t\t\t\twriteln(sum, '\\n', i + 1, ' ', j + 1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tulong sum;\n\tforeach (i, elS; s)\n\t\tif (elS != t[i])\n\t\t\t++sum;\n\n\twriteln(sum);\n\twriteln(\"-1 -1\");\n}"}, {"source_code": "import std.stdio : scanf, readf, writefln;\n\nvoid main() {\n\n\tuint n;\n\tstring s, t;\n\n\tscanf(\"%u\\n\", &n);\n\treadf(\"%s\\n%s\\n\", &s, &t);\n\n\tuint[] idx;\n\n\tuint distHam;\n\tforeach (i, elS; s)\n\t\tif (elS != t[i]) {\n\t\t\t++distHam;\n\t\t\tidx ~= i;\n\t\t}\n\n\tuint idxS, idxT;\n\tbool flag;\n\tforeach (i, elIdxT; idx)\n\t\tforeach (elIdxS; idx[i .. $])\n\t\t\tif (t[elIdxT] == s[elIdxS] && s[elIdxT] == t[elIdxS]) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, elIdxT + 1, elIdxS + 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse if (!flag && (t[elIdxT] == s[elIdxS] || s[elIdxT] == t[elIdxS])) {\n\t\t\t\tidxS = elIdxS + 1;\n\t\t\t\tidxT = elIdxT + 1;\n\t\t\t\tflag = true;\n\t\t\t}\n\n\t(idxS > 0 || idxT > 0) ? writefln(\"%s\\n%s %s\", distHam, idxT, idxS) : writefln(\"%s\\n-1 -1\", distHam);\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar s[200010];\n\tchar t[200010];\n\tscanf(\"%s\", s.ptr);\n\tscanf(\"%s\", t.ptr);\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio : scanf, writeln, writefln;\n\nvoid main() {\n\n\tchar[200005] s, t;\n\tint n, distHam;\n\n\tint[30] a, b;\n\tint c[30][30];\n\n\tscanf(\"%d\\n\", &n);\n\tscanf(\"%s %s\", s.ptr + 1, t.ptr + 1);\n\n\tforeach (i; 1 .. n + 1)\n\t\tif (s[i] != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[s[i] - 'a'] = i;\n\t\t\tb[t[i] - 'a'] = i;\n\t\t\tc[s[i] - 'a'][t[i] - 'a'] = i;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, c[i][j], c[j][i]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twritefln(\"%s\\n%s %s\", distHam - 1, a[i], b[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, \"\\n-1 -1\");\n}"}, {"source_code": "import std.stdio : writeln;\nimport std.c.stdio : scanf;\n\nvoid main() {\n\t\n\tint n;\n\tscanf(\"%s\", &n);\n\t\n\tchar[300000] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i, elS; s)\n\tif (elS != t[i]) {\n\t\t++distHam;\n\t\ta[elS - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[elS - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\n\tif (n == 200000) {\n\t\twrite('T');\n\t\tforeach (i; 0 .. n)\n\t\t\twriteln(t[i]);\n\t\twrite('T');\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio : scanf, writeln, writefln;\n\nvoid main() {\n\n\tchar[200005] s, t;\n\tint n, distHam;\n\n\tint[30] a, b;\n\tint c[30][30];\n\n\tscanf(\"%d\", &n);\n\tscanf(\"%s %s\", s.ptr + 1, t.ptr + 1);\n\n\tforeach (i; 1 .. n + 1)\n\t\tif (s[i] != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[s[i] - 'a'] = i;\n\t\t\tb[t[i] - 'a'] = i;\n\t\t\tc[s[i] - 'a'][t[i] - 'a'] = i;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, c[i][j], c[j][i]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twritefln(\"%s\\n%s %s\", distHam - 1, a[i], b[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, \"\\n-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar[200010] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\n\ts = s.strip;\n\tt = t.strip;\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar[200005] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i, elS; s)\n\tif (elS != t[i]) {\n\t\t++distHam;\n\t\ta[elS - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[elS - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio : readf, writeln;\nimport std.c.stdio : scanf;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar[200010] s, t;\n\tscanf(\"%s %s\", s.ptr, t.ptr);\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i, elS; s)\n\tif (elS != t[i]) {\n\t\t++distHam;\n\t\ta[elS - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[elS - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio : scanf, writeln, writefln;\n\nvoid main() {\n\n\tchar[200010] s, t;\n\tint n, distHam;\n\n\tint[30] a, b;\n\tint c[30][30];\n\n\tscanf(\"%d\\n\", &n);\n\tscanf(\"%s %s\", s.ptr + 1, t.ptr + 1);\n\n\tforeach (i; 1 .. n + 1)\n\t\tif (s[i] != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[s[i] - 'a'] = i;\n\t\t\tb[t[i] - 'a'] = i;\n\t\t\tc[s[i] - 'a'][t[i] - 'a'] = i;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, c[i][j], c[j][i]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twritefln(\"%s\\n%s %s\", distHam - 1, a[i], b[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, \"\\n-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar[200010] s, t;\n\tscanf(\"%s\\n%s\", s.ptr, t.ptr);\n\n\ts = s.strip;\n\tt = t.strip;\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\n\tif (n == 200000) {\n\t\twrite('T');\n\t\tforeach (i; 0 .. n)\n\t\t\twrite(t[i]);\n\t\twrite('T');\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar s[200010];\n\tchar t[200010];\n\tscanf(\"%s\", &s);\n\tscanf(\"%s\", &t);\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar[200010] s, t;\n\tscanf(\"%s\", s.ptr);\n\tscanf(\"%s\", t.ptr);\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\tscanf(\"%s%s\", cast(char*)s, cast(char*)t);\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tstring s, t;\n\ts = readln.strip;\n\tt = readln.strip;\n\n\tif (n == 200000) {\n\t\twriteln('T', t, 'T');\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio : readf, writeln;\nimport core.stdc.stdio;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tfflush(stdin);\n\t\n\tchar[200010] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\tscanf(\"%s %s\", s.ptr + 1, t.ptr + 1);\n\n\tint[30] a, b;\n\tint[30][30] c;\n\n\tint distHam;\n\tforeach (i; 1 .. n + 1)\n\t\tif (s[i] != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[s[i] - 'a'] = i;\n\t\t\tb[t[i] - 'a'] = i;\n\t\t\tc[s[i] - 'a'][t[i] - 'a'] = i;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, c[j][i], c[i][j]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twritefln(\"%s\\n%s %s\", distHam - 1, b[i], a[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, \"\\n-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tstring s, t;\n\ts = readln.strip;\n\tt = readln.strip;\n\n\tif (n == 200000) {\n\t\twriteln(t[100000 .. 100400]);\n\t\twriteln(t[100400 .. 100800]);\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\n\tif (n == 200000) {\n\t\tforeach (i; 0 .. n)\n\t\t\twrite('T', s[i], 'T');\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio : scanf, writeln, writefln;\n\nvoid main() {\n\n\tchar[200001] s, t;\n\tuint n, distHam;\n\n\tuint[26] a, b;\n\tuint c[26][26];\n\n\tscanf(\"%u%s%s\", &n, s.ptr + 1, t.ptr + 1);\n\n\tforeach (i; 1 .. n + 1)\n\t\tif (s[i] != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[s[i] - 'a'] = i;\n\t\t\tb[t[i] - 'a'] = i;\n\t\t\tc[s[i] - 'a'][t[i] - 'a'] = i;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, c[j][i], c[i][j]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twritefln(\"%s\\n%s %s\", distHam - 1, b[i], a[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, \"\\n-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\n int n;\n readf(\"%s\\n\", &n);\n\n char[200010] s, t;\n scanf(\"%s%s\", s.ptr, t.ptr);\n\n int[30] a, b;\n int[30][30] c;\n\n int distHam;\n foreach (i; 0 .. n)\n if (s[i] != t[i]) {\n ++distHam;\n a[s[i] - 'a'] = i + 1;\n b[t[i] - 'a'] = i + 1;\n c[s[i] - 'a'][t[i] - 'a'] = i + 1;\n }\n\n foreach (i; 0 .. 26)\n foreach (j; i + 1 .. 26)\n if (c[i][j] > 0 && c[j][i] > 0) {\n writeln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n return;\n }\n\n foreach (i; 0 .. 26)\n if (a[i] > 0 && b[i] > 0) {\n writeln(distHam - 1, '\\n', b[i], ' ', a[i]);\n return;\n }\n\n writeln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\n\tint n;\n\n\treadf(\" %s\\n\", &n);\n\n\tstring s = readln.strip;\n\tstring t = readln.strip;\n\n\tforeach (i, elS; s) {\n\t\tif (elS != t[i]) {\n\t\t\tforeach (j; i + 1 .. n) {\n\t\t\t\tif (t[i] == s[j] && s[j] != t[j]) {\n\t\t\t\t\tchar[] newS;\n\t\t\t\t\tforeach (el; s)\n\t\t\t\t\t\tnewS ~= el;\n\t\t\t\t\tnewS ~= '\\0';\n\t\t\t\t\tnewS[i] = s[j];\n\t\t\t\t\tnewS[j] = s[i];\n\t\t\t\t\tulong sum;\n\t\t\t\t\tforeach (k, elNewS; newS) {\n\t\t\t\t\t\tif (elNewS != '\\0' && elNewS != t[k])\n\t\t\t\t\t\t\t++sum;\n\t\t\t\t\t}\n\t\t\t\t\twriteln(sum, '\\n', i + 1, ' ', j + 1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (i, elS; s) {\n\t\tif (elS != t[i]) {\n\t\t\tforeach (j; i + 1 .. n) {\n\t\t\t\tif (t[i] == s[j]) {\n\t\t\t\t\tchar[] newS;\n\t\t\t\t\tforeach (el; s)\n\t\t\t\t\t\tnewS ~= el;\n\t\t\t\t\tnewS ~= '\\0';\n\t\t\t\t\tnewS[i] = s[j];\n\t\t\t\t\tnewS[j] = s[i];\n\t\t\t\t\tulong sum;\n\t\t\t\t\tforeach (k, elNewS; newS) {\n\t\t\t\t\t\tif (elNewS != '\\0' && elNewS != t[k])\n\t\t\t\t\t\t\t++sum;\n\t\t\t\t\t}\n\t\t\t\t\twriteln(sum, '\\n', i + 1, ' ', j + 1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tulong sum;\n\tforeach (i, elS; s)\n\t\tif (elS != t[i])\n\t\t\t++sum;\n\n\twriteln(sum);\n\twriteln(\"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\n\tuint n;\n\tstring s, t;\n\n\tscanf(\"%u\\n\", &n);\n\treadf(\"%s\\n%s\\n\", &s, &t);\n\n\tuint[] idx;\n\n\tuint distHam;\n\tforeach (i, elS; s)\n\t\tif (elS != t[i]) {\n\t\t\t++distHam;\n\t\t\tidx ~= i;\n\t\t}\n\n\tforeach (i, elIdxT; idx)\n\t\tforeach (elIdxS; idx[i .. $])\n\t\t\tif (t[elIdxT] == s[elIdxS] && s[elIdxT] == t[elIdxS]) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, elIdxT + 1, elIdxS + 1);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i, elIdxT; idx)\n\t\tforeach (elIdxS; idx[i .. $])\n\t\tif (t[elIdxT] == s[elIdxS]) {\n\t\t\twritefln(\"%s\\n%s %s\", distHam - 1, elIdxT + 1, elIdxS + 1);\n\t\t\treturn;\n\t\t}\n\n\twritefln(\"%s\\n-1 -1\", distHam);\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tstring s, t;\n\ts = readln.strip;\n\tt = readln.strip;\n\n\tif (n == 200000) {\n\t\tuint i, k;\n\t\tuint j = 500;\n\t\twriteln('T');\n\t\twhile (k < 150) {\n\t\t\twriteln(s[i .. j]);\n\t\t\ti += 500;\n\t\t\tj += 500;\n\t\t\t++k;\n\t\t}\n\t\twriteln('\\n', 'T');\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\tscanf(\"%s %s\", s.ptr, t.ptr);\n\n\tint[30] a, b;\n\tint[30][30] c;\n\n\tint distHam;\n\tforeach (i, elS; s)\n\t\tif (elS != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[elS - 'a'] = i + 1;\n\t\t\tb[t[i] - 'a'] = i + 1;\n\t\t\tc[elS - 'a'][t[i] - 'a'] = i + 1;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\n\tif (n == 200000) {\n\t\twrite('T');\n\t\tforeach (i; 0 .. n)\n\t\t\twrite(s[i]);\n\t\twrite('T');\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio : scanf, writeln, writefln;\n\nvoid main() {\n\n\tchar[200005] s, t;\n\tuint n, distHam;\n\n\tuint[26] a, b;\n\tuint c[26][26];\n\n\tscanf(\"%u%s%s\", &n, s.ptr + 1, t.ptr + 1);\n\n\tforeach (i; 1 .. n + 1)\n\t\tif (s[i] != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[s[i] - 'a'] = i;\n\t\t\tb[t[i] - 'a'] = i;\n\t\t\tc[s[i] - 'a'][t[i] - 'a'] = i;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, c[j][i], c[i][j]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twritefln(\"%s\\n%s %s\", distHam - 1, b[i], a[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, \"\\n-1 -1\");\n}"}, {"source_code": "import std.stdio : scanf, writeln, writefln;\n\nvoid main() {\n\n\tchar[200005] s, t;\n\tuint n, distHam;\n\n\tuint[30] a, b;\n\tuint c[30][30];\n\n\tscanf(\"%u%s%s\", &n, s.ptr + 1, t.ptr + 1);\n\n\tforeach (i; 1 .. n + 1)\n\t\tif (s[i] != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[s[i] - 'a'] = i;\n\t\t\tb[t[i] - 'a'] = i;\n\t\t\tc[s[i] - 'a'][t[i] - 'a'] = i;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twritefln(\"%s\\n%s %s\", distHam - 2, c[j][i], c[i][j]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twritefln(\"%s\\n%s %s\", distHam - 1, b[i], a[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, \"\\n-1 -1\");\n}"}, {"source_code": "import std.stdio : readf, writeln;\nimport core.stdc.stdio;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\t\n\tchar[200010] s, t;\n\tscanf(\"%s%s\", s.ptr, t.ptr);\n\t\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tstring s, t;\n\ts = readln.strip;\n\tt = readln.strip;\n\n\tif (n == 200000) {\n\t\tuint i, k;\n\t\tuint j = 300;\n\t\twhile (k < 150) {\n\t\t\twriteln(s[i .. j]);\n\t\t\ti += 300;\n\t\t\tj += 300;\n\t\t\t++k;\n\t\t}\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tstring s, t;\n\ts = readln.strip;\n\tt = readln.strip;\n\n\tif (n == 200000) {\n\t\twriteln('T', s, 'T');\n\t\twriteln('T', t, 'T');\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tchar[200010] s, t;\n\tscanf(\"%s %s\", s.ptr, t.ptr);\n\n\tint[30] a, b;\n\tint[30][30] c;\n\n\tint distHam;\n\tforeach (i; 0 .. n)\n\t\tif (s[i] != t[i]) {\n\t\t\t++distHam;\n\t\t\ta[s[i] - 'a'] = i + 1;\n\t\t\tb[t[i] - 'a'] = i + 1;\n\t\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\t\treturn;\n\t\t\t}\n\n\tforeach (i; 0 .. 26)\n\t\tif (a[i] > 0 && b[i] > 0) {\n\t\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\t\treturn;\n\t\t}\n\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\t\n\twriteln(__VERSION__);\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n;\n\treadf(\"%s\\n\", &n);\n\n\tstring s, t;\n\ts = readln.strip;\n\tt = readln.strip;\n\n\tif (n == 200000) {\n\t\twriteln(t[100000 .. 100400]);\n\t\treturn;\n\t}\n\n\tint[30] a, b;\n\tint[30][30] c;\n\t\n\tint distHam = 0;\n\tforeach (i; 0 .. n)\n\tif (s[i] != t[i]) {\n\t\t++distHam;\n\t\ta[s[i] - 'a'] = i + 1;\n\t\tb[t[i] - 'a'] = i + 1;\n\t\tc[s[i] - 'a'][t[i] - 'a'] = i + 1;\n\t}\n\t\n\tforeach (i; 0 .. 26)\n\t\tforeach (j; i + 1 .. 26)\n\t\tif (c[i][j] > 0 && c[j][i] > 0) {\n\t\t\twriteln(distHam - 2, '\\n', c[j][i], ' ', c[i][j]);\n\t\t\treturn;\n\t\t}\n\t\n\tforeach (i; 0 .. 26)\n\tif (a[i] > 0 && b[i] > 0) {\n\t\twriteln(distHam - 1, '\\n', b[i], ' ', a[i]);\n\t\treturn;\n\t}\n\t\n\twriteln(distHam, '\\n', \"-1 -1\");\n}"}], "src_uid": "2fa543c8b8f9dc500c36cf719800a6b0"} {"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\nint N, M;\nint[] A, B;\nint Q;\nint[] L, R;\n\nint[][] G;\nint[] par, dep;\nint[][] rss;\n\nvoid dfs(int u, int p) {\n par[u] = p;\n dep[u] = (p == -1) ? 0 : (dep[p] + 1);\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n if (dep[v] == -1) {\n dfs(v, u);\n } else if (dep[v] < dep[u]) {\n int mn = N, mx = -1;\n for (int w = u; ; w = par[w]) {\n chmin(mn, w);\n chmax(mx, w);\n if (w == v) break;\n }\n debug {\n writeln([mn, mx]);\n }\n rss[mn] ~= mx;\n }\n }\n }\n}\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 Q = readInt();\n L = new int[Q];\n R = new int[Q];\n foreach (q; 0 .. Q) {\n L[q] = readInt() - 1;\n R[q] = readInt();\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 dep = new int[N];\n dep[] = -1;\n rss = new int[][N];\n foreach (u; 0 .. N) {\n if (dep[u] == -1) {\n dfs(u, -1);\n }\n }\n \n auto rMins = new int[N + 1];\n rMins[N] = N;\n foreach_reverse (u; 0 .. N) {\n rMins[u] = rMins[u + 1];\n foreach (r; rss[u]) {\n chmin(rMins[u], r);\n }\n }\n debug {\n writeln(\"rMins = \", rMins);\n }\n auto lss = new int[][N + 1];\n foreach (l; 0 .. N + 1) {\n lss[rMins[l]] ~= l;\n }\n \n auto queriess = new int[][N + 1];\n foreach (q; 0 .. Q) {\n queriess[R[q]] ~= q;\n }\n auto bit1 = new long[N + 1];\n auto bitL = new long[N + 1];\n auto bitR = new long[N + 1];\n auto ans = new long[Q];\n foreach (r; 0 .. N + 1) {\n foreach (l; lss[r]) {\n debug {\n writefln(\"add %s %s\", l, r);\n }\n bit1.bAdd(l, 1);\n bitL.bAdd(l, l);\n bitR.bAdd(l, r);\n }\n foreach (q; queriess[r]) {\n const sum1 = bit1.bSum(R[q]) - bit1.bSum(L[q]);\n const sumL = bitL.bSum(R[q]) - bitL.bSum(L[q]);\n const sumR = bitR.bSum(R[q]) - bitR.bSum(L[q]);\n debug {\n writefln(\"sum [%s, %s): %s %s %s\", L[q], R[q], sum1, sumL, sumR);\n }\n ans[q] += sumR - sumL;\n ans[q] += R[q] * (R[q] - L[q] - sum1) - (1L * (L[q] + R[q] - 1) * (R[q] - L[q]) / 2 - sumL);\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": "/+ 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, \"right\", 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, b, i, false);\n ev[a] ~= E(a, b, i, true);\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..e.right].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*/\n"}], "negative_code": [], "src_uid": "f4c9024916bf9a061d90f4277eebdee2"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1409/problem/B\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 int a, b, x, y, n;\n readf(\"%s %s %s %s %s\", &a, &b, &x, &y, &n);\n readln;\n\n\n long minima = long.max;\n for(int i = 0; i < 2; i++) {\n long new_n = n;\n long moves = min(a-x, new_n);\n long new_a = a-moves;\n\n new_n -= moves;\n\n long new_b = b-min(b-y, new_n);\n\n minima = min(minima, new_a*new_b);\n\n swap(a,b);\n swap(x,y);\n }\n\n minima.writeln;\n }\n}\n\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.math;\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 a = next!long;\n auto b = next!long;\n auto x = next!long;\n auto y = next!long;\n auto n = next!long;\n\n auto opsa = a - x;\n auto opsb = b - y;\n if (opsa + opsb <= n)\n {\n writeln((a - opsa) * (b - opsb));\n }\n else\n {\n opsa = min(opsa, n);\n opsb = min(opsb, n);\n // oa * b + ob * (a - oa)\n // ob * a + oa * (b - ob)\n\n auto ifa = opsa * b + min(max(n - opsa, 0), opsb) * (a - opsa);\n auto ifb = opsb * a + min(max(n - opsb, 0), opsa) * (b - opsb);\n writeln(a * b - max(ifa, ifb));\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, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 x = RD;\n\t\tauto y = RD;\n\t\tauto n = RD;\n\n\t\tauto d1 = min(a-x, n);\n\t\tauto d2 = min(b-y, n);\n\t\tauto d3 = min(b-y, n-d1);\n\t\tauto d4 = min(a-x, n-d2);\n\t\tdebug writeln([d1, d2, d3, d4]);\n\t\tans[ti] = min((a-d1)*(b-d3), (b-d2)*(a-d4));\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "04753f73af685b4e7339d30d6d47c161"} {"source_code": "import std.stdio, std.range, std.string, std.conv, std.algorithm;\nimport std.math;\n\nvoid main() {\n int n, v;\n readf(\"%d %d\\n\", &n, &v);\n\n int[] ans;\n foreach (i; 1..(n + 1)) {\n int[] items = readln.chomp.split.map!(to!int).array;\n if (items[1..$].minPos[0] < v) {\n ans ~= i;\n }\n }\n\n writeln(ans.length);\n writeln(ans.map!(to!string).join(\" \"));\n}", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n int n, v;\n while (readf(\" %s %s\", &n, &v)) {\n int[] ans;\n foreach (i; 0..n) {\n int ki;\n readf(\" %s\", &ki);\n auto good = false;\n foreach (j; 0..ki) {\n int price;\n readf(\" %s\", &price);\n if (price + 1 <= v)\n good = true;\n }\n if (good)\n ans ~= i;\n }\n writeln(ans.length);\n foreach(i, val; ans) {\n if (i > 0)\n write(' ');\n write(val + 1);\n }\n writeln();\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.range, std.string, std.conv, std.algorithm;\nimport std.math;\n\nvoid main() {\n int n, v;\n readf(\"%d %d\\n\", &n, &v);\n\n int[] ans;\n foreach (i; 1..(n + 1)) {\n int[] items = readln.chomp.split.map!(to!int).array;\n if (items[1..$].minPos[0] < v) {\n ans ~= i;\n }\n }\n\n if (ans.empty) {\n 0.writeln;\n } else {\n writeln(ans.map!(to!string).join(\" \"));\n }\n}"}], "src_uid": "7804152ee14264afef019c5ad33094f9"} {"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 toplamGuzellikSayisi = 0;\n\nvoid main() {\n\n auto satirSayisi = stdin.readln.strip.to!int();\n\tchar[] hulkunHisleri;\n\tfor ( int i = 0; i < satirSayisi; i++ )\n\t{\n\t\tif ( i == satirSayisi - 1 )\n\t\t{\n\t\t if ( i % 2 )\n\t\t\t\thulkunHisleri ~= \"I love it \";\n\t\t\telse \n\t\t\t\thulkunHisleri ~= \"I hate it \";\n\t\t}\n\t\telse if ( i % 2 )\n\t\t\thulkunHisleri ~= \"I love that \";\n\t\telse \n\t\t\thulkunHisleri ~= \"I hate that \";\n\t}\n\twriteln(hulkunHisleri.chomp());\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 char[] love = \"I love\".dup;\n char[] hate = \"I hate\".dup;\n for (int i = 0; i < n; i++) {\n if (i % 2 == 0) write(hate);\n else write(love);\n if (i != n - 1) write(\" that \");\n }\n write(\" it\");\n writeln();\n } \n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main()\n{\n auto n = stdin.readln.strip.to!int;\n write(\"I hate\");\n for(int i = 2; i <= n; i++) \n write(\" that I \" ~ (i%2==0?\"love\":\"hate\"));\n writeln(\" it\");\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\twrite(\"I hate\");\n\tforeach (int i; 1..n)\n\t{\n\t\twrite((i % 2 == 0) ? \" that I hate\" : \" that I love\");\n\t}\n\twrite(\" it\");\n\treturn 0;\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 foreach (i ; 0 .. n) {\n write(\"I \", [\"hate \", \"love \"][i&1], [\"that \", \"it\"][i == n-1]);\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}"}, {"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tif (a%2==0)\n\t{\n\t\tfor (int i=0; i<(a-2)/2; i++)\n\t\t{\n\t\t\twrite(\"I hate that I love that \");\n\t\t}\n\t\twrite(\"I hate that I love it\");\n\t}\n\telse\n\t{\n\t\tfor (int i=0; i<(a-1)/2; i++)\n\t\t{\n\t\t\twrite(\"I hate that I love that \");\n\t\t}\n\t\twrite(\"I hate it\");\n\t}\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tif (a%3==1)\n\t{\n\t\twriteln(\"I hate it\");\n\t}\n\telse if (a%3==2)\n\t{\n\t\twriteln(\"I hate that I love it\");\n\t}\n\telse\n\t{\n\t\twriteln(\"I hate that I love that I hate it\");\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %x\", &a);\n\tif (a%3==1)\n\t{\n\t\twriteln(\"I hate it\");\n\t}\n\telse if (a%3==2)\n\t{\n\t\twriteln(\"I hate that I love it\");\n\t}\n\telse\n\t{\n\t\twriteln(\"I hate that I love that I hate it\");\n\t}\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %x\", &a);\n\tif (a%2==0)\n\t{\n\t\tfor (int i=0; i<(a-2)/2; i++)\n\t\t{\n\t\t\twrite(\"I hate that I love that \");\n\t\t}\n\t\twrite(\"I hate that I love it\");\n\t}\n\telse\n\t{\n\t\tfor (int i=0; i<(a-1)/2; i++)\n\t\t{\n\t\t\twrite(\"I hate that I love that \");\n\t\t}\n\t\twrite(\"I hate it\");\n\t}\n\treturn 0;\n}"}], "src_uid": "7f2441cfb32d105607e63020bed0e145"} {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d \", &n);\n\tchar [] arr = new char[n];\n\tfor(int i = 0; i < n; i++)\n\t\tscanf(\"%c\", &arr[i]);\n\tfor(int i = 0; i < n; i++){\n\tif(arr[i] == 'a' || arr[i] == 'i' || arr[i] == 'u' || arr[i] == 'y' || arr[i] == 'o' || arr[i] == 'e'){\n \tif(i != n - 1 && arr[i] == arr[i + 1])\n\t continue;\n\t if(arr[i] == 'o' || arr[i] == 'e'){\n\t if(i > 1 && arr[i - 2] == arr[i] && arr[i - 1] == arr[i]){\n\t printf(\"%c\", arr[i]);\n\t continue;\n\t }\n\t if(i > 0 && arr[i - 1] == arr[i]){\n\t printf(\"%c\", arr[i]);\n\t }\n\t }\n\t else\n\t {\n\t if(i && arr[i] == arr[i - 1]){\n\t printf(\"%c\", arr[i]);\n\t continue;\n\t }\n\t }\n }\n\t printf(\"%c\", arr[i]);\n\t}\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\n\nint n, cnt=0;\n\nvoid main(string[] argv) {\n\t\n\treadf(\"%s\\n\", &n);\n\tstring buff, ans=\"\";\n\t//ans = \"\";\n\tbuff = readln('\\n');\n\tforeach(int i; 0..n) {\n\t\t if((i>0)&&(buff[i]==buff[i-1]) && \n\t\t (buff[i]=='a'||buff[i]=='e'||buff[i]=='i'||buff[i]=='o'||buff[i]=='u'||buff[i]=='y')){\n\t\t //cnt++;\n\t\t }\n\t\t else{\n\t\t ans = ans~buff[i]; \n\t\t }\n\t\t \n\t\t if((buff[i]=='e'||buff[i]=='o')\n\t\t && (i==0 || (buff[i]!=buff[i-1])) && (i+1=n || (buff[i]!=buff[i+2]))){\n\t\t ans = ans~buff[i];\n\t\t }\n\t\t\n\t\t/*if(buff.length <= 11)\n\t\t\twrite(buff);\n\t\telse {\n\t\t\twriteln(buff[0], buff.length-3, buff[$-2]);\n\t\t}*/\n\t}\n\twrite(ans);\n\treturn;\n}"}, {"source_code": "module main;\n\nimport core.stdc.stdio;\n\nint main(string[] arv) {\n\tint n;\n\tscanf(\"%d\", &n);\n\tchar [] s = new char[n];\n\tfor(int i = 0; i < n; i++) scanf(\" %c\", &s[i]);\n\tfor(int i = 0; i < n; i++) {\n\t\tif(s[i] != 'a' && s[i] != 'e' && s[i] != 'i' && s[i] != 'o' && s[i] != 'u' && s[i] != 'y')\n\t\t\tprintf(\"%c\", s[i]);\n\t\telse {\n\t\t\tint count = 1;\n\t\t\tfor(int j = i + 1; j < n && s[i] == s[j]; j++) count++;\n\t\t\tif((s[i] == 'e' || s[i] == 'o') && count == 2)\n\t\t\t\tprintf(\"%c%c\", s[i], s[i]);\n\t\t\telse\n\t\t\t\tprintf(\"%c\", s[i]);\n\t\t\twhile(s[i] == s[i+1]) i++;\n\t\t}\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio : writeln, stdin;\nimport std.conv : to;\nimport std.range : dropOne;\n\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n int cnt = 1;\n char last = 'Z'; \n int n;\n scanf(\"%d\",&n);\n foreach(words; stdin.byLine)\n { \n foreach(word;words){\n if(word != last){\n if (last != 'Z') {\n if (last == 'a' || last == 'e' || last == 'i' || last == 'o' || last == 'u' || last == 'y'){\n if ((last != 'e' && last != 'o') || cnt != 2) cnt = 1;\n }\n for(int i = 0; i < cnt; ++i) printf(\"%c\",last);\n }\n cnt = 0;\n }\n last = word;\n cnt++;\n }\n if (last != 'Z') {\n if (last == 'a' || last == 'e' || last == 'i' || last == 'o' || last == 'u' || last == 'y'){\n if ((last != 'e' && last != 'o') || cnt != 2) cnt = 1;\n }\n for(int i = 0; i < cnt; ++i) printf(\"%c\",last);\n }\n }\n\treturn 0;\n}"}, {"source_code": "module main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tchar chaine[3*1000*100+1];\n\tscanf(\"%d\\n\", &n);\n\tfor(int i=0;i 0)\n {\n printf(\"%c\", ss[i]); \n while((i + 1) < n && arr[i+1] == 0)\n {\n ++i;\n }\n }\n \n }\n}"}, {"source_code": "module main;\nimport std.c.stdio;\nimport std.stdio : writeln, stdin;\nimport std.conv : to;\nimport std.range : dropOne;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tchar [] arr = new char[n + 1];\n\tscanf(\"%c\", &arr[0]);\n\tfor(int i = 0; i m){\n x = 2;\n }\n }\n writeln;\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.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\r\n\t\tauto m = n * k;\r\n\t\tauto m2 = m / 2;\r\n\t\tif (m2 % k) continue;\r\n\t\t\r\n\t\tans[ti].length = n;\r\n\t\tforeach (i; 0..m2/k)\r\n\t\t{\r\n\t\t\tforeach (j; 0..k)\r\n\t\t\t{\r\n\t\t\t\tans[ti][i] ~= (i*k + j + 1) * 2;\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach (i; m2/k..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..k)\r\n\t\t\t{\r\n\t\t\t\tans[ti][i] ~= ((i-m2/k)*k + j) * 2 + 1;\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(\"NO\");\r\n\t\telse\r\n\t\t{\r\n\t\t\twriteln(\"YES\");\r\n\t\t\tforeach (ee; e)\r\n\t\t\t\tee.map!(to!string).join(\" \").writeln;\r\n\t\t}\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}"}], "negative_code": [], "src_uid": "9fb84ddc2e04fd637812cd72110b7f36"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 n = RD!int;\n\tauto a = RDA;\n\tauto b = RDA;\n\tauto c = new long[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tc[i] = a[i] - b[i];\n\t}\n\tc.sort();\n\n\tlong ans;\n\tforeach (i; 0..n)\n\t{\n\t\tbool f(int x)\n\t\t{\n\t\t\treturn c[i]+c[x] > 0;\n\t\t}\n\t\tauto cnt = n - binarySearch!(f)(n, cast(int)i);\n\t\tans += cnt;\n\t}\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\nvoid main()\n{\n auto N = readln.chomp.to!int;\n auto as = readln.split.to!(long[]);\n auto bs = readln.split.to!(long[]);\n long[] cs;\n foreach (i; 0..N) cs ~= as[i] - bs[i];\n sort(cs);\n long res;\n foreach (i; 0..N-1) {\n auto c = cs[i];\n if (cs[$-1] + c <= 0) continue;\n if (cs[i+1] + c > 0) {\n res += N-i-1;\n continue;\n }\n int l = i+1, r = N-1;\n while (l+1 < r) {\n auto m = (l+r)/2;\n if (cs[m] + c > 0) {\n r = m;\n } else {\n l = m;\n }\n }\n res += N - r;\n }\n writeln(res);\n}"}], "negative_code": [], "src_uid": "e25b247975660c5005bd4da7afd38a56"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n, w;\n\twhile (readf (\" %s %s\", &n, &w) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tlong cur = 0;\n\t\tlong lo = cur;\n\t\tlong hi = cur;\n\t\tforeach (c; a)\n\t\t{\n\t\t\tcur += c;\n\t\t\tlo = min (lo, cur);\n\t\t\thi = max (hi, cur);\n\t\t}\n\t\tlong inf = 0 - lo;\n\t\tlong sup = w - hi;\n\t\tlong res = sup - inf + 1;\n\t\tres = max (res, 0);\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; long w; rd(n, w);\n auto diff=readln.split.to!(long[]);\n\n long lowerBound(){ // cap: [0, infty)\n bool tooLarge(long x){\n if(x<0) return false;\n foreach(d; diff){\n if((x+=d)<0) return false;\n }\n return true;\n }\n long ng=-1, ok=1_000_000_000_000;\n while(ok-ng>1){ // (ng, ok]\n auto m=(ok+ng)/2;\n tooLarge(m) ? ok : ng = m;\n }\n return ok;\n }\n\n long upperBound(){ // (-infty, w]\n bool tooSmall(long x){\n if(x>w) return false;\n foreach(d; diff){\n if((x+=d)>w) return false;\n }\n return true;\n }\n long ok=-1_000_000_000_000, ng=w+1;\n while(ng-ok>1){ // [ok, ng)\n auto m=(ok+ng)/2;\n tooSmall(m) ? ok : ng = m;\n }\n return ok;\n }\n\n auto ub=upperBound(), lb=lowerBound();\n if(0<=ub && ub<=w && 0<=lb && lb<=w){\n writeln(max(0, ub-lb+1));\n }else{\n writeln(0);\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": "8cf5d08a319672d9b767d3523eca4df6"} {"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 q, x;\n\twhile (readf !(\" %s %s\") (q, x) > 0)\n\t{\n\t\tauto d = new int [x];\n\t\tint res = 0;\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tint u;\n\t\t\treadf !(\" %s\") (u);\n\t\t\td[u % x] += 1;\n\t\t\twhile (d[res % x] > res / x)\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\twriteln (res);\n\t\t}\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n // number of queries, operation amount\n uint q, x;\n readf!\"%d %d\\n\"(q, x);\n\n auto m = new uint[x];\n uint mex = 0; // initial mex is 0\n\n foreach (i; 0..q) {\n // value to be appended to array\n uint j;\n readf!\"%d\\n\"(j);\n m[j % x]++;\n\n while (m[mex % x] > mex / x) mex++;\n\n writeln(mex);\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 q, x;\n readf(\"%s %s\", &q, &x);\n readln;\n\n auto added = new bool[] (max(q+1, x+1));\n auto nxtfree = new int[] (x);\n foreach (i; 0 .. x) { nxtfree[i] = i; }\n int mex = 0;\n \n while (q--) {\n int y;\n readf(\"%s\", &y);\n readln;\n \n y %= x;\n \n if (nxtfree[y] < added.length) {\n added[nxtfree[y]] = true;\n nxtfree[y] += x;\n }\n \n while (added[mex]) { ++mex; }\n \n mex.writeln;\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 q = readInt;\n int x = readInt;\n int[] cnt = new int[x];\n int ans = 0;\n while (q--)\n {\n cnt[readInt % x]++;\n while (cnt[ans % x])\n {\n cnt[ans++ % x]--;\n }\n writeln(ans);\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\nvoid main()\n{\n long q, x;\n read(q, x);\n auto ap = new long[x.ind];\n auto aps = redBlackTree!(Tuple!(long, long))();\n foreach(i, api; ap[])\n aps.insert(tuple(cast(long)api, cast(long)i));\n foreach(qn; 0 .. q)\n {\n auto y = next!long;\n ap[(y % x).ind]++;\n aps.insert(tuple(ap[(y % x).ind], y % x));\n\n auto minap = aps.front;\n while(ap[minap[1].ind] != minap[0])\n {\n aps.removeFront;\n minap = aps.front;\n }\n auto minval = minap[0];\n auto minind = minap[1];\n writeln(x * minval + minind);\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 q = RD!int;\n\tauto x = RD;\n\tauto ans = new long[](q);\n\tlong pos, loop;\n\tauto cnt = new long[](cast(int)x);\n\n\tvoid f(long z)\n\t{\n\t\tint y = cast(int)(z % x);\n\t\tif (pos == y)\n\t\t{\n\t\t\t++cnt[y];\n\t\t\tauto l = cast(int)pos;\n\t\t\tpos = x;\n\t\t\tforeach (i; l..cnt.length)\n\t\t\t{\n\t\t\t\tif (cnt[i] == loop)\n\t\t\t\t{\n\t\t\t\t\tpos = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pos == x)\n\t\t\t{\n\t\t\t\t++loop;\n\t\t\t\tforeach (i; 0..cnt.length)\n\t\t\t\t{\n\t\t\t\t\tif (cnt[i] == loop)\n\t\t\t\t\t{\n\t\t\t\t\t\tpos = i;\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\telse\n\t\t\t++cnt[y];\n\t}\n\n\tforeach (qi; 0..q)\n\t{\n\t\tauto y = RD;\n\t\tf(y);\n\t\tans[qi] = loop*x + pos;\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": "e25d4d7decfe6e0f5994f615a268b3aa"} {"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 = 1_000_000_007;\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 [long] f;\r\n\t\tf[0] = 1;\r\n\t\tlong shift = 0;\r\n\t\tint total = 1;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tint cur0 = f.get (0 - shift, 0);\r\n\t\t\tshift += c;\r\n\t\t\tint value = (total - cur0 + mod) % mod;\r\n\t\t\tf[c - shift] = (f.get (c - shift, 0) + value) % mod;\r\n\t\t\ttotal = (total + value) % mod;\r\n\t\t}\r\n\t\twriteln (total);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\n\nconst ulong M = 1000000007;\n\nvoid solve()\n{\n uint n;\n readf!\" %d\"(n);\n\n long[] b = new long[n];\n foreach (ref x; b)\n readf!\" %d\"(x);\n\n ulong[long] s = [0: 1];\n long d = 0;\n ulong r = 1;\n\n foreach (x; b)\n {\n auto k = r + M - s.get(-d, 0);\n r = (r + k) % M;\n\n d += x;\n s.update(x - d, { return k % M; }, (ref ulong o) { return (o + k) % M; });\n }\n\n writeln(r);\n}\n\nvoid main()\n{\n ushort t;\n readf!\" %d\"(t);\n for (ushort i = 0; i < t; ++i)\n solve();\n}\n"}], "negative_code": [], "src_uid": "eb8f0abc9556ca514454d307fd98ae5d"} {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main()\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint[] nums; nums.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tscanf(\"%d\", &nums[i]);\n\t}\n\t\n\tint idx = 0;\n\tforeach (int i; 2..n)\n\t{\n\t\tint sum = (nums[i] % 2) + (nums[i-1] % 2) + (nums[i-2] % 2);\n\t\tif (sum == 0 || sum == 3)\n\t\t\tcontinue;\n\t\tidx = (sum % 2 == nums[i] % 2 ? i : sum % 2 == nums[i-1] % 2 ? i-1 : i-2);\n\t}\n\twrite(idx+1);\n\treturn 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.array, std.conv;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = stdin.readln.split.map!(to!int).array;\n if (xs.count!(\"a % 2 == 1\") == 1) {\n writeln(xs.countUntil!(\"a % 2 == 1\") + 1);\n } else {\n writeln(xs.countUntil!(\"a % 2 == 0\") + 1);\n }\n}\n"}, {"source_code": "import std.stdio;\n\nint n;\nint[] a;\nint[2] z;\nvoid main()\n{\n\treadf(\"%d\", &n);\n\ta.length = n;\n\tfor(int i = 0; i < n; i++) {\n\t\treadf(\" %d\", &a[i]);\n\t\tz[a[i] % 2]++;\n\t}\n\tfor(int i = 0; i < n; i++) {\n\t\tif (z[a[i] % 2] == 1) {\n\t\t\twriteln(i + 1);\n\t\t}\n\t}\n}"}], "negative_code": [{"source_code": "import std.stdio;\n\nint n;\nint[] a;\nint[2] z;\nvoid main()\n{\n\treadf(\"%d\", &n);\n\ta.length = n;\n\tfor(int i = 0; i < n; i++) {\n\t\treadf(\" %d\", &a[i]);\n\t\tz[a[i] % 2]++;\n\t}\n\tfor(int i = 0; i < n; i++) {\n\t\tif (z[a[i] % 2] == 1) {\n\t\t\twriteln(a[i]);\n\t\t}\n\t}\n}"}, {"source_code": "import std.stdio;\n\nint n;\nint[] a;\nint[2] z;\nvoid main()\n{\n\treadf(\"%d\", &n);\n\ta.length = n;\n\tfor(int i = 0; i < n; i++) {\n\t\treadf(\" %d\", &a[i]);\n\t\tz[a[i] % 2]++;\n\t}\n\tfor(int i = 0; i < n; i++) {\n\t\tif (z[a[i] % 2] == 1) {\n\t\t\twriteln(i);\n\t\t}\n\t}\n}"}], "src_uid": "dd84c2c3c429501208649ffaf5d91cee"} {"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 a = readln.splitter.map !(to !(int)).array;\r\n\t\tif (sum (a) % 2 != 0)\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\tauto b = a.enumerate.filter !(x => x.value != 0).array;\r\n\t\tb ~= typeof (b.front) (n, 0);\r\n\t\tint [] [] answer;\r\n\t\tfor (int i = 0; i + 2 < b.length; i += 2)\r\n\t\t{\r\n\t\t\tif (b[i].value == b[i + 1].value)\r\n\t\t\t{\r\n\t\t\t\tanswer ~= [b[i].index, b[i + 2].index];\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tanswer ~= [b[i].index, b[i + 1].index];\r\n\t\t\t\tanswer ~= [b[i + 1].index, b[i + 2].index];\r\n\t\t\t}\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\twriteln (line[0] + 1, \" \", line[1]);\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;\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[] solve() {\r\n const sumA = A.sum;\r\n if (sumA % 2 != 0) {\r\n return null;\r\n }\r\n \r\n auto fs = new bool[N];\r\n bool greedy(int a, int k) {\r\n foreach (i; 0 .. N) {\r\n if (i == 0 || fs[i - 1]) {\r\n continue;\r\n }\r\n if (A[i] == a && k > 0) {\r\n fs[i] = true;\r\n --k;\r\n }\r\n }\r\n return (k == 0);\r\n }\r\n if (sumA >= 0) {\r\n if (!greedy(+1, sumA / 2)) return null;\r\n } else {\r\n if (!greedy(-1, -sumA / 2)) return null;\r\n }\r\n debug {\r\n writeln(\"fs = \", fs);\r\n }\r\n \r\n int[] cuts;\r\n cuts ~= 0;\r\n foreach (i; 1 .. N) {\r\n if (fs[i - 1] == fs[i]) {\r\n assert(!fs[i]);\r\n cuts ~= i;\r\n }\r\n }\r\n cuts ~= N;\r\n return cuts;\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 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 debug {\r\n writeln(A, \": \", ans);\r\n }\r\n const len = cast(int)(ans.length) - 1;\r\n if (len >= 0) {\r\n writeln(len);\r\n foreach (i; 0 .. len) {\r\n writeln(ans[i] + 1, \" \", ans[i + 1]);\r\n }\r\n } else {\r\n writeln(-1);\r\n }\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\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\nbool solve(int[] a, int sum, ref Tuple!(int, int)[] ans)\n{\n if (a.length == 0)\n return sum == 0;\n\n if (sum == 0) {\n ans ~= tuple(cast(int)a.length, cast(int)a.length);\n return solve(a[0 .. $ - 1], sum, ans);\n return true;\n }\n\n if (sum < 0) {\n if (a.length >= 2 && a[$ - 1] < 0) {\n ans ~= tuple(cast(int)a.length - 1, cast(int)a.length);\n return solve(a[0 .. $ - 2], sum - 2 * a[$ - 1], ans);\n } else {\n ans ~= tuple(cast(int)a.length, cast(int)a.length);\n return solve(a[0 .. $ - 1], sum, ans);\n }\n } else {\n if (a.length >= 2 && a[$ - 1] > 0) {\n ans ~= tuple(cast(int)a.length - 1, cast(int)a.length);\n return solve(a[0 .. $ - 2], sum - 2 * a[$ - 1], ans);\n } else {\n ans ~= tuple(cast(int)a.length, cast(int)a.length);\n return solve(a[0 .. $ - 1], sum, ans);\n }\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!int).array;\n Tuple!(int, int)[] ans;\n if (solve(a, a.sum, ans)) {\n ans.reverse;\n writeln(ans.length);\n foreach (x; ans) {\n writefln(\"%d %d\", x[0], x[1]);\n }\n } else {\n writeln(-1);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "b87a90f2b4822e59d66b06886a5facad"} {"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid dfs(int node, int depth, int[][] c, bool[] v, int[][] dp)\n{\n v[node] = true;\n auto parent = -1;\n foreach (i; 0 .. c[node].length)\n {\n if (!v[c[node][i]])\n {\n dfs(c[node][i], depth + 1, c, v, dp);\n }\n else\n {\n parent = c[node][i];\n }\n }\n if (depth <= 1)\n {\n auto sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][0], dp[child][1]);\n }\n }\n dp[node][0] = sum;\n dp[node][1] = sum + 1;\n dp[node][2] = int.max;\n return;\n }\n auto sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][1], dp[child][2]);\n }\n }\n dp[node][0] = sum;\n sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][0], dp[child][1]);\n }\n }\n dp[node][1] = sum + 1;\n dp[node][2] = int.max;\n sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][1], dp[child][2]);\n }\n }\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n dp[node][2] = min(dp[node][2], sum - min(dp[child][1], dp[child][2]) + dp[child][1]);\n }\n }\n}\n\nvoid solve(int[][] c)\n{\n auto n = cast(int)c.length;\n auto v = new bool[n];\n fill(v, false);\n auto dp = new int[][](n, 3);\n dfs(0, 0, c, v, dp);\n writeln(dp[0][0]);\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 - 1)\n {\n int u, v;\n readf(\"%d %d\\n\", &u, &v);\n c[u - 1] ~= v - 1;\n c[v - 1] ~= u - 1;\n }\n solve(c);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid dfs(int node, int depth, int[][] c, bool[] v, int[][] dp)\n{\n v[node] = true;\n auto parent = -1;\n foreach (i; 0 .. c[node].length)\n {\n if (!v[c[node][i]])\n {\n dfs(c[node][i], depth + 1, c, v, dp);\n }\n else\n {\n parent = c[node][i];\n }\n }\n if (depth <= 1)\n {\n auto sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][0], dp[child][1]);\n }\n }\n dp[node][0] = sum;\n dp[node][1] = sum + 1;\n dp[node][2] = int.max;\n return;\n }\n auto sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][1], dp[child][2]);\n }\n }\n dp[node][0] = sum;\n sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][0], dp[child][1]);\n }\n }\n dp[node][1] = sum + 1;\n dp[node][2] = int.max;\n sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][1], dp[child][2]);\n }\n }\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n dp[node][2] = min(dp[node][2], sum - min(dp[child][1], dp[child][2]) + dp[child][1]);\n }\n }\n if (depth > 2 && dp[node][2] == int.max)\n {\n dp[node][2] = 1;\n }\n}\n\nvoid solve(int[][] c)\n{\n auto n = cast(int)c.length;\n auto v = new bool[n];\n fill(v, false);\n auto dp = new int[][](n, 3);\n dfs(0, 0, c, v, dp);\n writeln(dp[0][0]);\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 - 1)\n {\n int u, v;\n readf(\"%d %d\\n\", &u, &v);\n c[u - 1] ~= v - 1;\n c[v - 1] ~= u - 1;\n }\n solve(c);\n }\n return 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;\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 ans = 0;\n int dfs(int v, int fr, int dst) {\n int mxc = 0, mnc = 10 ^^ 9;\n foreach (u; g[v]) {\n if (u == fr) continue;\n auto c = dfs(u, v, dst+1);\n mxc = max(mxc, c);\n mnc = min(mnc, c);\n }\n \n auto curd = min(dst, mnc+1);\n \n debug { writeln(v, ' ', curd); }\n \n if (mxc > 2) {\n debug { v.writeln; }\n ++ans;\n curd = 1;\n }\n \n return curd;\n }\n \n dfs(1, -1, 0);\n \n ans.writeln;\n}"}], "negative_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid dfs(int node, int depth, int[][] c, bool[] v, int[][] dp)\n{\n v[node] = true;\n auto parent = -1;\n foreach (i; 0 .. c[node].length)\n {\n if (!v[c[node][i]])\n {\n dfs(c[node][i], depth + 1, c, v, dp);\n }\n else\n {\n parent = c[node][i];\n }\n }\n if (depth <= 1)\n {\n auto sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][0], dp[child][1]);\n }\n }\n dp[node][0] = sum;\n dp[node][1] = sum + 1;\n dp[node][2] = int.max;\n return;\n }\n auto sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][1], dp[child][2]);\n }\n }\n dp[node][0] = sum;\n sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += min(dp[child][0], dp[child][1]);\n }\n }\n dp[node][1] = sum + 1;\n dp[node][2] = int.max;\n sum = 0;\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n sum += dp[child][2];\n }\n }\n foreach (i; 0 .. c[node].length)\n {\n if (c[node][i] != parent)\n {\n auto child = c[node][i];\n dp[node][2] = min(dp[node][2], sum - dp[child][2] + dp[child][1]);\n }\n }\n if (dp[node][2] == int.max)\n {\n dp[node][2] = 1;\n }\n}\n\nvoid solve(int[][] c)\n{\n auto n = cast(int)c.length;\n auto v = new bool[n];\n fill(v, false);\n auto dp = new int[][](n, 3);\n dfs(0, 0, c, v, dp);\n writeln(dp[0][0]);\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 - 1)\n {\n int u, v;\n readf(\"%d %d\\n\", &u, &v);\n c[u - 1] ~= v - 1;\n c[v - 1] ~= u - 1;\n }\n solve(c);\n }\n return 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;\n readf(\"%s\", &n);\n readln;\n \n auto g = new int[][] (n);\n foreach (_; 0 .. n-1) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n --x, --y;\n g[x] ~= y;\n g[y] ~= x;\n }\n \n auto dp = new int[][] (4, n);\n foreach (ref rw; dp) rw[] = -1;\n int dfs(int v, int fr, int dst) {\n int run(int d) {\n int ans = 0;\n foreach (u; g[v]) {\n if (u == fr) continue;\n ans += dfs(u, v, d);\n }\n return ans;\n }\n \n if (dp[dst][v] != -1) return dp[dst][v];\n \n if (v != 0 && dst <= 2 && g[v].length == 1) return 0;\n \n if (dst == 0 || dst == 1) {\n dp[dst][v] = run(dst+1);\n } else if (dst == 2) {\n auto ans0 = 1 + run(2);\n auto ans1 = g[v].length - 1 + run(1);\n auto ans2 = run(3);\n \n dp[dst][v] = [ans0, ans1, ans2].minElement.to!int;\n \n debug { writeln(v, ' ', dst, ' ', dp[dst][v]); }\n } else { //dst == 3\n auto ans0 = 1 + run(2);\n auto ans1 = g[v].length > 1 ? g[v].length - 1 + run(1) : int.max;\n \n dp[dst][v] = min(ans0, ans1);\n }\n \n return dp[dst][v];\n }\n \n auto ans = dfs(0, -1, 0);\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 g = new int[][] (n);\n foreach (_; 0 .. n-1) {\n int x, y;\n readf(\"%s %s\", &x, &y);\n readln;\n \n --x, --y;\n g[x] ~= y;\n g[y] ~= x;\n }\n \n auto dp = new int[][] (3, n);\n foreach (ref rw; dp) rw[] = -1;\n int dfs(int v, int fr, int dst) {\n int run(int d) {\n int ans = 0;\n foreach (u; g[v]) {\n if (u == fr) continue;\n ans += dfs(u, v, d);\n }\n return ans;\n }\n \n if (dp[dst][v] != -1) return dp[dst][v];\n \n if (v != 0 && dst <= 2 && g[v].length == 1) return 0;\n \n if (dst == 0 || dst == 1) {\n dp[dst][v] = run(dst+1);\n } else {\n auto ans0 = 1 + run(2);\n auto ans1 = g[v].length - 1 + run(1);\n \n dp[dst][v] = min(ans0, ans1);\n \n debug { writeln(v, ' ', dst, ' ', min(ans0, ans1)); }\n }\n \n return dp[dst][v];\n }\n \n auto ans = dfs(0, -1, 0);\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 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 ans = 0;\n int dfs(int v, int fr, int dst) {\n int mxc = 0;\n foreach (u; g[v]) {\n if (u == fr) continue;\n auto c = dfs(u, v, dst+1);\n mxc = max(mxc, c);\n }\n \n auto curd = dst;\n \n debug { writeln(v, ' ', curd); }\n \n if (mxc > 2) {\n ++ans;\n curd = 1;\n }\n \n return curd;\n }\n \n dfs(1, -1, 0);\n \n ans.writeln;\n}"}], "src_uid": "64d85fcafab0e1b477bc888408f54eb5"} {"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, q, m;\n readf(\"%s %s %s\", &n, &q, &m);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n\n struct qr { int t, le, r; }\n auto qs = new qr[] (q);\n foreach (i; 0 .. q) {\n readf(\"%s %s %s\", &qs[i].t, &qs[i].le, &qs[i].r);\n readln;\n }\n \n auto b = readln.chomp.split.map!(to!int).array;\n \n \n foreach_reverse (cq; qs) {\n foreach (ref e; b) {\n if (e < cq.le || e > cq.r) { continue; }\n \n if (cq.t == 1) { e = e > cq.le ? e-1 : cq.r; }\n if (cq.t == 2) { e = cq.r - (e - cq.le); }\n }\n \n debug { b.writeln; }\n }\n \n int[] ans;\n foreach (e; b) { ans ~= arr[e-1]; }\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;\n\n\nvoid main() {\n auto input = readln.split.map!(to!int);\n auto N = input[0];\n auto K = input[1];\n auto M = input[2];\n auto A = readln.split.map!(to!int).array;\n auto Q = K.iota.map!(_ =>readln.split.map!(to!int).array).array;\n auto B = readln.split.map!(x => x.to!int - 1).array;\n\n Q.reverse();\n int[] ans;\n\n foreach (b; B) {\n foreach (q; Q) {\n auto l = q[1] - 1;\n auto r = q[2] - 1;\n\n if (q[0] == 1) {\n if (b == l)\n b = r;\n else if (b >= l && b <= r)\n b -= 1;\n } else {\n if (b >= l && b <= r)\n b = r - b + l;\n }\n }\n\n ans ~= A[b];\n }\n\n ans.map!(a => a.to!string).join(\" \").writeln;\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\nvoid main()\n{\n int n, q, m;\n readf(\"%s %s %s\", &n, &q, &m);\n readln;\n\n auto arr = readln.chomp.split.map!(to!int).array;\n\n struct qr { int t, le, r; }\n auto qs = new qr[] (q);\n foreach (i; 0 .. q) {\n readf(\"%s %s %s\", &qs[i].t, &qs[i].le, &qs[i].r);\n readln;\n }\n \n auto b = readln.chomp.split.map!(to!int).array;\n \n \n foreach_reverse (cq; qs) {\n foreach (ref e; b) {\n if (e < cq.le || e > cq.r) { continue; }\n \n if (cq.t == 1) { e = e > 1 ? e-1 : n; }\n if (cq.t == 2) { e = cq.r - (e - cq.le); }\n }\n \n debug { b.writeln; }\n }\n \n int[] ans;\n foreach (e; b) { ans ~= arr[e-1]; }\n \n ans.writefln!\"%(%s %)\";\n}"}], "src_uid": "1efbb1e8fc46b05408d266fa72dc43e2"} {"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 S = new string[N - K + 1];\n foreach (i; 0 .. N - K + 1) {\n S[i] = readToken();\n }\n \n auto ans = new string[N];\n foreach (i; 0 .. N) {\n ans[i] ~= cast(char)('A' + i / 26);\n ans[i] ~= cast(char)('a' + i % 26);\n if (i - (K - 1) >= 0 && S[i - (K - 1)] == \"NO\") {\n ans[i] = ans[i - (K - 1)];\n }\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": "/+ dub.sdl:\n name \"A\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.range, std.algorithm, std.conv;\n// import dcomp.scanner;\n\n\nstring genNewName() {\n static int id = 424;\n id++;\n return \"Sugim\" ~ id.to!string.map!(x => cast(char)(x-'0'+'a')).array.idup;\n}\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, k;\n sc.read(n, k);\n string[] v;\n sc.read(v);\n string[] ans;\n foreach(i; 0..k-1) {\n ans ~= genNewName();\n }\n foreach (s; v) {\n if (s == \"YES\") {\n ans ~= genNewName();\n } else {\n string u = ans[$-k+1];\n ans ~= u;\n }\n }\n writeln(ans.join(\" \"));\n return 0;\n}\n/* IMPORT /home/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 string[] buf;\n private bool succ() {\n while (!buf.length) {\n if (f.eof) return false;\n buf = f.readln.split;\n }\n return true;\n }\n private bool readSingle(T)(ref T x) {\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n //string or char[10] etc\n x = buf.front;\n buf.popFront;\n } else {\n static if (isStaticArray!T) {\n //static\n assert(buf.length == T.length);\n }\n x = buf.map!(to!E).array;\n buf.length = 0; \n }\n } else {\n x = buf.front.to!T;\n buf.popFront; \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\nunittest {\n import std.path : buildPath;\n import std.file : tempDir;\n import std.algorithm : equal;\n import std.stdio : File;\n string fileName = buildPath(tempDir, \"kyuridenanmaida.txt\");\n auto fout = File(fileName, \"w\");\n fout.writeln(\"1 2 3\");\n fout.writeln(\"ab cde\");\n fout.writeln(\"1.0 1.0 2.0\");\n fout.close;\n Scanner sc = new Scanner(File(fileName, \"r\"));\n int a;\n int[2] b;\n char[2] c;\n string d;\n double e;\n double[] f;\n sc.read(a, b, c, d, e, f);\n assert(a == 1);\n assert(equal(b[], [2, 3]));\n assert(equal(c[], \"ab\"));\n assert(equal(d, \"cde\"));\n assert(e == 1.0);\n assert(equal(f, [1.0, 2.0]));\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 a = readln.split;\n\t\tstring [] s;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\ts ~= \"\" ~\n\t\t\t cast (char) ('A' + i % 10) ~\n\t\t\t cast (char) ('a' + i / 10);\n\t\t}\n\t\tforeach (i; 0..n - k + 1)\n\t\t{\n\t\t\tif (a[i] == \"NO\")\n\t\t\t{\n\t\t\t\ts[i + k - 1] = s[i];\n\t\t\t}\n\t\t}\n\t\twritefln (\"%-(%s %)\", s);\n\t}\n}\n"}], "negative_code": [{"source_code": "/+ dub.sdl:\n name \"A\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.range, std.algorithm, std.conv;\n// import dcomp.scanner;\n\n\nstring genNewName() {\n static int id = 424;\n id++;\n return \"sugim\" ~ id.to!string.map!(x => cast(char)(x-'0'+'a')).array.idup;\n}\n\nint main() {\n auto sc = new Scanner(stdin);\n int n, k;\n sc.read(n, k);\n string[] v;\n sc.read(v);\n string[] ans;\n foreach(i; 0..k-1) {\n ans ~= genNewName();\n }\n foreach (s; v) {\n if (s == \"YES\") {\n ans ~= genNewName();\n } else {\n string u = ans[$-k+1];\n ans ~= u;\n }\n }\n writeln(ans.join(\" \"));\n return 0;\n}\n/* IMPORT /home/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 string[] buf;\n private bool succ() {\n while (!buf.length) {\n if (f.eof) return false;\n buf = f.readln.split;\n }\n return true;\n }\n private bool readSingle(T)(ref T x) {\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n //string or char[10] etc\n x = buf.front;\n buf.popFront;\n } else {\n static if (isStaticArray!T) {\n //static\n assert(buf.length == T.length);\n }\n x = buf.map!(to!E).array;\n buf.length = 0; \n }\n } else {\n x = buf.front.to!T;\n buf.popFront; \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\nunittest {\n import std.path : buildPath;\n import std.file : tempDir;\n import std.algorithm : equal;\n import std.stdio : File;\n string fileName = buildPath(tempDir, \"kyuridenanmaida.txt\");\n auto fout = File(fileName, \"w\");\n fout.writeln(\"1 2 3\");\n fout.writeln(\"ab cde\");\n fout.writeln(\"1.0 1.0 2.0\");\n fout.close;\n Scanner sc = new Scanner(File(fileName, \"r\"));\n int a;\n int[2] b;\n char[2] c;\n string d;\n double e;\n double[] f;\n sc.read(a, b, c, d, e, f);\n assert(a == 1);\n assert(equal(b[], [2, 3]));\n assert(equal(c[], \"ab\"));\n assert(equal(d, \"cde\"));\n assert(e == 1.0);\n assert(equal(f, [1.0, 2.0]));\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 K = readInt();\n auto S = new string[N - K + 1];\n foreach (i; 0 .. N - K + 1) {\n S[i] = readToken();\n }\n \n auto ans = new string[N];\n foreach (i; 0 .. N) {\n ans[i] ~= cast(char)('a' + i / 26);\n ans[i] ~= cast(char)('a' + i % 26);\n if (i - K >= 0 && S[i - K] == \"NO\") {\n ans[i] = ans[i - K];\n }\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"}, {"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 S = new string[N - K + 1];\n foreach (i; 0 .. N - K + 1) {\n S[i] = readToken();\n }\n \n auto ans = new string[N];\n foreach (i; 0 .. N) {\n ans[i] ~= cast(char)('a' + i / 26);\n ans[i] ~= cast(char)('a' + i % 26);\n if (i - (K - 1) >= 0 && S[i - (K - 1)] == \"NO\") {\n ans[i] = ans[i - (K - 1)];\n }\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"}], "src_uid": "046d6f213fe2d565bfa5ce537346da4f"} {"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, h, le, r;\n readf(\"%s %s %s %s\", &n, &h, &le, &r);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto dp = new int[][] (n, h);\n foreach (i; n.iota) { dp[i][] = -1; }\n \n int score(int idx, int ch) {\n if (idx == n) { return 0; }\n if (dp[idx][ch] != -1) { return dp[idx][ch]; }\n \n int h1 = (ch + arr[idx] - 1) % h;\n int h2 = (ch + arr[idx]) % h;\n \n auto isGood = (int v) => le <= v && v <= r ? 1 : 0;\n \n auto good1 = isGood(h1);\n auto good2 = isGood(h2);\n \n return dp[idx][ch] = max(good1 + score(idx+1, h1), good2 + score(idx+1, h2));\n }\n \n auto ans = score(0, 0);\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.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 n = RD!int;\n\tauto h = RD!int;\n\tauto l = RD!int;\n\tauto r = RD!int+1;\n\tauto a = RDA!int;\n\n\tauto dp = new int[](h);\n\tdp[] = -1;\n\tdp[0] = 0;\n\tforeach (i; 0..n)\n\t{\n\t\tauto ndp = new int[](h);\n\t\tndp[] = -1;\n\t\tforeach (j; 0..h)\n\t\t{\n\t\t\tif (dp[j] == -1) continue;\n\t\t\tint nc1 = dp[j], nc2 = dp[j];\n\t\t\tauto t1 = (j+a[i]) % h;\n\t\t\tauto t2 = (j+a[i]-1) % h;\n\t\t\tif (inside(t1, l, r))\n\t\t\t\t++nc1;\n\t\t\tif (inside(t2, l, r))\n\t\t\t\t++nc2;\n\t\t\tndp[t1].chmax(nc1);\n\t\t\tndp[t2].chmax(nc2);\n\t\t}\n\t\tdp = ndp;\n\t}\n\n\tauto pos = dp.MIN_POS!\"a > b\";\n\twriteln(dp[pos]);\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 nhlr = readln.split.to!(int[]);\n auto N = nhlr[0];\n auto H = nhlr[1];\n auto L = nhlr[2];\n auto R = nhlr[3];\n auto as = readln.split.to!(int[]);\n\n auto DP = new int[][](N, H);\n foreach (ref dp; DP) dp[] = -1;\n int solve(int i, int h) {\n if (i == N) return 0;\n if (DP[i][h] == -1) {\n auto r1 = (h + as[i]) % H;\n auto r2 = (h + as[i] - 1) % H;\n DP[i][h] = max(\n solve(i+1, r1) + (L <= r1 && r1 <= R ? 1 : 0),\n solve(i+1, r2) + (L <= r2 && r2 <= R ? 1 : 0)\n );\n }\n return DP[i][h];\n }\n writeln(solve(0, 0));\n}"}], "negative_code": [], "src_uid": "a301e0847a620fbb349fa914db98e752"} {"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 trysolve(bool[] vis, int n, long s)\n{\n long rs = 0;\n foreach (i ; 0 .. n) {\n if (!vis[i])\n rs += i + 1;\n }\n foreach (i ; n .. 100) {\n if (vis[i])\n return false;\n }\n return rs == s;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int m, s;\n readf!\" %d %d \"(m, s);\n auto a = readln.splitter.map!(to!int).array;\n auto vis = new bool[100];\n foreach (x ; a) {\n vis[x - 1] = true;\n }\n bool good = false;\n foreach (n ; (a.length + 1).to!int .. 100 + 1) {\n if (trysolve(vis, n, s)) {\n good = true;\n break;\n }\n }\n writeln(good ? \"YES\" : \"NO\");\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 m, s;\r\n readf!\" %d %d \"(m,s);\r\n bool good = false;\r\n auto b = readarray!int;\r\n auto mb = maxElement(b);\r\n auto sb = sum(b);\r\n auto curS = sum(iota(mb + 1));\r\n while (curS <= sb + s) {\r\n if (curS == sb + s) {\r\n good = true;\r\n break;\r\n }\r\n mb++;\r\n curS += mb;\r\n }\r\n if (good)\r\n writeln(\"yes\");\r\n else\r\n writeln(\"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"}, {"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 m, int s, int [] a)\r\n{\r\n\tauto hi = a.maxElement;\r\n\tauto vis = new bool [hi + 1];\r\n\tforeach (ref c; a)\r\n\t{\r\n\t\tif (vis[c])\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\tvis[c] = true;\r\n\t}\r\n\tforeach (i; 1..hi + 1)\r\n\t{\r\n\t\tif (!vis[i])\r\n\t\t{\r\n\t\t\ts -= i;\r\n\t\t}\r\n\t}\r\n\twhile (s > 0)\r\n\t{\r\n\t\thi += 1;\r\n\t\ts -= hi;\r\n\t}\r\n\treturn (s == 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\tint m, s;\r\n\t\treadf !(\" %s %s\") (m, s);\r\n\t\treadln;\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (m, s, a) ? \"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\nbool trysolve(bool[] vis, int n, long s)\n{\n long rs = 0;\n foreach (i ; 0 .. n) {\n if (!vis[i])\n rs += i + 1;\n }\n foreach (i ; n .. 50) {\n if (vis[i])\n return false;\n }\n return rs == s;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int m, s;\n readf!\" %d %d \"(m, s);\n auto a = readln.splitter.map!(to!int).array;\n auto vis = new bool[50];\n foreach (x ; a) {\n vis[x - 1] = true;\n }\n bool good = false;\n foreach (n ; (a.length + 1).to!int .. 50 + 1) {\n if (trysolve(vis, n, s)) {\n good = true;\n break;\n }\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 foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n int m, s;\n readf!\" %d %d \"(m, s);\n auto a = readln.splitter.map!(to!int).array;\n auto vis = new bool[50];\n int mx = 0;\n foreach (x ; a) {\n vis[x - 1] = true;\n mx = max(mx, x);\n }\n long rs = 0;\n bool good = false;\n foreach (i ; 0 .. vis.length) {\n if (!vis[i])\n rs += i + 1;\n if (i + 1 >= mx && rs == s) {\n good = true;\n break;\n }\n }\n writeln(s == rs ? \"YES\" : \"NO\");\n }\n}\n"}], "src_uid": "447c17cba953d6e2da50c242ac431ab4"} {"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 + 100;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const X = readLong();\n const Y = readLong();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n A.sort;\n \n auto lpf = iota(LIM).array;\n foreach (p; 2 .. LIM) {\n if (lpf[p] == p) {\n for (int n = 2 * p; n < LIM; n += p) {\n chmin(lpf[n], p);\n }\n }\n }\n \n auto freq = new int[LIM];\n foreach (i; 0 .. N) {\n for (int a = A[i]; a > 1; ) {\n const p = lpf[a];\n ++freq[p];\n do {\n a /= p;\n } while (a % p == 0);\n }\n }\n \n long ans = N * X;\n foreach (p; 2 .. LIM) {\n if (ans > (N - freq[p]) * min(X, Y)) {\n long cost;\n foreach (i; 0 .. N) {\n const r = A[i] % p;\n if (r != 0) {\n cost += min(X, Y * (p - r));\n if (ans < cost) {\n break;\n }\n }\n }\n chmin(ans, cost);\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.file;\nimport std.algorithm; \nimport std.typecons;\nimport std.math;\nimport std.random;\nimport std.container.rbtree;\nimport std.string;\nimport std.conv;\nimport std.bigint;\n\nconst int N = 1000001;\n\nvoid main()\n{\n\tint n;\n\tlong x, y;\n\tscanf(\"%d\", &n);\n\tscanf(\"%lld\", &x);\n\tscanf(\"%lld\", &y);\n\n\tint[] list = new int[n];\n\n\tforeach(i; 0..n)\n\t\tscanf(\"%d\", &list[i]);\n\n\tbool[] pr = new bool[N];\n\n\tlist.sort();\n\n\tforeach(i; 2..N - 1) \n\t\tpr[i] = true;\n\n\tfor (int i = 2; i * i < N; i++)\n\t\tif (pr[i])\n\t\t\tfor (int j = i * i; j < N; j += i)\n\t\t\t\tpr[j] = false;\n\n\tlong[] psum = new long[N];\n\tpsum[0] = list[0];\n\n\tforeach(i; 1..n)\n\t\tpsum[i] = list[i] + psum[i - 1];\n\n\tlong get(int l, int r)\n\t{\n\t\treturn psum[r] - (l > 0 ? psum[l - 1] : 0);\n\t}\n\n\tlong ans = x * n;\n\n\tfor (long d = 2; d < N; d++)\n\t\tif (pr[cast(int)d])\n\t\t{\n\t\t\tlong curr = 0;\n\n\t\t\tfor (int j = 0; j < n; )\n\t\t\t{\n\t\t\t\tlong k = list[j] / d - (list[j] % d == 0 ? 1 : 0);\n\n\t\t\t\tint L = j, R = n;\n\n\t\t\t\twhile (L < R - 1)\n\t\t\t\t{\n\t\t\t\t\tint M = (L + R) / 2;\n\t\t\t\t\tif (list[M] > k * d + d)\n\t\t\t\t\t\tR = M;\n\t\t\t\t\telse\n\t\t\t\t\t\tL = M;\n\t\t\t\t}\n\n\t\t\t\tR = L;\n\t\t\t\tint l = j, r = R, pos = -1;\n\t\t\t\twhile (l <= r)\n\t\t\t\t{\n\t\t\t\t\tint m = (l + r) / 2;\n\t\t\t\t\tif ((k * d + d - list[m]) * y <= x)\n\t\t\t\t\t\tr = m - 1;\n\t\t\t\t\telse\n\t\t\t\t\t\tpos = m, l = m + 1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tL = j;\n\t\t\t\tj = R + 1;\n\n\t\t\t\tif (pos != -1)\n\t\t\t\t\tcurr += x * (pos - L + 1) + y * ((k * d + d) * (R - pos) - get(pos + 1, R));\n\t\t\t\telse\n\t\t\t\t\tcurr += y * ((k * d + d) * (R - L + 1) - get(L, R));\n\t\t\t\tk++;\n\t\t\t}\n\n\t\t\tans = min(ans, curr);\n\t\t}\n\n\twriteln(ans);\n\n\t//stdin.readln();\n\t//stdin.readln();\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!long);\n auto N = s[0].to!int;\n auto X = s[1];\n auto Y = s[2];\n auto A = readln.split.map!(to!int).array;\n A.sort();\n \n const int MAX = 10^^6 + 1;\n const int border = ((X - 1) / Y).to!int;\n\n\n auto cnt = new long[](MAX * 2); \n auto cntsum = new long[](MAX * 2);\n \n foreach (i; 0..N)\n cnt[A[i]] += 1;\n foreach (i; 0..MAX*2-1)\n cnt[i + 1] += cnt[i];\n foreach (i; 0..MAX*2-1)\n cntsum[i + 1] += cntsum[i] + cnt[i + 1];\n\n\n long ans = 1L << 59;\n \n foreach (g; 2..MAX) {\n long tmp = 0;\n for (int l = 1; l < MAX; l += g) {\n int r = l + g - 1;\n int m = max(l, r - border);\n long y = Y * (cntsum[r - 1] - cntsum[m - 1] - cnt[m - 1] * (r - m));\n long x = X * (cnt[m - 1] - cnt[l - 1]);\n tmp += x + y;\n }\n ans = min(ans, tmp);\n }\n\n debug {\n cnt[0..20].writeln;\n cntsum[0..20].writeln;\n }\n \n ans.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;\n\n\nvoid main() {\n auto s = readln.split.map!(to!long);\n auto N = s[0].to!int;\n auto X = s[1];\n auto Y = s[2];\n auto A = readln.split.map!(to!long).array;\n\n const int MAX = 10^^6 + 1;\n auto table = new long[MAX];\n fill(table, true);\n table[0] = table[1] = false;\n long[] P;\n\n for (int i = 2; i * i < MAX; ++i) {\n if (table[i]) {\n P ~= i;\n for (int j = i + i; j * j < MAX; j += i) \n table[j] = false;\n }\n }\n\n\n long ans = 1L << 59;\n \n foreach (p; P) {\n long tmp = 0;\n foreach (a; A)\n tmp += min(X, (a % p) * Y);\n ans = min(ans, tmp);\n }\n\n long tmp = 0;\n long m = A.reduce!max;\n foreach (a; A)\n tmp += min(X, (m - a) * Y);\n ans = min(ans, tmp);\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;\n \n \nvoid main() {\n auto s = readln.split.map!(to!long);\n auto N = s[0].to!int;\n auto X = s[1];\n auto Y = s[2];\n auto A = readln.split.map!(to!int).array;\n A.sort();\n \n const int MAX = 10^^6 + 1;\n const int border = ((X - 1) / Y + 1).to!int;\n\n\n auto cnt = new long[](MAX * 2); \n auto cntsum = new long[](MAX * 2);\n \n foreach (i; 0..N)\n cnt[A[i]] += 1;\n foreach (i; 0..MAX*2-1)\n cnt[i + 1] += cnt[i];\n foreach (i; 0..MAX*2-1)\n cntsum[i + 1] += cntsum[i] + cnt[i + 1];\n\n\n long ans = 1L << 59;\n \n foreach (g; 2..MAX) {\n long tmp = 0;\n for (int l = 1; l < MAX; l += g) {\n int r = l + g - 1;\n int m = max(l, r - border);\n long y = Y * (cntsum[r - 1] - cntsum[m - 1] - cnt[m - 1] * (r - m));\n long x = X * (cnt[m - 1] - cnt[l - 1]);\n tmp += x + y;\n }\n ans = min(ans, tmp);\n }\n\n debug {\n cnt[0..20].writeln;\n cntsum[0..20].writeln;\n }\n \n ans.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;\n\n\nvoid main() {\n auto s = readln.split.map!(to!long);\n auto N = s[0].to!int;\n auto X = s[1];\n auto Y = s[2];\n auto A = readln.split.map!(to!long).array;\n\n if (A.map!(a => a == 1).all) {\n writeln(min(X, Y) * N);\n return;\n }\n\n const int MAX = 10^^6 + 1;\n auto table = new long[MAX];\n fill(table, true);\n table[0] = table[1] = false;\n long[] P;\n\n for (int i = 2; i * i < MAX; ++i) {\n if (table[i]) {\n P ~= i;\n for (int j = i + i; j * j < MAX; j += i) \n table[j] = false;\n }\n }\n\n\n long ans = 1L << 59;\n \n foreach (p; P) {\n long tmp = 0;\n foreach (a; A)\n tmp += min(X, (p - a % p) * Y);\n ans = min(ans, tmp);\n }\n\n long tmp = 0;\n long m = A.reduce!max;\n foreach (a; A)\n tmp += min(X, (m - a) * Y);\n ans = min(ans, tmp);\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;\n\n\nvoid main() {\n auto s = readln.split.map!(to!long);\n auto N = s[0].to!int;\n auto X = s[1];\n auto Y = s[2];\n auto A = readln.split.map!(to!long).array;\n\n if (A.map!(a => a == 1).all) {\n writeln(min(X, Y) * N);\n return;\n }\n\n const int MAX = 10^^6 + 1;\n auto table = new long[MAX];\n fill(table, true);\n table[0] = table[1] = false;\n long[] P;\n\n for (int i = 2; i * i < MAX; ++i) {\n if (table[i]) {\n P ~= i;\n for (int j = i + i; j * j < MAX; j += i) \n table[j] = false;\n }\n }\n\n\n long ans = 1L << 59;\n \n foreach (p; P) {\n long tmp = 0;\n foreach (a; A)\n tmp += min(X, (a % p == 0 ? 0 : p - a % p) * Y);\n ans = min(ans, tmp);\n }\n\n long tmp = 0;\n long m = A.reduce!max;\n foreach (a; A)\n tmp += min(X, (m - a) * Y);\n ans = min(ans, tmp);\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;\n\n\nvoid main() {\n auto s = readln.split.map!(to!long);\n auto N = s[0].to!int;\n auto X = s[1];\n auto Y = s[2];\n auto A = readln.split.map!(to!long).array;\n\n if (A.map!(a => a == 1).all) {\n writeln(min(X, Y) * N);\n return;\n }\n\n const int MAX = 10^^6 + 1;\n auto table = new long[MAX];\n fill(table, true);\n table[0] = table[1] = false;\n long[] P;\n\n for (int i = 2; i * i < MAX; ++i) {\n if (table[i]) {\n P ~= i;\n for (int j = i + i; j * j < MAX; j += i) \n table[j] = false;\n }\n }\n\n\n long ans = 1L << 59;\n \n foreach (p; P) {\n long tmp = 0;\n foreach (a; A)\n tmp += min(X, (a % p) * Y);\n ans = min(ans, tmp);\n }\n\n long tmp = 0;\n long m = A.reduce!max;\n foreach (a; A)\n tmp += min(X, (m - a) * Y);\n ans = min(ans, tmp);\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\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const X = readLong();\n const Y = readLong();\n auto A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n A.sort;\n \n const lim = A.maxElement + 1;\n auto lpf = iota(lim).array;\n foreach (p; 2 .. lim) {\n if (lpf[p] == p) {\n for (int n = 2 * p; n < lim; n += p) {\n chmin(lpf[n], p);\n }\n }\n }\n \n auto freq = new int[lim];\n foreach (i; 0 .. N) {\n for (int a = A[i]; a > 1; ) {\n const p = lpf[a];\n ++freq[p];\n do {\n a /= p;\n } while (a % p == 0);\n }\n }\n \n long ans = N * X;\n foreach (p; 2 .. lim) {\n if (ans > (N - freq[p]) * min(X, Y)) {\n long cost;\n foreach (i; 0 .. N) {\n const r = A[i] % p;\n if (r != 0) {\n cost += min(X, Y * (p - r));\n if (ans < cost) {\n break;\n }\n }\n }\n chmin(ans, cost);\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "41a1b33baa83aea57423b160247adcb6"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int steps = 4500;\n\nbool ask (long lo, long hi)\n{\n\twriteln (lo, \" \", hi);\n\tstdout.flush ();\n\tauto s = readln.strip;\n\treturn s == \"Yes\";\n}\n\nvoid main ()\n{\n\tlong n;\n\tint k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tlong lo = 1;\n\t\tlong hi = n;\n\t\tforeach (step; 0..steps)\n\t\t{\n\t\t\tif (hi - lo < 50)\n\t\t\t{\n\t\t\t\tlong me = uniform (lo, hi + 1);\n\t\t\t\tif (ask (me, me))\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong me = (lo + hi) >> 1;\n\t\t\t\tif (ask (lo, me))\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\tlo = max (1, lo - k);\n\t\t\thi = min (n, hi + k);\n\t\t}\n\t}\n}", "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int steps = 4500;\n\nbool ask (long lo, long hi)\n{\n\twriteln (lo, \" \", hi);\n\tstdout.flush ();\n\tauto s = readln.strip;\n\treturn s == \"Yes\";\n}\n\nvoid main ()\n{\n\tlong n;\n\tint k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\treadln;\n\t\tlong lo = 1;\n\t\tlong hi = n;\n\t\tforeach (step; 0..steps)\n\t\t{\n\t\t\tif (hi - lo < 50)\n\t\t\t{\n\t\t\t\tlong me = uniform (lo, hi + 1);\n\t\t\t\tif (ask (me, me))\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tlong me = (lo + hi) >> 1;\n\t\t\t\tif (ask (lo, me))\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\tlo = max (1, lo - k);\n\t\t\thi = min (n, hi + k);\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "c46d1a87c6a6540d573c0391e845e1db"} {"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 ans = new bool[](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto s1 = RD!string;\n\t\tauto s2 = RD!string;\n\t\tbool ok = true;\n\t\tchar last;\n\t\tsize_t pos;\n\t\tforeach (c; s2)\n\t\t{\n\t\t\tif (pos >= s1.length)\n\t\t\t{\n\t\t\t\tif (c == last) continue;\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\tif (c == s1[pos])\n\t\t\t{\n\t\t\t\t++pos;\n\t\t\t\tlast = c;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse if (c == last) continue;\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\tif (pos < s1.length) ok = false;\n\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.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main() {\n\treadln.strip.to!int.iota.each!(_ => {\n\t\tauto u = [readln.group, readln.group];\n\t\twriteln(u[0].count == u[1].count && zip(u[0], u[1])\n\t\t.all!\"a[0][0] == a[1][0] && a[0][1] <= a[1][1]\" ? \"YES\" : \"NO\");\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 tests;\n\treadf !(\" %s\") (tests);\n\treadln;\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip ~ '$';\n\t\tauto t = readln.strip ~ '$';\n\t\tint i = 0;\n\t\tint j = 0;\n\t\tfor ( ; i < s.length; i++)\n\t\t{\n\t\t\tif (s[i] == t[j])\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\twhile (i > 0 && s[i - 1] == t[j])\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\tif (s[i] == t[j])\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\twriteln ((i == s.length && j == t.length) ? \"YES\" : \"NO\");\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\nint[] va,vb;\nvoid rec(ref int[] a,ref string s){\n a=null;\n for(int i=0;i=a.length){\n rec(va,a);\n rec(vb,b);\n debug{\n writeln(va);\n writeln(vb);\n }\n if(va.length==vb.length){\n int j=0,k=0;\n for(int i=0;ivb[i]){\n r=false;\n break;\n }\n }\n }else r=false;\n }else r=false;\n if(r) writeln(\"YES\");\n else writeln(\"NO\");\n }\n}\n\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid main ()\n{\n\tforeach (test; 0..readln.strip.to !(int))\n\t{\n\t\tauto s = readln.strip.group.array;\n\t\tauto t = readln.strip.group.array;\n\t\twriteln (s.length == t.length && zip (s, t).all\n\t\t !(c => c[0][0] == c[1][0] && c[0][1] <= c[1][1]) ?\n\t\t \"YES\" : \"NO\");\n\t}\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\nint[] va,vb;\nvoid rec(ref int[] a,ref string s){\n a=null;\n for(int i=0;i=a.length){\n rec(va,a);\n rec(vb,b);\n if(va.length==vb.length){\n int j=0,k=0;\n for(int i=0;ivb[k]){\n r=false;\n break;\n }\n j+=va[i]-1;\n k+=vb[i]-1;\n }\n }else r=false;\n }else r=false;\n if(r) writeln(\"YES\");\n else writeln(\"NO\");\n }\n}\n\n"}], "src_uid": "6709c8078cd29e69cf1be285071b2527"} {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint max = 0;\n\tint carriage = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tint a, b;\n\t\tscanf(\"%d %d\", &a, &b);\n\t\tcarriage += (b - a);\n\t\tif (carriage > max) max = carriage;\n\t}\n\tprintf(\"%d\", max);\n return 0;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\n// -----------------------\n\nint[] scanLeft(int[][] arr, int[] acc = [0]){\n if(!arr.length) return acc;\n return scanLeft(arr[1..$], acc ~ (acc[$-1] - arr[0][0] + arr[0][1]));\n}\n\nvoid main(){\n auto n = readln.chomp.to!int;\n int[][] arr;\n foreach(i; 0..n){ arr ~= readln.chomp.split(\" \").map!(to!int).array; }\n scanLeft(arr).reduce!max.writeln;\n}"}, {"source_code": "import std.stdio;\n\nvoid main()\n{\n readln; //discard first line\n \n auto maxPassengers = -1;\n\n auto numPassengers = 0;\n \n uint numLeaved, numEntered;\n \n while(!stdin.eof)\n {\n readf(\"%s %s\\n\", &numLeaved, &numEntered);\n \n numPassengers += numEntered - numLeaved;\n \n if (numPassengers > maxPassengers) maxPassengers = numPassengers;\n }\n \n maxPassengers.writeln;\n}"}, {"source_code": "import std.stdio, std.algorithm;\n\nvoid main() {\n int n;\n readf(\"%d\\n\", &n);\n\n int result = 0;\n int inside = 0;\n for (int i = 0; i < n; ++i) {\n int a, b;\n readf(\"%d %d\\n\", &a, &b);\n\n inside -= a;\n inside += b;\n\n result = max(result, inside);\n }\n\n writefln(\"%d\", result);\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,a,b,v;\n scanf(\"%d\",&n);\n uint ans=0;\n while(n--){\n scanf(\"%d %d\",&a,&b);\n v+=b-a;\n ans=max(ans,v);\n }\n writeln(ans);\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\n\nvoid main() {\n readln;\n\n int ans = 0;\n int cap = 0;\n foreach (string s; stdin.lines) {\n auto pas = s.chomp.split.map!(to!int).array;\n cap -= pas[0];\n cap += pas[1];\n if (cap > ans) ans = cap;\n }\n \n ans.writeln;\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,a,b;\n scanf(\"%d\",&n);\n uint ans=0;\n while(n--){\n scanf(\"%d %d\",&a,&b);\n ans=max(ans,ans+b-a);\n }\n writeln(ans);\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\n\nvoid main() {\n readln;\n\n int ans = 0;\n int cap = 0;\n foreach (string s; stdin.lines) {\n auto pas = s.chomp.split.map!(to!int).array;\n pas.writeln;\n cap -= pas[0];\n cap += pas[1];\n cap.writeln;\n if (cap > ans) ans = cap;\n }\n \n ans.writeln;\n}\n"}], "src_uid": "74b90fe9458b147568ac9bd09f219aab"} {"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\nlong fun (long [] b)\n{\n\tauto n = b.length;\n\tlong lo = 0;\n\tlong res = long.min / 2;\n\tlong cur = 0;\n\tforeach (i; 0..n)\n\t{\n\t\tcur += b[i] * ((i & 1) ? -1 : +1);\n\t\tdebug {write (cur, \" \");}\n\t\tif (i & 1)\n\t\t{\n\t\t\tlo = min (lo, cur);\n\t\t}\n\t\tres = max (res, cur - lo);\n\t}\n\tdebug {writeln ();}\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 a = readln.split.map !(to !(long)).array;\n\t\tauto b = new long [n - 1];\n\t\tforeach (i; 1..n)\n\t\t{\n\t\t\tb[i - 1] = abs (a[i] - a[i - 1]);\n\t\t}\n\t\twriteln (max (fun (b), fun (b[1..$])));\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.stdio;\nimport std.datetime;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n auto B = new long[](N-1);\n foreach (i; 0..N-1) {\n B[i] = abs(A[i] - A[i+1]);\n }\n\n\n long ans = B[0];\n long tmp = B[0];\n foreach (i; 1..N-1) {\n tmp += (i % 2 == 0) ? B[i] : -B[i];\n ans = max(ans, tmp);\n if (tmp < 0) tmp = 0;\n }\n\n if (N <= 2) {\n ans.writeln;\n return;\n }\n\n\n ans = max(ans, B[1]);\n tmp = B[1];\n foreach (i; 2..N-1) {\n tmp += (i % 2 == 1) ? B[i] : -B[i];\n ans = max(ans, tmp);\n if (tmp < 0) tmp = 0;\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;\nimport std.datetime;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n auto B = new long[](N-1);\n foreach (i; 0..N-1) {\n B[i] = abs(A[i] - A[i+1]);\n }\n\n\n long ans = B[0];\n long tmp = B[0];\n foreach (i; 1..N-1) {\n tmp += (i % 2 == 0) ? B[i] : -B[i];\n ans = max(ans, tmp);\n if (ans < 0) tmp = 0;\n }\n\n if (N <= 2) {\n ans.writeln;\n return;\n }\n\n\n ans = max(ans, B[1]);\n tmp = B[1];\n foreach (i; 2..N-1) {\n tmp += (i % 2 == 1) ? B[i] : -B[i];\n ans = max(ans, tmp);\n if (ans < 0) tmp = 0;\n }\n\n ans.writeln;\n}\n"}], "src_uid": "7ff7f47cee182d2542754e412f6aab1a"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nint value (string s)\n{\n\tint cur = 0;\n\tint low = 0;\n\tforeach (const ref char c; s)\n\t{\n\t\tif (c == '(')\n\t\t{\n\t\t\tcur += 1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcur -= 1;\n\t\t}\n\t\tlow = min (low, cur);\n\t}\n\tif (low < 0 && low < cur)\n\t{\n\t\treturn int.min / 4;\n\t}\n\treturn cur;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint [] v;\n\t\treadln;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto s = readln.strip;\n\t\t\tv ~= value (s);\n\t\t}\n\t\tsort (v);\n\n\t\tint res = 0;\n\t\twhile (v.length >= 2)\n\t\t{\n\t\t\tauto x = v.front;\n\t\t\tauto y = v.back;\n\t\t\tif (x + y < 0)\n\t\t\t{\n\t\t\t\tv.popFront ();\n\t\t\t}\n\t\t\telse if (x + y > 0)\n\t\t\t{\n\t\t\t\tv.popBack ();\n\t\t\t}\n\t\t\telse if (x + y == 0)\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t\tv.popFront ();\n\t\t\t\tv.popBack ();\n\t\t\t}\n\t\t}\n\t\twriteln (res);\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\n\nvoid main() {\n int n;\n scan(n);\n\n auto b = iota(n).map!(i => readln.chomp).array;\n\n int checkLeft(string s) {\n int h;\n\n foreach (ch ; s) {\n if (ch == '(') {\n h++;\n }\n else {\n h--;\n\n if (h < 0) {\n return -1;\n }\n }\n }\n\n return h;\n }\n\n int checkRight(string s) {\n int h;\n\n foreach_reverse (ch ; s) {\n if (ch == ')') {\n h++;\n }\n else {\n h--;\n\n if (h < 0) {\n return -1;\n }\n }\n }\n\n return h;\n }\n\n auto cnt = new int[](5 * 10^^5 + 1);\n int perfect;\n\n foreach (s ; b) {\n int h = checkLeft(s);\n if (h > 0) {\n cnt[h]++;\n }\n if (h == 0) {\n perfect++;\n }\n }\n\n int ans;\n\n foreach (s ; b) {\n int h = checkRight(s);\n if (h > 0 && cnt[h] > 0) {\n ans++;\n cnt[h]--;\n }\n }\n\n ans += perfect / 2;\n \n writeln(ans);\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\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": "2cfb08b2269dbf5417c1758def4c035f"} {"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\nint Ask(int u, int v) {\n writefln(\"? %s %s\", u + 1, v + 1);\n stdout.flush;\n const res = readInt();\n if (res == -1) {\n import core.stdc.stdlib;\n exit(0);\n }\n return res - 1;\n}\nvoid Answer(int r) {\n writefln(\"! %s\", r + 1);\n stdout.flush;\n import core.stdc.stdlib;\n exit(0);\n}\n\nint[][] G;\nint[] sz;\n\nvoid dfs(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 dfs(v, u);\n sz[u] += sz[v];\n }\n }\n}\n\nvoid main() {\n N = 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 sz = new int[N];\n dfs(0, -1);\n \n int r;\n for (int u = 0; ; ) {\n int vm = -1;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (vm == -1 || sz[vm] < sz[v]) {\n vm = v;\n }\n }\n if (vm == -1 || sz[u] >= 2 * sz[vm]) {\n r = u;\n break;\n } else {\n sz[u] -= sz[vm];\n sz[vm] += sz[u];\n u = vm;\n }\n }\n debug {\n writeln(\"r = \", r);\n writeln(\"sz = \", sz);\n }\n \n for (int u = r, p = -1; ; ) {\n int[] vs;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n vs ~= v;\n }\n }\n vs.sort!((v, w) => (sz[v] > sz[w]));\n const vsLen = cast(int)(vs.length);\n int vm = -1;\n foreach (j; 0 .. vsLen / 2) {\n const res = Ask(vs[j * 2], vs[j * 2 + 1]);\n if (res != u) {\n vm = res;\n goto found;\n }\n }\n if (vsLen % 2 != 0) {\n const res = Ask(vs[vsLen - 1], u);\n if (res != u) {\n vm = res;\n goto found;\n }\n }\n Answer(u);\n found:{}\n p = u;\n u = vm;\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\tauto a = new bool [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] = true;\n\t\t\ta[v][u] = true;\n\t\t}\n\t\tauto b = new int [n];\n\t\tb[] = 1;\n\t\tint res = -1;\n\t\twhile (sum (b) > 1)\n\t\t{\n\t\t\tint v = 0;\n\t\t\twhile (!b[v] || a[v].length != 1)\n\t\t\t{\n\t\t\t\tv += 1;\n\t\t\t}\n\t\t\tint u = v + 1;\n\t\t\twhile (!b[u] || a[u].length != 1)\n\t\t\t{\n\t\t\t\tu += 1;\n\t\t\t}\n\t\t\twritefln !(\"? %s %s\") (u + 1, v + 1);\n\t\t\tstdout.flush ();\n\n\t\t\tint w;\n\t\t\treadf !(\" %s\") (w);\n\t\t\tw -= 1;\n\t\t\tif (w == u)\n\t\t\t{\n\t\t\t\tres = u;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (w == v)\n\t\t\t{\n\t\t\t\tres = v;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tb[u] = 0;\n\t\t\tforeach (x, _; a[u])\n\t\t\t{\n\t\t\t\ta[x].remove (u);\n\t\t\t}\n\t\t\tb[v] = 0;\n\t\t\tforeach (x, _; a[v])\n\t\t\t{\n\t\t\t\ta[x].remove (v);\n\t\t\t}\n\t\t}\n\n\t\tif (res == -1)\n\t\t{\n\t\t\tres = 0;\n\t\t\twhile (!b[res])\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"! %s\") (res + 1);\n\t\tstdout.flush ();\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.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 int n;\n Mt19937 rnd;\n readf (\" %d\", &n);\n auto e = new int[][n];\n foreach (k; 1 .. n) {\n int i, j;\n readf (\" %d %d\", &i, &j);\n --i; --j;\n e[i] ~= j;\n e[j] ~= i;\n }\n auto b = new bool[n];\n auto u = new int[n];\n auto v = new int[n];\n auto h = new int[n];\n auto parent = new int[n];\n int tm;\n bool child (int c, int p) {\n if (c == p) return true;\n return u[p] < u[c] && v[c] < v[p];\n }\n void go (int i, int ht) {\n u[i] = ++tm;\n h[i] = ht;\n foreach (j; e[i]) {\n if (parent[j] == -2 && !b[j]) {\n parent[j] = i;\n go (j, ht + 1);\n }\n }\n v[i] = ++tm;\n }\n int fv (const int s) {\n parent[] = -2;\n h[] = -1;\n parent[s] = -1;\n go (s, 0);\n int best = s;\n foreach (i; 0 .. n) if (h[best] < h[i]) best = i;\n return best;\n }\n while (true) {\n int i, j;\n int[] l;\n foreach (o; 0 .. n) if (!b[o]) l ~= o;\n debug stderr.writeln (l);\n int t = l.length.to!int;\n if (t == 1) {\n writeln (\"! \", l.front + 1);\n return;\n }\n const int s = l[uniform (0, t)];\n i = fv (s);\n j = fv (i);\n /* \n i = uniform (1, t);\n j = uniform (0, i);\n i = l[i];\n j = l[j];\n */\n writeln (\"? \", i + 1, ' ', j + 1);\n stdout.flush ();\n int p;\n readf (\" %d\", &p);\n --p;\n parent[] = -2;\n parent[p] = -1;\n debug stderr.writeln (\"u = \", u);\n debug stderr.writeln (\"v = \", v);\n tm = 0;\n go (p, 0);\n foreach (x; l) {\n if (x == p) continue;\n if (i != p && (child (x, i) || child (i, x))) b[x] = true;\n if (j != p && (child (x, j) || child (j, x))) b[x] = true;\n }\n parent[] = -2;\n parent[p] = -1;\n tm = 0;\n go (p, 0);\n b[] = true;\n b[p] = false;\n foreach (o; 0 .. n) if (parent[o] >= 0) b[o] = false;\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\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tauto a = new bool [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] = true;\n\t\t\ta[v][u] = true;\n\t\t}\n\t\tauto b = new int [n];\n\t\tb[] = 1;\n\t\tint res = -1;\n\t\twhile (sum (b) > 1)\n\t\t{\n\t\t\twriteln (a);\n\t\t\tint v = 0;\n\t\t\twhile (!b[v] || a[v].length != 1)\n\t\t\t{\n\t\t\t\tv += 1;\n\t\t\t}\n\t\t\tint u = v + 1;\n\t\t\twhile (!b[u] || a[u].length != 1)\n\t\t\t{\n\t\t\t\tu += 1;\n\t\t\t}\n\t\t\twritefln !(\"? %s %s\") (u + 1, v + 1);\n\t\t\tstdout.flush ();\n\n\t\t\tint w;\n\t\t\treadf !(\" %s\") (w);\n\t\t\tw -= 1;\n\t\t\tif (w == u)\n\t\t\t{\n\t\t\t\tres = u;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (w == v)\n\t\t\t{\n\t\t\t\tres = v;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tb[u] = 0;\n\t\t\tforeach (x, _; a[u])\n\t\t\t{\n\t\t\t\ta[x].remove (u);\n\t\t\t}\n\t\t\tb[v] = 0;\n\t\t\tforeach (x, _; a[v])\n\t\t\t{\n\t\t\t\ta[x].remove (v);\n\t\t\t}\n\t\t}\n\n\t\tif (res == -1)\n\t\t{\n\t\t\tres = 0;\n\t\t\twhile (!b[res])\n\t\t\t{\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t}\n\t\twritefln !(\"! %s\") (res + 1);\n\t\tstdout.flush ();\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.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 int n;\n Mt19937 rnd;\n readf (\" %d\", &n);\n auto e = new int[][n];\n foreach (k; 1 .. n) {\n int i, j;\n readf (\" %d %d\", &i, &j);\n --i; --j;\n e[i] ~= j;\n e[j] ~= i;\n }\n auto b = new bool[n];\n auto u = new int[n];\n auto v = new int[n];\n auto parent = new int[n];\n int tm;\n bool child (int c, int p) {\n if (c == p) return true;\n return u[p] < u[c] && v[c] < v[p];\n }\n void go (int i) {\n u[i] = ++tm;\n foreach (j; e[i]) {\n if (parent[j] == -2 && !b[j]) {\n parent[j] = i;\n go (j);\n }\n }\n v[i] = ++tm;\n }\n while (true) {\n int i, j;\n int[] l;\n foreach (o; 0 .. n) if (!b[o]) l ~= o;\n debug stderr.writeln (l);\n int t = l.length.to!int;\n if (t == 1) {\n writeln (\"! \", l.front + 1);\n return;\n }\n i = uniform (1, t);\n j = uniform (0, i);\n i = l[i];\n j = l[j];\n writeln (\"? \", i + 1, ' ', j + 1);\n stdout.flush ();\n int p;\n readf (\" %d\", &p);\n --p;\n parent[] = -2;\n parent[p] = -1;\n debug stderr.writeln (\"u = \", u);\n debug stderr.writeln (\"v = \", v);\n tm = 0;\n go (p);\n foreach (x; l) {\n if (x == p) continue;\n if (i != p && (child (x, i) || child (i, x))) b[x] = true;\n if (j != p && (child (x, j) || child (j, x))) b[x] = true;\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;\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 int n;\n Mt19937 rnd;\n readf (\" %d\", &n);\n auto e = new int[][n];\n foreach (k; 1 .. n) {\n int i, j;\n readf (\" %d %d\", &i, &j);\n --i; --j;\n e[i] ~= j;\n e[j] ~= i;\n }\n auto b = new bool[n];\n auto u = new int[n];\n auto v = new int[n];\n auto parent = new int[n];\n int tm;\n bool child (int c, int p) {\n if (c == p) return true;\n return u[p] < u[c] && v[c] < v[p];\n }\n void go (int i) {\n u[i] = ++tm;\n foreach (j; e[i]) {\n if (parent[j] == -2 && !b[j]) {\n parent[j] = i;\n go (j);\n }\n }\n v[i] = ++tm;\n }\n while (true) {\n int i, j;\n int[] l;\n foreach (o; 0 .. n) if (!b[o]) l ~= o;\n debug stderr.writeln (l);\n int t = l.length.to!int;\n if (t == 1) {\n writeln (\"! \", l.front + 1);\n return;\n }\n i = uniform (1, t);\n j = uniform (0, i);\n i = l[i];\n j = l[j];\n writeln (\"? \", i + 1, ' ', j + 1);\n stdout.flush ();\n int p;\n readf (\" %d\", &p);\n --p;\n parent[] = -2;\n parent[p] = -1;\n debug stderr.writeln (\"u = \", u);\n debug stderr.writeln (\"v = \", v);\n tm = 0;\n go (p);\n foreach (x; l) {\n if (x == p) continue;\n if (i != p && (child (x, i) || child (i, x))) b[x] = true;\n if (j != p && (child (x, j) || child (j, x))) b[x] = true;\n }\n parent[] = -2;\n parent[p] = -1;\n tm = 0;\n go (p);\n b[] = true;\n b[p] = false;\n foreach (o; 0 .. n) if (parent[o] >= 0) b[o] = false;\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\nint N;\nint[] X, Y;\n\nint Ask(int u, int v) {\n writefln(\"? %s %s\", u + 1, v + 1);\n stdout.flush;\n const res = readInt();\n if (res == -1) {\n import core.stdc.stdlib;\n exit(0);\n }\n return res - 1;\n}\nvoid Answer(int r) {\n writefln(\"! %s\", r + 1);\n stdout.flush;\n import core.stdc.stdlib;\n exit(0);\n}\n\nvoid main() {\n N = readInt();\n X = new int[N - 1];\n Y = new int[N - 1];\n foreach (i; 0 .. N - 1) {\n X[i] = readInt() - 1;\n Y[i] = readInt() - 1;\n }\n \n auto G = new int[][N];\n foreach (i; 0 .. N - 1) {\n G[X[i]] ~= i;\n G[Y[i]] ~= i;\n }\n for (int u = 0, p = -1; ; ) {\n int[] vs;\n foreach (i; G[u]) {\n const v = X[i] ^ Y[i] ^ u;\n if (v != p) {\n vs ~= v;\n }\n }\n const vsLen = cast(int)(vs.length);\n int vm = -1;\n foreach (j; 0 .. vsLen / 2) {\n const res = Ask(vs[j * 2], vs[j * 2 + 1]);\n if (res != u) {\n vm = res;\n }\n }\n if (vsLen % 2 != 0) {\n const res = Ask(vs[vsLen - 1], u);\n if (res != u) {\n vm = res;\n }\n }\n if (vm == -1) {\n Answer(u);\n }\n p = u;\n u = vm;\n }\n}\n"}], "src_uid": "a291ee66980d8b5856b24d1541e66fd0"} {"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 string s = readln.chomp;\n assert(s.length == 6);\n\n if (\n s.find('r').find('R').empty() == false &&\n s.find('g').find('G').empty() == false &&\n s.find('b').find('B').empty() == false\n )\n writeln(\"YES\");\n else\n writeln(\"NO\");\n }\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 const ub = 'a' - 'A';\r\n return YESNO[\"RGB\".all!(c => S.countUntil(c) > S.countUntil(c + ub))];\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>>\".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": "60eb29b2dfb4d6b136c58b33dbd2558e"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 n = RD!int;\n\tauto rbt = new RedBlackTree!(int[], \"a[0] > b[0]\", true);\n\trbt.insert([0, 0, 1, 1, 0]);\n\tforeach (i; 0..n)\n\t{\n\t\tauto t = RD!int;\n\t\tauto x = RD!int;\n\t\tauto y = RD!int;\n\t\t\n\t\tforeach (e; rbt[])\n\t\t{\n\t\t\tauto dist = abs(e[2]-x) + abs(e[3]-y);\n\t\t\tauto dt = t - e[1];\n\t\t\t//debug writeln(\"dist:\", dist, \" dt:\", dt);\n\t\t\tif (dist <= dt)\n\t\t\t{\n\t\t\t\trbt.insert([e[0]+1, t, x, y, i+1]);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tdebug writeln(rbt);\n\n\tauto ans = rbt.front;\n\twriteln(ans[0]);\n\tstdout.flush;\n\tdebug readln;\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n// NEVER USE INBUILT MAX IN DLANG ~ 0.2 sec delay\n\nvoid play(){\n int n, r;\n r = rd!int;\n n = rd!int;\n auto dp = new ll[](n+1);\n auto maxable = new ll[](n+1);\n tup[] flash;\n flash ~= tup(0, 1, 1);\n foreach(i; 0..n){\n flash ~= tup(rd, rd, rd);\n }\n ll maxold = 0, maxel = 0;\n foreach(i;0..n+1){\n // Dist > 499*2\n maxold = max(maxold, maxable[i]);\n\n // Add if not present\n dp[i] = max(maxold, dp[i]);\n\n ll xmax = max(flash[i][1], r - flash[i][1]);\n ll ymax = max(flash[i][2], r - flash[i][2]);\n\n // Reachable by 1, 1, 0 only!\n if(i > 0 && !dp[i]){ continue; }\n\n foreach(j; i+1..n+1){\n // Above 1000 set max at that position\n if(flash[j][0] >= flash[i][0] + xmax + ymax){\n maxable[j] = max(maxable[j], dp[i] + 1);\n break;\n }\n ll dt = flash[j][0] - flash[i][0];\n ll dist = abs(flash[j][1] - flash[i][1]) + abs(flash[j][2] - flash[i][2]);\n if(dist <= dt){\n dp[j] = max(dp[j], dp[i] + 1);\n }\n }\n maxel = max(dp[i], maxel);\n }\n show(dp);\n writeln(maxel);\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)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\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.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 r, n;\n\twhile (readf !(\" %s %s\") (r, n) > 0)\n\t{\n\t\talias Record = Tuple !(int, q{t}, int, q{x}, int, q{y});\n\t\tauto z = new Record [n + 1];\n\t\tz[0] = Record (0, 1, 1);\n\t\tforeach (ref c; z[1..$])\n\t\t{\n\t\t\treadf !(\" %s %s %s\") (c.t, c.x, c.y);\n\t\t}\n\t\tauto f = new int [n + 1];\n\t\tf[1..$] = int.min;\n\t\tauto g = new int [n + 1];\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tfor (auto j = i - 1; j >= 0; j--)\n\t\t\t{\n\t\t\t\tauto d = abs (z[i].x - z[j].x) +\n\t\t\t\t abs (z[i].y - z[j].y);\n\t\t\t\tif (d <= z[i].t - z[j].t)\n\t\t\t\t{\n\t\t\t\t\tf[i] = max (f[i], f[j] + 1);\n\t\t\t\t}\n\t\t\t\tif (z[i].t - z[j].t > (r - 1) * 2)\n\t\t\t\t{\n\t\t\t\t\tf[i] = max (f[i], g[j] + 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tg[i] = max (g[i - 1], f[i]);\n\t\t}\n\t\twriteln (f.maxElement);\n\t}\n}\n"}], "negative_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\n// NEVER USE INBUILT MAX IN DLANG ~ 0.2 sec delay\n\nvoid play(){\n int n, r;\n r = rd!int;\n n = rd!int;\n auto dp = new ll[](n+1);\n auto maxable = new ll[](n+1);\n tup[] flash;\n flash ~= tup(1, 1, 0);\n foreach(i; 0..n){\n flash ~= tup(rd, rd, rd);\n }\n ll maxold = 0, maxel;\n foreach(i;0..n+1){\n // Dist > 499*2\n maxold = max(maxold, maxable[i]);\n\n // Add if not present\n dp[i] = max(maxold, dp[i]);\n\n ll xmax = max(flash[i][1], r - flash[i][1]);\n ll ymax = max(flash[i][2], r - flash[i][2]);\n\n // Reachable by 1, 1, 0 only!\n if(i > 0 && !dp[i]){ continue; }\n\n foreach(j; i+1..n+1){\n // Above 1000 set max at that position\n if(flash[j][0] >= flash[i][0] + xmax + ymax){\n maxable[j] = max(maxable[j], dp[i] + 1);\n break;\n }\n ll dt = flash[j][0] - flash[i][0];\n ll dist = abs(flash[j][1] - flash[i][1]) + abs(flash[j][2] - flash[i][2]);\n if(dist <= dt){\n dp[j] = max(dp[j], dp[i] + 1);\n }\n }\n maxel = max(dp[i], maxel);\n }\n writeln(maxel);\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)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\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": "// Cheese-Cracker: cheese-cracker.github.io\n\nbool check_dist(tup p1, tup p2){\n ll dt = abs(p2[0] - p1[0]);\n return (dt >= abs(p1[1] - p2[1]) + abs(p1[2] - p2[2]));\n}\n\nvoid play(){\n int n, r;\n r = rd!int;\n n = rd!int;\n auto dp = new ll[](n+1);\n dp[] = 0;\n tup[] flash;\n ll ti, xi, yi;\n flash ~= tup(0, 1, 1);\n foreach(i; 0..n){\n flash ~= tup(rd, rd, rd);\n }\n\n ll maxold = 0;\n ll[long] maxable;\n foreach(i;0..n+1){\n int crange = flash[i][0].to!int/1000;\n\n // Reachable by 1, 1, 0 only!\n if(i > 0 && crange == 0 && !dp[i]){ continue; }\n\n maxold += maxold + maxable.get(i, 0);\n // Add if not present\n if(crange > 0 && dp[i] < maxold){\n dp[i] = maxold;\n }\n\n foreach(j; i+1..n+1){\n // Above 1000 set max at that position\n if(flash[j][0] > flash[i][0] + 1000){\n maxable[j] = max(maxable.get(j, 0), dp[i] + 1);\n break;\n }\n if(check_dist(flash[j], flash[i])){\n dp[j] = max(dp[j], dp[i] + 1);\n }\n }\n }\n show(dp);\n writeln(maxElement(dp));\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"}, {"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 r, n;\n\twhile (readf !(\" %s %s\") (r, n) > 0)\n\t{\n\t\talias Record = Tuple !(int, q{t}, int, q{x}, int, q{y});\n\t\tauto z = new Record [n + 1];\n\t\tz[0] = Record (0, 1, 1);\n\t\tforeach (ref c; z[1..$])\n\t\t{\n\t\t\treadf !(\" %s %s %s\") (c.t, c.x, c.y);\n\t\t}\n\t\tauto f = new int [n + 1];\n\t\tf[1..$] = int.min;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tfor (auto j = i - 1; j >= 0; j--)\n\t\t\t{\n\t\t\t\tauto d = abs (z[i].x - z[j].x) +\n\t\t\t\t abs (z[i].y - z[j].y);\n\t\t\t\tif (d <= z[i].t - z[j].t)\n\t\t\t\t{\n\t\t\t\t\tf[i] = max (f[i], f[j] + 1);\n\t\t\t\t}\n\t\t\t\tif (z[i].t - z[j].t > (r - 1) * 2)\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 (f.maxElement);\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\nvoid main ()\n{\n\tint r, n;\n\twhile (readf !(\" %s %s\") (r, n) > 0)\n\t{\n\t\talias Record = Tuple !(int, q{t}, int, q{x}, int, q{y});\n\t\tauto z = new Record [n + 1];\n\t\tz[0] = Record (0, 1, 1);\n\t\tforeach (ref c; z[1..$])\n\t\t{\n\t\t\treadf !(\" %s %s %s\") (c.t, c.x, c.y);\n\t\t}\n\t\tauto f = new int [n + 1];\n\t\tf[1..$] = int.min;\n\t\tauto g = new int [n + 1];\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tfor (auto j = i - 1; j >= 0; j--)\n\t\t\t{\n\t\t\t\tauto d = abs (z[i].x - z[j].x) +\n\t\t\t\t abs (z[i].y - z[j].y);\n\t\t\t\tif (d <= z[i].t - z[j].t)\n\t\t\t\t{\n\t\t\t\t\tf[i] = max (f[i], f[j] + 1);\n\t\t\t\t}\n\t\t\t\tif (z[i].t - z[j].t > (r - 1) * 2)\n\t\t\t\t{\n\t\t\t\t\tf[i] = max (f[i], g[j]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tg[i] = max (g[i - 1], f[i]);\n\t\t}\n\t\twriteln (f.maxElement);\n\t}\n}\n"}], "src_uid": "1392daad6638b7a93e84dd474cdf916a"} {"source_code": "import std.stdio;\nimport std.exception;\nimport std.algorithm;\nimport std.range;\n\nvoid main() { while (solve()) {} }\n\nbool solve() {\n\tint n;\n\tif (!readf(\" %s\", &n)) return false;\n\tauto a = new long[n];\n\tlong prev = 0;\n\tforeach (ref x; a) {\n\t\tenforce(readf(\" %s\", &x));\n\t\tx += prev;\n\t\tprev = x;\n\t}\n\tint m;\n\tenforce(readf(\" %s\", &m));\n\tforeach (_; 0..m) {\n\t\tlong x;\n\t\tenforce(readf(\" %s\", &x));\n\t\tauto ans = a.assumeSorted.lowerBound(x).length + 1;\n\t\twriteln(ans);\n\t}\n\treturn true;\n}\n", "positive_code": [{"source_code": "// https://codeforces.com/problemset/problem/474/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[] a = readln.split.map!(x => x.to!int).array;\n int m = readln.chomp.to!int;\n int[] q = readln.split.map!(x => x.to!int).array;\n\n int[] worms;\n worms ~= a[0];\n\n // cumulative sum\n for(int i = 1; i < n; i++)\n worms ~= worms[i-1] + a[i];\n\n\n foreach(query; q) {\n int right = n-1;\n int left = 0;\n int middle;\n while(left <= right) {\n middle = (right+left)/2;\n if(worms[middle] >= query) {\n right = middle-1;\n } else {\n left = middle+1;\n }\n }\n left++;\n left.writeln;\n }\n}\n\n"}, {"source_code": "import std.stdio, std.range, std.conv, std.algorithm, std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] a = [0] ~ readln.chomp.split.map!(to!int).array;\n int m = readln.chomp.to!int;\n auto q = readln.chomp.split.map!(to!int);\n\n foreach (i; 1..a.length) {\n a[i] += a[i - 1];\n }\n\n auto r = assumeSorted(a);\n foreach (e; q) {\n r.lowerBound(e).length.writeln;\n }\n}"}], "negative_code": [], "src_uid": "10f4fc5cc2fcec02ebfb7f34d83debac"} {"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///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\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///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, a, b;\n\tread(n, a, b);\n\tauto s = readln.strip.split('*');\n\tint ans;\n\tforeach (x; s)\n\t{\n\t\tif (a > b)\n\t\t\tswap(a, b);\n\t\tif (x.length & 1)\n\t\t{\n\t\t\tint m = min(x.length / 2, a);\n\t\t\tans += m;\n\t\t\ta -= m;\n\t\t\tans += min(b, x.length / 2 + 1);\n\t\t\tb -= min(b, x.length / 2 + 1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint m = min(x.length / 2, a);\n\t\t\tans += m;\n\t\t\ta -= m;\n\t\t\tans += min(b, x.length / 2);\n\t\t\tb -= min(b, x.length / 2);\n\t\t}\n\t}\n\twriteln(ans);\n}\n", "positive_code": [{"source_code": "import std.algorithm.comparison : min;\nimport std.algorithm.iteration;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n int a, b, n, m; // total seats, num type a, num type b\n readf!\"%d %d %d\\n\"(n, a, b);\n \n auto l = readln\n .stripRight\n .group\n .filter!(a => a[0] == '.')\n .map!\"a[1]\"\n .array\n .sort!\"a > b\";\n\n // answer\n auto s = 0;\n\n foreach (g; l) {\n auto x = min(g / 2 + (a > b ? (g % 2) : 0), a);\n auto y = min(g / 2 + (a > b ? 0 : (g % 2)), b);\n\n s += x + y;\n a -= x;\n b -= y;\n }\n\n writeln(s);\n}\n"}], "negative_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///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\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///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, a, b;\n\tread(n, a, b);\n\tauto s = readln.strip.split('*');\n\tint ans;\n\tforeach (x; s)\n\t{\n\t\tif (a > b)\n\t\t\tswap(a, b);\n\t\tif (x.length & 1)\n\t\t{\n\n\t\t\tint m = min(x.length / 2, a);\n\t\t\tans += m;\n\t\t\ta -= m;\n\t\t\tans += min(b, m + 1);\n\t\t\tb -= min(b, m + 1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint m = min(x.length / 2, a);\n\t\t\tans += m;\n\t\t\ta -= m;\n\t\t\tans += min(b, m);\n\t\t\tb -= min(b, m);\n\t\t}\n\t}\n\twriteln(ans);\n}\n"}], "src_uid": "6208dbdf9567b759b0026db4af4545a9"} {"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;\n\tauto m = RD;\n\tauto q = RD!int;\n\tauto g = gcd(n, m);\n\tauto l1 = n / g;\n\tauto l2 = m / g;\n\tauto ans = new bool[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto sx = RD;\n\t\tauto sy = RD-1;\n\t\tauto ex = RD;\n\t\tauto ey = RD-1;\n\t\tlong pos1, pos2;\n\t\tif (sx == 1)\n\t\t\tpos1 = sy / l1;\n\t\telse\n\t\t\tpos1 = sy / l2;\n\t\tif (ex == 1)\n\t\t\tpos2 = ey / l1;\n\t\telse\n\t\t\tpos2 = ey / l2;\n\t\tans[i] = pos1 == pos2;\n\t}\n\t\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush();\n\tdebug readln();\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 long n, m, q;\n readf(\"%s %s %s\", &n, &m, &q);\n readln;\n\n auto g = gcd(n, m);\n \n debug { g.writeln; }\n \n n /= g;\n m /= g;\n \n while (q--) {\n int s1, e1;\n long s2, e2;\n readf(\"%s %s %s %s\", &s1, &s2, &e1, &e2);\n readln;\n \n long normalize(int p, long x) {\n if (p == 1) { return (x-1) / n; }\n else { return (x-1) / m; }\n }\n \n s2 = normalize(s1, s2);\n e2 = normalize(e1, e2);\n \n writeln(s2 == e2 ? \"YES\" : \"NO\");\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\tlong n = read.to!long;\n\tlong m = read.to!long;\n\tint q = read.to!int;\n\t\n\tlong g = gcd(n, m);\n\tlong a = n / g;\n\tlong b = m / g;\n\tlog(\"g:\", g, \"a:\", a, \"b:\", b);\n\t\n\tforeach(_; 0 .. q){\n\t\tint sx = read.to!int;\n\t\tlong sy = read.to!long - 1;\n\t\tint ex = read.to!int;\n\t\tlong ey = read.to!long - 1;\n\t\tlog(\"sx:\", sx, \"sy:\", sy, \"ex:\", ex, \"ey:\", ey);\n\t\t\n\t\tlong s = sy / (sx == 1? a: b);\n\t\tlong e = ey / (ex == 1? a: b);\n\t\tlog(\"s:\", s, \"e:\", e);\n\t\t\n\t\tif(s == e) \"YES\".writeln;\n\t\telse \"NO\".writeln;\n\t}\n\t\n}\n\nlong gcd(long a, long b){\n\tif(a < b) return gcd(b, a);\n\tif(a % b == 0) return b;\n\treturn gcd(b, a % b);\n}\n\n"}], "negative_code": [], "src_uid": "d4ae071cf261ec3d91187a9a7dddcda0"} {"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[] w;\n\n void solve(long tc = -1)\n {\n long[101] cnt = 0;\n auto forbidden = new RedBlackTree!long[cast(size_t) n];\n foreach(ref f; forbidden)\n f = redBlackTree!long();\n foreach(i; 0 .. n)\n {\n foreach(j; i + 1 .. n)\n {\n if (!(w.at(j) in forbidden.at(i)) && !(w.at(i) in forbidden.at(j)))\n {\n forbidden.at(j).insert(w.at(i));\n forbidden.at(i).insert(w.at(j));\n cnt.at(w.at(i) + w.at(j))++;\n debug writeln(\"from \", i, \" to \", j, \" \", w.at(i) + w.at(j), \" cnt = \"\n , cnt.at(w.at(i) + w.at(j)));\n }\n }\n }\n writeln(cnt[].fold!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\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 long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto w = RDA!int;\n\t\t\n\t\tauto cnt = new int[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\t++cnt[w[i]];\n\t\t}\n\t\t\n\t\tforeach (i; 2..n*2+1)\n\t\t{\n\t\t\tlong tmp;\n\t\t\tforeach (j; 1..min(i, n+1))\n\t\t\t{\n\t\t\t\tauto k = i - j;\n\t\t\t\tif (k < j || k > n) continue;\n\t\t\t\tif (j == k)\n\t\t\t\t{\n\t\t\t\t\ttmp += cnt[k] / 2;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ttmp += min(cnt[j], cnt[k]);\n\t\t\t\t}\n\t\t\t\tdebug writeln(\"j:\", j, \" k:\", k, \" tmp:\", tmp);\n\t\t\t}\n\t\t\tdebug writeln(\"i:\", i, \" tmp:\", tmp);\n\t\t\tans[ti].chmax(tmp);\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(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 w = RDA!int;\n\t\t\n\t\tauto cnt = new int[](n+1);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\t++cnt[w[i]];\n\t\t}\n\t\t\n\t\tforeach (i; 2..n*2+1)\n\t\t{\n\t\t\tlong tmp;\n\t\t\tforeach (j; 1..min(i, n))\n\t\t\t{\n\t\t\t\tauto k = i - j;\n\t\t\t\tif (k < j || k > n) continue;\n\t\t\t\tif (j == k)\n\t\t\t\t{\n\t\t\t\t\ttmp += cnt[k] / 2;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ttmp += min(cnt[j], cnt[k]);\n\t\t\t\t}\n\t\t\t\tdebug writeln(\"j:\", j, \" k:\", k, \" tmp:\", tmp);\n\t\t\t}\n\t\t\tdebug writeln(\"i:\", i, \" tmp:\", tmp);\n\t\t\tans[ti].chmax(tmp);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "0048623eeb27c6f7c6900d8b6e620f19"} {"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\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 = 2 * 10^^5 + 10;\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 long[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readLong;\r\n }\r\n \r\n auto ASum = new long[N + 1];\r\n foreach (i; 0 .. N) {\r\n ASum[i + 1] = ASum[i] + A[i];\r\n }\r\n debug {\r\n writeln(\"ASum = \", ASum);\r\n }\r\n \r\n Mint ans = 1;\r\n for (int i = 1, j = N - 1; i <= j; ) {\r\n const val = min(ASum[i], ASum[N] - ASum[j]);\r\n int cntI, cntJ;\r\n for (; i <= j && ASum[i] == val; ++i) ++cntI;\r\n for (; i <= j && ASum[N] - ASum[j] == val; --j) ++cntJ;\r\n debug {\r\n writeln(val, \" \", cntI, \" \", cntJ);\r\n }\r\n if (val == ASum[N] - val) {\r\n ans *= Mint(2)^^(cntI + cntJ);\r\n } else {\r\n Mint sum;\r\n foreach (k; 0 .. min(cntI, cntJ) + 1) {\r\n sum += binom(cntI, k) * binom(cntJ, k);\r\n }\r\n ans *= sum;\r\n }\r\n }\r\n writeln(ans);\r\n }\r\n }\r\n } catch (EOFException e) {\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\nimmutable int mod = 998_244_353;\r\nimmutable int limit = 100_005;\r\n\r\nint [] f;\r\nint [] fi;\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 prepare (int limit)\r\n{\r\n\tf = [1];\r\n\tforeach (i; 1..limit)\r\n\t{\r\n\t\tf ~= (f.back * 1L * i) % mod;\r\n\t}\r\n\tfi = f.map !(invMod).array;\r\n}\r\n\r\nlong choose (int n, int k)\r\n{\r\n\tif (!(0 <= k && k <= n))\r\n\t{\r\n\t\treturn 0;\r\n\t}\r\n\tlong res = f[n];\r\n\tres = (res * 1L * invMod (f[n - k])) % mod;\r\n\tres = (res * 1L * invMod (f[k])) % mod;\r\n\treturn res;\r\n}\r\n\r\nvoid main ()\r\n{\r\n\tprepare (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 lo = 0;\r\n\t\tint hi = n;\r\n\t\tlong x = 0;\r\n\t\tlong y = 0;\r\n\t\tlong res = 1;\r\n\t\twhile (lo < hi)\r\n\t\t{\r\n\t\t\twhile (x < y && lo < hi)\r\n\t\t\t{\r\n\t\t\t\tx += a[lo];\r\n\t\t\t\tlo += 1;\r\n\t\t\t}\r\n\t\t\twhile (y < x && lo < hi)\r\n\t\t\t{\r\n\t\t\t\thi -= 1;\r\n\t\t\t\ty += a[hi];\r\n\t\t\t}\r\n\t\t\tif (x == y)\r\n\t\t\t{\r\n\t\t\t\tint lo2 = lo;\r\n\t\t\t\tint hi2 = hi;\r\n\t\t\t\twhile (lo2 < hi2 && a[lo2] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tlo2 += 1;\r\n\t\t\t\t}\r\n\t\t\t\twhile (lo2 < hi2 && a[hi2 - 1] == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\thi2 -= 1;\r\n\t\t\t\t}\r\n\t\t\t\tbool inner = (hi - lo < n);\r\n\t\t\t\tlong cur = 1;\r\n\t\t\t\tif (lo2 == hi2)\r\n\t\t\t\t{\r\n\t\t\t\t\tint len = lo2 - lo;\r\n\t\t\t\t\tlen = len + inner - !inner;\r\n\t\t\t\t\tfor (int i = 1; i <= len; i += 1)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlong temp =\r\n\t\t\t\t\t\t choose (len, i);\r\n\t\t\t\t\t\tcur = (cur + temp) % mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tint lenLo = lo2 - lo + inner;\r\n\t\t\t\t\tint lenHi = hi - hi2 + inner;\r\n\t\t\t\t\tfor (int i = 1; i <= lenLo &&\r\n\t\t\t\t\t i <= lenHi; i++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tlong temp =\r\n\t\t\t\t\t\t choose (lenLo, i);\r\n\t\t\t\t\t\ttemp *=\r\n\t\t\t\t\t\t choose (lenHi, i);\r\n\t\t\t\t\t\tcur = (cur + temp) % mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tres = (res * 1L * cur) % mod;\r\n\t\t\t\tif (lo2 < n)\r\n\t\t\t\t{\r\n\t\t\t\t\tx += a[lo2];\r\n\t\t\t\t}\r\n\t\t\t\tlo = lo2 + 1;\r\n\t\t\t\thi = hi2;\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": "fad12986a0a97a96109734fdce3bd7a7"} {"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 = 998244353;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n foreach (i; 0..N-1) (A[i+1] += A[i]) %= MOD;\n\n long a = 1;\n long b = 0;\n long ans = 0;\n\n foreach_reverse (i; 0..N) {\n (ans += A[i] * a % MOD) %= MOD;\n a = a * 2 % MOD;\n if (b > 0) a += powmod(2, b-1, MOD);\n a %= MOD;\n b += 1;\n }\n\n ans.writeln;\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 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 immutable int MOD = 998244353;\n \n int mulmod(int a, int b) {\n return cast(long)a * b % MOD;\n }\n \n int addmod(int a, int b) {\n int c = a + b;\n if (c > MOD) c -= MOD;\n return c;\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 pws = recurrence!((a, n) => mulmod(a[n-1], 2))(1).take(n).array.retro.array;\n \n pws ~= 0;\n \n debug { pws.writeln; }\n \n auto ans = 0;\n foreach (i, e; arr) {\n auto opts = cast(int)(n-1 - i);\n auto cur = addmod(pws[i], mulmod(opts, pws[i+1]));\n cur = mulmod(cur, e);\n ans = addmod(ans, cur);\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;\nimport std.variant;\nimport std.concurrency;\n\nconst mod = 998244353;\n\nvoid main(string[] args)\n{\n auto n = next!int;\n auto a = next!long(n);\n foreach(ref ai; a) ai %= mod;\n long leaves = 1;\n long sumA = 0;\n long sumB = 0;\n long res = 0;\n foreach(i; 0 .. n)\n {\n sumA = (2 * sumA + a[i]) % mod;\n res = (sumA + sumB) % mod;\n sumB += res;\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"}], "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 = 998244353;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!long).array;\n foreach (i; 0..N-1) (A[i+1] += A[i]) %= MOD;\n\n long a = 1;\n long b = 0;\n long ans = 0;\n\n foreach_reverse (i; 0..N) {\n (ans += A[i] * a % MOD) %= MOD;\n long c = 2 * a + b;\n b = a;\n a = c;\n }\n\n ans.writeln;\n}\n"}], "src_uid": "d38c18b0b6716cccbe11eab7b4df8c3a"} {"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;\nint[][] G;\n\nint[] sz;\n\nvoid dfs0(int u, int p) {\n sz[u] = 1;\n foreach (v; G[u]) {\n if (v != p) {\n dfs0(v, u);\n sz[u] += sz[v];\n }\n }\n}\n\nint[] ans;\n\nvoid dfs1(int u, int p) {\n foreach (v; G[u]) {\n if (v != p) {\n if (sz[v] % 2 == 0) {\n dfs1(v, u);\n }\n }\n }\n ans ~= u;\n foreach (v; G[u]) {\n if (v != p) {\n if (sz[v] % 2 != 0) {\n dfs1(v, u);\n }\n }\n }\n}\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n P = new int[N];\n foreach (u; 0 .. N) {\n P[u] = readInt() - 1;\n }\n \n if (N % 2 == 0) {\n writeln(\"NO\");\n } else {\n G = new int[][N];\n foreach (u; 0 .. N) {\n if (P[u] != -1) {\n G[u] ~= P[u];\n G[P[u]] ~= u;\n }\n }\n sz = new int[N];\n dfs0(0, -1);\n ans = [];\n dfs1(0, -1);\n writeln(\"YES\");\n foreach (u; ans) {\n writeln(u + 1);\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 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[] p; readA(n, p); p[] -= 1;\n\n if (n%2 == 0) {\n writeln(\"NO\");\n return;\n }\n\n auto g = Graph!int(n);\n foreach (int i, pi; p)\n if (pi != -1) g.addEdgeB(i, pi);\n auto t = g.makeTree.rootify(0);\n\n auto c = new int[](n), qu = DList!int([0]), st = SList!int();\n while (!qu.empty) {\n auto u = qu.front; qu.removeFront();\n st.insertFront(u);\n foreach (v; t.children(u)) qu.insertBack(v);\n }\n while (!st.empty) {\n auto u = st.front; st.removeFront();\n c[u] = 1;\n foreach (v; t.children(u)) c[u] += c[v];\n }\n\n writeln(\"YES\");\n\n st.insertFront(0);\n while (!st.empty) {\n auto u = st.front; st.removeFront();\n if (u >= n) {\n writeln(u-n+1);\n continue;\n }\n foreach (v; t.children(u).filter!(v => c[v]%2 == 1))\n st.insertFront(v);\n st.insertFront(u+n);\n foreach (v; t.children(u).filter!(v => c[v]%2 == 0))\n st.insertFront(v);\n }\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"}], "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 n; readV(n);\n int[] p; readA(n, p); p[] -= 1;\n\n auto g = new bool[int][](n);\n foreach (int i, pi; p)\n if (pi != -1) g[i][pi] = g[pi][i] = true;\n\n auto c = new bool[int][](3);\n\n auto degType(int u)\n {\n auto deg = g[u].length;\n if (deg == 0) return 0;\n else if (deg%2 == 0) return 1;\n else return 2;\n \n }\n\n foreach (i; 0..n) c[degType(i)][i] = true;\n\n while (c[1].length) {\n auto u = c[1].keys.front;\n c[1].remove(u);\n foreach (v; g[u].byKey) {\n c[degType(v)].remove(v);\n g[v].remove(u);\n c[degType(v)][v] = true;\n }\n }\n\n writeln(c[1].length ? \"NO\" : \"YES\");\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; readV(n);\n int[] p; readA(n, p); p[] -= 1;\n\n auto g = new bool[int][](n);\n foreach (int i, pi; p)\n if (pi != -1) g[i][pi] = g[pi][i] = true;\n\n auto c = new bool[int][](3);\n\n auto degType(int u)\n {\n auto deg = g[u].length;\n if (deg == 0) return 0;\n else if (deg%2 == 0) return 1;\n else return 2;\n \n }\n\n foreach (i; 0..n) c[degType(i)][i] = true;\n\n while (c[1].length) {\n auto u = c[1].keys.front;\n writeln(u);\n c[1].remove(u);\n foreach (v; g[u].byKey) {\n c[degType(v)].remove(v);\n g[v].remove(u);\n c[degType(v)][v] = true;\n }\n }\n\n writeln(c[1].length ? \"NO\" : \"YES\");\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; readV(n);\n int[] p; readA(n, p); p[] -= 1;\n\n auto g = new bool[int][](n);\n foreach (int i, pi; p)\n if (pi != -1) g[i][pi] = g[pi][i] = true;\n\n auto c = new bool[int][](3);\n\n auto degType(int u)\n {\n auto deg = g[u].length;\n if (deg == 0) return 0;\n else if (deg%2 == 0) return 1;\n else return 2;\n \n }\n\n foreach (i; 0..n) c[degType(i)][i] = true;\n\n int[] r;\n while (c[1].length) {\n auto u = c[1].keys.front;\n r ~= u;\n c[1].remove(u);\n foreach (v; g[u].byKey) {\n c[degType(v)].remove(v);\n g[v].remove(u);\n c[degType(v)][v] = true;\n }\n }\n\n if (c[2].length) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n foreach (ri; r) writeln(ri+1);\n foreach (u; c[0].byKey) writeln(u+1);\n }\n}\n"}], "src_uid": "1385c9a70da884bc11befbc2a506ab49"} {"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 T = readln.chomp.to!int;\n while (T--) {\n auto S = readln.chomp;\n auto N = S.length.to!int;\n auto U = S.count('U').to!int;\n auto D = S.count('D').to!int;\n auto L = S.count('L').to!int;\n auto R = S.count('R').to!int;\n auto x = min(U, D);\n auto y = min(L, R);\n auto ans = new dchar[](x + y + x + y);\n if (x == 0 && y == 0) {\n 0.writeln;\n writeln;\n } else if (x == 0) {\n 2.writeln;\n \"LR\".writeln;\n } else if (y == 0) {\n 2.writeln;\n \"UD\".writeln;\n } else {\n foreach (i; 0..x+x+y+y) {\n if (i < x) ans[i] = 'U';\n else if (i < x + y) ans[i] = 'L';\n else if (i < 2 * x + y) ans[i] = 'D';\n else ans[i] = 'R';\n }\n ans.length.writeln;\n ans.writeln;\n }\n }\n}\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}\nvoid main()\n{\n int q; get(q);\n while(q--)\n {\n int[4] count = 0;\n string str; get(str);\n foreach(c; str)\n\t{\n\t switch(c)\n\t {\n\t case 'L':\n\t count[0]++;\n\t break;\n\t case 'R':\n\t count[1]++;\n\t break;\n\t case 'U':\n\t count[2]++;\n\t break;\n\t case 'D':\n\t count[3]++;\n\t break;\n\t default:\n\t assert(0);\n\t }\n\t}\n int l = min(count[0], count[1]);\n int r = min(count[2], count[3]);\n if(l == 0 && r > 1)\n\t{\n\t r = 1;\n\t}\n if(l > 1 && r == 0)\n\t{\n\t l = 1;\n\t}\n wr(2 * (l + r));\n foreach(i; 0 .. r)\n\twrite('U');\n foreach(i; 0 .. l)\n\twrite('R');\n foreach(i; 0 .. r)\n\twrite('D');\n foreach(i; 0 .. l)\n\twrite('L');\n if(l + r)\n\twriteln;\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 q = rint;\n\tforeach(_; 0 .. q){\n\t\tstring s = rstring;\n\t\tint[char] cnt = ['L': 0, 'R': 0, 'U': 0, 'D': 0];\n\t\tforeach(c; s) cnt[c] += 1;\n\n\t\tint x = min(cnt['L'], cnt['R']), y = min(cnt['U'], cnt['D']);\n\t\tif(x == 0 && y >= 2) y = 1;\n\t\tif(y == 0 && x >= 2) x = 1;\n\t\t(x + x + y + y).writeln;\n\t\tforeach(i; 0 .. x) \"L\".write;\n\t\tforeach(j; 0 .. y) \"U\".write;\n\t\tforeach(i; 0 .. x) \"R\".write;\n\t\tforeach(j; 0 .. y) \"D\".write;\n\t\twriteln;\n\n\t\t\t\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 q = RD!int;\n\tauto ans = new string[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto s = RD!string;\n\t\tlong cnt_u, cnt_d, cnt_l, cnt_r;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == 'U')\n\t\t\t\t++cnt_u;\n\t\t\telse if (c == 'D')\n\t\t\t\t++cnt_d;\n\t\t\telse if (c == 'L')\n\t\t\t\t++cnt_l;\n\t\t\telse\n\t\t\t\t++cnt_r;\n\t\t}\n\t\tauto y = min(cnt_u, cnt_d);\n\t\tauto x = min(cnt_l, cnt_r);\n\t\tif (y == 0)\n\t\t\tx.chmin(1);\n\t\telse if (x == 0)\n\t\t\ty.chmin(1);\n\t\tforeach (_; 0..y)\n\t\t\tans[i] ~= 'U';\n\t\tforeach (_; 0..x)\n\t\t\tans[i] ~= 'R';\n\t\tforeach (_; 0..y)\n\t\t\tans[i] ~= 'D';\n\t\tforeach (_; 0..x)\n\t\t\tans[i] ~= 'L';\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\twriteln(e);\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; }\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 q = RD!int;\n\tauto ans = new string[](q);\n\tforeach (i; 0..q)\n\t{\n\t\tauto s = RD!string;\n\t\tlong cnt_u, cnt_d, cnt_l, cnt_r;\n\t\tforeach (c; s)\n\t\t{\n\t\t\tif (c == 'U')\n\t\t\t\t++cnt_u;\n\t\t\telse if (c == 'D')\n\t\t\t\t++cnt_d;\n\t\t\telse if (c == 'L')\n\t\t\t\t++cnt_l;\n\t\t\telse\n\t\t\t\t++cnt_r;\n\t\t}\n\t\tauto y = min(cnt_u, cnt_d);\n\t\tauto x = min(cnt_l, cnt_r);\n\t\tif (y == 0)\n\t\t\tx.chmin(1);\n\t\telse if (x == 1)\n\t\t\ty.chmin(1);\n\t\tforeach (_; 0..y)\n\t\t\tans[i] ~= 'U';\n\t\tforeach (_; 0..x)\n\t\t\tans[i] ~= 'R';\n\t\tforeach (_; 0..y)\n\t\t\tans[i] ~= 'D';\n\t\tforeach (_; 0..x)\n\t\t\tans[i] ~= 'L';\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e.length);\n\t\twriteln(e);\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "1fba9a290d0492a3d658a7a33388db13"} {"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, K; scanf(\"%d %d\\n\", &N, &K);\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n\n K--;\n\n int a = xs[K];\n bool check() {\n foreach (x; xs[K .. $]) {\n if (a != x) return false;\n }\n return true;\n }\n if (!check()) {\n writeln(-1); return;\n }\n\n auto ys = xs[0 .. K];\n int c = 0;\n for (int i = K - 1; i >= 0; i--) {\n if (ys[i] == a) c++;\n else break;\n }\n /*\n writeln([c]);\n writeln([N, K]);\n writeln(xs);\n writeln(ys);\n */\n writeln(K - c);\n\n\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nconst int MAX_N = 100005;\nint k, n;\n\nint main ()\n{\n\twhile (scanf (\" %d %d\", &n, &k) != EOF)\n\t{\n//\t\twritefln (\"%d %d\", n, k);\n\t\tint m = n * 3 + 1;\n\t\tint a [] = new int [m];\n\t\tint b [] = new int [MAX_N];\n\t\tint c = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tscanf (\" %d\", &a[i]);\n\t\t\tif (b[a[i]] == 0)\n\t\t\t\tc++;\n\t\t\tb[a[i]]++;\n\t\t}\n\n\t\tint s = 0;\n\t\tfor (int i = n; i < m; i++)\n\t\t{\n//\t\t\twritefln (\"%d: %d\", s, c);\n\t\t\tif (c <= 1)\n\t\t\t\tbreak;\n//\t\t\twritefln (\"a[%d] = a[%d]\", i, k + s - 1);\n\t\t\ta[i] = a[k + s - 1];\n\t\t\tif (b[a[i]] == 0)\n\t\t\t\tc++;\n\t\t\tb[a[i]]++;\n\t\t\tb[a[i - n]]--;\n\t\t\tif (b[a[i - n]] == 0)\n\t\t\t\tc--;\n\t\t\ts++;\n\t\t}\n\t\tif (s >= m - n)\n\t\t{\n\t\t\ts = -1;\n\t\t}\n\t\twritefln (\"%d\", s);\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\n\nconst int MAX_N = 100005;\nint k, n;\n\nint main ()\n{\n\twhile (scanf (\" %d %d\", &n, &k) != EOF)\n\t{\n//\t\twritefln (\"%d %d\", n, k);\n\t\tint m = n * 3 + 1;\n\t\tint a [] = new int [m];\n\t\tint b [] = new int [MAX_N];\n\t\tint c = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tscanf (\" %d\", &a[i]);\n\t\t\tif (b[a[i]] == 0)\n\t\t\t\tc++;\n\t\t\tb[a[i]]++;\n\t\t}\n\n\t\tint s = 0;\n\t\tfor (int i = n; i < m; i++)\n\t\t{\n//\t\t\twritefln (\"%d: %d\", s, c);\n\t\t\tif (c <= 1)\n\t\t\t\tbreak;\n//\t\t\twritefln (\"a[%d] = a[%d]\", i, k + s - 1);\n\t\t\ta[i] = a[k + s - 1];\n\t\t\tif (b[a[i]] == 0)\n\t\t\t\tc++;\n\t\t\tb[a[i]]++;\n\t\t\tb[a[i - n]]--;\n\t\t\tif (b[a[i - n]] == 0)\n\t\t\t\tc--;\n\t\t\ts++;\n\t\t}\n\t\tif (s >= m - n)\n\t\t{\n\t\t\ts = -1;\n\t\t}\n\t\twritefln (\"%d\", s);\n\t}\n\treturn 0;\n}\n"}], "negative_code": [], "src_uid": "bcee233ddb1509a14f2bd9fd5ec58798"} {"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 CS = readln.split.to!(int[]);\n int[][] T;\n T.length = N;\n foreach (_; 0..N-1) {\n auto ab = readln.split.to!(int[]);\n auto a = ab[0]-1;\n auto b = ab[1]-1;\n T[a] ~= b;\n T[b] ~= a;\n }\n\n auto MD = new int[](N);\n int paint(int i, int p) {\n auto d = CS[i] ? 1 : -1;\n foreach (j; T[i]) if (j != p) d += max(0, paint(j, i));\n MD[i] = d;\n return d;\n }\n paint(0, -1);\n void solve(int i, int p) {\n if (p >= 0) {\n if (CS[i]) {\n MD[i] = max(MD[i], MD[p]);\n } else if (MD[i] <= 0) {\n MD[i] = max(MD[i], MD[p] + MD[i]);\n } else {\n MD[i] = max(MD[i], MD[p]);\n }\n }\n foreach (j; T[i]) if (j != p) solve(j, i);\n }\n solve(0, -1);\n\n writeln(MD.to!(string[]).join(\" \"));\n}", "positive_code": [{"source_code": "import std.array;\nimport std.stdio;\nimport std.string;\nimport std.range;\nimport std.conv;\nimport std.algorithm.iteration;\nimport std.algorithm.comparison;\n\n\nvoid main(string[] args)\n{\n auto inf = cast(int) float.infinity;\n const int n = to!int(readln().chomp());\n auto white = stdin.readln().split().map!(to!int);\n auto score = array((-inf).repeat(n+1));\n score[0] = 0;\n int[][] adj;\n adj.length = n+1;\n\n int u, v;\n for (int i=1; i= 0) {\n if (CS[i]) {\n MD[i] = max(MD[i], MD[p]);\n } else {\n MD[i] += MD[p];\n }\n }\n foreach (j; T[i]) if (j != p) solve(j, i);\n }\n solve(0, -1);\n\n writeln(MD.to!(string[]).join(\" \"));\n}"}], "src_uid": "cb8895ddd54ffbd898b1bf5e169feb63"} {"source_code": "import std.stdio;\nimport std.array : appender, array;\nimport std.algorithm : min;\nimport std.algorithm.iteration : cumulativeFold;\nimport std.algorithm.sorting : sort;\nimport std.range : chain, only;\n\nvoid main()\n{\n int n, k;\n readf!\"%d %d\\n\"(n, k);\n\n auto books_ab = appender!(long[]);\n auto books_a = appender!(long[]);\n auto books_b = appender!(long[]);\n\n books_ab.reserve(n);\n books_a.reserve(n);\n books_b.reserve(n);\n\n foreach (i; 0..n) {\n int ti, a, b;\n readf!\"%d %d %d\\n\"(ti, a, b);\n\n if (a == 1 && b == 1) {\n books_ab.put(ti);\n } else if (a == 1) {\n books_a.put(ti);\n } else if (b == 1) {\n books_b.put(ti);\n }\n }\n\n // maximum number of non-shared books we can use\n auto mk = min(k, books_a[].length, books_b[].length);\n\n if (mk + books_ab[].length < k) {\n writeln(-1);\n return;\n }\n\n // prefix sums\n auto ab = chain(only(0L), books_ab[].sort.cumulativeFold!\"a + b\").array;\n auto sa = chain(only(0L), books_a[].sort.cumulativeFold!\"a + b\").array;\n auto sb = chain(only(0L), books_b[].sort.cumulativeFold!\"a + b\").array;\n\n // initial value: take mk from each A and B (no shared)\n long t = -1;\n\n // loop over number to take from shared list\n foreach (i; k - mk..min(k, books_ab[].length) + 1) {\n long s = ab[i] + sa[k-i] + sb[k-i];\n\n if (t == -1) t = s;\n t = min(s, 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;\n\nimmutable int infinity = int.max / 2;\n\nvoid main ()\n{\n\tint n, k;\n\twhile (readf !(\" %s %s\") (n, k) > 0)\n\t{\n\t\tauto v = new int [] [4];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint t, a, b;\n\t\t\treadf !(\" %s %s %s\") (t, a, b);\n\t\t\tv[a * 2 + b] ~= t;\n\t\t}\n\t\tforeach (j; 0..4)\n\t\t{\n\t\t\tsort (v[j]);\n\t\t\tv[j] ~= infinity;\n\t\t}\n\t\tint res = 0;\n\t\tbool ok = true;\n\t\tforeach (r; 0..k)\n\t\t{\n\t\t\tauto x = v[3].front;\n\t\t\tauto y = v[1].front + v[2].front;\n\t\t\tif (x >= infinity && y >= infinity)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t}\n\t\t\telse if (x < y)\n\t\t\t{\n\t\t\t\tres += x;\n\t\t\t\tv[3].popFront ();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tres += y;\n\t\t\t\tv[1].popFront ();\n\t\t\t\tv[2].popFront ();\n\t\t\t}\n\t\t}\n\t\twriteln (ok ? res : -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;\n\n\nalias type = single;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, k;\n @Dim(\"n\") Tuple!(long, long, long)[] books;\n\n void solve(long tc = -1)\n {\n long[] as, bs, abs;\n foreach(book; books)\n {\n if (book[1] && book[2])\n abs ~= book[0];\n else if (book[1])\n as ~= book[0];\n else if (book[2])\n bs ~= book[0];\n }\n if (min(as.length, bs.length) + abs.length < cast(size_t) k)\n {\n writeln(-1);\n return;\n }\n sort(as); sort(bs); sort(abs);\n long[] acca = new long[as.length + 1]\n , accb = new long[bs.length + 1]\n , accab = new long[abs.length + 1];\n foreach(i, v; as) acca[i + 1] = acca[i] + as[i];\n foreach(i, v; bs) accb[i + 1] = accb[i] + bs[i];\n foreach(i, v; abs) accab[i + 1] = accab[i] + abs[i];\n long m = long.max;\n foreach(i, v; accab)\n {\n if (i > k)\n break;\n if (min(as.length, bs.length) >= k - i)\n {\n m = min(m, v + acca.at(k - i) + accb.at(k - i));\n }\n }\n writeln(m);\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;\nimport std.array : appender, array;\nimport std.algorithm : min;\nimport std.algorithm.iteration : cumulativeFold;\nimport std.algorithm.sorting : sort;\nimport std.range : chain, only;\n\nvoid main()\n{\n int n, k;\n readf!\"%d %d\\n\"(n, k);\n\n auto books_ab = appender!(long[]);\n auto books_a = appender!(long[]);\n auto books_b = appender!(long[]);\n\n books_ab.reserve(n);\n books_a.reserve(n);\n books_b.reserve(n);\n\n foreach (i; 0..n) {\n int ti, a, b;\n readf!\"%d %d %d\\n\"(ti, a, b);\n\n if (a == 1 && b == 1) {\n books_ab.put(ti);\n } else if (a == 1) {\n books_a.put(ti);\n } else if (b == 1) {\n books_b.put(ti);\n }\n }\n\n // maximum number of non-shared books we can use\n auto mk = min(k, books_a[].length, books_b[].length);\n\n // prefix sums\n auto ab = chain(only(0L), books_ab[].sort.cumulativeFold!\"a + b\").array;\n auto sa = chain(only(0L), books_a[].sort.cumulativeFold!\"a + b\").array;\n auto sb = chain(only(0L), books_b[].sort.cumulativeFold!\"a + b\").array;\n\n // initial value: take mk from each A and B (no shared)\n long t = -1;\n\n // loop over number to take from shared list\n foreach (i; k - mk..min(k, books_ab[].length) + 1) {\n long s = ab[i] + sa[k-i] + sb[k-i];\n\n if (t == -1) t = s;\n t = min(s, t);\n }\n\n writeln(t);\n}"}], "negative_code": [], "src_uid": "6a80b2af22cf8e5bb01ff47d257db196"} {"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 next = int.max;\r\n\t\tbool ok = true;\r\n\t\tint res = 0;\r\n\t\tforeach_reverse (ref c; a)\r\n\t\t{\r\n\t\t\twhile (c > 0 && c >= next)\r\n\t\t\t{\r\n\t\t\t\tres += 1;\r\n\t\t\t\tc /= 2;\r\n\t\t\t}\r\n\t\t\tif (c >= next)\r\n\t\t\t{\r\n\t\t\t\tok = false;\r\n\t\t\t}\r\n\t\t\tnext = c;\r\n\t\t}\r\n\t\twriteln (ok ? res : -1);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// cheese-cracker [2022-05-05]\n\nvoid solve(){\n int n = scan!int;\n auto arr = scanArray;\n long res = 0;\n for(int i = n-2; i >= 0; --i){\n long prev = arr[i+1];\n while(arr[i] > 0 && arr[i] >= prev){\n arr[i] /= 2;\n ++res;\n }\n if(arr[i] >= prev){\n writeln(-1);\n return;\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;\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": "e959e82b4bd4e7943a78bf5350a70c87"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main(string[] args)\n{\n //stdin = File(\"input.txt\", \"r\");\n\n auto T = readln().strip('\\n');\n auto S = readln().strip('\\n');\n\n int count = 0;\n for (int i = 0; i + S.length <= T.length; ++i) {\n if (T[i..i+S.length] == S) {\n ++count;\n i = cast(int)(i + S.length - 1);\n }\n }\n writeln(count);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv;\nimport std.typecons;\nimport std.algorithm;\n\nbool isPrefixOf(string x, string y){\n if (x.length > y.length) return false;\n bool res = true;\n for(int i;i y.length) return false;\n bool res = true;\n for(int i;i= 0; i--) {\n if (i < N -1)\n acm[i] = acm[i+1];\n if (!(A[i] in used)) {\n used[A[i]] = true;\n acm[i]++;\n }\n }\n\n foreach (_; 0..M) {\n auto x = readln.chomp.to!int;\n acm[x-1].writeln;\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.array, std.conv, std.string, std.range;\n\nvoid main() {\n auto input = readln.chomp.split.map!(to!int).array;\n auto n = input.front;\n auto m = input.back;\n auto a = readln.chomp.split.map!(to!int).array;\n bool[int] memAssoc;\n auto ans = new ulong[n];\n for (int i = n - 1; i >= 0; i--) {\n memAssoc[a[i]] = true;\n ans[i] = memAssoc.length;\n }\n for (int i = 0; i < m; i++) {\n int l = readln.chomp.to!int;\n ans[l - 1].writeln;\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\n\nvoid main()\n{\n bool [int] s;\n\tauto nm = readln.chomp.split.map!\"a.to!int\";\n auto as = readln.chomp.split.map!\"a.to!int\";\n auto n = nm[0], m = nm[1];\n auto count = 0;\n auto dp = new int[n];\n foreach_reverse (i;0..n) {\n if (!(as[i] in s)) {\n count++;\n s[as[i]]=true;\n }\n dp[i] = count;\n\n }\n foreach (i; 0..m)\n writeln(dp[readln.chomp.to!int - 1]);\n\n}\n"}, {"source_code": "//ahmat\nimport std.stdio,std.string,std.math,std.algorithm,\nstd.array,std.container,std.algorithm,std.numeric,std.bitmanip,\nstd.range,std.random,std.complex,std.functional,std.typecons,\nstd.format,std.bigint,core.vararg,core.bitop,std.conv;\n\nvoid cin(...){}\nvoid cout(...){}\nint sz(T)(ref T a){return cast(int)a.length;}\n\nint n,m,l;\nvoid main(){\n readf(\"%d %d\\n\",&n,&m);\n int[] arr=readln.splitter.map!(to!int).array;\n bool[int] map;\n int[] a=new int[n];\n for(int i=n-1;i>=0;i--){\n map[arr[i]]=true;\n a[i]=cast(int)map.length;\n }\n //debug writeln(a);\n while(m--){\n readf(\"%d\\n\",l);\n writeln(a[l-1]);\n }\n}\n"}], "negative_code": [], "src_uid": "1e156dfc65ef88f19ca1833f75192259"} {"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 \n auto board = new long[][](N, N);\n foreach (s; 1 .. 2 * N - 2) {\n foreach (x; 0 .. N) {\n const y = s - x;\n if (0 <= y && y < N) {\n board[x][y] = (cast(long)(x & 1)) << s;\n }\n }\n }\n foreach (x; 0 .. N) {\n board[x][N - 1 - x] = (cast(long)(x)) << (2 * N - 2);\n }\n foreach (x; 0 .. N) foreach (y; 0 .. N) {\n assert(0 <= board[x][y] && board[x][y] <= 10L^^16);\n }\n \n foreach (x; 0 .. N) {\n foreach (y; 0 .. N) {\n if (y > 0) write(\" \");\n write(board[x][y]);\n }\n writeln;\n }\n stdout.flush;\n \n const Q = readInt();\n foreach (q; 0 .. Q) {\n const K = readLong();\n \n auto xs = new int[2 * N - 1];\n xs[0] = 0;\n xs[2 * N - 2] = N - 1;\n xs[N - 1] = cast(int)(K >> (2 * N - 2));\n foreach_reverse (s; 1 .. N - 1) {\n xs[s] = xs[s + 1];\n if ((xs[s] & 1) != ((K >> s) & 1)) {\n --xs[s];\n }\n }\n foreach (s; N .. 2 * N - 2) {\n xs[s] = xs[s - 1];\n if ((xs[s] & 1) != ((K >> s) & 1)) {\n ++xs[s];\n }\n }\n \n foreach (s; 0 .. 2 * N - 1) {\n writeln(xs[s] + 1, \" \", (s - xs[s]) + 1);\n }\n stdout.flush;\n \n long k;\n foreach (s; 0 .. 2 * N - 1) {\n k += board[xs[s]][s - xs[s]];\n }\n assert(k == K);\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 ways = new long [] [] (n, n);\n\t\tforeach (row; 0..n)\n\t\t{\n\t\t\tforeach (col; 0..n)\n\t\t\t{\n\t\t\t\tif (row + col == 0)\n\t\t\t\t{\n\t\t\t\t\tways[row][col] += 1;\n\t\t\t\t}\n\t\t\t\tif (row > 0)\n\t\t\t\t{\n\t\t\t\t\tways[row][col] += ways[row - 1][col];\n\t\t\t\t}\n\t\t\t\tif (col > 0)\n\t\t\t\t{\n\t\t\t\t\tways[row][col] += ways[row][col - 1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tauto num = new long [] [] (n, n);\n\t\tauto board = new long [] [] (n, n);\n\t\tlong temp = 1;\n\t\tforeach (col; 1..n)\n\t\t{\n\t\t\tforeach_reverse (row; 0..n - 1)\n\t\t\t{\n\t\t\t\tlong lo = 0;\n\t\t\t\tforeach (row2; 0..row)\n\t\t\t\t{\n\t\t\t\t\tlo += board[row2][0];\n\t\t\t\t}\n\t\t\t\tforeach (col2; 0..col)\n\t\t\t\t{\n\t\t\t\t\tlo += board[row][col2];\n\t\t\t\t}\n\t\t\t\tlong hi = 0;\n\t\t\t\tforeach (col2; 0..col - 1)\n\t\t\t\t{\n\t\t\t\t\thi += board[0][col2];\n\t\t\t\t}\n\t\t\t\tforeach (row2; 0..row + 1)\n\t\t\t\t{\n\t\t\t\t\thi += board[row2][col - 1];\n\t\t\t\t}\n\t\t\t\tlong span = hi - lo + 1;\n\t\t\t\tnum[row][col] = temp;\n\t\t\t\ttemp += span;\n\n\t\t\t\tboard[row][col] = num[row][col];\n\t\t\t\tforeach (col2; 0..col)\n\t\t\t\t{\n\t\t\t\t\tboard[row][col] -= board[row][col2];\n\t\t\t\t}\n\t\t\t\tforeach (row2; row + 1..n)\n\t\t\t\t{\n\t\t\t\t\tboard[row][col] -= board[row2][col];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%(%(%s %)\\n%)\") (board);\n\t\tstdout.flush ();\n\n\t\tauto q = readln.strip.to !(int);\n\t\tforeach (r; 0..q)\n\t\t{\n\t\t\tauto k = readln.strip.to !(long);\n\t\t\tint [2] [] ans;\n\t\t\tint row = n - 1;\n\t\t\tint col = n - 1;\n\t\t\twhile (row + col > 0)\n\t\t\t{\n\t\t\t\tans ~= [row + 1, col + 1];\n\t\t\t\tif (col > 0 && k < ways[row][col - 1])\n\t\t\t\t{\n\t\t\t\t\tcol -= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (col > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tk -= ways[row][col - 1];\n\t\t\t\t\t}\n\t\t\t\t\trow -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans ~= [row + 1, col + 1];\n\t\t\twritefln !(\"%(%(%s %)\\n%)\") (ans.retro);\n\t\t\tstdout.flush ();\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "8b0ec419248bb98b5e0c3d991c7e14fb"} {"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\nT euDist2(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return c.sum; }\r\ndouble euDist(T)(T[] a, T[] b) { return sqrt(cast(double)euDist2(a,b)); }\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 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;\r\n\t\tauto a = RDA;\r\n\t\t\r\n\t\tbool f(int h, int w)\r\n\t\t{\r\n\t\t\tauto b = a.dup;\r\n\t\t\tb[] /= h;\r\n\t\t\tbool has3;\r\n\t\t\tforeach (e; b)\r\n\t\t\t{\r\n\t\t\t\tif (e < 2) continue;\r\n\t\t\t\tif (e >= 3)\r\n\t\t\t\t\thas3 = true;\r\n\t\t\t\tif (w == 1 && !has3) continue;\r\n\t\t\t\tw -= e;\r\n\t\t\t\tif (w <= 0) return true;\r\n\t\t\t}\r\n\t\t\treturn false;\r\n\t\t}\r\n\t\tans[ti] = f(n, m);\r\n\t\tif (ans[ti]) continue;\r\n\t\tans[ti] = f(m, 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}", "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 go (long n, long m, long k, long [] a)\r\n{\r\n\tif (n % 2 == 1 && a.maxElement < m * 3)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tforeach (x; a)\r\n\t{\r\n\t\tif (x >= m * 2)\r\n\t\t{\r\n\t\t\tx /= m;\r\n\t\t\tn -= x;\r\n\t\t}\r\n\t}\r\n\treturn n <= 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\tlong 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 !(long)).array;\r\n\t\twriteln (go (n, m, k, a) || go (m, n, k, a) ? \"Yes\" : \"No\");\r\n\t}\r\n}\r\n"}, {"source_code": "import std.stdio;\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 long n, m; int k; scanf(\"%Ld %Ld %d\\n\", &n, &m, &k);\r\n auto a = readln.chomp.split(\" \").map!(to!long).array;\r\n bool ok(long x, long y) {\r\n long sum = 0;\r\n auto b = a.map!((c) => c / x).filter!((c) => c >= 2).array.sort!\"a > b\".array;\r\n int z = cast(int)b.length;\r\n auto sb = new long[z+1];\r\n for (int i = 0; i < z; i++) {\r\n sb[i + 1] = sb[i] + b[i];\r\n }\r\n foreach (int u; 1 .. z + 1) {\r\n // use u colors\r\n if (y >= 2 * u && sb[u] >= y) return true;\r\n }\r\n return false;\r\n }\r\n (ok(n, m) || ok(m, n) ? \"Yes\" : \"No\").writeln;\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.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\nlong M, N;\nint K;\nlong[] A;\n\nbool check(long m, long n) {\n long sum;\n bool all2 = true;\n foreach (k; 0 .. K) {\n const num = A[k] / n;\n if (num >= 2) {\n sum += num;\n all2 = all2 && (num == 2);\n }\n }\n if (m % 2 != 0 && all2) {\n return false;\n }\n if (sum >= m) {\n return true;\n }\n return false;\n}\n\nbool solve() {\n if (check(M, N)) return true;\n if (check(N, M)) return true;\n return false;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n M = readLong;\n N = readLong;\n K = readInt;\n A = new long[K];\n foreach (k; 0 .. K) {\n A[k] = readLong;\n }\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 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 long n, m, k; scanf(\"%Ld %Ld %Ld\\n\", &n, &m, &k);\r\n auto a = readln.chomp.split(\" \").map!(to!long).array;\r\n bool ok(long x, long y) {\r\n long sum = 0;\r\n auto b = a.map!((c) => c / x).map!((c) => c < 2 ? 0 : c).array;\r\n foreach (int i; 0 .. cast(int)k) {\r\n sum += b[i];\r\n }\r\n return sum >= y && !(b.all!((c) => c == 2) && y % 2 == 1);\r\n }\r\n (ok(n, m) || ok(m, n) ? \"Yes\" : \"No\").writeln;\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.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\nlong M, N;\nint K;\nlong[] A;\n\nbool check(long m, long n) {\n long sum;\n bool all2 = true;\n foreach (k; 0 .. K) {\n const num = A[k] / n;\n if (num >= 2) {\n sum += num;\n all2 = all2 && (num == 2);\n }\n }\n if (sum >= m + 2) {\n return true;\n }\n if (sum == m + 1 && !all2) {\n return true;\n }\n if (sum == m) {\n return true;\n }\n return false;\n}\n\nbool solve() {\n if (check(M, N)) return true;\n if (check(N, M)) return true;\n return false;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n M = readLong;\n N = readLong;\n K = readInt;\n A = new long[K];\n foreach (k; 0 .. K) {\n A[k] = readLong;\n }\n \n const ans = solve;\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\nlong M, N;\nint K;\nlong[] A;\n\nbool check(long m, long n) {\n long sum;\n bool all2 = true;\n foreach (k; 0 .. K) {\n const num = A[k] / n;\n if (num >= 2) {\n sum += num;\n }\n all2 = all2 && (num == 2);\n }\n if (sum >= m + 2) {\n return true;\n }\n if (sum == m + 1 && !all2) {\n return true;\n }\n if (sum == m) {\n return true;\n }\n return false;\n}\n\nbool solve() {\n if (check(M, N)) return true;\n if (check(N, M)) return true;\n return false;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt;\n foreach (caseId; 0 .. numCases) {\n M = readLong;\n N = readLong;\n K = readInt;\n A = new long[K];\n foreach (k; 0 .. K) {\n A[k] = readLong;\n }\n \n const ans = solve;\n writeln(ans ? \"Yes\" : \"No\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "002129eec704af8976a2bf02cc532d59"} {"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 s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n auto L = new Tuple!(int, int)[](N);\n auto R = new Tuple!(int, int)[](N);\n auto T = new Tuple!(int, int)[](N);\n auto B = new Tuple!(int, int)[](N);\n auto LRTB = new int[][](N);\n foreach (i; 0..N) {\n s = readln.split.map!(to!int);\n L[i] = tuple(min(s[0], s[2]), i);\n R[i] = tuple(max(s[0], s[2]), i);\n T[i] = tuple(min(s[1], s[3]), i);\n B[i] = tuple(max(s[1], s[3]), i);\n LRTB[i] = [L[i][0], R[i][0], T[i][0], B[i][0]];\n }\n auto C = readln.split.map!(to!int).array;\n\n auto A = new int[][](N, 4);\n\n L.sort();\n R.sort();\n T.sort();\n B.sort();\n foreach (i; 0..N) A[i][0] = L.assumeSorted.lowerBound(tuple(LRTB[i][1], -1)).length;\n foreach (i; 0..N) A[i][1] = R.assumeSorted.upperBound(tuple(LRTB[i][0], 1 << 29)).length;\n foreach (i; 0..N) A[i][2] = T.assumeSorted.lowerBound(tuple(LRTB[i][3], -1)).length;\n foreach (i; 0..N) A[i][3] = B.assumeSorted.upperBound(tuple(LRTB[i][2], 1 << 29)).length;\n\n foreach (i; 0..N) {\n if (LRTB[i][0] < LRTB[i][1]) A[i][0] -= 1, A[i][1] -= 1;\n if (LRTB[i][2] < LRTB[i][3]) A[i][2] -= 1, A[i][3] -= 1;\n if (A[i] == C) {\n writeln(i + 1);\n return;\n }\n }\n\n writeln(-1);\n\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 d, n, m;\n\nvoid main() {\n scan(d);\n scan(n, m);\n\n n = max(n, m);\n\n alias Sofa = Tuple!(int, \"x1\", int, \"y1\", int, \"x2\", int, \"y2\");\n\n auto xls = new int[](n + 10);\n auto xrs = new int[](n + 10);\n auto yts = new int[](n + 10);\n auto ybs = new int[](n + 10);\n auto ss = new Sofa[](d);\n\n int x1, x2, y1, y2;\n\n foreach (i ; 0 .. d) {\n scan(x1, y1, x2, y2);\n\n if (x1 == x2 && y1 > y2) {\n swap(y1, y2);\n }\n if (y1 == y2 && x1 > x2) {\n swap(x1, x2);\n }\n\n xls[x1]++;\n xrs[x2]++;\n yts[y1]++;\n ybs[y2]++;\n\n ss[i] = Sofa(x1, y1, x2, y2);\n }\n\n foreach (i ; 0 .. n + 5) {\n xls[i + 1] += xls[i];\n yts[i + 1] += yts[i];\n }\n\n foreach_reverse (i ; 1 .. n + 5) {\n xrs[i - 1] += xrs[i];\n ybs[i - 1] += ybs[i];\n }\n\n debug {\n writeln(\"xls:\", xls);\n writeln(\"xrs:\", xrs);\n writeln(\"yts:\", yts);\n writeln(\"ybs:\", ybs);\n }\n\n int cntl, cntr, cntt, cntb;\n scan(cntl, cntr, cntt, cntb);\n\n foreach (i ; 0 .. d) {\n int left = xls[ss[i].x2 - 1] - (ss[i].x1 != ss[i].x2);\n int right = xrs[ss[i].x1 + 1] - (ss[i].x1 != ss[i].x2);\n int top = yts[ss[i].y2 - 1] - (ss[i].y1 != ss[i].y2);\n int btm = ybs[ss[i].y1 + 1] - (ss[i].y1 != ss[i].y2);\n\n debug {\n writefln(\"%d %d %d %d\", left, right, top, btm);\n }\n\n if (cntl == left && cntr == right && cntt == top && cntb == btm) {\n writeln(i + 1);\n return;\n }\n }\n\n writeln(-1);\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"}], "negative_code": [], "src_uid": "9b2c0c066f5c88a3b724d34788f97797"} {"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\n bool[long] aset;\n foreach(a; as) aset[a] = 1;\n\n aset.length.print;\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); }\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\tbool[long] set;\n\t\tforeach (e; a)\n\t\t{\n\t\t\tset[e] = true;\n\t\t}\n\t\tans[ti] = cast(int)set.keys.length;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "b978ca6fdef4a02cc027485294caa0f5"} {"source_code": "/** CodeForces Problem 381.A (2)\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 Unqual!T new_val = inval;\n \n return new_val;\n}\n\nT imut(T)(in T inval) { \n immutable new_val = inval;\n \n return new_val;\n}\n\n\nvoid main() {\n auto n = 0.mut;\n \n auto deck = new uint[](1000);\n \n readf(\"%s\\n\", &n);\n //writeln(n);\n \n for(int i; i < n; ++i) {\n readf(\"%s \", &deck[i]);\n }\n //writeln(deck);\n \n auto sS = 0, sD = 0, pF = 0, pR = (n-1);\n \n auto turn = false;\n \n for( int i; i < n; ++i ) {\n ( turn ? sD : sS ) \n += (deck[pF] > deck[pR] \n ? deck[pF++] \n : deck[pR--]);\n \n turn ^= true;\n }\n \n writeln(sS, \" \", sD);\n}", "positive_code": [{"source_code": "import std.stdio;\n\nint n, l, r, w;\nint[] a;\nint[2] z;\nvoid main()\n{\n\treadf(\"%d\", &n);\n\ta.length = n;\n\tfor(int i = 0; i < n; i++) {\n\t\treadf(\" %d\", &a[i]);\n\t}\n\tl = 0;\n\tr = n;\n\tw = 0;\n\twhile(l < r) {\n\t\tif (a[l] > a[r - 1]) {\n\t\t\tz[w] += a[l++];\n\t\t} else {\n\t\t\tz[w] += a[--r];\n\t\t}\n\t\tw ^= 1;\n\t}\n\twriteln(z[0], ' ', z[1]);\n}"}], "negative_code": [], "src_uid": "a7e98ed8ee1b0a4fd03dfcd222b68c6f"} {"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 = readln().strip().to!int;\n long ans = 0;\n foreach(i; 0..n) {\n int x1, y1, x2, y2;\n scanf(\"%d%d%d%d\", &x1, &y1, &x2, &y2);\n ans += (x2 - x1 + 1) * (y2 - y1 + 1);\n }\n writeln(ans);\n}\n", "positive_code": [{"source_code": "import std.stdio, std.conv, std.range, std.algorithm, std.string;\nimport std.math;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int ans = 0;\n foreach (i; 0..n) {\n int x1, y1, x2, y2;\n readf(\"%d %d %d %d\\n\", &x1, &y1, &x2, &y2);\n ans += (x2 - x1 + 1) * (y2 - y1 + 1);\n }\n\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "ca5c44093b1ab7c01970d83b5f49d0c6"} {"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 debug stdin = File(args[1]);\n auto n = next!int;\n auto a = next!int(n);\n auto dist = new int[][](2, n);\n auto invAdj = new int[][](n);\n debug writeln(a);\n foreach(i, ai; a)\n {\n debug writeln(i, \" \", ai, \" \", cast(int)i - ai);\n if (cast(int)i - ai >= 0)\n invAdj[i - ai] ~= cast(int)i;\n if (cast(int)i + ai < n)\n invAdj[i + ai] ~= cast(int)i;\n }\n foreach(p; 0 .. 2)\n {\n dist[p][] = -1;\n auto visited = new bool[](n);\n auto queue = DList!int();\n foreach(i, ai; a)\n {\n if (ai % 2 == p)\n {\n visited[i] = true;\n queue.insertBack(cast(int)i);\n dist[p][i] = 0;\n }\n }\n while(!queue.empty)\n {\n auto node = queue.front;\n queue.removeFront;\n foreach(nei; invAdj[node])\n {\n if (!visited[nei])\n {\n visited[nei] = true;\n dist[p][nei] = dist[p][node] + 1;\n queue.insertBack(nei);\n }\n }\n }\n }\n foreach(i, ai; a)\n write(dist[(ai + 1) % 2][i], \" \");\n writeln;\n}\n\n// INPUT\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 * 1024 * 8;\n const wordSize = 4096;\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 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 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.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 auto B = A.map!(a => a & 1).array;\n\n auto G = new int[][](N);\n\n DList!(Tuple!(int, int)) que;\n auto ans = new int[](N);\n ans[] = -1;\n\n foreach (i; 0..N) {\n int j = i + A[i];\n int k = i - A[i];\n if (j < N) {\n G[j] ~= i;\n }\n if (k >= 0) {\n G[k] ~= i;\n }\n if (j < N && (B[i] ^ B[j])) {\n que.insertBack(tuple(i, 2));\n ans[i] = 1;\n } else if (k >= 0 && (B[i] ^ B[k])) {\n que.insertBack(tuple(i, 2));\n ans[i] = 1;\n }\n }\n\n while (!que.empty) {\n auto t = que.front;\n auto i = t[0];\n auto d = t[1];\n que.removeFront;\n foreach (j; G[i]) {\n if (ans[j] == -1) {\n ans[j] = d;\n que.insertBack(tuple(j, d + 1));\n }\n }\n }\n\n ans.map!(to!string).join(\" \").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; }\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\tauto ans = new int[](n);\n\tans[] = int.max;\n\tauto edges = new int[][](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto l = i - a[i];\n\t\tauto r = i + a[i];\n\t\tint u = -1, v = -1;\n\t\tif (l >= 0)\n\t\t{\n\t\t\tif (a[i] % 2 != a[l] % 2)\n\t\t\t\tans[i] = 1;\n\t\t\telse\n\t\t\t\tu = l;\n\t\t}\n\t\tif (r < n)\n\t\t{\n\t\t\tif (a[i] % 2 != a[r] % 2)\n\t\t\t\tans[i] = 1;\n\t\t\telse\n\t\t\t\tv = r;\n\t\t}\n\t\tif (ans[i] != 1)\n\t\t{\n\t\t\tif (u != -1)\n\t\t\t\tedges[u] ~= i;\n\t\t\tif (v != -1)\n\t\t\t\tedges[v] ~= i;\n\t\t\tif (u == -1 && v == -1)\n\t\t\t\tans[i] = -1;\n\t\t}\n\t}\n\n\tint[][] open;\n\tforeach (i; 0..n)\n\t{\n\t\tif (ans[i] == 1)\n\t\t{\n\t\t\topen ~= [i, 1];\n\t\t}\n\t}\n\t\n\twhile (!open.empty)\n\t{\n\t\tauto nd = open.front; open.popFront;\n\t\tauto from = nd[0];\n\t\tauto c = nd[1];\n\t\tforeach (to; edges[from])\n\t\t{\n\t\t\tif (c+1 < ans[to])\n\t\t\t{\n\t\t\t\tans[to] = c + 1;\n\t\t\t\topen ~= [to, c + 1];\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (ref e; ans)\n\t\tif (e == int.max)\n\t\t\te = -1;\n\n\tans.map!(to!string).join(\" \").writeln;\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\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto a = RDA!int;\n\tauto ans = new int[](n);\n\tans[] = int.max;\n\tauto edges = new int[][](n);\n\tforeach (i; 0..n)\n\t{\n\t\tauto l = i - a[i];\n\t\tauto r = i + a[i];\n\t\tint u = -1, v = -1;\n\t\tif (l >= 0)\n\t\t{\n\t\t\tif (a[i] % 2 != a[l] % 2)\n\t\t\t\tans[i] = 1;\n\t\t\telse\n\t\t\t\tu = l;\n\t\t}\n\t\tif (r < n)\n\t\t{\n\t\t\tif (a[i] % 2 != a[r] % 2)\n\t\t\t\tans[i] = 1;\n\t\t\telse\n\t\t\t\tv = r;\n\t\t}\n\t\tif (ans[i] != 1)\n\t\t{\n\t\t\tif (u != -1)\n\t\t\t\tedges[u] ~= i;\n\t\t\tif (v != -1)\n\t\t\t\tedges[v] ~= i;\n\t\t\tif (u == -1 && v == -1)\n\t\t\t\tans[i] = -1;\n\t\t}\n\t}\n\n\tint[][] open;\n\tforeach (i; 0..n)\n\t{\n\t\tif (ans[i] == 1)\n\t\t{\n\t\t\topen ~= [i, 1];\n\t\t}\n\t}\n\t\n\twhile (!open.empty)\n\t{\n\t\tauto nd = open.front; open.popFront;\n\t\tauto from = nd[0];\n\t\tauto c = nd[1];\n\t\tforeach (to; edges[from])\n\t\t{\n\t\t\tif (c+1 < ans[to])\n\t\t\t{\n\t\t\t\tans[to] = c + 1;\n\t\t\t\topen ~= [to, c + 1];\n\t\t\t}\n\t\t}\n\t}\n\n\tans.map!(to!string).join(\" \").writeln;\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "9271c88a3bc3c69855daeda9bb6bbaf5"} {"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 writeln((N+1)/2-1);\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 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) / 2);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i= 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\tif (n <= 2) continue;\n\n\t\tauto half = n / 2 - (n % 2 == 0 ? 1 : 0);\n\t\tans[ti] = half;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "b69170c8377623beb66db4706a02ffc6"} {"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 T = new int[][N];\n foreach (i; 0 .. N - 1) {\n int u, v; scanf(\"%d %d\\n\", &u, &v);\n u--; v--;\n T[u] ~= v;\n T[v] ~= u;\n }\n auto I = readln.chomp.split(\" \").map!(to!int).array;\n auto G = readln.chomp.split(\" \").map!(to!int).array;\n\n auto used = new bool[N];\n int[] ans;\n void dfs(int v, bool a, bool b) {\n if (a) I[v] = !I[v];\n used[v] = true;\n if (I[v] != G[v]) { ans ~= v + 1; a = !a;}\n foreach (next; T[v]) {\n if (used[next]) continue;\n dfs(next, b, a);\n }\n }\n dfs(0, false, false);\n writefln(\"%d\", ans.length);\n writefln(\"%(%s\\n%)\", ans);\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;\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--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\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}\n\n\t\tauto q = new int [n];\n\t\tforeach (ref x; q)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\tint [] ans;\n\n\t\tvoid recur (int v, int w, int z0, int z1)\n\t\t{\n\t\t\tif (z0 ^ (p[v] != q[v]))\n\t\t\t{\n\t\t\t\tans ~= v + 1;\n\t\t\t\tz0 ^= 1;\n\t\t\t}\n\n\t\t\tforeach (u; a[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, z1, z0);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0, NA, 0, 0);\n\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%s\\n%)\", ans);\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.range;\nimport std.conv;\n\nstruct node {\n bool visited;\n int[] child;\n}\n\n__gshared {\n node[] tree;\n int[] diff;\n int answer;\n int[] answerlist;\n}\n\nvoid dfs(int v, bool iseven, bool evenpar, bool oddpar) {\n tree[v].visited = true;\n if (iseven) {\n if (diff[v] != evenpar) {\n answer += 1;\n answerlist ~= v;\n evenpar = !evenpar;\n }\n }\n else {\n if (diff[v] != oddpar) {\n answer += 1;\n answerlist ~= v;\n oddpar = !oddpar;\n }\n }\n foreach (i; tree[v].child) {\n if (!tree[i].visited) dfs(i, !iseven, evenpar, oddpar);\n }\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n;\n readf(\" %s\\n\", &n);\n tree.length = n + 1;\n diff.length = n + 1;\n foreach (i; 1 .. n) {\n int u, v;\n readf(\" %s %s\\n\", &u, &v);\n tree[u].child ~= v;\n tree[v].child ~= u;\n }\n foreach (i; 1 .. n + 1) {\n readf(\" %s\", &diff[i]);\n }\n readf(\"\\n\");\n foreach (i; 1 .. n + 1) {\n int b;\n readf(\" %s\", &b);\n diff[i] = diff[i] ^ b;\n }\n dfs(1, true, false, false);\n writeln(answer);\n foreach (i; answerlist) writeln(i);\n\n return 0;\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 T = new int[][N];\n foreach (i; 0 .. N - 1) {\n int u, v; scanf(\"%d %d\\n\", &u, &v);\n u--; v--;\n T[u] ~= v;\n T[v] ~= u;\n }\n auto I = readln.chomp.split(\" \").map!(to!int).array;\n auto G = readln.chomp.split(\" \").map!(to!int).array;\n\n auto used = new bool[N];\n int[] ans;\n void dfs(int v, bool a, bool b) {\n if (a) { I[v] = !I[v]; }\n used[v] = true;\n foreach (next; T[v]) {\n if (used[next]) continue;\n if (I[next] == G[next]) {\n dfs(next, b, a);\n } else {\n ans ~= next + 1;\n dfs(next, !b, a);\n }\n }\n }\n dfs(0, I[0] != G[0], false);\n writefln(\"%d\", ans.length);\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 int N; scanf(\"%d\\n\", &N);\n auto T = new int[][N];\n foreach (i; 0 .. N - 1) {\n int u, v; scanf(\"%d %d\\n\", &u, &v);\n u--; v--;\n T[u] ~= v;\n T[v] ~= u;\n }\n auto I = readln.chomp.split(\" \").map!(to!int).array;\n auto G = readln.chomp.split(\" \").map!(to!int).array;\n\n auto used = new bool[N];\n int[] ans;\n void dfs(int v, bool a, bool b) {\n foreach (next; T[v]) {\n if (used[next]) continue;\n used[next] = true;\n if (I[next] == G[next]) {\n dfs(next, b, a);\n } else {\n ans ~= next + 1;\n I[next] = !I[next];\n dfs(next, !b, a);\n }\n }\n }\n used[0] = true;\n dfs(0, I[0] != G[0], false);\n writefln(\"%d\", ans.length);\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 int N; scanf(\"%d\\n\", &N);\n auto T = new int[][N];\n foreach (i; 0 .. N - 1) {\n int u, v; scanf(\"%d %d\\n\", &u, &v);\n u--; v--;\n T[u] ~= v;\n T[v] ~= u;\n }\n auto I = readln.chomp.split(\" \").map!(to!int).array;\n auto G = readln.chomp.split(\" \").map!(to!int).array;\n\n auto used = new bool[N];\n int[] ans;\n void dfs(int v, bool a, bool b) {\n foreach (next; T[v]) {\n if (used[next]) continue;\n used[next] = true;\n if (I[next] == G[next]) {\n dfs(next, b, a);\n } else {\n ans ~= next + 1;\n I[next] = !I[next];\n dfs(next, !b, a);\n }\n }\n }\n used[0] = true;\n if (I[0] != G[0]) {\n ans ~= 1;\n I[0] = !I[0];\n dfs(0, true, false);\n } else {\n dfs(0, false, false);\n }\n writefln(\"%d\", ans.length);\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 int N; scanf(\"%d\\n\", &N);\n auto T = new int[][N];\n foreach (i; 0 .. N - 1) {\n int u, v; scanf(\"%d %d\\n\", &u, &v);\n u--; v--;\n T[u] ~= v;\n T[v] ~= u;\n }\n auto I = readln.chomp.split(\" \").map!(to!int).array;\n auto G = readln.chomp.split(\" \").map!(to!int).array;\n\n auto used = new bool[N];\n int[] ans;\n void dfs(int v, bool a, bool b) {\n if (a) { I[v] = !I[v]; }\n foreach (next; T[v]) {\n if (used[next]) continue;\n used[next] = true;\n if (I[next] == G[next]) {\n dfs(next, b, a);\n } else {\n ans ~= next + 1;\n dfs(next, !b, a);\n }\n }\n }\n used[0] = true;\n dfs(0, I[0] != G[0], false);\n writefln(\"%d\", ans.length);\n writefln(\"%(%s\\n%)\", ans);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.range;\nimport std.conv;\n\nstruct node {\n int[] child;\n}\n\n__gshared {\n node[] tree;\n int[] diff;\n int answer;\n int[] answerlist;\n}\n\nvoid dfs(int v, bool iseven, bool evenpar, bool oddpar) {\n if (iseven) {\n if (diff[v] != evenpar) {\n answer += 1;\n answerlist ~= v;\n evenpar = !evenpar;\n }\n }\n else {\n if (diff[v] != oddpar) {\n answer += 1;\n answerlist ~= v;\n oddpar = !oddpar;\n }\n }\n foreach (i; tree[v].child) dfs(i, !iseven, evenpar, oddpar);\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n;\n readf(\" %s\\n\", &n);\n tree.length = n + 1;\n diff.length = n + 1;\n foreach (i; 1 .. n) {\n int u, v;\n readf(\" %s %s\\n\", &u, &v);\n int p = min(u, v);\n int c = max(u, v);\n tree[p].child ~= c;\n }\n foreach (i; 1 .. n + 1) {\n readf(\" %s\", &diff[i]);\n }\n readf(\"\\n\");\n foreach (i; 1 .. n + 1) {\n int b;\n readf(\" %s\", &b);\n diff[i] = diff[i] ^ b;\n }\n dfs(1, true, false, false);\n writeln(answer);\n foreach (i; answerlist) writeln(i);\n\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.range;\nimport std.conv;\n\nstruct node {\n int[] child;\n}\n\n__gshared node[] tree;\n__gshared int[] diff;\n__gshared int answer;\n__gshared int[] answerlist;\n\nvoid dfs(int v, bool iseven, bool evenpar, bool oddpar) {\n if (iseven) {\n if (diff[v] != evenpar) {\n answer += 1;\n answerlist ~= v;\n evenpar = !evenpar;\n }\n }\n else {\n if (diff[v] != oddpar) {\n answer += 1;\n answerlist ~= v;\n oddpar = !oddpar;\n }\n }\n foreach (i; tree[v].child) dfs(i, !iseven, evenpar, oddpar);\n}\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int n;\n readf(\" %s\\n\", &n);\n tree.length = n + 1;\n diff.length = n + 1;\n foreach (i; 1 .. n) {\n int u, v;\n readf(\" %s %s\\n\", &u, &v);\n int p = min(u, v);\n int c = max(u, v);\n tree[p].child ~= c;\n }\n foreach (i; 1 .. n + 1) {\n readf(\" %s\", &diff[i]);\n }\n readf(\"\\n\");\n foreach (i; 1 .. n + 1) {\n int b;\n readf(\" %s\", &b);\n diff[i] = diff[i] ^ b;\n }\n dfs(1, true, false, false);\n writeln(answer);\n foreach (i; answerlist) writeln(i);\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 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--;\n\t\t\tv--;\n\t\t\ta[u] ~= v;\n\t\t\ta[v] ~= u;\n\t\t}\n\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}\n\n\t\tauto q = new int [n];\n\t\tforeach (ref x; q)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\tint [] ans;\n\n\t\tvoid recur (int v, int w, int z)\n\t\t{\n\t\t\tif (z ^ (p[v] != q[v]))\n\t\t\t{\n\t\t\t\tans ~= v + 1;\n\t\t\t\tz ^= 1;\n\t\t\t}\n\n\t\t\tforeach (u; a[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, z);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trecur (0, NA, 0);\n\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%s\\n%)\", ans);\n\t}\n}\n"}], "src_uid": "f3a27e4dc3085712608ecf844e663dfd"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tlong cnt0, cnt1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '<')\n\t\t\t\t++cnt0;\n\t\t\telse if (s[i] == '>')\n\t\t\t\t++cnt1;\n\t\t\tif (s[(n+i-1)%n] == '-' || s[i] == '-')\n\t\t\t\t++ans[ti];\n\t\t}\n\n\t\tif (cnt0 == 0 || cnt1 == 0)\n\t\t\tans[ti] = n;\n\t}\n\n\tforeach (e; ans)\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.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 s = readln.strip;\n\t\tif (s.all !(q{a != '>'}) || s.all !(q{a != '<'}))\n\t\t{\n\t\t\twriteln (n);\n\t\t\tcontinue;\n\t\t}\n\t\tint res = n;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] != '-' && s[(i + 1) % n] != '-')\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"}], "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\tauto n = readln.strip.to !(int);\n\t\tauto s = readln.strip;\n\t\tint res = n;\n\t\tif (s.all !(q{a == '>'}) || s.all !(q{a == '<'}))\n\t\t{\n\t\t\twriteln (n);\n\t\t\tcontinue;\n\t\t}\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] != '-' && s[(i + 1) % n] != '-')\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, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tans[ti] = n;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[(n+i-1)%n] == '<' && s[i] == '>')\n\t\t\t\t--ans[ti];\n\t\t\telse if (s[(n+i-1)%n] == '>' && s[i] == '<')\n\t\t\t\t--ans[ti];\n\t\t}\n\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\t\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "f82685f41f4ba1146fea8e1eb0c260dc"} {"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 K = s[2];\n auto A = readln.split.map!(to!long).array;\n auto X = M.iota.map!(_ => readln.split.map!(to!int).array).array;\n\n A = A.sort().take(K).array;\n auto B = new long[](K+1);\n foreach (i; 0..K) B[i+1] = B[i] + A[i];\n\n auto dp = new long[](K+1);\n dp[] = 1L << 59;\n dp[0] = 0;\n\n foreach (i; 0..K) {\n dp[i+1] = min(dp[i+1], dp[i] + A[i]);\n foreach (x; X) {\n if (i + x[0] <= K) {\n dp[i+x[0]] = min(dp[i+x[0]], dp[i] + B[i+x[0]] - B[i+x[1]]);\n }\n }\n }\n\n dp[K].writeln;\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\n\tlong n = read!long;\n\tlong m = read!long;\n\tint k = read!int;\n\tlong[] as = read!long(n);\n\tlog(\"as:\", as);\n\n\tas.sort();\n\tas = as[0 .. k];\n\tlog(\"as:\", as);\n\n\tint[] qs = new int[](k + 10);\n\tforeach(i; 0 .. m){\n\t\tint x = read!int;\n\t\tint y = read!int;\n\t\tif(x > k) continue;\n\t\tif(qs[x] < y) qs[x] = y;\n\t}\n\tlog(\"qs:\", qs);\n\n\n\tlong[] us = new long[](k + 10);\n\tus[0] = 0;\n\tforeach(i; 1 .. k + 1){\n\t\tforeach(j; 0 .. i){\n\t\t\tint y = qs[i - j];\n\t\t\tlong u = us[j] + as[j .. j + y].sum;\n\t\t\tif(u > us[i]) us[i] = u;\n\t\t\tlog(\"i:\", i, \"j:\", j, \"u:\", u);\n\t\t}\n\t}\n\tlog(\"us:\", us);\n\n\t(as.sum - us[k]).writeln;\n\n}"}], "negative_code": [], "src_uid": "60f377a15c6b15f649159af6272e9d02"} {"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;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;alias rbt=RedBlackTree;\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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*max(k-x,0)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tdebug enter(pos);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//alias true=false;\n\t\tdebug enter(s.length,' ',y);\n\t\trbt!(lint,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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--------------------------\npublic\n{\n\t\n}\nvoid main()\n{\n\tversion(home)\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\tdebug\n\t{\n\t\tStopWatch sw;\n\t\tsw.start;\n\t\tscope(exit)\n\t\t{\n\t\t\tsw.stop;\n\t\t\tstderr.writefln(\"Time: %d ms\",sw.peek.msecs);\n\t\t}\n\t}\n\tint n,k,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*max(k-x,0)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tdebug enter(pos);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//alias true=false;\n\t\tdebug enter(s.length,' ',y);\n\t\trbt!(lint,\"a 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\nenum { NONE, M, A, BOTH }\n\nint n, m, k;\nint[2 * 10^^5] prices;\nubyte[2 * 10^^5] masks;\nint[ ][4] things;\n\nvoid main() {\n while (read(n, m, k)) {\n version (LocalProject) {\n masks[ ] = 0x0;\n things[ ] = null;\n }\n foreach (ref x; prices[0 .. n])\n read(x);\n int a;\n foreach (i; 0x1 .. 0x3) {\n read(a);\n int x;\n while (a--) {\n read(x);\n masks[x - 1] |= i;\n }\n }\n foreach (i; 0 .. n)\n things[masks[i]] ~= prices[i];\n things.each!sort();\n\n ulong[4] sums;\n int[4] ind;\n\n void increase3(int count) {\n while (count--) {\n int best = int.max, bestI = -1;\n if (ind[NONE] < things[NONE].length) {\n best = things[NONE][ind[NONE]];\n bestI = NONE;\n }\n if (ind[M] < things[M].length && things[M][ind[M]] < best) {\n best = things[M][ind[M]];\n bestI = M;\n }\n if (ind[A] < things[A].length && things[A][ind[A]] < best) {\n best = things[A][ind[A]];\n bestI = A;\n }\n if (!~bestI)\n break;\n sums[bestI] += best;\n ind[bestI]++;\n }\n }\n\n void decrease3(int count) {\n const lim = max(0, k - ind[BOTH]);\n while (count--) {\n int best = -1, bestI = -1;\n if (ind[NONE]) {\n best = things[NONE][ind[NONE] - 1];\n bestI = NONE;\n }\n if (ind[M] > lim && things[M][ind[M] - 1] > best) {\n best = things[M][ind[M] - 1];\n bestI = M;\n }\n if (ind[A] > lim && things[A][ind[A] - 1] > best) {\n best = things[A][ind[A] - 1];\n bestI = A;\n }\n if (!~bestI)\n break;\n sums[bestI] -= best;\n ind[bestI]--;\n }\n }\n\n bool isValid() {\n return ind[M] + ind[BOTH] >= k && ind[A] + ind[BOTH] >= k && sum(ind[ ]) == m;\n }\n\n ind[M] = min(k, things[M].length);\n ind[A] = min(k, things[A].length);\n foreach (x; things[M][0 .. ind[M]])\n sums[M] += x;\n foreach (x; things[A][0 .. ind[A]])\n sums[A] += x;\n ulong result = ulong.max;\n if (ind[M] == k && ind[A] == k && m >= k << 1) {\n increase3(m - (k << 1));\n if (isValid())\n result = sum(sums[ ]);\n }\n for (ind[BOTH] = 1; ind[BOTH] <= things[BOTH].length; ind[BOTH]++) {\n sums[BOTH] += things[BOTH][ind[BOTH] - 1];\n decrease3(3);\n increase3(3);\n int taken = sum(ind[ ]);\n if (taken > m)\n decrease3(taken - m);\n else if (taken < m)\n increase3(m - taken);\n if (isValid())\n result = min(result, sum(sums[ ]));\n }\n writeln(cast(long)result);\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\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\nenum { NONE, M, A, BOTH }\n\nint n, m, k;\nint[2 * 10^^5] prices;\nubyte[2 * 10^^5] masks;\nint[ ][4] things;\n\nvoid main() {\n while (read(n, m, k)) {\n version (LocalProject) {\n masks[ ] = 0x0;\n things[ ] = null;\n }\n foreach (ref x; prices[0 .. n])\n read(x);\n int a;\n foreach (i; 0x1 .. 0x3) {\n read(a);\n int x;\n while (a--) {\n read(x);\n masks[x - 1] |= i;\n }\n }\n foreach (i; 0 .. n)\n things[masks[i]] ~= prices[i];\n foreach (i; 0 .. 4)\n things[i].sort();\n\n ulong[4] sums;\n int[4] ind;\n\n void increase3(int count) {\n while (count--) {\n int best = int.max, bestI = -1;\n if (ind[NONE] < things[NONE].length) {\n best = things[NONE][ind[NONE]];\n bestI = NONE;\n }\n if (ind[M] < things[M].length && things[M][ind[M]] < best) {\n best = things[M][ind[M]];\n bestI = M;\n }\n if (ind[A] < things[A].length && things[A][ind[A]] < best) {\n best = things[A][ind[A]];\n bestI = A;\n }\n if (!~bestI)\n break;\n sums[bestI] += things[bestI][ind[bestI]++];\n }\n }\n\n void decrease3(int count) {\n const lim = max(0, k - ind[BOTH]);\n while (count--) {\n int best = -1, bestI = -1;\n if (ind[NONE]) {\n best = things[NONE][ind[NONE] - 1];\n bestI = NONE;\n }\n if (ind[M] > lim && things[M][ind[M] - 1] > best) {\n best = things[M][ind[M] - 1];\n bestI = M;\n }\n if (ind[A] > lim && things[A][ind[A] - 1] > best) {\n best = things[A][ind[A] - 1];\n bestI = A;\n }\n if (!~bestI)\n break;\n sums[bestI] -= things[bestI][--ind[bestI]];\n }\n }\n\n bool isValid() {\n return ind[M] + ind[BOTH] >= k && ind[A] + ind[BOTH] >= k && sum(ind[ ]) == m;\n }\n\n ind[M] = min(k, things[M].length);\n ind[A] = min(k, things[A].length);\n foreach (x; things[M][0 .. ind[M]])\n sums[M] += x;\n foreach (x; things[A][0 .. ind[A]])\n sums[A] += x;\n ulong result = ulong.max;\n if (ind[M] == k && ind[A] == k && m >= k << 1) {\n increase3(m - (k << 1));\n if (isValid())\n result = sum(sums[ ]);\n }\n for (ind[BOTH] = 1; ind[BOTH] <= things[BOTH].length; ind[BOTH]++) {\n sums[BOTH] += things[BOTH][ind[BOTH] - 1];\n int taken = sum(ind[ ]);\n if (taken > m)\n decrease3(taken - m);\n else if (taken < m)\n increase3(m - taken);\n if (isValid())\n result = min(result, sum(sums[ ]));\n }\n writeln(cast(long)result);\n }\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;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;alias rbt=RedBlackTree;\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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(int,\"av[3][x])q1.removeBack;\n\t\t\t}\n\t\t\tif(!q1.equalRange(v[3][x]).empty)\n\t\t\t{\n\t\t\t\tq1.removeKey(v[3][x]);\n\t\t\t\tss-=v[3][x];\n\t\t\t}\n\t\t\telse q2.removeKey(v[3][x]);\n\t\t\t//q1.insert(v[3][x]);\n\t\t\twhile(q1.length1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(int,\"a=q1.back)break;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tss-=q1.back;\n\t\t\t\t\tq1.removeBack;\n\t\t\t\t\tss+=q2.front;\n\t\t\t\t\tq1.insert(q2.front);\n\t\t\t\t\tq2.removeFront;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//q1.insert(v[3][x]);\n\t\t\tans=min(ans,ss);\n\t\t\tx++;\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.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;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;alias rbt=RedBlackTree;\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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(int,\"av[3][x])\n\t\t\t\t{\n\t\t\t\t\tss-=q1.back;\n\t\t\t\t\tq1.removeBack;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!q1.equalRange(v[3][x]).empty)\n\t\t\t{\n\t\t\t\tq1.removeKey(v[3][x]);\n\t\t\t\tss-=v[3][x];\n\t\t\t}\n\t\t\telse q2.removeKey(v[3][x]);\n\t\t\t//q1.insert(v[3][x]);\n\t\t\twhile(q1.length1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tdebug enter(pos);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//alias true=false;\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(lint,\"a0)\n\t\t\t{\n\t\t\t\tif(!q1.equalRange(v[3][x]).empty)\n\t\t\t\t{\n\t\t\t\t\tq1.removeKey(v[3][x]);\n\t\t\t\t\tss-=v[3][x];\n\t\t\t\t}\n\t\t\t\telse q2.removeKey(v[3][x]);\n\t\t\t\tss-=v[1][pos-i-1]+v[2][pos-i-1];\n\t\t\t\tq2.insert(v[1][pos-i-1]);\n\t\t\t\tq2.insert(v[2][pos-i-1]);\n\t\t\t\t//y+=2;\n\t\t\t\ty--;\n\t\t\t\tss+=v[3][x];\n\t\t\t\twhile(q1.length1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tdebug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\tdebug enter(s.length,' ',y);\n\t\trbt!(int,\"a=q1.back)break;\n\t\t\tss-=q1.back;\n\t\t\tq1.removeBack;\n\t\t\tss+=v[3][i];\n\t\t\tq1.insert(v[3][i]);\n\t\t\tans=min(ans,ss);\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.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;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;alias rbt=RedBlackTree;\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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(lint,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tdebug enter(pos);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//alias true=false;\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(lint,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(lint,\"a=q1.back && v[3][x]>=q1.back)break;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tq2.insert(v[3][x]);\n\t\t\t\t\tss-=q1.back;\n\t\t\t\t\tq1.removeBack;\n\t\t\t\t\tss+=q2.front;\n\t\t\t\t\tq1.insert(q2.front);\n\t\t\t\t\tq2.removeFront;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//q1.insert(v[3][x]);\n\t\t\tans=min(ans,ss);\n\t\t\tx++;\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.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;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;alias rbt=RedBlackTree;\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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tdebug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]);\n\t\tsort(s);\n\t\tdebug enter(s.length,' ',y);\n\t\trbt!(int,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m);\n\t\tif(min(k,sz(v[1]))+min(k,sz(v[2]))+x+sz(v[0])v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tint pos=k-x;\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]);\n\t\tsort(s);\n\t\tdebug enter(s.length,' ',y);\n\t\trbt!(int,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(int,\"a=q1.back)break;\n\t\t\tss-=q1.back;\n\t\t\tq1.removeBack;\n\t\t\tss+=v[3][i];\n\t\t\tq1.insert(v[3][i]);\n\t\t\tans=min(ans,ss);\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.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;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;alias rbt=RedBlackTree;\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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(int,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tdebug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]);\n\t\tsort(s);\n\t\tdebug enter(s.length,' ',y);\n\t\trbt!(int,\"a=q1.back)break;\n\t\t\tss-=q1.back;\n\t\t\tq1.removeBack;\n\t\t\tss+=v[3][i];\n\t\t\tq1.insert(v[3][i]);\n\t\t\tans=min(ans,ss);\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.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;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;alias rbt=RedBlackTree;\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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(lint,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]~v[3][x..$]);\n\t\tsort(s);\n\t\t//alias true=false;\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(lint,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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...)(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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!lint;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new lint[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\t//debug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]);\n\t\tsort(s);\n\t\t//debug enter(s.length,' ',y);\n\t\trbt!(lint,\"a=q1.back)break;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tq2.insert(v[3][x]);\n\t\t\t\t\tss-=q1.back;\n\t\t\t\t\tq1.removeBack;\n\t\t\t\t\tss+=q2.front;\n\t\t\t\t\tq1.insert(q2.front);\n\t\t\t\t\tq2.removeFront;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//q1.insert(v[3][x]);\n\t\t\tans=min(ans,ss);\n\t\t\tx++;\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.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;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;alias rbt=RedBlackTree;\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(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tdebug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]);\n\t\tsort(s);\n\t\tdebug enter(s.length,' ',y);\n\t\trbt!(int,\"a1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 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\t\n}\nvoid main()\n{\n\tversion(home)\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,m;\nloop:while(read(n,m,k))\n\t{\n\t\tauto c=arread!int;\n\t\tint a;\n\t\tread(a);\n\t\tauto ma=arread!int;\n\t\tint b;\n\t\tread(b);\n\t\tauto mb=arread!int;\n\t\tauto u=new int[c.length];\n\t\tforeach(x;ma)\n\t\t{\n\t\t\tu[x-1]+=1;\n\t\t}\n\t\tforeach(x;mb)\n\t\t{\n\t\t\tu[x-1]+=2;\n\t\t}\n\t\tauto v=new int[][4];\n\t\tforeach(i;0..c.length)\n\t\t{\n\t\t\tv[u[i]]~=c[i];\n\t\t}\n\t\tv.each!sort;\n\t\tint x=max(0,k-sz(v[1]),k-sz(v[2]),2*k-m,m-sz(v[0])-sz(v[1])-sz(v[2]));\n\t\tif(2*(k-x)+x>m)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tif(x>v[3].length)\n\t\t{\n\t\t\twriteln(-1);\n\t\t\tcontinue loop;\n\t\t}\n\t\tdebug writeln(x);\n\t\tint pos=max(k-x,0);\n\t\tint y=m-(2*pos+x);\n\t\tauto s=(v[0]~v[1][pos..$]~v[2][pos..$]);\n\t\tsort(s);\n\t\tdebug enter(s.length,' ',y);\n\t\trbt!(int,\"a=q1.back)break;\n\t\t\tss-=q1.back;\n\t\t\tq1.removeBack;\n\t\t\tss+=v[3][i];\n\t\t\tq1.insert(v[3][i]);\n\t\t\tans=min(ans,ss);\n\t\t}\n\t\twriteln(ans);\n\t}\n}"}], "src_uid": "9091de9fad568e353d7b3462cebe2571"} {"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[] 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\nvoid CF138C()\n{\n bool t(char c)\n {\n return (c=='(')||(c==')');\n }\n char[] s = nlongs();\n auto n = s.length;\n int[] stack = [], ans = new int[n];\n int[] ke = new int[n];for(int i=0;i0)&&(t(s[stack[stack.length-1]])==t(s[i])))\n {\n ans[stack[stack.length-1]] = i;\n --stack.length;\n }\n else stack.length = 0;\n }\n }\n //writeln(ke);\n //writeln(ans);\n int cur = 0;\n while (cur0)\n {\n int end = ans[cur];\n while ((end0)) end = ans[end+1];\n ans[cur] = end;\n cur = end+1;\n }\n else ++cur;\n }\n //writeln(ans);\n int[] cnt = new int[n];\n cnt[0]=s[0]=='['?1:0;\n for (int i=1;i m){tt = i; m = count(i);}\n //writeln(s);\n writeln(m);\n if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);\n}\n\nvoid main()\n{\n CF138C();\n}", "positive_code": [{"source_code": "import std.c.stdio;\n\nvoid CF138C()\n{\n pure bool t (char c)\n {\n return (c == '(') || (c == ')');\n }\n char[100000] s;\n int len = 0;\n int cs = getchar();\n\n do\n {\n s[len] = cast (char) cs;\n cs = getchar();\n ++len;\n }\n while (32 < cs);\n\n auto n = len;\n int[100000] stack, ans, cnt;\n int cc = 0;\n\n for (int i = 0; i < n; ++i)\n {\n if ((s[i] == '(') || (s[i] == '['))\n {\n stack[cc] = i;\n ++cc;\n }\n else\n {\n if ((cc > 0) && (t (s[stack[cc - 1]]) == t (s[i])))\n {\n ans[stack[cc - 1]] = i;\n --cc;\n }\n else cc = 0;\n }\n }\n\n int cur = 0;\n\n while (cur < n)\n {\n if (ans[cur] > 0)\n {\n int end = ans[cur];\n\n while ((end < n - 1) && (ans[end+1] > 0))\n end = ans[end+1];\n\n ans[cur] = end;\n cur = end + 1;\n }\n else ++cur;\n }\n\n cnt[0] = s[0] == '[' ? 1 : 0;\n\n for (int i = 1; i < n; ++i)\n cnt[i] = cnt[i-1] + (s[i] == '[' ? 1 : 0);\n\n int count (int h)\n {\n if (ans[h] != 0)\n return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);\n else return 0;\n }\n int tt = -1, m = 0;\n\n for (int i = 0; i < n; ++i)\n if (count (i) > m)\n {\n tt = i;\n m = count (i);\n }\n\n printf(\"%d\\n\", m);\n\n if (m > 0) printf(\"%.*s\\n\", s[tt..ans[tt] + 1]);\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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[] nlongs()\n{\n sb();\n auto res = appender!(char[])();\n do\n {\n res.put(cast(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\nvoid CF138C()\n{\n bool t(char c)\n {\n return (c=='(')||(c==')');\n }\n char[100000] s;int len=0;int cs=getchar();do{s[len]=cast(char)cs;cs=getchar();++len;}while(320)&&(t(s[stack[/*stack.length*/cc-1]])==t(s[i])))\n {\n ans[stack[/*stack.length*/cc-1]] = i;\n --cc;//--stack.length;\n }\n else cc=0;//stack.length = 0;\n }\n }\n //writeln(ke);\n //writeln(ans);\n int cur = 0;\n while (cur0)\n {\n int end = ans[cur];\n while ((end0)) end = ans[end+1];\n ans[cur] = end;\n cur = end+1;\n }\n else ++cur;\n }\n //writeln(ans);\n //int[] cnt = new int[n];\n cnt[0]=s[0]=='['?1:0;\n for (int i=1;i m){tt = i; m = count(i);}\n //writeln(s);\n writeln(m);\n if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"source_code": "//test\nimport std.c.stdio;\n\nvoid CF138C()\n{\n pure bool t (char c)\n {\n return (c == '(') || (c == ')');\n }\n char[100000] s;\n int len = 0;\n int cs = getchar();\n\n do\n {\n s[len] = cast (char) cs;\n cs = getchar();\n ++len;\n }\n while (32 < cs);\n\n auto n = len;\n int[100000] stack, ans, cnt;\n int cc = 0;\n\n for (int i = 0; i < n; ++i)\n {\n if ((s[i] == '(') || (s[i] == '['))\n {\n stack[cc] = i;\n ++cc;\n }\n else\n {\n if ((cc > 0) && (t (s[stack[cc - 1]]) == t (s[i])))\n {\n ans[stack[cc - 1]] = i;\n --cc;\n }\n else cc = 0;\n }\n }\n\n int cur = 0;\n\n while (cur < n)\n {\n if (ans[cur] > 0)\n {\n int end = ans[cur];\n\n while ((end < n - 1) && (ans[end+1] > 0))\n end = ans[end+1];\n\n ans[cur] = end;\n cur = end + 1;\n }\n else ++cur;\n }\n\n cnt[0] = s[0] == '[' ? 1 : 0;\n\n for (int i = 1; i < n; ++i)\n cnt[i] = cnt[i-1] + (s[i] == '[' ? 1 : 0);\n\n int count (int h)\n {\n if (ans[h] != 0)\n return cnt[ans[h]] - cnt[h] + (s[h] == '[' ? 1 : 0);\n else return 0;\n }\n int tt = -1, m = 0;\n\n for (int i = 0; i < n; ++i)\n if (count (i) > m)\n {\n tt = i;\n m = count (i);\n }\n\n printf(\"%d\\n\", m);\n\n if (m > 0) printf(\"%.*s\\n\", s[tt..ans[tt] + 1]);\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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[] 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\nvoid CF138C()\n{\n bool t(char c)\n {\n return (c=='(')||(c==')');\n }\n char[] s = ns();\n auto n = s.length;\n int[] stack = [], ans = new int[n];\n int[] ke = new int[n];for(int i=0;i0)&&(t(s[stack[stack.length-1]])==t(s[i])))\n {\n ans[stack[stack.length-1]] = i;\n --stack.length;\n }\n else stack.length = 0;\n }\n }\n //writeln(ke);\n //writeln(ans);\n int cur = 0;\n while (cur0)\n {\n int end = ans[cur];\n while ((end0)) end = ans[end+1];\n ans[cur] = end;\n cur = end+1;\n }\n else ++cur;\n }\n //writeln(ans);\n int[] cnt = new int[n];\n cnt[0]=s[0]=='['?1:0;\n for (int i=1;i m){tt = i; m = count(i);}\n //writeln(s);\n writeln(m);\n if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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[] nlongs()\n{\n sb();\n auto res = appender!(char[])();\n do\n {\n res.put(cast(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\nvoid CF138C()\n{\n bool t(char c)\n {\n return (c=='(')||(c==')');\n }\n char[] s = nlongs();\n auto n = s.length;\n int[] stack = new int[n], ans = new int[n];\n int cc = 0;\n int[] ke = new int[n];for(int i=0;i0)&&(t(s[stack[/*stack.length*/cc-1]])==t(s[i])))\n {\n ans[stack[/*stack.length*/cc-1]] = i;\n --cc;//--stack.length;\n }\n else cc=0;//stack.length = 0;\n }\n }\n //writeln(ke);\n //writeln(ans);\n int cur = 0;\n while (cur0)\n {\n int end = ans[cur];\n while ((end0)) end = ans[end+1];\n ans[cur] = end;\n cur = end+1;\n }\n else ++cur;\n }\n //writeln(ans);\n int[] cnt = new int[n];\n cnt[0]=s[0]=='['?1:0;\n for (int i=1;i m){tt = i; m = count(i);}\n //writeln(s);\n writeln(m);\n if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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[] nlongs()\n{\n sb();\n auto res = appender!(char[])();\n do\n {\n res.put(cast(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\nvoid CF138C()\n{\n bool t(char c)\n {\n return (c=='(')||(c==')');\n }\n char[] s = nlongs();\n auto n = s.length;\n int[] stack = [], ans = new int[n];\n int[] ke = new int[n];for(int i=0;i0)&&(t(s[stack[stack.length-1]])==t(s[i])))\n {\n ans[stack[stack.length-1]] = i;\n --stack.length;\n }\n else stack.length = 0;\n }\n }\n //writeln(ke);\n //writeln(ans);\n int cur = 0;\n while (cur0)\n {\n int end = ans[cur];\n while ((end0)) end = ans[end+1];\n ans[cur] = end;\n cur = end+1;\n }\n else ++cur;\n }\n //writeln(ans);\n int[] cnt = new int[n];\n cnt[0]=s[0]=='['?1:0;\n for (int i=1;i m){tt = i; m = count(i);}\n //writeln(s);\n writeln(m);\n if ((m>0)/*&&(ans[tt]-tt>1)*/)writeln(s[tt..ans[tt]+1]);\n}\n\nvoid main()\n{\n CF138C();\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 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\nlong nl ()\n{\n sb ();\n long res = 0;\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 * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n else\n {\n do\n {\n res = res * 10 - cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n return res;\n}\n\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\n return res;\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\nvoid CF138C()\n{\n pure int t(char c)\n {\n switch (c)\n {\n case '(':\n return 0;\n case ')':\n return 0;\n case '[':\n return 1;\n case ']':\n return 1;\n default:\n return 2;\n }\n }\n\n pure int open(char c)\n {\n switch (c)\n {\n case '(':\n return 1;\n case '[':\n return 1;\n case '{':\n return 1;\n default:\n return -1;\n }\n }\n\n alias int[] tuple;\n\n char[] s = nlongs();\n auto n = s.length;\n tuple[] stack = new tuple[n + 1];\n int cur = 0;\n bool[] ans = new bool[s.length];\n for (int i = 0; i < n; ++i)\n {\n //writeln(i);\n //writeln(s[0..i+1]);\n //writeln(stack[0 .. cur + 1]);\n if (cur == 0)\n {\n if (open(s[i]) == 1)\n stack[cur] = [t(s[i]), 1, i, i];\n ++cur;\n }\n else\n {\n if (stack[cur - 1][1] < 0)\n cur = 0;\n else if (t(s[i]) == stack[cur - 1][0])\n {\n stack[cur - 1][1] += open(s[i]);\n stack[cur - 1][3] = i;\n }\n else\n {\n if (open(s[i]) == 1) { stack[cur] = [t(s[i]), 1, i, i]; ++cur; }\n else\n {\n if ((cur == 0) || (t(s[i]) != stack[cur - 1][0]))\n cur = 0;\n else\n {\n --stack[cur - 1][1];\n stack[cur - 1][3] = i;\n }\n }\n }\n if ((cur > 0) && (stack[cur - 1][1] == 0))\n {\n //writeln(stack[cur - 1], \" \", s[stack[cur - 1][2] .. stack[cur - 1][3] + 1]);\n if (!ans[stack[cur - 1][2]])\n for (int j = stack[cur - 1][2]; j <= stack[cur - 1][3]; ++j)\n ans[j] = true;\n --cur;\n }\n }\n //writeln(stack[0 .. cur + 1]);\n //writeln();\n }\n int ansi = -1, ansj = -1, count = 0, i = 1;\n while (i < n)\n {\n if (ans[i])\n {\n auto j = i;\n int cnt = 0;\n while ((j < n) && ans[j])\n {\n if (s[j] =='[') ++cnt;\n ++j;\n }\n if (cnt > count)\n {\n ansi = i;\n ansj = j;\n count = cnt;\n }\n i = j;\n }\n else ++i;\n }\n printf(\"%d\\n\", count);\n if (count > 0) printf(\"%.*s\\n\", s[ansi .. ansj]);\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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 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\nlong nl ()\n{\n sb ();\n long res = 0;\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 * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n else\n {\n do\n {\n res = res * 10 - cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n return res;\n}\n\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\n return res;\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\nvoid CF138C()\n{\n int t(char c)\n {\n switch (c)\n {\n case '(':\n return 0;\n case ')':\n return 0;\n case '[':\n return 1;\n case ']':\n return 1;\n default:\n return 2;\n }\n }\n\n int open(char c)\n {\n switch (c)\n {\n case '(':\n return 1;\n case '[':\n return 1;\n case '{':\n return 1;\n default:\n return -1;\n }\n }\n\n alias int[] tuple;\n\n char[] s = nlongs();\n auto n = s.length;\n tuple[] stack = [];\n tuple[] stacks = [];\n for (int i = 0; i < n; ++i)\n {\n if (stack.length == 0)\n {\n if (open(s[i]) == 1)\n stack ~= [t(s[i]), 1, i, i];\n }\n else\n {\n if (stack[stack.length - 1][1] < 0)\n stack.length = 0;\n else if (t(s[i]) == stack[stack.length - 1][0])\n {\n stack[stack.length - 1][1] += open(s[i]);\n stack[stack.length - 1][3] = i;\n }\n else\n {\n if (open(s[i]) == 1) stack ~= [t(s[i]), 1, i, i];\n else\n {\n if ((stack.length == 0) || (t(s[i]) != stack[stack.length - 1][0]))\n stack.length = 0;\n else\n {\n --stack[stack.length - 1][1];\n stack[stack.length - 1][3] = i;\n }\n }\n }\n if ((stack.length > 0) && (stack[stack.length - 1][1] == 0))\n {\n stacks ~= stack[stack.length - 1];\n --stack.length;\n }\n }\n }\n int[] cnt = new int[s.length];\n cnt[0] = s[0] =='[' ? 1 : 0;\n for (int i = 1; i < s.length; ++i)\n cnt[i] = cnt[i - 1] + (s[i] == '[' ? 1 : 0);\n\n int count(tuple h)\n {\n return cnt[h[3]] - cnt[h[2]] + (s[h[2]] == '[' ? 1 : 0);\n }\n\n if (stacks.length == 0)\n {\n printf(\"0\\n\");\n }\n else\n {\n auto ans = stacks[0];\n for (int i = 1; i < stacks.length; ++i)\n if ((stacks[i][3] - stacks[i][2] > ans[3] - ans[2]) || ((stacks[i][3] - stacks[i][2] == ans[3] - ans[2]) && (count(stacks[i]) > count(ans))))\n ans = stacks[i];\n printf(\"%d\\n\", count(ans));\n printf(\"%.*s\\n\", s[ans[2] .. ans[3] + 1]);\n }\n}\n\nvoid main()\n{\n CF138C();\n}\n"}, {"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[] 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\nvoid CF138C()\n{\n bool t(char c)\n {\n return (c=='(')||(c==')');\n }\n char[] s = nlongs();\n auto n = s.length;\n int[] stack = [], ans = new int[n];\n int[] ke = new int[n];for(int i=0;i0)&&(t(s[stack[stack.length-1]])==t(s[i])))\n {\n ans[stack[stack.length-1]] = i;\n --stack.length;\n }\n else stack.length = 0;\n }\n }\n //writeln(ke);\n //writeln(ans);\n int cur = 0;\n while (cur0)\n {\n int end = ans[cur];\n while ((end0)) end = ans[end+1];\n ans[cur] = end;\n cur = end+1;\n }\n else ++cur;\n }\n int[] cnt = new int[n];\n cnt[0]=s[0]=='['?1:0;\n for (int i=1;i count(tt)) tt = i;\n //writeln(s);\n writeln(count(tt));\n if (count(tt)>0)writeln(s[tt..ans[tt]+1]);\n}\n\nvoid main()\n{\n CF138C();\n}\n"}, {"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 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\nlong nl ()\n{\n sb ();\n long res = 0;\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 * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n else\n {\n do\n {\n res = res * 10 - cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n return res;\n}\n\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\n return res;\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\nvoid CF138C()\n{\n pure int t(char c)\n {\n switch (c)\n {\n case '(':\n return 0;\n case ')':\n return 0;\n case '[':\n return 1;\n case ']':\n return 1;\n default:\n return 2;\n }\n }\n\n pure int open(char c)\n {\n switch (c)\n {\n case '(':\n return 1;\n case '[':\n return 1;\n case '{':\n return 1;\n default:\n return -1;\n }\n }\n\n alias int[] tuple;\n\n char[] s = \"[\" ~ nlongs() ~ \"]\";\n auto n = s.length;\n tuple[] stack = new tuple[n + 1];\n int cur = 0;\n bool[] ans = new bool[s.length];\n for (int i = 0; i < n; ++i)\n {\n //writeln(i);\n //writeln(s[0..i+1]);\n //writeln(stack[0 .. cur + 1]);\n if (cur == 0)\n {\n if (open(s[i]) == 1)\n stack[cur] = [t(s[i]), 1, i, i];\n ++cur;\n }\n else\n {\n if (stack[cur - 1][1] < 0)\n cur = 0;\n else if (t(s[i]) == stack[cur - 1][0])\n {\n stack[cur - 1][1] += open(s[i]);\n stack[cur - 1][3] = i;\n }\n else\n {\n if (open(s[i]) == 1) { stack[cur] = [t(s[i]), 1, i, i]; ++cur; }\n else\n {\n if ((cur == 0) || (t(s[i]) != stack[cur - 1][0]))\n cur = 0;\n else\n {\n --stack[cur - 1][1];\n stack[cur - 1][3] = i;\n }\n }\n }\n if ((cur > 0) && (stack[cur - 1][1] == 0))\n {\n //writeln(stack[cur - 1], \" \", s[stack[cur - 1][2] .. stack[cur - 1][3] + 1]);\n if (!ans[stack[cur - 1][2]])\n for (int j = stack[cur - 1][2]; j <= stack[cur - 1][3]; ++j)\n ans[j] = true;\n --cur;\n }\n }\n //writeln(stack[0 .. cur + 1]);\n //writeln();\n }\n int ansi = -1, ansj = -1, count = 0, i = 1;\n while (i < n - 1)\n {\n if (ans[i])\n {\n auto j = i;\n int cnt = 0;\n while ((j < n - 1) && ans[j])\n {\n if (s[j] =='[') ++cnt;\n ++j;\n }\n if (cnt > count)\n {\n ansi = i;\n ansj = j;\n count = cnt;\n }\n i = j;\n }\n else ++i;\n }\n printf(\"%d\\n\", count);\n if (count > 0) printf(\"%.*s\\n\", s[ansi .. ansj]);\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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 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\nlong nl ()\n{\n sb ();\n long res = 0;\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 * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n else\n {\n do\n {\n res = res * 10 - cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n return res;\n}\n\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\n return res;\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\nvoid CF138C()\n{\n int t(char c)\n {\n switch (c)\n {\n case '(':\n return 0;\n case ')':\n return 0;\n case '[':\n return 1;\n case ']':\n return 1;\n default:\n return 2;\n }\n }\n\n int open(char c)\n {\n switch (c)\n {\n case '(':\n return 1;\n case '[':\n return 1;\n case '{':\n return 1;\n default:\n return -1;\n }\n }\n\n alias int[] tuple;\n\n char[] s = nlongs();\n char[] test = to!(char[])(\"))[[]]((](])(])(][)](]([([([]))[()]))([[()[([]))[[])\");\n if ((s.length>test.length)&&(s[0..test.length]==test)) write(s.length, \" \");\n auto n = s.length;\n tuple[] stack = [];\n tuple[] stacks = [];\n for (int i = 0; i < n; ++i)\n {\n if (stack.length == 0)\n {\n if (open(s[i]) == 1)\n stack ~= [t(s[i]), 1, i, i];\n }\n else\n {\n if (stack[stack.length - 1][1] < 0)\n stack.length = 0;\n else if (t(s[i]) == stack[stack.length - 1][0])\n {\n stack[stack.length - 1][1] += open(s[i]);\n stack[stack.length - 1][3] = i;\n }\n else\n {\n if (open(s[i]) == 1) stack ~= [t(s[i]), 1, i, i];\n else\n {\n if ((stack.length == 0) || (t(s[i]) != stack[stack.length - 1][0]))\n stack.length = 0;\n else\n {\n --stack[stack.length - 1][1];\n stack[stack.length - 1][3] = i;\n }\n }\n }\n if ((stack.length > 0) && (stack[stack.length - 1][1] == 0))\n {\n stacks ~= stack[stack.length - 1];\n --stack.length;\n }\n }\n }\n if (stacks.length == 0)\n {\n writeln(0);\n }\n else\n {\n bool[] ans = new bool[s.length];\n foreach (tuple seq; stacks)\n for (auto i = seq[2]; i <= seq[3]; ++i)\n ans[i] = true;\n int ansi = -1, ansj = -1, count = 0, i = 0;\n while (i < s.length)\n {\n if (ans[i])\n {\n auto j = i;\n int cnt = 0;\n while ((j < s.length) && ans[j])\n {\n if (s[j] =='[') ++cnt;\n ++j; \n } \n if ((j - i > ansj - ansi) | ((j - i == ansj - ansi) & (cnt > count)))\n {\n ansi = i;\n ansj = j;\n count = cnt;\n }\n i = j;\n }\n else ++i;\n }\n printf(\"%d\\n\", count);\n printf(\"%.*s\\n\", s[ansi .. ansj]);\n }\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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 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\nlong nl ()\n{\n sb ();\n long res = 0;\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 * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n else\n {\n do\n {\n res = res * 10 - cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n return res;\n}\n\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\n return res;\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\nvoid CF138C()\n{\n pure int t(char c)\n {\n switch (c)\n {\n case '(':\n return 0;\n case ')':\n return 0;\n case '[':\n return 1;\n case ']':\n return 1;\n default:\n return 2;\n }\n }\n\n pure int open(char c)\n {\n switch (c)\n {\n case '(':\n return 1;\n case '[':\n return 1;\n case '{':\n return 1;\n default:\n return -1;\n }\n }\n\n alias int[4] tuple;\n\n char[] s = nlongs();\n auto n = s.length;\n tuple[] stack = new tuple[n + 1];\n int cur = 0;\n bool[] ans = new bool[s.length];\n for (int i = 0; i < n; ++i)\n {\n if (cur == 0)\n {\n if (open(s[i]) == 1)\n stack[cur] = [t(s[i]), 1, i, i];\n ++cur;\n }\n else\n {\n if (stack[cur - 1][1] < 0)\n cur = 0;\n else if (t(s[i]) == stack[cur - 1][0])\n {\n stack[cur - 1][1] += open(s[i]);\n stack[cur - 1][3] = i;\n }\n else\n {\n if (open(s[i]) == 1) { stack[cur] = [t(s[i]), 1, i, i]; ++cur; }\n else\n {\n if ((cur == 0) || (t(s[i]) != stack[cur - 1][0]))\n cur = 0;\n else\n {\n --stack[cur - 1][1];\n stack[cur - 1][3] = i;\n }\n }\n }\n if ((cur > 0) && (stack[cur - 1][1] == 0))\n {\n if (!ans[stack[cur - 1][2]])\n for (int j = stack[cur - 1][2]; j <= stack[cur - 1][3]; ++j)\n ans[j] = true;\n --cur;\n }\n }\n }\n int ansi = -1, ansj = -1, count = 0, i = 0;\n while (i < n)\n {\n if (ans[i])\n {\n auto j = i;\n int cnt = 0;\n while ((j < n) && ans[j])\n {\n if (s[j] =='[') ++cnt;\n ++j;\n }\n if (cnt > count)\n {\n ansi = i;\n ansj = j;\n count = cnt;\n }\n i = j;\n }\n else ++i;\n }\n printf(\"%d\\n\", count);\n if (count > 0) printf(\"%.*s\\n\", s[ansi .. ansj]);\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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 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\nlong nl ()\n{\n sb ();\n long res = 0;\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 * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n else\n {\n do\n {\n res = res * 10 - cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n return res;\n}\n\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\n return res;\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\nvoid CF138C()\n{\n int t(char c)\n {\n switch (c)\n {\n case '(':\n return 0;\n case ')':\n return 0;\n case '[':\n return 1;\n case ']':\n return 1;\n default:\n return 2;\n }\n }\n\n int open(char c)\n {\n switch (c)\n {\n case '(':\n return 1;\n case '[':\n return 1;\n case '{':\n return 1;\n default:\n return -1;\n }\n }\n\n alias int[] tuple;\n\n char[] s = nlongs();\n char[] test = to!(char[])(\"))[[]]((](])(])(][)](]([([([]))[()]))([[()[([]))[[])\");\n if ((s.length>test.length)&&(s[0..test.length]==test)) write(s.length, \" \");\n auto n = s.length;\n tuple[] stack = [];\n tuple[] stacks = [];\n for (int i = 0; i < n; ++i)\n {\n if (stack.length == 0)\n {\n if (open(s[i]) == 1)\n stack ~= [t(s[i]), 1, i, i];\n }\n else\n {\n if (stack[stack.length - 1][1] < 0)\n stack.length = 0;\n else if (t(s[i]) == stack[stack.length - 1][0])\n {\n stack[stack.length - 1][1] += open(s[i]);\n stack[stack.length - 1][3] = i;\n }\n else\n {\n if (open(s[i]) == 1) stack ~= [t(s[i]), 1, i, i];\n else\n {\n if ((stack.length == 0) || (t(s[i]) != stack[stack.length - 1][0]))\n stack.length = 0;\n else\n {\n --stack[stack.length - 1][1];\n stack[stack.length - 1][3] = i;\n }\n }\n }\n if ((stack.length > 0) && (stack[stack.length - 1][1] == 0))\n {\n stacks ~= stack[stack.length - 1];\n --stack.length;\n }\n }\n }\n int[] cnt = new int[s.length];\n cnt[0] = s[0] =='[' ? 1 : 0;\n for (int i = 1; i < s.length; ++i)\n cnt[i] = cnt[i - 1] + (s[i] == '[' ? 1 : 0);\n\n int count(tuple h)\n {\n return cnt[h[3]] - cnt[h[2]] + (s[h[2]] == '[' ? 1 : 0);\n }\n\n if (stacks.length == 0)\n {\n printf(\"0\\n\");\n }\n else\n {\n auto ans = stacks[0];\n for (int i = 1; i < stacks.length; ++i)\n if ((stacks[i][3] - stacks[i][2] > ans[3] - ans[2]) || ((stacks[i][3] - stacks[i][2] == ans[3] - ans[2]) && (count(stacks[i]) > count(ans))))\n ans = stacks[i];\n printf(\"%d\\n\", count(ans));\n printf(\"%.*s\\n\", s[ans[2] .. ans[3] + 1]);\n }\n}\n\nvoid main()\n{\n CF138C();\n}\n"}, {"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[] 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\nvoid CF138C()\n{\n bool t(char c)\n {\n return (c=='(')||(c==')');\n }\n char[] s = nlongs();\n auto n = s.length;\n int[] stack = [], ans = new int[n];\n int[] ke = new int[n];for(int i=0;i0)&&(t(s[stack[stack.length-1]])==t(s[i])))\n {\n ans[stack[stack.length-1]] = i;\n --stack.length;\n }\n else stack.length = 0;\n }\n }\n //writeln(ke);\n //writeln(ans);\n int cur = 0;\n while (cur0)\n {\n int end = ans[cur];\n while ((end0)) end = ans[end+1];\n ans[cur] = end;\n cur = end+1;\n }\n else ++cur;\n }\n int[] cnt = new int[n];\n cnt[0]=s[0]=='['?1:0;\n for (int i=1;i count(tt)) tt = i;\n //writeln(s);\n writeln(count(tt));\n writeln(s[tt..ans[tt]+1]);\n}\n\nvoid main()\n{\n CF138C();\n}\n"}, {"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 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\nlong nl ()\n{\n sb ();\n long res = 0;\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 * 10 + cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n else\n {\n do\n {\n res = res * 10 - cast (long) (curc - '0');\n curc = getchar ();\n }\n while (32 < curc);\n }\n return res;\n}\n\ndouble nd()\n{\n sb();\n double res = 0;\n while ((curc != '.') & (32 < curc))\n {\n res = res * 10 + cast(int)(curc - '0');\n curc = getchar();\n }\n if (curc == '.')\n {\n curc = getchar();\n double exp = 10;\n while (32 < curc)\n {\n res += cast(double)(curc - '0') / exp;\n exp *= 10;\n curc = getchar();\n }\n }\n return res;\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\nvoid CF138C()\n{\n int t(char c)\n {\n switch (c)\n {\n case '(':\n return 0;\n case ')':\n return 0;\n case '[':\n return 1;\n case ']':\n return 1;\n default:\n return 2;\n }\n }\n\n int open(char c)\n {\n switch (c)\n {\n case '(':\n return 1;\n case '[':\n return 1;\n case '{':\n return 1;\n default:\n return -1;\n }\n }\n\n alias int[] tuple;\n\n char[] s = nlongs();\n char[] test = to!(char[])(\"))[[]]((](])(])(][)](]([([([]))[()]))([[()[([]))[[])\");\n if ((s.length>test.length)&&(s[0..test.length]==test)) write(s.length, \" \");\n auto n = s.length;\n tuple[] stack = [];\n tuple[] stacks = [];\n for (int i = 0; i < n; ++i)\n {\n if (stack.length == 0)\n {\n if (open(s[i]) == 1)\n stack ~= [t(s[i]), 1, i, i];\n }\n else\n {\n if (stack[stack.length - 1][1] < 0)\n stack.length = 0;\n else if (t(s[i]) == stack[stack.length - 1][0])\n {\n stack[stack.length - 1][1] += open(s[i]);\n stack[stack.length - 1][3] = i;\n }\n else\n {\n if (open(s[i]) == 1) stack ~= [t(s[i]), 1, i, i];\n else\n {\n if ((stack.length == 0) || (t(s[i]) != stack[stack.length - 1][0]))\n stack.length = 0;\n else\n {\n --stack[stack.length - 1][1];\n stack[stack.length - 1][3] = i;\n }\n }\n }\n if ((stack.length > 0) && (stack[stack.length - 1][1] == 0))\n {\n stacks ~= stack[stack.length - 1];\n --stack.length;\n }\n }\n }\n if (stacks.length == 0)\n {\n writeln(0);\n }\n else\n {\n bool[] ans = new bool[s.length];\n foreach (tuple seq; stacks)\n for (auto i = seq[2]; i <= seq[3]; ++i)\n ans[i] = true;\n int ansi = -1, ansj = -1, count = 0, i = 0;\n while (i < s.length)\n {\n if (ans[i])\n {\n auto j = i;\n int cnt = 0;\n while ((j < s.length) && ans[j])\n {\n if (s[j] =='[') ++cnt;\n ++j; \n } \n if (cnt > count)\n {\n ansi = i;\n ansj = j;\n count = cnt;\n }\n i = j;\n }\n else ++i;\n }\n printf(\"%d\\n\", count);\n printf(\"%.*s\\n\", s[ansi .. ansj]);\n }\n}\n\nvoid main()\n{\n CF138C();\n}"}, {"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[] 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\nvoid CF138C()\n{\n bool t(char c)\n {\n return (c=='(')||(c==')');\n }\n char[] s = nlongs();\n auto n = s.length;\n int[] stack = [], ans = new int[n];\n int[] ke = new int[n];for(int i=0;i0)&&(t(s[stack[stack.length-1]])==t(s[i])))\n {\n ans[stack[stack.length-1]] = i;\n --stack.length;\n }\n else stack.length = 0;\n }\n }\n //writeln(ke);\n //writeln(ans);\n int cur = 0;\n while (cur0)\n {\n int end = ans[cur];\n while ((end0)) end = ans[end+1];\n ans[cur] = end;\n cur = end+1;\n }\n else ++cur;\n }\n //writeln(ans);\n int[] cnt = new int[n];\n cnt[0]=s[0]=='['?1:0;\n for (int i=1;i m){tt = i; m = count(i);}\n //writeln(s);\n writeln(m);\n if ((m>0)&&(ans[tt]-tt>1))writeln(s[tt..ans[tt]+1]);\n}\n\nvoid main()\n{\n CF138C();\n}"}], "src_uid": "5ce8de80c6953cd1e6e6eefd9ad35f7e"} {"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\tbool [int] b;\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\tb[c] = true;\r\n\t\t}\r\n\t\tbool ok = a.any !(c => (c - k) in b);\r\n\t\twriteln (ok ? \"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 k = 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\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (set.get(a[i]-k, false))\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": "aae82b2687786818996e4e94c5505d8e"} {"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 logLimit = 20;\r\n\r\nint fun (int len)\r\n{\r\n\tif (len == 0)\r\n\t{\r\n\t\treturn 1;\r\n\t}\r\n\tint cur = len;\r\n\twhile (cur & (cur - 1))\r\n\t{\r\n\t\tcur += cur & -cur;\r\n\t}\r\n\tdebug {writeln (\"fun (\", len, \") = \", cur, \" - \", len);}\r\n\treturn cur - len;\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\tsort (a);\r\n\r\n\t\tauto prev = new int [n];\r\n\t\tprev[0] = -1;\r\n\t\tforeach (i; 1..n)\r\n\t\t{\r\n\t\t\tprev[i] = (a[i] == a[i - 1]) ? prev[i - 1] : i - 1;\r\n\t\t}\t\r\n\t\tauto next = new int [n];\r\n\t\tnext[n - 1] = n;\r\n\t\tforeach_reverse (i; 0..n - 1)\r\n\t\t{\r\n\t\t\tnext[i] = (a[i] == a[i + 1]) ? next[i + 1] : i + 1;\r\n\t\t}\r\n\r\n\t\tint res = int.max;\r\n\t\tforeach (logLo; 0..logLimit)\r\n\t\t{\r\n\t\t\tint lo = min (n - 1, 0 + (1 << logLo));\r\n\t\t\tlo = prev[lo] + 1;\r\n\t\t\tforeach (logHi; 0..logLimit)\r\n\t\t\t{\r\n\t\t\t\tint hi = max (0, n - 1 - (1 << logHi));\r\n\t\t\t\thi = next[hi] - 0;\r\n\t\t\t\thi = max (hi, lo);\r\n\r\n\t\t\t\tdebug {writeln (lo, \" \", hi - lo, \" \", n - hi);}\r\n\t\t\t\tres = min (res, fun (lo) + fun (hi - lo) +\r\n\t\t\t\t fun (n - hi));\r\n\t\t\t\tdebug {writeln (\"res = \", res);}\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 long[] pow2 = 19L.iota.map!\"2 ^^ a\".array;\r\n long extraPow2(long x) {\r\n long t = 1;\r\n while(x > t) t *= 2;\r\n return t - x;\r\n }\r\n\r\n pow2.deb;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto H = scan!long(N);\r\n\r\n long[] acc = [0];\r\n foreach(g; H.sort.group) acc ~= acc[$ - 1] + g[1];\r\n auto accs = acc.assumeSorted;\r\n\r\n long ans = long.max;\r\n auto p2 = pow2.filter!(p => p <= N + extraPow2(N)).array;\r\n foreach(a; p2) foreach(b; p2) foreach(c; p2) {\r\n long cur;\r\n long ex;\r\n long sum;\r\n foreach(x; [a, b, c]) {\r\n auto r = accs.upperBound(cur).lowerBound(x + cur + 1);\r\n if (r.empty) {\r\n ex++;\r\n sum++;\r\n } else {\r\n // [a, b, c, x, r.back, cur].deb;\r\n ex += x - r.back + cur;\r\n sum += x;\r\n cur = r.back;\r\n }\r\n }\r\n if (cur == accs[$ - 1]) ans = min(ans, ex);\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>>\".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": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n \r\n long[] pow2 = 19L.iota.map!\"2 ^^ a\".array;\r\n long extraPow2(long x) {\r\n long t = 1;\r\n while(x > t) t *= 2;\r\n return t - x;\r\n }\r\n\r\n pow2.deb;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto H = scan!long(N);\r\n\r\n long[] acc = [0];\r\n foreach(g; H.sort.group) acc ~= acc[$ - 1] + g[1];\r\n auto accs = acc.assumeSorted;\r\n\r\n long ans = long.max;\r\n auto p2 = pow2.filter!(p => p <= N + extraPow2(N)).array;\r\n foreach(a; p2) foreach(b; p2) foreach(c; p2) {\r\n long cur;\r\n long ex;\r\n long sum;\r\n foreach(x; [a, b, c]) {\r\n auto r = accs.upperBound(cur).lowerBound(x + cur + 1);\r\n if (r.empty) {\r\n ex++;\r\n sum++;\r\n } else {\r\n // [a, b, c, x, r.back, cur].deb;\r\n ex += x - r.back + cur;\r\n sum += x;\r\n cur = r.back;\r\n }\r\n }\r\n if (sum >= N) ans = min(ans, ex);\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>>\".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": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n \r\n long[] pow2 = 19L.iota.map!\"2 ^^ a\".array;\r\n long extraPow2(long x) {\r\n long t = 1;\r\n while(x > t) t *= 2;\r\n return t - x;\r\n }\r\n\r\n pow2.deb;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto H = scan!long(N);\r\n\r\n long[] acc = [0];\r\n foreach(g; H.sort.group) acc ~= acc[$ - 1] + g[1];\r\n auto accs = acc.assumeSorted;\r\n\r\n long ans = long.max;\r\n auto p2 = pow2.filter!(p => p <= N + extraPow2(N)).array;\r\n foreach(a; p2) foreach(b; p2) foreach(c; p2) {\r\n long cur;\r\n long ex;\r\n foreach(x; [a, b, c]) {\r\n auto r = accs.upperBound(cur).lowerBound(x + cur + 1);\r\n if (r.empty) {\r\n ex++;\r\n } else {\r\n // [a, b, c, x, r.back, cur].deb;\r\n ex += x - r.back + cur;\r\n cur = r.back;\r\n }\r\n }\r\n ans = min(ans, ex);\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>>\".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": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = scan!int;\r\n \r\n long[] pow2 = 19L.iota.map!\"2 ^^ a\".array;\r\n long extraPow2(long x) {\r\n long t = 1;\r\n while(x > t) t *= 2;\r\n return t - x;\r\n }\r\n\r\n pow2.deb;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto H = scan!long(N);\r\n\r\n long[] acc = [0];\r\n foreach(g; H.sort.group) acc ~= acc[$ - 1] + g[1];\r\n auto accs = acc.assumeSorted;\r\n\r\n long ans = long.max;\r\n auto p2 = pow2.filter!(p => p <= N).array;\r\n foreach(a; p2) foreach(b; p2) foreach(c; p2) {\r\n long cur;\r\n long ex;\r\n foreach(x; [a, b, c]) {\r\n auto r = accs.upperBound(cur).lowerBound(x + cur + 1);\r\n if (r.empty) {\r\n ex++;\r\n } else {\r\n // [a, b, c, x, r.back, cur].deb;\r\n ex += x - r.back + cur;\r\n cur = r.back;\r\n }\r\n }\r\n ans = min(ans, ex);\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>>\".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}"}], "src_uid": "003a8719fbf3683671fafe3f01711a0a"} {"source_code": "// https://codeforces.com/problemset/problem/1238/B\nimport std.algorithm;\nimport std.container.rbtree;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int q = readln.chomp.to!int;\n\n foreach(query; 0..q) {\n int n, r;\n readf(\"%s %s\\n\", &n, &r);\n\n int[] x = readln.split.map!(to!int).array;\n\n auto monsters = redBlackTree!\"a > b\"(x);\n\n int damage = 0;\n\n while(damage*r < monsters.front()) {\n auto monster = monsters.front();\n monsters.removeFront();\n damage += 1;\n }\n damage.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.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;\n\t\tauto r = RD;\n\t\tauto x = RDA;\n\t\tx.sort!\"a > b\"();\n\t\tlong cnt, last;\n\t\tforeach (e; x)\n\t\t{\n\t\t\tif (e <= cnt * r)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (e == last)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t++cnt;\n\t\t\tlast = e;\n\t\t}\n\t\tans[i] = cnt;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "60b6c6f047051eeabfe4e3a9e045c6b0"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n;\n\tscanf(\"%d\\n\", &n);\n\t\n\tSong[] arr;\n\t\n\tforeach (line; stdin.byLine) {\n\t\tSong s;\n\t\tline.to!string.formattedRead!\"%d %d\"(s.len, s.percentage);\n\t\tarr ~= s;\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n;\n\tscanf(\"%d\", &n);\n\t\n\tSong[] arr = new Song[n];\n\t\n\tforeach (i; 0 .. n) {\n\t\tscanf(\"%d %d\", &arr[i].len, &arr[i].percentage);\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n} \n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n;\n\tscanf(\"%d\\n\", &n);\n\t\n\tSong[] arr;\n\tarr.reserve(n);\n\t\n\tforeach (line; stdin.byLine) {\n\t\tSong s;\n\t\tline.to!string.formattedRead!\"%d %d\"(s.len, s.percentage);\n\t\tarr ~= s;\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n;\n\treadf!\" %d\"(n);\n\t\n\tSong[] arr = new Song[n];\n\tforeach (i; 0 .. n) {\n\t\treadf!\" %d %d\"(arr[i].len, arr[i].percentage);\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n;\n\tscanf(\"%d\", &n);\n\t\n\tSong[] arr = new Song[n];\n\t\n\tforeach (i; 0 .. n) {\n\t\tscanf(\"%d %d\", &arr[i].len, &arr[i].percentage);\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n;\n\tscanf(\"%d\", &n);\n\t\n\tSong[] arr = new Song[n];\n\tforeach (i; 0 .. n) {\n\t\tscanf(\"%d %d\", &arr[i].len, &arr[i].percentage);\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n;\n\tscanf(\"%d\", &n);\n\t\n\tSong[] arr = new Song[n];\n\tforeach (i; 0 .. n) {\n\t\tscanf(\"%d %d\", &arr[i].len, &arr[i].percentage);\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\n\nvoid r(ref int d) { scanf(\"%d\", &d); }\nvoid r(ref long d) { scanf(\"%lld\", &d); }\nvoid r(ref double d) { scanf(\"%f\", &d); }\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n; r(n);\n\t\n\tSong[] arr = new Song[n];\n\tforeach (i; 0 .. n) {\n\t\tr(arr[i].len);\n\t\tr(arr[i].percentage);\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\n\nvoid r(ref int d) { scanf(\"%d\", &d); }\nvoid r(ref int a, ref int b) { scanf(\"%d %d\", &a, &b); }\nvoid r(ref long d) { scanf(\"%lld\", &d); }\nvoid r(ref double d) { scanf(\"%f\", &d); }\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n; r(n);\n\t\n\tSong[] arr = new Song[n];\n\tforeach (i; 0 .. n) {\n\t\tr(arr[i].len, arr[i].percentage);\n\t}\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.format;\n\nvoid main() {\n\tstruct Song {\n\t\tint len, percentage;\n\t}\n\t\n\tint n;\n\tscanf(\"%d\\n\", &n);\n\t\n\tSong[] arr;\n\t\n\tforeach (line; stdin.byLine) {\n\t\tSong s;\n\t\tline.to!string.formattedRead!\"%d %d\"(s.len, s.percentage);\n\t\tarr ~= s;\n\t}\n\t\n\twriteln(arr);\n\treturn;\n\t\n\tbool compare(Song a, Song b) {\n\t\tif (a.percentage == 100 && b.percentage != 100) return true;\n\t\tif (a.percentage != 100 && b.percentage == 100) return false;\n\t\tdouble x = a.len * (a.percentage / 100.0) / (1 - a.percentage / 100.0);\n\t\tdouble y = b.len * (b.percentage / 100.0) / (1 - b.percentage / 100.0);\n\t\treturn x > y;\n\t}\n\t\n\tsort!compare(arr);\n\t\n\tdouble answer = 0;\n\tdouble exp = 0;\n\tforeach (s; arr) {\n\t\tanswer += s.len;\n\t\tanswer += exp * ((100 - s.percentage) / 100.0);\n\t\texp += s.len * (s.percentage / 100.0);\n\t}\n\t\n\twritef(\"%0.12f\\n\", answer);\n}\n"}], "src_uid": "295c768a404d11a4ac480aaaf653c45c"} {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n ll n = scan;\n writeln(-(n-1), \" \", 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, 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 long n;\r\n scanf(\"%lld\", &n);\r\n getchar();\r\n writeln(-1 * (n - 1), ' ', n);\r\n }\r\n}"}], "negative_code": [], "src_uid": "a4628208668e9d838cd019e9dc03e470"} {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.random, std.array;\n\n // const int n=10;\n // auto rnd=Random(unpredictableSeed);\n // auto a=new char[](n), b=new char[](n);\n // foreach(i; 0..n){\n // a[i]=(uniform!\"[]\"(0, 1, rnd)+'0').to!(char);\n // b[i]=(uniform!\"[]\"(0, 1, rnd)+'0').to!(char);\n // }\n \n int n; rd(n);\n auto a=readln.chomp.to!(char[]);\n auto b=readln.chomp.to!(char[]);\n\n long solve(){\n long p, q, r, s;\n foreach(i; 0..n){\n if(a[i]=='0' && b[i]=='0') p++;\n else if(a[i]=='0' && b[i]=='1') q++;\n else if(a[i]=='1' && b[i]=='0') r++;\n else s++;\n }\n return p*r+p*s+q*r;\n }\n\n long brute(){\n auto _a=a.map!((e)=>(e-'0')).array, _b=b.map!((e)=>(e-'0')).array;\n long ret=0;\n foreach(i; 0..n)foreach(j; 0..i){\n int o1=_a[i]|_b[i], o2=_a[j]|_b[j];\n if(o1!=(_a[j]|_b[i]) || o2!=(_a[i]|_b[j])) ret++;\n }\n return ret;\n }\n\n // if (solve()!=brute()){\n // writeln(a);\n // writeln(b);\n // writeln(solve());\n // writeln(brute());\n // }\n\n writeln(solve());\n}\n\n/*\n 0 0 p\n 0 1 q\n 1 0 r\n 1 1 s\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 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;\n auto t = readln.chomp;\n \n int oo = 0, oz = 0, zo = 0, zz = 0;\n foreach (a, b; lockstep(s, t)) {\n if (a == '1' && b == '1') ++oo;\n if (a == '1' && b == '0') ++oz;\n if (a == '0' && b == '1') ++zo;\n if (a == '0' && b == '0') ++zz;\n }\n \n auto ans = cast(long)oo * zz + cast(long)oz * (zo + zz);\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;\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\tint [2] [2] d;\n\t\tforeach (k; 0..n)\n\t\t{\n\t\t\td[s[k] - '0'][t[k] - '0'] += 1;\n\t\t}\n\n\t\tlong res = 0;\n\t\tforeach (i; 0..2)\n\t\t{\n\t\t\tforeach (j; 0..2)\n\t\t\t{\n\t\t\t\tforeach (p; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (q; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (i != p &&\n\t\t\t\t\t\t (((i | j) != (p | q)) ||\n\t\t\t\t\t\t ((i | q) != (p | j))))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdebug {writeln (i, j,\n\t\t\t\t\t\t\t p, q, \" \", d[i][j],\n\t\t\t\t\t\t\t \" \", d[p][q]);}\n\t\t\t\t\t\t\tres += d[i][j] * 1L *\n\t\t\t\t\t\t\t d[p][q];\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 (res / 2);\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 A = readToken();\n const B = readToken();\n \n long[2][2] cnt;\n foreach (i; 0 .. N) {\n ++cnt[A[i] - '0'][B[i] - '0'];\n }\n \n long ans;\n foreach (p; 0 .. 2) foreach (q; 0 .. 2) foreach (r; 0 .. 2) foreach (s; 0 .. 2) {\n if ((p | q) != (r | q) || (r | s) != (p | s)) {\n if ([p, q] == [r, s]) {\n ans += cnt[p][q] * (cnt[p][q] - 1) / 2;\n } else if ([p, q] < [r, s]) {\n ans += cnt[p][q] * cnt[r][s];\n }\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\nimmutable long MOD = 10^^9 + 7;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.chomp.map!(a => a == '1').array;\n auto B = readln.chomp.map!(a => a == '1').array;\n\n auto cnt = new long[](4);\n\n foreach (i; 0..N) {\n if (!A[i] && !B[i]) {\n cnt[0] += 1;\n } else if (A[i] && !B[i]) {\n cnt[1] += 1;\n } else if (!A[i] && B[i]) {\n cnt[2] += 1;\n } else {\n cnt[3] += 1;\n }\n }\n\n auto ans = cnt[0] * cnt[1] + cnt[0] * cnt[3] + cnt[1] * cnt[2];\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "621c82478be3dadcf60c383ba078a49e"} {"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!int;\n\t\tauto k = RD!int;\n\t\tauto s = RD!string;\n\t\t\n\t\tauto dp = new long[3][](n+1);\n\t\tauto str = \"RGB\";\n\t\tlong cnt = k;\n\t\tforeach (j; 0..3)\n\t\t{\n\t\t\tforeach (l; 0..n)\n\t\t\t{\n\t\t\t\tdp[l+1][j] = dp[l][j];\n\t\t\t\tif (s[l] != str[(j+l)%3])\n\t\t\t\t\t++dp[l+1][j];\n\t\t\t\tif (l+1 >= k)\n\t\t\t\t{\n\t\t\t\t\tcnt = min(cnt, dp[l+1][j] - dp[l+1-k][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans[i] = cnt;\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;\nimport std.algorithm;\n\nchar[] charset = ['R', 'G', 'B'];\nint[200005] sum;\n\nvoid main() {\n int q;\n readf(\" %s\", q);\n \n foreach (_; 0..q) {\n int n, k;\n readf(\" %s %s\", n, k);\n\n readln();\n string s = \" \" ~ readln();\n\n auto result = n;\n foreach (j; 0..3) {\n foreach (i; 1..s.length) {\n auto ch = charset[(i + j) % 3];\n if (ch == s[i]) {\n sum[i] = sum[i-1] + 1;\n } else {\n sum[i] = sum[i-1];\n }\n }\n foreach(i; k..s.length) {\n result = min(result, k - (sum[i] - sum[i-k]));\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.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!int;\n\t\tauto k = RD!int;\n\t\tauto s = RD!string;\n\t\t\n\t\tauto dp = new long[3][](n+1);\n\t\tauto str = \"RGB\";\n\t\tlong cnt = k;\n\t\tforeach (j; 0..3)\n\t\t{\n\t\t\tforeach (l; 0..n)\n\t\t\t{\n\t\t\t\tdp[l+1][j] = dp[l][j];\n\t\t\t\tif (s[l] != str[(j+l)%3])\n\t\t\t\t\t++dp[l+1][j];\n\t\t\t\tif (l+1 >= k)\n\t\t\t\t{\n\t\t\t\t\tcnt = min(cnt, dp[l+1][j] - dp[l+1-k][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tans[i] = cnt;\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\twriteln(e);\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nchar[] charset = ['R', 'G', 'B'];\nint[200005] sum;\n\nvoid main() {\n int q;\n readf(\" %s\", q);\n \n foreach (_; 0..q) {\n int n, k;\n readf(\" %s %s\", n, k);\n\n readln;\n string s = \" \" ~ readln;\n\n auto result = n;\n foreach (j; 0..3) {\n foreach (i; 1..s.length) {\n auto ch = charset[(i + j) % 3];\n if (ch == s[i]) {\n sum[i] = sum[i-1] + 1;\n } else {\n sum[i] = sum[i-1];\n }\n }\n foreach(i; k..s.length) {\n result = min(result, k - (sum[i] - sum[i-k]));\n }\n }\n writeln(result);\n }\n}\n"}], "negative_code": [], "src_uid": "1aa8f887eb3b09decb223c71b40bb25b"} {"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 NA = -1;\n\nvoid main ()\n{\n\tint n;\n\tint k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tauto p = new int [n];\n\t\tp[] = NA;\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tint m;\n\t\t\treadf (\" %s\", &m);\n\t\t\tint prev;\n\t\t\treadf (\" %s\", &prev);\n\t\t\tforeach (i; 1..m)\n\t\t\t{\n\t\t\t\tint next;\n\t\t\t\treadf (\" %s\", &next);\n\t\t\t\tp[n - next] = n - prev;\n\t\t\t\tprev = next;\n\t\t\t}\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (p[i] != NA && p[i] != i + 1)\n\t\t\t{\n\t\t\t\tp[i] = NA;\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\n\t\tforeach_reverse (i; 0..n - 2)\n\t\t{\n\t\t\tif (p[i] != NA && p[i + 1] == NA)\n\t\t\t{\n\t\t\t\tp[i] = NA;\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tif (p[i] == NA)\n\t\t\t{\n\t\t\t\tp[i] = i + 1;\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tassert (p[i] == i + 1);\n\t\t}\n\t\tassert (p[n - 1] == NA);\n\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.stdio;\n\nimmutable int NA = -1;\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\tp[] = NA;\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\tint m, prev;\n\t\t\treadf (\" %s %s\", &m, &prev);\n\t\t\tforeach (i; 1..m)\n\t\t\t{\n\t\t\t\tint next;\n\t\t\t\treadf (\" %s\", &next);\n\t\t\t\tp[n - next] = n - prev;\n\t\t\t\tprev = next;\n\t\t\t}\n\t\t}\n\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (p[i] != NA && p[i] != i + 1)\n\t\t\t{\n\t\t\t\tp[i] = NA;\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\n\t\tforeach_reverse (i; 0..n - 2)\n\t\t{\n\t\t\tif (p[i] != NA && p[i + 1] == NA)\n\t\t\t{\n\t\t\t\tp[i] = NA;\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tif (p[i] == NA)\n\t\t\t{\n\t\t\t\tp[i] = i + 1;\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main(string[] args) {\n //stdin = File(\"input.txt\", \"r\");\n\n int n, k;\n readf(\"%d %d\\n\", &n, &k);\n int answer = 0;\n foreach (int i; 0..k) {\n int m;\n readf(\"%d\", &m);\n int[] a = new int[m];\n foreach (int j; 0..m) {\n readf(\" %d\", &a[j]);\n }\n readf(\"\\n\");\n\n if (a[0] == 1) {\n int j = 1;\n while (j < m && a[j] == j + 1) {\n ++j;\n }\n answer += 2 * (m - j + 1) - 1;\n } else {\n answer += 2 * m - 1;\n }\n }\n answer -= 1;\n writeln(answer);\n}\n"}], "negative_code": [], "src_uid": "6590c99e35f6f65e1b1bbd4f5bdca43a"} {"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, h, a, b, k;\n readf(\"%s %s %s %s %s\", &n, &h, &a, &b, &k);\n readln;\n \n while (k--) {\n int ta, fa, tb, fb;\n readf(\"%s %s %s %s\", &ta, &fa, &tb, &fb);\n readln;\n \n auto ans = 0;\n if (ta == tb) {\n ans = abs(fa - fb);\n } else {\n if (fa > fb) swap(fa, fb);\n \n ans = abs(ta - tb);\n if ((fa >= a && fa <= b) || (fb >= a && fb <= b)) {\n ans += abs(fa - fb);\n } else {\n ans += min(abs(fa - a) + abs(fb - a), abs(fa - b) + abs(fb - b));\n }\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, h, a, b, k; rd(n, h, a, b, k);\n struct T{long t, f;}\n import std.math;\n while(k--){\n auto data=new T[](2);\n rd(data[0].t, data[0].f, data[1].t, data[1].f);\n data.sort!\"a.t==b.t ? a.fb){\n d+=(data[0].f-b);\n d+=abs(b-data[1].f);\n }else{\n d+=abs(data[0].f-data[1].f);\n }\n writeln(d);\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": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n, h, a, b, k; rd(n, h, a, b, k);\n struct T{long t, f;}\n import std.math;\n while(k--){\n auto data=new T[](2);\n rd(data[0].t, data[0].f, data[1].t, data[1].f);\n data.sort!\"a.t==b.t ? a.fb){\n d+=(data[0].f-b);\n d+=abs(b-data[1].f);\n }else{\n d+=abs(a-data[1].f);\n }\n writeln(d);\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"}], "src_uid": "bdce4761496c88a3de00aa863ba7308d"} {"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.bigint;\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!uint;\n immutable k = r.next!uint;\n immutable a = r.nextA!int(n).idup;\n auto s = new long[n];\n long cur;\n foreach_reverse (i; 0 .. n) {\n cur += a[i];\n s[i] = cur;\n }\n auto res = BigInt(s[0]);\n auto t = new long[n-1];\n s[1 .. n].copy (t);\n debug stderr.writeln (s);\n t.sort ();\n t.reverse ();\n foreach (i; 0 .. k - 1) {\n res += BigInt (t[i]);\n }\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\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\n\t\tlong [] s = [0];\n\t\tforeach_reverse (c; a)\n\t\t{\n\t\t\ts ~= s.back + c;\n\t\t}\n\t\treverse (s);\n\t\tdebug {writeln (s);}\n\n\t\tlong res = s[0];\n\t\tsort (s[1..$ - 1]);\n\t\treverse (s[1..$ - 1]);\n\t\tdebug {writeln (s[1..$ - 1]);}\n\t\tforeach (i; 1..k)\n\t\t{\n\t\t\tres += s[i];\n\t\t}\n\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 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 n = read.to!int;\n\tint k = read.to!int;\n\t\n\tlong[] as;\n\tforeach(i; 0 .. n) as ~= read.to!long;\n\tlog(\"as:\", as);\n\t\n\tS[] bs;\n\tlong sum = 0;\n\tforeach_reverse(i; 1 .. n){\n\t\tsum += as[i];\n\t\tbs ~= S(i, sum);\n\t}\n\tlog(\"bs:\", bs);\n\t\n\tbs.sort!\"a.sum>b.sum\"();\n\tlog(\"bs:\", bs);\n\t\n\tbool[] ys = new bool[](n);\n\tforeach(i; 0 .. k - 1){\n\t\tlog(\"i:\", i, \" b:\", bs[i]);\n\t\tys[bs[i].id] = 1;\n\t}\n\tlog(\"ys:\", ys);\n\t\n\tlong ans;\n\tlong f = 1;\n\tforeach(i, a; as){\n\t\tif(ys[i]) f += 1;\n\t\tans += f * a;\n\t}\n\t\n\tans.writeln;\n}\n\nstruct S{\n\tint id;\n\tlong sum;\n}\n"}], "negative_code": [], "src_uid": "c7a37e8220d5fc44556dff66c1e129e7"} {"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 long INF = long.max >> 1;\n\nvoid main ()\n{\n\tint n, m;\n\tlong b;\n\twhile (readf (\" %s %s %s\", &n, &m, &b) > 0)\n\t{\n\t\talias Player = Tuple !(int, \"x\", long, \"y\", int, \"z\");\n\t\tauto p = new Player [n];\n\t\tforeach (ref q; p)\n\t\t{\n\t\t\tint k;\n\t\t\treadf (\" %s %s %s\", &q.x, &q.y, &k);\n\t\t\tq.z = 0;\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\tv--;\n\t\t\t\tq.z |= 1 << v;\n\t\t\t}\n\t\t}\n\t\tsort !(\"a.y < b.y\") (p);\n\t\tlong res = INF;\n\t\tint m2 = 1 << m;\n\t\tauto f = new long [m2];\n\t\tf[] = INF;\n\t\tf[0] = 0L;\n\t\tforeach (ref q; p)\n\t\t{\n\t\t\tforeach (u; 0..m2)\n\t\t\t{\n\t\t\t\tint v = u | q.z;\n\t\t\t\tf[v] = min (f[v], f[u] + q.x);\n\t\t\t}\n\t\t\tdebug {writeln (f, ' ', q.y);}\n\t\t\tif (f[m2 - 1] != INF)\n\t\t\t{\n\t\t\t\tres = min (res, f[m2 - 1] + b * q.y);\n\t\t\t}\n\t\t}\n\t\tif (res == INF)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.stdio, std.typecons;\nimmutable long INF = long.max >> 1;\nvoid main () {\n\tint n, m, b, k, v;\n\treadf (\" %s %s %s\", &n, &m, &b);\n\talias Player = Tuple !(int, \"x\", long, \"y\", int, \"z\");\n\tauto p = new Player [n];\n\tforeach (ref q; p) {\n\t\treadf (\" %s %s %s\", &q.x, &q.y, &k);\n\t\tforeach (j; 0..k) {\n\t\t\treadf (\" %s\", &v);\n\t\t\tq.z |= 1 << (v - 1);\n\t\t}\n\t}\n\tp.sort !\"a.y < b.y\";\n\tlong res = INF;\n\tauto f = new long [1 << m];\n\tf[1..$] = INF;\n\tforeach (q; p) {\n\t\tforeach (u; 0..1 << m)\n\t\t\tf[u | q.z] = min (f[u | q.z], f[u] + q.x);\n\t\tres = min (res, f[$ - 1] + b * q.y);\n\t}\n\twriteln (res < INF ? res : -1);\n}\n"}, {"source_code": "import std.algorithm, std.stdio, std.typecons;\nimmutable long INF = long.max >> 1;\nvoid main () {\n\tint n, m, b, k, v;\n\treadf (\" %s %s %s\", &n, &m, &b);\n\talias Player = Tuple !(int, \"x\", long, \"y\", int, \"z\");\n\tauto p = new Player [n];\n\tforeach (ref q; p) {\n\t\treadf (\" %s %s %s\", &q.x, &q.y, &k);\n\t\tforeach (j; 0..k) {\n\t\t\treadf (\" %s\", &v);\n\t\t\tq.z |= 1 << (v - 1);\n\t\t}\n\t}\n\tp.sort !\"a.y < b.y\";\n\tlong res = INF;\n\tauto f = new long [1 << m];\n\tf[1..$] = INF;\n\tforeach (q; p) {\n\t\tforeach (u; 0..1 << m)\n\t\t\tf[u | q.z] = min (f[u | q.z], f[u] + q.x);\n\t\tres = min (res, f[$ - 1] + b * q.y);\n\t}\n\twriteln (res < INF ? res : -1);\n}\n"}, {"source_code": "import std.algorithm, std.stdio, std.typecons;\nimmutable long INF = long.max >> 1;\nvoid main ()\n{\n\tint n, m, b, k, v;\n\treadf (\" %s %s %s\", &n, &m, &b);\n\talias Player = Tuple !(int, \"x\", long, \"y\", int, \"z\");\n\tauto p = new Player [n];\n\tforeach (ref q; p)\n\t{\n\t\treadf (\" %s %s %s\", &q.x, &q.y, &k);\n\t\tforeach (j; 0..k)\n\t\t{\n\t\t\treadf (\" %s\", &v);\n\t\t\tq.z |= 1 << (v - 1);\n\t\t}\n\t}\n\tp.sort !\"a.y < b.y\";\n\tlong res = INF;\n\tauto f = new long [1 << m];\n\tf[1..$] = INF;\n\tforeach (q; p)\n\t{\n\t\tforeach (u; 0..1 << m)\n\t\t\tf[u | q.z] = min (f[u | q.z], f[u] + q.x);\n\t\tres = min (res, f[$ - 1] + b * q.y);\n\t}\n\twriteln (res < INF ? res : -1);\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 long INF = long.max >> 1;\n\nvoid main ()\n{\n\tint n, m;\n\tlong b;\n\twhile (readf (\" %s %s %s\", &n, &m, &b) > 0)\n\t{\n\t\talias Player = Tuple !(int, \"x\", long, \"y\", int, \"z\");\n\t\tauto p = new Player [n];\n\t\tforeach (ref q; p)\n\t\t{\n\t\t\tint k;\n\t\t\treadf (\" %s %s %s\", &q.x, &q.y, &k);\n\t\t\tq.z = 0;\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\tv--;\n\t\t\t\tq.z |= 1 << v;\n\t\t\t}\n\t\t}\n\t\tsort !(\"a.z < b.z\") (p);\n\t\tlong res = INF;\n\t\tint m2 = 1 << m;\n\t\tauto f = new long [m2];\n\t\tf[] = INF;\n\t\tf[0] = 0L;\n\t\tforeach (ref q; p)\n\t\t{\n\t\t\tforeach (u; 0..m2)\n\t\t\t{\n\t\t\t\tint v = u | q.z;\n\t\t\t\tf[v] = min (f[v], f[u] + q.x);\n\t\t\t}\n\t\t\tif (f[m2 - 1] != INF)\n\t\t\t{\n\t\t\t\tres = min (res, f[m2 - 1] + b * q.y);\n\t\t\t}\n\t\t}\n\t\tif (res == INF)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "bc5b2d1413efcaddbf3bf1d905000159"} {"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\n\nconst int oo = 10000000;\n\nvoid main()\n{\n int n;\n scanf(\"%d\", &n);\n \n int sum = 0, cnt = 0, minx = oo;\n bool has = false;\n \n for (int i = 0; i < 2 * n - 1; ++i)\n {\n\tint x;\n\tscanf(\"%d\", &x);\n\tsum += abs(x);\n\tcnt += x < 0;\n\tminx = min(minx, abs(x));\n\tif (x == 0)\n\t has = true;\n }\n \n if (n % 2 == 1 || has)\n\twrite(sum);\n else\n {\n\tif (cnt % 2 == 0)\n\t write(sum);\n\telse\n\t write(sum - 2 * minx);\n }\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\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;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint m = n * 2 - 1;\n\t\tauto a = new int [m];\n\t\tint s = 0;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t\ts += (a[i] <= 0);\n\t\t\ta[i] = abs (a[i]);\n\t\t}\n\t\tsort (a);\n\t\tint res = reduce !(\"a + b\") (a);\n\t\tif ((n % 2 == 0) && (s % 2 != 0))\n\t\t{\n\t\t\tres -= 2 * a[0];\n\t\t}\n\t\twriteln (res);\n\t}\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\nint sum(int[] xs) {\n int ret = 0;\n foreach (x; xs) ret += x;\n return ret;\n}\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n auto minus = cast(int)xs.count!\"a < 0\";\n\n if (N % 2 == 1 || minus % 2 == 0) {\n int ans = 0;\n foreach (x; xs) {\n ans += x.abs;\n }\n writeln(ans);\n } else {\n int ans = 0;\n auto as = xs.filter!\"a < 0\".array,\n bs = xs.filter!\"a >= 0\".array;\n ans -= as[0 .. minus - 1].sum;\n\n if (bs.empty) {\n ans += as.back;\n } else {\n int a = as.back.abs;\n int b = bs.front;\n ans += bs[1 .. $].sum;\n ans += max(a, b) - min(a, b);\n }\n writeln(ans);\n }\n\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.container;\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;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint m = n * 2 - 1;\n\t\tauto a = new int [m];\n\t\tint s = 0;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\treadf (\" %s\", &a[i]);\n\t\t\ts += (a[i] <= 0);\n\t\t\ta[i] = abs (a[i]);\n\t\t}\n\t\tint res = reduce !(\"a + b\") (a);\n\t\tif ((n % 2 == 0) && (s % 2 != 0))\n\t\t{\n\t\t\tres -= 2 * a[0];\n\t\t}\n\t\twriteln (res);\n\t}\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\nint sum(int[] xs) {\n int ret = 0;\n foreach (x; xs) ret += x;\n return ret;\n}\n\nvoid main() {\n int N; scanf(\"%d\\n\", &N);\n auto xs = readln.chomp.split(\" \").map!(to!int).array;\n xs.sort;\n auto minus = cast(int)xs.count!\"a < 0\";\n\n if (N % 2 == 1 || minus % 2 == 0) {\n int ans = 0;\n foreach (x; xs) {\n ans += x.abs;\n }\n writeln(ans);\n } else {\n int ans = 0;\n auto as = xs.filter!\"a < 0\".array,\n bs = xs.filter!\"a >= 0\".array;\n ans -= as[0 .. minus - 1].sum;\n\n if (bs.empty) {\n ans += as.back;\n } else {\n int a = as.back.abs;\n int b = bs.front;\n ans += max(a, b) - min(a, b);\n }\n writeln(ans);\n }\n\n}\n"}], "src_uid": "9b907b3e96e78c84d11032a0f0b0fa53"} {"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 ans = new int[](N);\n\n int tmp = 1<<29;\n int x = 1;\n for (int i = 1; i <= N; ++i) {\n if (i + N/i + (N%i>0) < tmp) {\n tmp = i + N/i + (N%i>0);\n x = i;\n }\n }\n\n for (int i = 1, p = 0; p < N; i += x) {\n for (int j = min(N, i + x - 1); j >= i && p < N; --j, ++p) {\n ans[p] = j;\n }\n }\n\n ans.map!(to!string).join(\" \").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;\n readf(\"%s\", &n);\n readln;\n\n auto sq = sqrt(cast(double) n).to!int;\n \n debug { sq.writeln; }\n \n auto chks = (n+1).iota.dropOne.chunks(sq).map!(c => c.array).array;\n \n debug { chks.writeln; }\n \n auto ans = chks.map!(c => retro(c)).join();\n \n ans.writefln!(\"%(%s %)\");\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\tauto t = cast (int) (sqrt (n - 1.0) + 1);\n\t\tauto s = t;\n\t\tif (t * (s - 1) >= n)\n\t\t{\n\t\t\ts -= 1;\n\t\t}\n\t\tint [] ans;\n\t\tforeach_reverse (i; 0..s)\n\t\t{\n\t\t\tforeach (j; 0..t)\n\t\t\t{\n\t\t\t\tint c = i * t + j + 1;\n\t\t\t\tif (1 <= c && c <= n)\n\t\t\t\t{\n\t\t\t\t\tans ~= c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (s, \" x \", t);}\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n; rd(n);\n int k=1;\n while((k+1)*(k+1)<=n) k++;\n int[] perm;\n for(int i=1; i<=n; ){\n int[] a;\n for(int j=0; j f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] 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 const sqrtN = cast(int)(floorSqrt(N - 1)) + 1;\n debug {\n writeln(N, \": \", sqrtN);\n }\n \n int[] ans;\n foreach_reverse (x; 0 .. sqrtN) {\n foreach (y; 0 .. sqrtN) {\n const a = x * sqrtN + y;\n if (0 <= a && a < N) {\n ans ~= a;\n }\n }\n }\n assert(ans.length == N);\n \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"}], "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 N = readln.chomp.to!int;\n auto ans = new int[](N);\n\n int tmp = N+1;\n int x = 1;\n for (int i = 2; i <= N; ++i) {\n if (i + N/i + (N%i>0) < tmp) {\n tmp = i + N/i + (N%i>0);\n x = i;\n }\n }\n\n for (int i = 1, p = 0; p < N; i += x) {\n for (int j = i + x - 1; j >= i && p < N; --j, ++p) {\n ans[p] = j;\n }\n }\n\n ans.map!(to!string).join(\" \").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;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto ans = new int[](N);\n\n int tmp = N;\n int x = 1;\n for (int i = 2; i <= N; ++i) {\n if (i + N/i + (N%i>0) < tmp) {\n tmp = i + N/i + (N%i>0);\n x = i;\n }\n }\n\n for (int i = 1, p = 0; i < N && p < N; i += x) {\n for (int j = i + x - 1; j >= i && p < N; --j, ++p) {\n ans[p] = j;\n }\n }\n\n ans.map!(to!string).join(\" \").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;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto ans = new int[](N);\n\n int tmp = N;\n int x = 1;\n for (int i = 2; i <= N; ++i) {\n if (i + N/i + (N%i>0) < tmp) {\n tmp = i + N/i + (N%i>0);\n x = i;\n }\n }\n\n for (int i = 1, p = 0; p < N; i += x) {\n for (int j = i + x - 1; j >= i && p < N; --j, ++p) {\n ans[p] = j;\n }\n }\n\n ans.map!(to!string).join(\" \").writeln;\n}\n"}], "src_uid": "6ea899e915cfc95a43f0e16d6d08cc1e"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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\tans[ti] = n / 2;\n\t}\n\t\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\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\n\tforeach (test; 0..tests)\n\t{\n\t\twriteln (readln.strip.to !(int) / 2);\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 N = readln.chomp.to!int;\n writeln(N/2);\n }\n}"}], "negative_code": [], "src_uid": "b46244f39e30c0cfab592a97105c60f4"} {"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 A = readln.split.map!(to!long).array;\n auto M = A.reduce!min;\n\n int last = - (1 << 29);\n int ans = 1 << 29;\n foreach (i; 0..N) {\n if (A[i] == M) {\n ans = min(ans, i - last);\n last = i;\n }\n }\n\n ans.writeln;\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;\n scan(n);\n auto a = readln.split.to!(int[]);\n auto amin = a.reduce!min;\n auto b = iota(n).filter!(i => a[i] == amin).array;\n\n int ans = 2*10^^5;\n\n foreach (i ; 0 .. b.length - 1) {\n ans = min(ans, b[i+1] - b[i]);\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": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.exception;\n\n int n; rd(n);\n auto a=readln.split.to!(int[]);\n\n auto mn=reduce!(min)(a);\n int[] ids;\n foreach(int i; 0..n){\n if(a[i]==mn) ids~=i;\n }\n int dist=n;\n foreach(i; 0..(ids.length-1)){\n dist=min(dist, ids[i+1]-ids[i]);\n }\n\n writeln(dist);\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": [], "src_uid": "67af292ff23880ad9fd4349729e36158"} {"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\r\n\t\tforeach (i; 0..n)\r\n\t\t{\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}\r\n\r\n\t\tauto c = new int [n];\r\n\t\tc[] = b[] - a[];\r\n\t\tauto total = sum (c);\r\n\r\n\t\tauto f = new bool [total + 1];\r\n\t\tf[0] = true;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach_reverse (j; c[i]..total + 1)\r\n\t\t\t{\r\n\t\t\t\tf[j] |= f[j - c[i]];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto half = total / 2;\r\n\t\twhile (!f[half])\r\n\t\t{\r\n\t\t\thalf -= 1;\r\n\t\t}\r\n\r\n\t\tint res = 0;\r\n\t\tres += (sum (a) + half) ^^ 2;\r\n\t\tres += (sum (a) + total - half) ^^ 2;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tres += (n - 2) * a[i] ^^ 2;\r\n\t\t\tres += (n - 2) * b[i] ^^ 2;\r\n\t\t}\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "// cheese-cracker [2022-02-12]\n\nint[][] dp;\nint[][] par;\nint[] a, b;\n\nint go(int i, int s){\n if(s < 0){\n return 0;\n }\n if(i < 0){\n return (s == 0);\n }\n if(dp[i][s] != -1){\n return dp[i][s];\n }\n int res = 0;\n if(go(i-1, s - a[i])){\n par[i][s] = 1;\n res = 1;\n }else if(go(i-1, s - b[i])){\n par[i][s] = 2;\n res = 1;\n }\n dp[i][s] = res;\n\n return res;\n}\n\nint[] res;\n\nvoid btrack(int i, int s){\n if(i < 0){\n return;\n }\n res ~= par[i][s];\n\n if(res.back == 2){\n btrack(i-1, s - b[i]);\n }else{\n btrack(i-1, s - a[i]);\n }\n}\n\nlong valu(int[] arr){\n long summ = 0;\n for(int i = 0; i < arr.length; ++i){\n for(int j = i+1; j < arr.length; ++j){\n summ += (arr[i] + arr[j])* (arr[i] + arr[j]);\n }\n }\n return summ;\n}\n\n\n\nvoid solve(){\n int n = scan!int;\n\n dp = new int[][](n, 10005);\n for(int i = 0; i < n; ++i){\n dp[i][] = -1;\n }\n par = new int[][](n, 10005);\n a = scanArray!int;\n b = scanArray!int;\n int summ = a.sum + b.sum;\n for(int s = summ/2; s >= 0; --s){\n if(go(n-1, s)){\n btrack(n-1, s);\n res.reverse;\n break;\n }\n }\n\n int[] t1, t2;\n for(int i = 0; i < n; ++i){\n if(res[i] == 1){\n t1 ~= a[i];\n t2 ~= b[i];\n }else if(res[i] == 2){\n t1 ~= b[i];\n t2 ~= a[i];\n }\n }\n /* show(t1, t2); */\n writeln(valu(t1) + valu(t2));\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, int, int, int , 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.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!int;\r\n\t\tauto b = RDA!int;\r\n\t\t\r\n\t\tauto dp = new int[][](n+1, n*100+1);\r\n\t\tdp[0][0] = 1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tforeach (j; 0..i*100+1)\r\n\t\t\t{\r\n\t\t\t\tif (dp[i][j] == 0) continue;\r\n\t\t\t\tdp[i+1][j+a[i]] = 1;\r\n\t\t\t\tdp[i+1][j+b[i]] = 2;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto tot = a.sum + b.sum;\r\n\t\tint p;\r\n\t\tforeach (j; 0..n*100+1)\r\n\t\t{\r\n\t\t\tif (dp[n][j] == 0) continue;\r\n\t\t\tif (abs(j*2 - tot) < abs(p*2 - tot))\r\n\t\t\t{\r\n\t\t\t\tp = j;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlong[] aa, bb;\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tauto num = dp[i+1][p];\r\n\t\t\tif (num == 1)\r\n\t\t\t{\r\n\t\t\t\taa ~= a[i];\r\n\t\t\t\tbb ~= b[i];\r\n\t\t\t\tp -= a[i];\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\taa ~= b[i];\r\n\t\t\t\tbb ~= a[i];\r\n\t\t\t\tp -= b[i];\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; i+1..n)\r\n\t\t\t{\r\n\t\t\t\tans[ti] += (aa[i]+aa[j])^^2 + (bb[i]+bb[j])^^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.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]; foreach (i; 0 .. N) A[i] = readInt;\n auto B = new int[N]; foreach (i; 0 .. N) B[i] = readInt;\n \n foreach (i; 0 .. N) {\n if (A[i] > B[i]) {\n swap(A[i], B[i]);\n }\n }\n const sumA = A.sum;\n const sumB = B.sum;\n const lim = sumB - sumA;\n auto dp = new bool[lim + 1];\n dp[0] = 1;\n foreach (i; 0 .. N) {\n const d = B[i] - A[i];\n foreach_reverse (x; 0 .. lim - d + 1) {\n if (dp[x]) {\n dp[x + d] = true;\n }\n }\n }\n \n long ans = long.max;\n foreach (x; 0 .. lim + 1) if (dp[x]) {\n const long sa = sumA + x;\n const long sb = sumB - x;\n chmin(ans, sa^^2 + sb^^2);\n }\n foreach (i; 0 .. N) {\n ans += 1L * (N - 2) * (A[i]^^2 + B[i]^^2);\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\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\nenum long INF = 1L<<56;\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto A = readarray!int;\r\n auto B = readarray!int;\r\n\r\n long sq(int x) {\r\n return x*x;\r\n }\r\n\r\n int L = 100*100;\r\n auto f = new long[][](N + 1, L + 1);\r\n auto s = new int[N + 1];\r\n foreach (i; 0 .. N) {\r\n s[i + 1] = s[i] + A[i] + B[i];\r\n }\r\n foreach (ref l; f) l[] = INF;\r\n f[1][A[0]] = f[1][B[0]] = 0;\r\n for (int k = 1; k < N; k++) {\r\n for (int sa = 0; sa <= L; sa++) {\r\n if (sa + A[k] > L || sa + B[k] > L) continue;\r\n int sb = s[k] - sa;\r\n f[k + 1][sa + A[k]] = min(f[k + 1][sa + A[k]], f[k][sa] + sa * A[k] + sb * B[k]);\r\n f[k + 1][sa + B[k]] = min(f[k + 1][sa + B[k]], f[k][sa] + sa * B[k] + sb * A[k]);\r\n }\r\n }\r\n long base = 0;\r\n for (int i = 0; i < N; i++) {\r\n for (int j = i + 1; j < N; j++) {\r\n base += sq(A[i]) + sq(A[j]) + sq(B[i]) + sq(B[j]);\r\n }\r\n }\r\n long add = INF;\r\n foreach (x; f[N]) {\r\n add = min(add, x);\r\n }\r\n writeln(base + add * 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": "b57066317ae2f2280d7351ff12e0c959"} {"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 Disc\n {\n int outer;\n int inner;\n int height;\n }\n Disc[] discs = new Disc[](n);\n foreach(ref disc; discs)\n {\n disc.inner = next!int;\n disc.outer = next!int;\n disc.height = next!int;\n }\n discs.multiSort!(\"a.outer > b.outer\",\n\t\t \"a.inner > b.inner\",\n\t\t \"a.height > b.height\",\n\t\t SwapStrategy.unstable);\n debug writeln(\"sorted discs: \", discs);\n auto nextDisc = DList!int();\n auto best = new long[](n);\n foreach(i, disc; discs)\n {\n while(!nextDisc.empty &&\n\t discs[nextDisc.front].inner >= disc.outer)\n\tnextDisc.removeFront;\n if (nextDisc.empty)\n\tbest[i] = disc.height;\n else\n\tbest[i] = best[nextDisc.front] + disc.height;\n nextDisc.insertFront([cast(int)i]);\n }\n debug best.writeln;\n best.fold!max.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.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 Disc\n {\n int outer;\n int inner;\n int height;\n }\n Disc[] discs = new Disc[](n);\n foreach(ref disc; discs)\n {\n disc.inner = next!int;\n disc.outer = next!int;\n disc.height = next!int;\n }\n discs.multiSort!(\"a.outer > b.outer\",\n\t\t \"a.inner > b.inner\",\n\t\t \"a.height > b.height\");\n debug writeln(\"sorted discs: \", discs);\n auto nextDisc = DList!int();\n auto best = new long[](n);\n foreach(i, disc; discs)\n {\n while(!nextDisc.empty &&\n\t discs[nextDisc.front].inner >= disc.outer)\n\tnextDisc.removeFront;\n if (nextDisc.empty)\n\tbest[i] = disc.height;\n else\n\tbest[i] = best[nextDisc.front] + disc.height;\n nextDisc.insertFront([cast(int)i]);\n }\n debug best.writeln;\n best.fold!max.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;\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 Disc\n {\n int outer;\n int inner;\n int height;\n }\n Disc[] discs = new Disc[](n);\n foreach(ref disc; discs)\n {\n disc.inner = next!int;\n disc.outer = next!int;\n disc.height = next!int;\n }\n discs.sort!((a, b) {\n if (a.outer > b.outer) return true;\n if (a.outer < b.outer) return false;\n if (a.inner > b.inner) return true;\n if (a.inner < b.inner) return false;\n if (a.height > b.height) return true;\n if (b.height > b.height) return false;\n return false;\n });\n debug writeln(\"sorted discs: \", discs);\n auto nextDisc = DList!int();\n auto best = new long[](n);\n foreach(i, disc; discs)\n {\n while(!nextDisc.empty &&\n\t discs[nextDisc.front].inner >= disc.outer)\n\tnextDisc.removeFront;\n if (nextDisc.empty)\n\tbest[i] = disc.height;\n else\n\tbest[i] = best[nextDisc.front] + disc.height;\n nextDisc.insertFront([cast(int)i]);\n }\n debug best.writeln;\n best.fold!max.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;\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 Disc\n {\n int outer;\n int inner;\n int height;\n }\n Disc[] discs = new Disc[](n);\n foreach(ref disc; discs)\n {\n disc.inner = next!int;\n disc.outer = next!int;\n disc.height = next!int;\n }\n discs.sort!((a, b) {\n if (a.outer > b.outer) return true;\n if (a.outer < b.outer) return false;\n if (a.inner > b.inner) return true;\n if (a.inner < b.inner) return false;\n if (a.height > b.height) return true;\n if (b.height > b.height) return false;\n return false;\n });\n debug writeln(\"sorted discs: \", discs);\n auto nextDisc = DList!int();\n auto best = new int[](n);\n foreach(i, disc; discs)\n {\n while(!nextDisc.empty &&\n\t discs[nextDisc.front].inner >= disc.outer)\n\tnextDisc.removeFront;\n if (nextDisc.empty)\n\tbest[i] = disc.height;\n else\n\tbest[i] = best[nextDisc.front] + disc.height;\n nextDisc.insertFront([cast(int)i]);\n }\n best.fold!max.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": "8d0f569359f655f3685c68fb364114a9"} {"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\nvoid main() {\n GC.disable();\n\n int n;\n readf(\" %s\", n);\n\n if (n == 1) {\n writeln(\"1\\n1 1\\n\");\n return;\n }\n\n writeln((n + 2) / 2);\n\n int c = 0;\n foreach (i; 0 .. n / 2 + 1) {\n c++;\n if (c > n)\n break;\n writefln(\"%s %s\", i + 1, i + 1);\n c++;\n if (c > n)\n break;\n writefln(\"%s %s\", i + 1, i + 2);\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 n = RD!int;\n\tauto x = n / 2;\n\twriteln(x + 1);\n\tforeach (i; 0..n)\n\t{\n\t\twriteln(i / 2 + 1, \" \", (i+1) / 2 + 1);\n\t}\n\n\t//writeln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.math : abs;\n\n int n;\n rd(n);\n\n auto m = n / 2 + 1;\n writeln(m);\n for (int i = 1, r = 1, c = 1; i <= n; i++) {\n writeln(r, \" \", c);\n if (i & 1) {\n c++;\n } else {\n r++;\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": "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 writeln( n / 2 + 1);\n foreach(i; 1..n+1) {\n if (i % 2==1) {\n auto idx = (i+1)/2;\n writeln(idx, \" \", idx);\n } else {\n auto idx = i/2;\n writeln(idx, \" \", idx+1);\n }\n }\n}\n"}], "negative_code": [], "src_uid": "6bd7cab93a779e066af39a671aba3239"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.range;\nimport std.bigint;\nimport std.string;\nimport std.algorithm;\nimport std.container.rbtree;\n\nvoid main() {\n\treadln;\n\tuint[uint] aa;\n\n\tforeach(a; readln.strip.splitter(' ').map!(a => a.to!uint).array)\n\t\taa[a]++;\n\n\tauto keys = aa.keys;\n\tsort(keys);\n\n\tforeach_reverse(k; keys) {\n\t\tauto cnt = &aa[k];\n\n\t\tif(*cnt % 2) {\n\t\t\t(*cnt)--;\n\t\t\taa[k - 1]++;\n\t\t}\n\t}\n\n\t//keys = aa.keys;\n\t//sort(keys);\n\n\tBigInt res;\n\n\tuint p;\n\n\tforeach_reverse(k; keys) {\n\t\tint cnt = aa[k] / 2;\n\n\t\tif(!cnt) continue;\n\n\t\tif(p) {\n\t\t\tres += ulong(p) * k;\n\t\t\tcnt--;\n\t\t}\n\n\t\tres += (ulong(k) * k) * (cnt / 2);\n\t\tp = cnt % 2 ? k : 0;\n \t}\n\n\n\tres.write;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm, std.math;\n\nvoid solve(int[] arr)\n{\n sort(arr);\n long ans = 0;\n int[] nums, cnt;\n for (int i = 0, next; i < arr.length; i = next)\n {\n next = i + 1;\n while (next < arr.length && arr[next] == arr[i]) ++ next;\n nums ~= arr[i];\n cnt ~= next - i;\n }\n for (int i = cast(int)nums.length - 1, next; i >= 0; i = next)\n {\n auto d = cnt[i] / 4;\n auto r = cnt[i] % 4;\n ans += cast(long)nums[i] * nums[i] * d;\n if (i > 0)\n {\n if (r == 0) \n {\n next = i - 1;\n continue;\n }\n else if (r == 1)\n {\n if (nums[i] - nums[i - 1] == 1)\n {\n ++ cnt[i - 1];\n }\n next = i - 1;\n continue;\n }\n else if (r == 3)\n {\n if (nums[i] - nums[i - 1] == 1)\n {\n ans += cast(long)nums[i] * nums[i - 1];\n -- cnt[i - 1];\n next = i - 1;\n continue;\n }\n }\n int j;\n for (j = i - 1; j >= 0; -- j)\n {\n if (cnt[j] >= 2) break;\n if (j > 0 && nums[j] - nums[j - 1] == 1) break;\n }\n if (j == -1) break;\n if (cnt[j] >= 2)\n {\n ans += cast(long)nums[i] * nums[j];\n cnt[j] -= 2;\n next = j;\n }\n else\n {\n ans += cast(long)nums[i] * nums[j - 1];\n -- cnt[j - 1];\n next = j - 1;\n }\n }\n else\n {\n next = -1;\n }\n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto arr = new int[n];\n foreach (i; 0 .. n) scanf(\"%d\", &arr[i]);\n solve(arr);\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.range;\nimport std.bigint;\nimport std.string;\nimport std.algorithm;\nimport std.container.rbtree;\n\nstruct S {\n\tuint len;\n\tuint *p;\n}\n\nvoid main() {\n\treadln;\n\tauto arr = readln.strip.splitter(' ').map!(a => a.to!uint).array;\n\n\tS[] ss;\n\n\tforeach(ref v; arr) {\n\t\tif(v > 1) ss ~= S(v - 1, &v);\n\t\tss ~= S(v, &v);\n\t}\n\n\tsort!((a, b) => a.len < b.len)(ss);\n\n\tauto r = ss.assumeSorted!((a, b) => a.len < b.len);\n\n\tauto equalS(ref in S s, in S *sa[]...) {\n\t\tloop: foreach(ref e; r.equalRange(s))\n\t\t\tif(*e.p && e.p != s.p) {\n\t\t\t\tforeach(a; sa) if(e.p == a.p) continue loop;\n\t\t\t\treturn e;\n\t\t\t}\n\t\treturn S.init;\n\t}\n\n\tulong square(ref S a1) {\n\t\tS a2 = equalS(a1);\n\n\t\tif(!a2.len) return 0;\n\n\t\tS b1 = equalS(a1, &a2), b2;\n\n\t\tif(b1.len) b2 = equalS(a1, &a2, &b1);\n\n\t\tif(!b2.len)\n\t\t\tforeach_reverse(ref e; r.lowerBound(a1)) {\n\t\t\t\tif(!*e.p)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tb2 = equalS(e, &a1, &a2);\n\n\t\t\t\tif(b2.len) {\n\t\t\t\t\tb1 = e;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t//writefln(`%s %s %s %s`, a1, a2, b1, b2);\n\n\t\tif(b2.len) {\n\t\t\t*a1.p = 0;\n\t\t\t*a2.p = 0;\n\t\t\t*b1.p = 0;\n\t\t\t*b2.p = 0;\n\t\t\treturn ulong(a1.len) * b1.len;\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tBigInt res;\n\n\tforeach_reverse(ref s; ss) {\n\t\tres += square(s);\n\t}\n\n\tres.write;\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.range;\nimport std.bigint;\nimport std.string;\nimport std.algorithm;\nimport std.container.rbtree;\n\nstruct S {\n\tuint len;\n\tuint *p;\n}\n\nvoid main() {\n\treadln;\n\tauto arr = readln.strip.splitter(' ').map!(a => a.to!uint).array;\n\n\tS[] ss;\n\n\tforeach(ref v; arr) {\n\t\tif(v > 1) ss ~= S(v - 1, &v);\n\t\tss ~= S(v, &v);\n\t}\n\n\tsort!((a, b) => a.len < b.len)(ss);\n\n\tauto r = ss.assumeSorted!((a, b) => a.len < b.len);\n\n\tauto equalS(ref in S s, in S *s2 = null) {\n\t\tforeach(ref e; r.equalRange(s)) {\n\t\t\t//e.writeln;\n\t\t\tif(*e.p && e.p != s.p && (!s2 || e.p != s2.p))\n\t\t\t\treturn e;\n\t\t}\n\t\treturn S.init;\n\t}\n\n\tulong square(ref S s) {\n\t\tS a = equalS(s);\n\n\t\tif(!a.len) return 0;\n\n\t\tS b, c;\n\n\t\tforeach_reverse(ref e; r.lowerBound(a)) {\n\t\t\tif(e.p != a.p) {\n\t\t\t\tc = equalS(e, &a);\n\n\t\t\t\tif(c.len) {\n\t\t\t\t\tb = e;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif(b.len) {\n\t\t\t*a.p = 0;\n\t\t\t*b.p = 0;\n\t\t\t*s.p = 0;\n\t\t\t*c.p = 0;\n\t\t\treturn ulong(a.len) * b.len;\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tBigInt res;// = square(ss[$ - 1]);\n\n\tforeach_reverse(ref s; ss) {\n\t\tres += square(s);\n\t}\n\n\tres.write;\n\n\n\tstatic if(0) {\n\tauto t = arr.redBlackTree!(/*(a, b) => a.len < b.len,*/ true);\n\n\t;\n\n\tuint canMake(uint len) {\n\t\tuint a;\n\n\t\tforeach(i; 0..2) {\n\t\t\tauto r = t.equalRange(len);\n\t\t\tif(r.empty) return 0;\n\t\t\tif(!i) r.popBack;\n\t\t\tif(!r.empty) {\n\t\t\t\ta = len;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlen--;\n\t\t}\n\n\t\tuint b;\n\n\t\t{\n\t\t\tauto r = t.lowerRange(a);\n\n\t\t\twhile(!r.empty) {\n\t\t\t\tb = r.back;\n\t\t\t\tr.popBack;\n\t\t\t}\n\t\t}\n\n\t\t/*auto a = t.equalRange(len).length > 1 ? len : (t.equalRange(len - 1).length ? len - 1 : 0);\n\n\t\tif(!a) return 0;\n\n foreach_reverse(k; t.lowerRange(a)) {}*/\n return 0;\n\t}\n\n\tforeach_reverse(len; arr) {\n\t\t;\n\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.range;\nimport std.bigint;\nimport std.string;\nimport std.algorithm;\nimport std.container.rbtree;\n\nstruct S {\n\tuint len;\n\tuint *p;\n}\n\nvoid main() {\n\treadln;\n\tauto arr = readln.strip.splitter(' ').map!(a => a.to!uint).array;\n\n\tS[] ss;\n\n\tforeach(ref v; arr) {\n\t\tif(v > 1) ss ~= S(v - 1, &v);\n\t\tss ~= S(v, &v);\n\t}\n\n\tsort!((a, b) => a.len < b.len)(ss);\n\n\tauto r = ss.assumeSorted!((a, b) => a.len < b.len);\n\n\tauto equalS(ref in S s, in S *sa[]...) {\n\t\tloop: foreach(ref e; r.equalRange(s))\n\t\t\tif(*e.p && e.p != s.p) {\n\t\t\t\tforeach(a; sa) if(e.p == a.p) continue loop;\n\t\t\t\treturn e;\n\t\t\t}\n\t\treturn S.init;\n\t}\n\n\tulong square(ref S a1) {\n\t\tS a2 = equalS(a1);\n\n\t\tif(!a2.len) return 0;\n\n\t\tS b1 = equalS(a1, &a2), b2;\n\n\t\tif(b1.len) b2 = equalS(a1, &a2, &b1);\n\n\t\tif(!b2.len)\n\t\t\tforeach_reverse(ref e; r.lowerBound(a1)) {\n\t\t\t\tif(!(*e.p))\n\t\t\t\t\tcontinue;\n\n\t\t\t\tb2 = equalS(e);\n\n\t\t\t\tif(b2.len) {\n\t\t\t\t\tb1 = e;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\tif(b2.len) {\n\t\t\t*a1.p = 0;\n\t\t\t*a2.p = 0;\n\t\t\t*b1.p = 0;\n\t\t\t*b2.p = 0;\n\t\t\treturn ulong(a1.len) * b1.len;\n\t\t}\n\n\t\treturn 0;\n\t}\n\n\tBigInt res;// = square(ss[$ - 1]);\n\n\tforeach_reverse(ref s; ss) {\n\t\tres += square(s);\n\t}\n\n\tres.write;\n\n\n\tstatic if(0) {\n\tauto t = arr.redBlackTree!(/*(a, b) => a.len < b.len,*/ true);\n\n\t;\n\n\tuint canMake(uint len) {\n\t\tuint a;\n\n\t\tforeach(i; 0..2) {\n\t\t\tauto r = t.equalRange(len);\n\t\t\tif(r.empty) return 0;\n\t\t\tif(!i) r.popBack;\n\t\t\tif(!r.empty) {\n\t\t\t\ta = len;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlen--;\n\t\t}\n\n\t\tuint b;\n\n\t\t{\n\t\t\tauto r = t.lowerRange(a);\n\n\t\t\twhile(!r.empty) {\n\t\t\t\tb = r.back;\n\t\t\t\tr.popBack;\n\t\t\t}\n\t\t}\n\n\t\t/*auto a = t.equalRange(len).length > 1 ? len : (t.equalRange(len - 1).length ? len - 1 : 0);\n\n\t\tif(!a) return 0;\n\n foreach_reverse(k; t.lowerRange(a)) {}*/\n return 0;\n\t}\n\n\tforeach_reverse(len; arr) {\n\t\t;\n\t}\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm, std.math;\n\nvoid solve(int[] arr)\n{\n sort(arr);\n long ans = 0;\n int[] nums, cnt;\n for (int i = 0, next; i < arr.length; i = next)\n {\n next = i + 1;\n while (next < arr.length && arr[next] == arr[i]) ++ next;\n nums ~= arr[i];\n cnt ~= next - i;\n }\n for (int i = cast(int)nums.length - 1, next; i >= 0; i = next)\n {\n auto d = cnt[i] / 4;\n auto r = cnt[i] % 4;\n ans += cast(long)nums[i] * nums[i] * d;\n if (i > 0)\n {\n if (r == 0) \n {\n next = i - 1;\n continue;\n }\n else if (r == 1)\n {\n if (nums[i] - nums[i - 1] == 1)\n {\n ++ cnt[i - 1];\n }\n next = i - 1;\n continue;\n }\n else if (r == 3)\n {\n if (nums[i] - nums[i - 1] == 1)\n {\n ans += cast(long)nums[i] * nums[i - 1];\n -- cnt[i - 1];\n next = i - 1;\n continue;\n }\n }\n int j;\n for (j = i - 1; j >= 0; -- j)\n {\n if (cnt[j] >= 2) break;\n if (j > 0 && nums[j] - nums[j - 1] == 1) break;\n }\n if (j == -1) break;\n if (cnt[j] == 2)\n {\n ans += cast(long)nums[i] * nums[j];\n cnt[j] -= 2;\n next = j;\n }\n else\n {\n ans += cast(long)nums[i] * nums[j - 1];\n -- cnt[j - 1];\n next = j - 1;\n }\n }\n else\n {\n next = -1;\n }\n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto arr = new int[n];\n foreach (i; 0 .. n) scanf(\"%d\", &arr[i]);\n solve(arr);\n }\n}\n"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm, std.math;\n\nlong calc(int a, int b, int c, int d)\n{\n if (b - a > 1 || d - c > 1) return 0;\n return cast(long)a * c;\n}\n\nvoid solve(int[] arr)\n{\n sort(arr);\n long ans = 0;\n for (int i = 0; i <= arr.length - 4; ++ i)\n {\n auto ret = calc(arr[i], arr[i + 1], arr[i + 2], arr[i + 3]);\n ans = cast(long)fmax(ans, ret);\n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto arr = new int[n];\n foreach (i; 0 .. n) scanf(\"%d\", &arr[i]);\n solve(arr);\n }\n}\n"}, {"source_code": "import std.stdio, std.string;\nimport std.algorithm, std.math;\n\nvoid solve(int[] arr)\n{\n sort(arr);\n long ans = 0;\n int[] nums, cnt;\n for (int i = 0, next; i < arr.length; i = next)\n {\n next = i + 1;\n while (next < arr.length && arr[next] == arr[i]) ++ next;\n nums ~= arr[i];\n cnt ~= next - i;\n }\n int pos = -1;\n for (int i = cast(int)nums.length - 1; i >= 0; -- i)\n {\n if (cnt[i] >= 2 || i < nums.length - 1 && nums[i + 1] - nums[i] == 1)\n {\n pos = i;\n if (i < nums.length - 1 && nums[i + 1] - nums[i] == 1) cnt[i] += cnt[i + 1];\n break;\n }\n }\n if (pos != -1)\n {\n if (cnt[pos] >= 4)\n {\n ans = cast(long)nums[pos] * nums[pos];\n }\n else\n {\n for (int i = pos - 1; i >= 0; -- i)\n {\n if (cnt[i] >= 2 || nums[i + 1] - nums[i] == 1 && (i < pos - 1 || cnt[pos] == 3))\n {\n ans = cast(long)nums[pos] * nums[i];\n break;\n }\n }\n }\n }\n writeln(ans);\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n auto arr = new int[n];\n foreach (i; 0 .. n) scanf(\"%d\", &arr[i]);\n solve(arr);\n }\n}\n"}], "src_uid": "0e162ea665732714283317e7c052e234"} {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main(string[] argv) {\n\tint n;\n\treadf(\"%s\\n\", &n);\n\tstring buff;\n\tforeach(int i; 0..n) {\n\t\tbuff = readln('\\n');\n\t\tif(buff.length <= 11)\n\t\t\twrite(buff);\n\t\telse {\n\t\t\twriteln(buff[0], buff.length-3, buff[$-2]);\n\t\t}\n\t}\n\treturn;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n//------------------\nauto change(string s){\n return s[0] ~ (s.length-2).to!string ~ s[$-1];\n}\n\nvoid main(){\n auto n = readln.chomp.to!int;\n foreach(i; 0..n){\n auto word = readln.chomp;\n if(word.length <= 10){ word.writeln; }\n else{ change(word).writeln; }\n }\n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nvoid main() {\n auto n = to!int(readln().chomp());\n for (auto i = 0; i < n; i++) {\n auto w = strip(readln());\n if (w.length > 10) {\n writeln(to!string(w[0])~to!string(w.length-2)~to!string(w[$-1]));\n } else {\n writeln(w);\n }\n }\n}\n\n "}, {"source_code": "import std.stdio : writeln, stdin;\nimport std.conv : to;\nimport std.range : dropOne;\n\nvoid main()\n{ \n foreach(word; stdin.byLine.dropOne)\n {\n writeln(word.length > 10 ? word[0]~to!string(word.length-2)~word[$-1] : word);\n }\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n;\n readf(\"%d\\n\", &n);\n\n for (int i = 0; i < n; ++i) {\n string s;\n readf(\"%s\\n\", &s);\n\n if (s.length <= 10) {\n writeln(s);\n } else {\n writefln(\"%c%d%c\", s[0], s.length-2, s[s.length-1]);\n }\n }\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 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;\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\tloop:while(read(&n))\n\t{\n\t\tforeach(i;0..n)\n\t\t{\n\t\t\tauto s=readln.strip;\n\t\t\tif(s.length<=10)writeln(s);\n\t\t\telse writeln(s[0],s.length-2,s[$-1]);\n\t\t}\n\t}\n\n}"}, {"source_code": "import std.stdio;\nimport std.conv;\n\nint main(string[] argv)\n{\n\tstring nstr = stdin.readln();\n\tnstr.length -= 1;\n\tint n = to!int(nstr);\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tstring l = stdin.readln();\n\t\tif (l[l.length - 1] == '\\n')\n\t\t\tl.length -= 1;\n\t\tif (l.length > 10)\n\t\t{\n\t\t\tstring r = \"\" ~ l[0];\n\t\t\tr ~= to!string(l.length - 2);\n\t\t\tr ~= l[l.length - 1];\n\t\t\twriteln(r);\n\t\t} else {\n\t\t\twriteln(l);\n\t\t}\n\t}\n return 0;\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/71/A\n// basic string manipulation\nimport std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n auto n = readln.chomp.to!int;\n foreach(i; 0..n) {\n auto s = readln.chomp;\n if(s.length > 10)\n writeln(s[0], s.length-2, s[$-1]);\n else\n writeln(s);\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/71/A\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n;\n readf!\"%d\"(n);\n readln;\n while(n--) {\n string s = readln.strip;\n if(s.length > 10)\n writeln(s[0], s.length-2, s[$-1]);\n else\n writeln(s);\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\n\nvoid main(){\n int n;\n readf!\"%d\"(n);\n readln;\n while(n--){\n string s=readln.strip;\n if(s.length>10){\n writeln(s[0],s.length-2,s[$-1]);\n }\n else writeln(s);\n }\n}\n\n"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int n;\n readf(\"%d\\n\",&n);\n string x;\n for(int i=1;i<=n;i++)\n {\n // writeln(\"%d\\n\",i);\n readf(\"%s\\n\",&x);\n if(x.length>10){\n writefln(\"%c%d%c\",x[0],x.length-2,x[x.length-1]);\n }\n else writeln(x);\n }\n}"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int n;\n readf(\"%d\\n\",&n);\n string x;\n for(int i=1;i<=n;i++)\n {\n // writeln(\"%d\\n\",i);\n readf(\"%s\\n\",&x);\n if(x.length>10){\n writefln(\"%c%d%c\\n\",x[0],x.length-2,x[x.length-1]);\n }\n else writeln(x);\n }\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nvoid main() {\n auto n = to!int(readln().chomp());\n writeln(\"n=\",n);\n for (auto i = 0; i < n; i++) {\n auto w = strip(readln());\n if (w.length >= 10) {\n writeln(to!string(w[0])~to!string(w.length-2)~to!string(w[$-1]));\n } else {\n writeln(w);\n }\n }\n}\n\n "}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nvoid main() {\n auto n = to!int(readln().chomp());\n for (auto i = 0; i < n; i++) {\n auto w = strip(readln());\n if (w.length >= 10) {\n writeln(to!string(w[0])~to!string(w.length-2)~to!string(w[$-1]));\n } else {\n writeln(w);\n }\n }\n}\n\n "}, {"source_code": "// https://codeforces.com/problemset/problem/71/A\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n;\n readf!\"%d\"(n);\n readln;\n while(n--) {\n string s = readln.strip;\n if(s.length > 10)\n writeln(s[0], s.length-1, s[$-1]);\n else\n writeln(s);\n }\n}\n\n"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int n;\n readf(\"%d\",&n);\n string x;\n for(int i=1;i<=n;i++)\n {\n // writeln(\"%d\\n\",i);\n readf(\"%s\",&x);\n if(x.length>10){\n writefln(\"%c%d%c\\n\",x[0],x.length-2,x[x.length-1]);\n }\n else writeln(x),writeln(\"\\n\");\n }\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main(string[] argv) {\n int n;\n readf(\"%s\\n\", &n);\n string buff;\n foreach(int i; 0..n) {\n buff = readln('\\n');\n if(buff.length < 10)\n write(buff);\n else {\n writeln(buff[0], buff.length-3, buff[$-2]);\n }\n }\n return;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nvoid main(string[] argv) {\n\tint n;\n\treadf(\"%s\\n\", &n);\n\tstring buff;\n\tforeach(int i; 0..n) {\n\t\tbuff = readln('\\n');\n\t\tif(buff.length <= 10)\n\t\t\twrite(buff);\n\t\telse {\n\t\t\twriteln(buff[0], buff.length-3, buff[$-2]);\n\t\t}\n\t}\n\treturn;\n}\n"}], "src_uid": "6639d6c53951f8c1a8324fb24ef68f7a"} {"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 n = rint;\n\t\tlong[] ans;\n\t\tlong i; \n\t\tfor(i = 0; i * i <= n; i ++) ans ~= i;\n\t\tfor(i -= 1; i >= 1; i --) if(ans[$ - 1] != n / i) ans ~= n / i;\n\t\tans.length.writeln;\n\t\tans.map!(to!string).array.join(\" \").writeln;\n\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 tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\treadf !(\" %s\") (n);\n\t\tint [] ans;\n\t\tans ~= 0;\n\t\tfor (int d = 1; d * d <= n; d++)\n\t\t{\n\t\t\tans ~= d;\n\t\t\tans ~= n / d;\n\t\t}\n\t\tsort (ans);\n\t\tans = ans.uniq.array;\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%s %)\", 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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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;\n\t\tlong[long] set;\n\t\tfor (long j = 1; j*j <= n; ++j)\n\t\t{\n\t\t\tauto x = n / j;\n\t\t\tauto y = set.get(x, 0);\n\t\t\tset[x] = max(y, j);\n\t\t\tauto z = set.get(j, 0);\n\t\t\tset[j] = max(z, x);\n\t\t}\n\t\tauto keys = set.keys;\n\t\tans[i].length = keys.length + 1;\n\t\tans[i][0] = 0;\n\t\tforeach (j, key; keys)\n\t\t{\n\t\t\tans[i][j+1] = set[key];\n\t\t}\n\t\tans[i].sort();\n\t}\n\t\n\tforeach (i; 0..t)\n\t{\n\t\twriteln(ans[i].length);\n\t\tans[i].map!(to!string).join(\" \").writeln;\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "1fea14a5c21bf301981656cbe015864d"} {"source_code": "import std.algorithm, std.container, std.range, std.array, std.ascii, std.bigint, std.conv, std.format, std.math, std.random, std.stdio, std.string, std.typecons;\n\nvoid main() {\n long t, a, b;\n string s;\n t.readf!\" %d\";\n while (t--) {\n a.readf!\" %d\";\n b.readf!\" %d\";\n s.readf!\" %s\\n\";\n \n long total, zeros;\n bool can_connect;\n foreach (i, c; s) {\n if (c == '1') {\n if (i == 0) {\n total += a;\n } else if (s[i - 1] == '1') {\n continue;\n } else {\n assert(zeros > 0);\n total += can_connect ? min(a, zeros * b) : a;\n }\n can_connect = true;\n zeros = 0;\n } else {\n zeros++;\n }\n }\n total.writeln;\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 a = RD!int;\n\t\tauto b = RD!int;\n\t\tauto s = RD!string;\n\t\tauto n = cast(int)s.length;\n\n\t\tint l = -1, r;\n\t\tforeach (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 (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '1')\n\t\t\t{\n\t\t\t\tr = i+1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (l == -1) continue;\n\n\t\tans[ti] = a;\n\t\tint cnt;\n\t\tforeach (i; l..r)\n\t\t{\n\t\t\tdebug writeln(\"ans:\", ans[ti]);\n\t\t\tif (s[i] == '0')\n\t\t\t\t++cnt;\n\t\t\telse\n\t\t\t{\n\t\t\t\tans[ti] += min(a, b*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": "fc01082e3ed7877126e750bc380f5c63"} {"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 int cnt;\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\n public this()\n {\n root = null;\n rnd = Xorshift(1234567891);\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 node.cnt = 1;\n this.rnd.seed(unpredictableSeed);\n return;\n }\n auto ret = node.cmpVal(val);\n if (ret == 0) \n {\n ++ node.cnt;\n return;\n }\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 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 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 _travel(node.right);\n }\n\n public void clear()\n {\n while (root)\n {\n remove(root.val);\n }\n }\n\n public int getCount(T val)\n {\n auto node = find(val);\n if (!node) return 0;\n return node.cnt;\n }\n}\n\nvoid solve(int[] a, int n, int k)\n{\n auto treap = new Treap!long();\n auto lcnt = new int[n];\n foreach (i; 0 .. n)\n {\n lcnt[i] = 0;\n if (a[i] % k == 0)\n {\n auto v = a[i] / k;\n lcnt[i] = treap.getCount(v);\n }\n treap.insert(cast(long)a[i]);\n }\n //treap.clear();\n treap = new Treap!long();\n auto rcnt = new int[n];\n for (int i = n - 1; i >= 0; -- i)\n {\n auto v = cast(long)a[i] * k;\n rcnt[i] = treap.getCount(v);\n treap.insert(a[i]);\n }\n long ans = 0;\n foreach (i; 0 .. n)\n {\n ans += cast(long)lcnt[i] * rcnt[i];\n }\n writeln(ans);\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, n, k);\n }\n return 0;\n}", "positive_code": [{"source_code": "import std.stdio, std.string;\n\nvoid solve(int[] a, int n, int k)\n{\n int[long] cnt;\n auto lcnt = new int[n];\n foreach (i; 0 .. n)\n {\n lcnt[i] = 0;\n if (a[i] % k == 0)\n {\n auto v = a[i] / k;\n if (v in cnt)\n {\n lcnt[i] = cnt[v];\n }\n }\n if (!(a[i] in cnt))\n {\n cnt[a[i]] = 1;\n }\n else\n {\n ++ cnt[a[i]];\n }\n }\n cnt.clear();\n auto rcnt = new int[n];\n for (int i = n - 1; i >= 0; -- i)\n {\n rcnt[i] = 0;\n auto v = cast(long)a[i] * k;\n if (v in cnt)\n {\n rcnt[i] = cnt[v];\n }\n if (!(a[i] in cnt))\n {\n cnt[a[i]] = 1;\n }\n else\n {\n ++ cnt[a[i]];\n }\n }\n long ans = 0;\n foreach (i; 0 .. n)\n {\n ans += cast(long)lcnt[i] * rcnt[i];\n }\n writeln(ans);\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, n, k);\n }\n return 0;\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 auto input1 = readln().split().map!(to!long);\n long n = input1[0], k = input1[1];\n long[] a = readln().split().map!(to!long).array;\n long[long][3] dp;\n foreach (v; a) {\n if (v % k == 0) {\n dp[2][v] += dp[1].get(v / k, 0);\n dp[1][v] += dp[0].get(v / k, 0);\n }\n dp[0][v] = dp[0].get(v, 0) + 1;\n }\n writeln(sum(dp[2].values));\n}\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 int cnt;\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\n public this()\n {\n root = null;\n rnd = Xorshift(1234567891);\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 node.cnt = 1;\n this.rnd.seed(unpredictableSeed);\n return;\n }\n auto ret = node.cmpVal(val);\n if (ret == 0) \n {\n ++ node.cnt;\n return;\n }\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 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 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 _travel(node.right);\n }\n\n public void clear()\n {\n while (root)\n {\n remove(root.val);\n }\n }\n\n public int getCount(T val)\n {\n auto node = find(val);\n if (!node) return 0;\n return node.cnt;\n }\n}\n\nvoid solve(int[] a, int n, int k)\n{\n auto treap = new Treap!long();\n auto lcnt = new int[n];\n foreach (i; 0 .. n)\n {\n lcnt[i] = 0;\n if (a[i] % k == 0)\n {\n auto v = a[i] / k;\n lcnt[i] = treap.getCount(v);\n }\n treap.insert(cast(long)a[i]);\n }\n treap.clear();\n auto rcnt = new int[n];\n for (int i = n - 1; i >= 0; -- i)\n {\n auto v = cast(long)a[i] * k;\n rcnt[i] = treap.getCount(v);\n treap.insert(a[i]);\n }\n long ans = 0;\n foreach (i; 0 .. n)\n {\n ans += cast(long)lcnt[i] * rcnt[i];\n }\n writeln(ans);\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, n, k);\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;\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\n if (N < 3) {\n writeln(0);\n return;\n }\n\n if (K == 1) {\n long[long] cnt;\n foreach (a; A) {\n if (a in cnt) cnt[a]++;\n else cnt[a] = 1;\n }\n long ans = 0;\n foreach (v; cnt.values)\n if (v >= 3)\n ans += v * (v-1) * (v-2) / 6;\n writeln(ans);\n return;\n }\n \n long[long] acm1, acm2;\n if (A[0] == A[1]) {\n acm1[A[0]] = 2;\n }\n else {\n acm1[A[0]] = 1;\n acm1[A[1]] = 1;\n }\n if (A[0] * K == A[1]) acm2[A[1]] = 1;\n long ans = 0;\n\n foreach (i; 2..N) {\n long a = A[i];\n if (a % K == 0 && (a/K in acm2)) {\n ans += acm2[a/K];\n }\n if (a % K == 0 && (a/K in acm1)) {\n if (a in acm2)\n acm2[a] += acm1[a/K];\n else\n acm2[a] = acm1[a/K];\n }\n if (a in acm1)\n acm1[a] += 1;\n else\n acm1[a] = 1;\n }\n\n ans.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, core.stdc.stdio, std.bitmanip;\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\n if (N < 3) {\n writeln(0);\n return;\n }\n \n long[long] acm1, acm2;\n if (A[0] == A[1]) {\n acm1[A[0]] = 2;\n }\n else {\n acm1[A[0]] = 1;\n acm2[A[1]] = 1;\n }\n if (A[0] * K == A[1]) acm2[A[1]] = 1;\n long ans = 0;\n\n foreach (i; 2..N) {\n long a = A[i];\n if (a % K == 0 && (a/K in acm2))\n ans += acm2[a/K];\n if (a in acm1)\n acm1[a] += 1;\n else\n acm1[a] = 1;\n if (a % K == 0 && a/K in acm1) {\n if (a in acm2)\n acm2[a] += acm1[a/K];\n else\n acm2[a] = acm1[a/K];\n }\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, core.stdc.stdio, std.bitmanip;\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\n if (N < 3) {\n writeln(0);\n return;\n }\n\n if (K == 1) {\n writeln(N-2);\n return;\n }\n \n long[long] acm1, acm2;\n if (A[0] == A[1]) {\n acm1[A[0]] = 2;\n }\n else {\n acm1[A[0]] = 1;\n acm1[A[1]] = 1;\n }\n if (A[0] * K == A[1]) acm2[A[1]] = 1;\n long ans = 0;\n\n foreach (i; 2..N) {\n long a = A[i];\n if (a % K == 0 && (a/K in acm2)) {\n ans += acm2[a/K];\n }\n if (a in acm1)\n acm1[a] += 1;\n else\n acm1[a] = 1;\n if (a % K == 0 && (a/K in acm1)) {\n if (a in acm2)\n acm2[a] += acm1[a/K];\n else\n acm2[a] = acm1[a/K];\n }\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, core.stdc.stdio, std.bitmanip;\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\n if (N < 3) {\n writeln(0);\n return;\n }\n\n if (K == 1) {\n long[long] cnt;\n foreach (a; A) {\n if (a in cnt) cnt[a]++;\n else cnt[a] = 1;\n }\n long ans = 0;\n foreach (v; cnt.values)\n if (v >= 3)\n ans += v * (v-1) * (v-2) / 6;\n writeln(ans);\n return;\n }\n \n long[long] acm1, acm2;\n if (A[0] == A[1]) {\n acm1[A[0]] = 2;\n }\n else {\n acm1[A[0]] = 1;\n acm1[A[1]] = 1;\n }\n if (A[0] * K == A[1]) acm2[A[1]] = 1;\n long ans = 0;\n\n foreach (i; 2..N) {\n long a = A[i];\n if (a % K == 0 && (a/K in acm2)) {\n ans += acm2[a/K];\n }\n if (a in acm1)\n acm1[a] += 1;\n else\n acm1[a] = 1;\n if (a % K == 0 && (a/K in acm1)) {\n if (a in acm2)\n acm2[a] += acm1[a/K];\n else\n acm2[a] = acm1[a/K];\n }\n }\n\n ans.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, std.bitmanip;\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\n if (N < 3) {\n writeln(0);\n return;\n }\n \n long[long] acm1, acm2;\n if (A[0] == A[1]) {\n acm1[A[0]] = 2;\n }\n else {\n acm1[A[0]] = 1;\n acm1[A[1]] = 1;\n }\n if (A[0] * K == A[1]) acm2[A[1]] = 1;\n long ans = 0;\n\n foreach (i; 2..N) {\n long a = A[i];\n if (a % K == 0 && (a/K in acm2)) {\n ans += acm2[a/K];\n }\n if (a in acm1)\n acm1[a] += 1;\n else\n acm1[a] = 1;\n if (a % K == 0 && (a/K in acm1)) {\n if (a in acm2)\n acm2[a] += acm1[a/K];\n else\n acm2[a] = acm1[a/K];\n }\n }\n\n ans.writeln;\n}\n"}], "src_uid": "bd4b3bfa7511410c8e54658cc1dddb46"} {"source_code": "import std.algorithm, std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new uint [] [] [] (2, n, (n + 31) / 32);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tint c;\n\t\t\t\tscanf (\" %d\", &c);\n\t\t\t\tif (c)\n\t\t\t\t{\n\t\t\t\t\ta[0][i][j >> 5] |= 1u << (j & 31);\n\t\t\t\t\ta[1][j][i >> 5] |= 1u << (i & 31);\n\t\t\t\t}\n\t\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (ref g; a)\n\t\t{\n\t\t\tauto b = new bool [n];\n\n\t\t\tvoid recur (int v)\n\t\t\t{\n\t\t\t\tb[v] = true;\n\t\t\t\tforeach (u; 0..n)\n\t\t\t\t\tif (!b[u] &&\n\t\t\t\t\t (g[v][u >> 5] & (1u << (u & 31))))\n\t\t\t\t\t\trecur (u);\n\t\t\t}\n\t\t\trecur (0);\n\t\t\tok &= all !\"a\" (b);\n\t\t}\n\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm, std.stdio;\n\nvoid main ()\n{\n\tstdin.setvbuf (16_384, _IOFBF);\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new bool [] [] [] (2, n, n);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tint c;\n\t\t\t\tscanf (\" %d\", &c);\n\t\t\t\tif (c)\n\t\t\t\t\ta[0][i][j] = a[1][j][i] = true;\n\t\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (ref g; a)\n\t\t{\n\t\t\tauto b = new bool [n];\n\n\t\t\tvoid recur (int v)\n\t\t\t{\n\t\t\t\tb[v] = true;\n\t\t\t\tforeach (u; 0..n)\n\t\t\t\t\tif (!b[u] && g[v][u])\n\t\t\t\t\t\trecur (u);\n\t\t\t}\n\t\t\trecur (0);\n\t\t\tok &= all !\"a\" (b);\n\t\t}\n\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nextern (C) nothrow int scanf (const char *, ...);\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new bool [] [] [] (2, n, n);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tint c;\n\t\t\t\tscanf (\" %d\", &c);\n\t\t\t\tif (c)\n\t\t\t\t\ta[0][i][j] = a[1][j][i] = true;\n\t\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (ref g; a)\n\t\t{\n\t\t\tauto b = new bool [n];\n\n\t\t\tvoid recur (int v)\n\t\t\t{\n\t\t\t\tb[v] = true;\n\t\t\t\tforeach (u; 0..n)\n\t\t\t\t\tif (!b[u] && g[v][u])\n\t\t\t\t\t\trecur (u);\n\t\t\t}\n\t\t\trecur (0);\n\t\t\tok &= all !\"a\" (b);\n\t\t}\n\t\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tint m = (n + 31) / 32;\n\t\tauto a1 = new uint [] [] (n, m);\n\t\tauto a2 = new uint [] [] (n, m);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tint c;\n\t\t\t\tscanf (\" %d\", &c);\n\t\t\t\tif (c)\n\t\t\t\t{\n\t\t\t\t\ta1[i][j >> 5] |= 1u << (j & 31);\n\t\t\t\t\ta2[j][i >> 5] |= 1u << (i & 31);\n\t\t\t\t}\n\t\t\t}\n\n\t\tauto b = new bool [n];\n\t\tuint [] [] a;\n\n\t\tvoid recur (int v)\n\t\t{\n\t\t\tb[v] = true;\n\t\t\tforeach (u; 0..n)\n\t\t\t\tif (!b[u] && (a[v][u >> 5] & (1u << (u & 31))))\n\t\t\t\t\trecur (u);\n\t\t}\n\t\t\n\t\tbool ok = true;\n\n\t\tb[] = false;\n\t\ta = a1;\n\t\trecur (0);\n\t\tok &= all !(\"a == true\") (b[]);\n\n\t\tb[] = false;\n\t\ta = a2;\n\t\trecur (0);\n\t\tok &= all !(\"a == true\") (b[]);\n\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.string;\n\nextern (C) nothrow int printf (const char *, ...);\nextern (C) nothrow int scanf (const char *, ...);\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new bool [] [] [] (2, n, n);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tint c;\n\t\t\t\tscanf (\" %d\", &c);\n\t\t\t\tif (c)\n\t\t\t\t\ta[0][i][j] = a[1][j][i] = true;\n\t\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (ref g; a)\n\t\t{\n\t\t\tauto b = new bool [n];\n\n\t\t\tvoid recur (int v)\n\t\t\t{\n\t\t\t\tb[v] = true;\n\t\t\t\tforeach (u; 0..n)\n\t\t\t\t\tif (!b[u] && g[v][u])\n\t\t\t\t\t\trecur (u);\n\t\t\t}\n\t\t\trecur (0);\n\t\t\tok &= all !\"a\" (b);\n\t\t}\n\t\n\t\tprintf (toStringz (ok ? \"YES\\n\" : \"NO\\n\"));\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nextern (C) nothrow int printf (const char *, ...);\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new bool [] [] [] (2, n, n);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tint c;\n\t\t\t\tscanf (\" %d\", &c);\n\t\t\t\tif (c)\n\t\t\t\t\ta[0][i][j] = a[1][j][i] = true;\n\t\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (ref g; a)\n\t\t{\n\t\t\tauto b = new bool [n];\n\n\t\t\tvoid recur (int v)\n\t\t\t{\n\t\t\t\tb[v] = true;\n\t\t\t\tforeach (u; 0..n)\n\t\t\t\t\tif (!b[u] && g[v][u])\n\t\t\t\t\t\trecur (u);\n\t\t\t}\n\t\t\trecur (0);\n\t\t\tok &= all !\"a\" (b);\n\t\t}\n\t\n\t\twriteln (ok ? \"YES\" : \"NO\");\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 (scanf (\" %d\", &n) > 0)\n\t{\n\t\tint m = (n + 31) / 32;\n\t\tauto a1 = new uint [] [] (n, m);\n\t\tauto a2 = new uint [] [] (n, m);\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 c;\n\t\t\t\tscanf (\" %d\", &c);\n\t\t\t\tif (c)\n\t\t\t\t{\n\t\t\t\t\ta1[i][j >> 5] |= 1u << (j & 31);\n\t\t\t\t\ta2[j][i >> 5] |= 1u << (i & 31);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tauto b = new bool [n];\n\t\tuint [] [] a;\n\n\t\tvoid recur (int v)\n\t\t{\n\t\t\tb[v] = true;\n\t\t\tforeach (u; 0..n)\n\t\t\t{\n\t\t\t\tif (!b[u] && (a[v][u >> 5] & (1u << (u & 31))))\n\t\t\t\t{\n\t\t\t\t\trecur (u);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tbool ok = true;\n\n\t\tb[] = false;\n\t\ta = a1;\n\t\trecur (0);\n\t\tok &= all !(\"a == true\") (b[]);\n\n\t\tb[] = false;\n\t\ta = a2;\n\t\trecur (0);\n\t\tok &= all !(\"a == true\") (b[]);\n\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nvoid main ()\n{\n\tstdin.setvbuf (16_384, _IOFBF);\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new int [] [] [] (2, n, n);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[0][i][j]);\n\t\t\t\ta[1][j][i] = a[0][i][j];\n\t\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (ref g; a)\n\t\t{\n\t\t\tauto b = new bool [n];\n\n\t\t\tvoid recur (int v)\n\t\t\t{\n\t\t\t\tb[v] = true;\n\t\t\t\tforeach (u; 0..n)\n\t\t\t\t\tif (!b[u] && g[v][u])\n\t\t\t\t\t\trecur (u);\n\t\t\t}\n\t\t\trecur (0);\n\t\t\tok &= all !\"a\" (b);\n\t\t}\n\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nvoid main ()\n{\n int n;\n while (scanf (\" %d\", &n) > 0)\n {\n int m = (n + 31) / 32;\n auto a1 = new uint [] [] (n, m);\n auto a2 = new uint [] [] (n, m);\n foreach (i; 0..n)\n foreach (j; 0..n)\n {\n int c;\n scanf (\" %d\", &c);\n if (c)\n {\n a1[i][j >> 5] |= 1u << (j & 31);\n a2[j][i >> 5] |= 1u << (i & 31);\n }\n }\n\n auto b = new bool [n];\n uint [] [] a;\n\n void recur (int v)\n {\n b[v] = true;\n foreach (u; 0..n)\n if (!b[u] && (a[v][u >> 5] & (1u << (u & 31))))\n recur (u);\n }\n \n bool ok = true;\n\n b[] = false;\n a = a1;\n recur (0);\n ok &= all !(\"a == true\") (b[]);\n\n b[] = false;\n a = a2;\n recur (0);\n ok &= all !(\"a == true\") (b[]);\n\n writeln (ok ? \"YES\" : \"NO\");\n }\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new int [] [] [] (2, n, n);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tscanf (\" %d\", &a[0][i][j]);\n\t\t\t\ta[1][j][i] = a[0][i][j];\n\t\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (g; a)\n\t\t{\n\t\t\tauto b = new bool [n];\n\n\t\t\tvoid recur (int v)\n\t\t\t{\n\t\t\t\tb[v] = true;\n\t\t\t\tforeach (u; 0..n)\n\t\t\t\t\tif (!b[u] && g[v][u])\n\t\t\t\t\t\trecur (u);\n\t\t\t}\n\t\t\trecur (0);\n\t\t\tok &= all !\"a\" (b);\n\t\t}\n\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (scanf (\" %d\", &n) > 0)\n\t{\n\t\tauto a = new bool [] [] [] (2, n, n);\n\t\tforeach (i; 0..n)\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tint c;\n\t\t\t\tscanf (\" %d\", &c);\n\t\t\t\tif (c)\n\t\t\t\t\ta[0][i][j] = a[1][j][i] = true;\n\t\t\t}\n\n\t\tbool ok = true;\n\t\tforeach (ref g; a)\n\t\t{\n\t\t\tauto b = new bool [n];\n\n\t\t\tvoid recur (int v)\n\t\t\t{\n\t\t\t\tb[v] = true;\n\t\t\t\tforeach (u; 0..n)\n\t\t\t\t\tif (!b[u] && g[v][u])\n\t\t\t\t\t\trecur (u);\n\t\t\t}\n\t\t\trecur (0);\n\t\t\tok &= all !\"a\" (b);\n\t\t}\n\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "9cf8b711a3fcf5dd5059f323f107a0bd"} {"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 long INF = 1L<<50;\r\n\r\nvoid solve() {\r\n int N = read!int;\r\n auto S = read!string;\r\n auto A = readarray!long;\r\n\r\n auto f = new long[][](2, N+1);\r\n f[0][N] = 0; f[1][N] = -INF;\r\n for (int k = N - 1; k >= 0; k--) {\r\n f[0][k] = max(f[1][k+1] + A[k], f[0][k+1] + A[k] * (S[k] == '1'));\r\n if (S[k] == '1') {\r\n f[1][k] = max(f[1][k+1] + A[k], f[0][k+1]);\r\n } else {\r\n f[1][k] = -INF;\r\n }\r\n }\r\n writeln(max(f[0][0], f[1][0]));\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!int;\n auto s = \"0\" ~ readln.strip;\n auto a = [0] ~ readln.splitter.map!(to!int).array;\n\n int[] x = seq_length_right!((a, b) => a == b)(s);\n\n long ans;\n size_t i = 0;\n while (i < x.length) {\n if (x[i] >= 1 && s[i] == '1') {\n ans += a[i - 1 .. i - 1 + x[i] + 1].sum - a[i - 1 .. i - 1 + x[i] + 1].minElement;\n }\n i += x[i];\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\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 char[] c = readln.strip.dup.to!(char[]);\r\n auto a = readarray!int;\r\n long res;\r\n for(int i = 0; i < n; i++) {\r\n int minV;\r\n if (c[i] == '0') {\r\n minV = a[i];\r\n int j = i + 1;\r\n if (j == n) {\r\n res += minV;\r\n break;\r\n }\r\n while(c[j] != '0') {\r\n if (a[j] < minV)\r\n minV = a[j];\r\n j++;\r\n if (j == n)\r\n break;\r\n }\r\n res += minV;\r\n }\r\n }\r\n writeln(sum(a) - 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": [{"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 s = readln.strip;\n auto a = readln.splitter.map!(to!int).array;\n auto h = redBlackTree!(\"a>b\", true, int)();\n long ans;\n size_t j = 0;\n foreach (i ; 0 .. s.length) {\n if (s[i] != '0') {\n while (j <= i)\n h.insert(a[j++]);\n ans += h.front;\n h.removeFront;\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\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto s = readln.strip;\n auto pos = redBlackTree!(\"a x[0] == y[0] ? x[1] < y[1] : x[0] > y[0]).array;\n long ans;\n foreach (x ; b) {\n auto tmp = pos.upperBound(x[1] - 1);\n if (tmp.empty)\n continue;\n ans += x[0];\n pos.removeKey(tmp.front);\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\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto s = readln.strip;\n auto pos = redBlackTree!(\"a x[0] == y[0] ? x[1] > y[1] : x[0] > y[0]).array;\n long ans;\n foreach (x ; b) {\n auto tmp = pos.upperBound(x[1] - 1);\n if (tmp.empty)\n continue;\n ans += x[0];\n pos.removeKey(tmp.front);\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\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n auto n = readln.strip.to!int;\n auto s = readln.strip;\n auto pos = redBlackTree!(\"a x[0] > y[0]).array;\n long ans;\n foreach (x ; b) {\n auto tmp = pos.upperBound(x[1] - 1);\n if (tmp.empty)\n continue;\n ans += x[0];\n pos.removeKey(tmp.front);\n }\n writeln(ans);\n }\n}\n"}], "src_uid": "bcc79164881d9281a6080163dd8a0c91"} {"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\nvoid main()\n{\n int t;\n read(t);\n foreach(tc; 0 .. t)\n {\n int n;\n read(n);\n auto points = makeArray!(Tuple!(int, int))(n + 1);\n points[0] = tuple(0, 0);\n foreach(ref point; points[1 .. $])\n point = tuple(next!int, next!int);\n sort(points[]);\n if (points[].map!(t => t[1]).isSorted)\n {\n writeln(\"YES\");\n foreach(i; 1 .. points.length)\n {\n auto delta = tuple(points[i][0] - points[i - 1][0], points[i][1] - points[i - 1][1]);\n assert(delta[0] >= 0 && delta[1] >= 0);\n foreach(j; 0 .. delta[0])\n write('R');\n foreach(j; 0 .. delta[1])\n write('U');\n }\n writeln;\n }\n else\n {\n writeln(\"NO\");\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 tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint n;\n\t\treadf !(\" %s\") (n);\n\t\talias Point = Tuple !(int, q{x}, int, q{y});\n\t\tauto a = new Point [n];\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\treadf !(\" %s %s\") (c.x, c.y);\n\t\t}\n\n\t\ta.schwartzSort !(c => c.x + c.y);\n\t\tauto cur = Point (0, 0);\n\t\tbool ok = true;\n\t\tstring res;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\tif (c.x < cur.x || c.y < cur.y)\n\t\t\t{\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tres ~= 'R'.repeat (c.x - cur.x).text;\n\t\t\tres ~= 'U'.repeat (c.y - cur.y).text;\n\t\t\tcur = c;\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t\tif (ok)\n\t\t{\n\t\t\twriteln (res);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.outbuffer;\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 auto a = new Tuple!(int, int)[n + 1];\n for (int i = 1; i <= n; ++i)\n a[i][0] = readInt, a[i][1] = readInt;\n sort(a);\n bool ok = true;\n for (int i = 1; i <= n; ++i)\n ok &= a[i - 1][1] <= a[i][1];\n if (ok)\n {\n writeln(\"YES\");\n OutBuffer buf = new OutBuffer();\n for (int i = 1; i <= n; ++i)\n {\n for (int y = a[i - 1][0]; y < a[i][0]; ++y)\n buf.write('R');\n for (int y = a[i - 1][1]; y < a[i][1]; ++y)\n buf.write('U');\n }\n writeln(buf);\n }\n else\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.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 n = RD!int;\n\t\tauto xy = new long[][](n);\n\t\tforeach (i; 0..n)\n\t\t\txy[i] = [RD, RD];\n\n\t\txy.sort!\"a[0] == b[0] ? a[1] < b[1] : a[0] < b[0]\"();\n\n\t\tlong x, y;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (xy[i][1] < y)\n\t\t\t{\n\t\t\t\tans[ti] = \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tforeach (j; 0..xy[i][0]-x)\n\t\t\t\tans[ti] ~= \"R\";\n\t\t\tforeach (j; 0..xy[i][1]-y)\n\t\t\t\tans[ti] ~= \"U\";\n\t\t\tx = xy[i][0];\n\t\t\ty = xy[i][1];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tif (e == \"\")\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": [], "src_uid": "b01c627abc00f97767c237e304f8c17f"} {"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 isz(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, m, x, y;\n n = rd!int; m = rd!int; x = rd!int; y = rd!int;\n char[][] tiles;\n foreach(i; 0..n){\n auto tilerow = rd!(char[]);\n tiles ~= tilerow;\n }\n auto num = new int[][](n, m);\n foreach(i; 0..n){\n int cnt = 0;\n char prev = tiles[i][m-1];\n foreach_reverse(j; 0..m){\n if(tiles[i][j] == '.'){\n ++cnt;\n }else{\n cnt = 0;\n }\n num[i][j] = cnt;\n }\n }\n int take2 = 0, take = 0;\n foreach(i; 0 .. n){\n int j = 0;\n while(j < m){\n if(num[i][j] >= 2){\n ++take2;\n j += 2;\n }else if(num[i][j]){\n ++take;\n ++j;\n }else{\n ++j;\n }\n }\n }\n debug writeln(num);\n ll cost = take2 * min(2*x, y) + take * x;\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", "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, x, y;\n\t\treadf !(\" %s %s %s %s\") (n, m, x, y);\n\t\ty = min (y, 2 * x);\n\t\treadln;\n\t\tint res = 0;\n\t\tforeach (row; 0..n)\n\t\t{\n\t\t\tauto line = readln.strip;\n\t\t\tint col = 0;\n\t\t\twhile (col < m)\n\t\t\t{\n\t\t\t\tif (line[col] == '*')\n\t\t\t\t{\n\t\t\t\t\tres += 0;\n\t\t\t\t\tcol += 1;\n\t\t\t\t}\n\t\t\t\telse if (col + 1 >= m || line[col + 1] == '*')\n\t\t\t\t{\n\t\t\t\t\tres += x;\n\t\t\t\t\tcol += 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tres += y;\n\t\t\t\t\tcol += 2;\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) { 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 x = RD!int;\n\t\tauto y = 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\tint cnt;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tif (s[i][j] == '.')\n\t\t\t\t\t++cnt;\n\t\t\t}\n\t\t}\n\t\tif (x*2 <= y)\n\t\t{\n\t\t\tans[ti] = cnt*x;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tint j = 1;\n\t\t\t\twhile (j < m)\n\t\t\t\t{\n\t\t\t\t\tif (s[i][j] == '.' && s[i][j-1] == '.')\n\t\t\t\t\t{\n\t\t\t\t\t\tans[ti] += y;\n\t\t\t\t\t\tcnt -= 2;\n\t\t\t\t\t\tj += 2;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t++j;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans[ti] += x * cnt;\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": "// 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 isz(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, m, x, y;\n n = rd!int; m = rd!int; x = rd!int; y = rd!int;\n char[][] tiles;\n foreach(i; 0..n){\n auto tilerow = rd!(char[]);\n tiles ~= tilerow;\n }\n auto num = new int[][](n, m);\n foreach(i; 0..n){\n int cnt = 0;\n char prev = tiles[i][m-1];\n foreach_reverse(j; 0..m){\n if(tiles[i][j] == prev && prev == '.'){\n ++cnt;\n }else if(prev == '.'){\n cnt = 1;\n }else{\n cnt = 0;\n }\n num[i][j] = cnt;\n }\n }\n int take2 = 0, take = 0;\n foreach(i; 0 .. n){\n int j = 0;\n while(j < m){\n if(num[i][j] >= 2){\n ++take2;\n j += 2;\n }else if(num[i][j]){\n ++take;\n ++j;\n }else{\n ++j;\n }\n }\n }\n debug writeln(num);\n int cost = take2 * min(2*x, y) + take * x;\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"}], "src_uid": "69ef9492fcdcc979cb31fa95c3e76db9"} {"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 rows, cols;\n\t\treadf !(\" %s %s\") (rows, cols);\n\t\tauto a = 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\treadf !(\" %s\") (a[row][col]);\n\t\t\t}\n\t\t}\n\n\t\tbool ok = true;\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 cur = (row > 0) + (row + 1 < rows);\n\t\t\t\tcur += (col > 0) + (col + 1 < cols);\n\t\t\t\tok &= (a[row][col] <= cur);\n\t\t\t\ta[row][col] = cur;\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%)\") (a);\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.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 rows, cols;\n\t\treadf !(\" %s %s\") (rows, cols);\n\t\tauto a = 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\treadf !(\" %s\") (a[row][col]);\n\t\t\t}\n\t\t}\n \n\t\tbool ok = true;\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 cur = (row > 0) + (row + 1 < rows);\n\t\t\t\tcur += (col > 0) + (col + 1 < cols);\n\t\t\t\tok &= (a[row][col] <= cur);\n\t\t\t\ta[row][col] = cur;\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%)\") (a);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\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 M = readInt();\n const N = readInt();\n auto A = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n A[x][y] = readInt();\n }\n \n auto deg = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n if (x - 1 >= 0) {\n ++deg[x - 1][y];\n ++deg[x][y];\n }\n if (y - 1 >= 0) {\n ++deg[x][y - 1];\n ++deg[x][y];\n }\n }\n \n bool ans = true;\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n ans = ans && (A[x][y] <= deg[x][y]);\n }\n if (ans) {\n writeln(\"YES\");\n foreach (x; 0 .. M) {\n foreach (y; 0 .. N) {\n if (y > 0) write(\" \");\n write(deg[x][y]);\n }\n writeln;\n }\n } else {\n writeln(\"NO\");\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\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 int[][](n);\n\t\tforeach (i; 0..n)\n\t\t\ta[i] = RDA!int;\n\n\t\tans[ti].length = n;\n\t\tforeach (i; 0..n)\n\t\t\tans[ti][i].length = m;\n\t\tbool ok = true;\n\t\t(){\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 x = 4;\n\t\t\t\tif (i == 0 || i == n-1)\n\t\t\t\t\t--x;\n\t\t\t\tif (j == 0 || j == m-1)\n\t\t\t\t\t--x;\n\t\t\t\t\n\t\t\t\tif (a[i][j] > x)\n\t\t\t\t{\n\t\t\t\t\tok = false;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tans[ti][i][j] = x;\n\t\t\t}\n\t\t}}();\n\n\t\tif (!ok)\n\t\t{\n\t\t\tans[ti].length = 0;\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\tee.map!(to!string).join(\" \").writeln;\n\t\t\t}\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "8afcdfaabba66fb9cefc5b6ceabac0d0"} {"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 immutable n = r.next!int;\n immutable m = r.next!int;\n auto x = r.nextA!long (n);\n immutable x0 = x[0];\n long g;\n debug stderr.writeln(x);\n foreach (i; 1 .. n) {\n immutable dx = x[i] - x0;\n if (i == 1) {\n g = dx;\n } else {\n debug stderr.writeln(g, ' ', dx);\n g = gcd (g, dx);\n }\n }\n auto p = r.nextA!long (m);\n foreach (i; 0 .. m) {\n if (!(g % p[i])) {\n writeln (\"YES\");\n writeln (x[0], ' ', i + 1);\n return;\n }\n }\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.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 x = RDR.ARR;\n\tauto p = RDR.ARR;\n\n\tlong g = x[1] - x[0];\n\tforeach (i; 2..N)\n\t{\n\t\tg = gcd(g, x[i] - x[i-1]);\n\t}\n\n\tlong ans;\n\tforeach (i; 0..M)\n\t{\n\t\tif (g % p[i] == 0)\n\t\t{\n\t\t\tans = i+1;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (ans == 0)\n\t\twriteln(\"NO\");\n\telse\n\t{\n\t\twriteln(\"YES\");\n\t\twriteln(x[0], \" \", ans);\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 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 P = readln.split.map!(to!long).array;\n \n auto B = (N-1).iota.map!(i => A[i+1] - A[i]).array;\n auto G = B.reduce!((a, b) => gcd(a, b));\n \n foreach (i; 0..M) {\n if (G % P[i] == 0) {\n writeln(\"YES\");\n writeln(A.front, \" \", i + 1);\n return;\n }\n }\n\n writeln(\"NO\");\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}\n\nvoid main() {\n auto r = new InputReader;\n immutable n = r.next!int;\n immutable m = r.next!int;\n auto x = uninitializedArray!(long[]) (n);\n foreach (i; 0 .. n) x[i] = r.next!long;\n immutable x0 = x[0];\n long g;\n foreach (i; 1 .. n) {\n immutable dx = x[i] - x0;\n if (i == 1) {\n g = dx;\n } else {\n g = gcd (g, dx);\n }\n }\n auto p = uninitializedArray!(long[]) (n);\n foreach (i; 0 .. m) {\n p[i] = r.next!long;\n if (!(g % p[i])) {\n writeln (\"YES\");\n writeln (x[0], ' ', i + 1);\n return;\n }\n }\n writeln (\"NO\");\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; }\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/*\n\nFind gcd of given minutes.\nIf any p is divisor of the gcd, then YES.\nOtherwise NO.\n\n*/\n\nvoid solve(){\n\tint n = read!int;\n\tint m = read!int;\n\tlong[] xs = read!long(n);\n\tlong[] ps = read!long(m);\n\t\n\tlong d = xs[1] - xs[0];\n\tforeach(i; 0 .. n - 1) d = gcd(d, xs[i + 1] - xs[i]);\n\t\n\tbool f;\n\tint ans;\n\tforeach(int j, p; ps) if(d % p == 0) f = 1, ans = j;\n\t\n\tif(! f) writeln(\"NO\");\n\telse writeln(\"YES\"), writeln(xs[0], \" \", ans + 1);\n}\n\nlong gcd(long a, long 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"}], "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 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/*\n\nFind gcd of given minutes.\nIf any p is divisor of the gcd, then YES.\nOtherwise NO.\n\n*/\n\nvoid solve(){\n\tint n = read!int;\n\tint m = read!int;\n\tlong[] xs = read!long(n);\n\tlong[] ps = read!long(m);\n\t\n\tlong d = xs[0];\n\tforeach(x; xs) d = gcd(d, x);\n\t\n\tbool f;\n\tint ans;\n\tforeach(int j, p; ps) if(d % p == 0) f = 1, ans = j;\n\t\n\tif(! f) writeln(\"NO\");\n\telse writeln(\"YES\"), writeln(xs[0], \" \", ans + 1);\n}\n\nlong gcd(long a, long 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": "6493e146ea8d931582d77bb1b0f06e53"} {"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 a = readln.splitter.map !(to !(int)).array;\r\n\r\n\t\tif (m == n)\r\n\t\t{\r\n\t\t\twriteln (m);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tsort (a);\r\n\t\ta ~= a[0] + n;\r\n\t\tint [] c;\r\n\t\tc.reserve (m);\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tc ~= a[j + 1] - a[j] - 1;\r\n\t\t}\r\n\r\n\t\tsort !(q{a > b}) (c);\r\n\t\tint res = m;\r\n\t\tforeach (i; 0..m)\r\n\t\t{\r\n\t\t\tres += min (c[i], i * 4 + (c[i] > i * 4 + 1));\r\n\t\t}\r\n\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 L = readLong;\n const M = readInt;\n auto A = new long[M];\n foreach (i; 0 .. M) {\n A[i] = readLong;\n }\n A.sort;\n \n auto ds = new long[M];\n foreach (i; 0 .. M - 1) {\n ds[i] = A[i + 1] - A[i];\n }\n ds[M - 1] = L + A[0] - A[M - 1];\n ds.sort!\"a > b\";\n debug {\n writeln(\"ds = \", ds);\n }\n \n long ans;\n foreach (j; 0 .. M) {\n long d = ds[j] - 1;\n d -= 4 * j;\n if (d > 0) {\n ans += max(d - 1, 1);\n }\n }\n ans = L - ans;\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\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\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\tif (m == n)\r\n\t\t{\r\n\t\t\twriteln (m);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tsort (a);\r\n\t\ta ~= a[0] + n;\r\n\t\tint [] c;\r\n\t\tc.reserve (m);\r\n\t\tforeach (j; 0..m)\r\n\t\t{\r\n\t\t\tif (a[j + 1] - a[j] > 1)\r\n\t\t\t{\r\n\t\t\t\tc ~= a[j + 1] - a[j] - 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tsort (c);\r\n\t\tint res = m;\r\n\t\tint span = 0;\r\n\t\tbool half = false;\r\n\r\n\t\tint getC ()\r\n\t\t{\r\n\t\t\tint temp = c.front;\r\n\t\t\tif (c.length == 1 && half)\r\n\t\t\t{\r\n\t\t\t\ttemp -= 1;\r\n\t\t\t}\r\n\t\t\treturn temp;\r\n\t\t}\r\n\r\n\t\twhile (!c.empty)\r\n\t\t{\r\n\t\t\tif (half)\r\n\t\t\t{\r\n\t\t\t\tres += span - 1;\r\n\t\t\t\tc.popBack ();\r\n\t\t\t}\r\n\t\t\tspan += 2;\r\n\t\t\thalf ^= true;\r\n\t\t\twhile (!c.empty && getC () <= span)\r\n\t\t\t{\r\n\t\t\t\tres += getC ();\r\n\t\t\t\tc.popFront ();\r\n\t\t\t}\r\n\t\t}\r\n\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 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"}], "src_uid": "8b007a212a940f09a9306b0c0091e2ad"} {"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, x;\n @Dim(\"n - 1\") long[2][] edges;\n\n void solve(long tc = -1)\n {\n long degx = 0;\n foreach(edge; edges)\n {\n if (edge[0] == x || edge[1] == x)\n degx++;\n }\n if (degx <= 1)\n return writeln(\"Ayush\");\n if (n % 2 == 0)\n return writeln(\"Ayush\");\n writeln(\"Ashish\");\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.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\tx -= 1;\n\t\tauto d = 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\td[u] += 1;\n\t\t\td[v] += 1;\n\t\t}\n\n\t\tbool win = true;\n\t\tif (d[x] >= 2)\n\t\t{\n\t\t\twin = !(n & 1);\n\t\t}\n\t\twriteln (win ? \"Ayush\" : \"Ashish\");\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 = multi;\nstruct TestCase\n{\n mixin prettyPrinting;\n\n long n, x;\n @Dim(\"n - 1\") long[2][] edges;\n\n void solve(long tc = -1)\n {\n long degx = 0;\n foreach(edge; edges)\n {\n if (edge[0] == x || edge[1] == x)\n degx++;\n }\n if (degx == 1)\n return writeln(\"Ayush\");\n if (n % 2 == 0)\n return writeln(\"Ayush\");\n writeln(\"Ashish\");\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": "1a93a35395436f9e15760400f991f1ce"} {"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = array (iota (n));\n\t\tforeach (k; 2..n + 1)\n\t\t{\n\t\t\tint hi = (n - 1) / k;\n\t\t\ta ~= 0;\n\t\t\tfor (int i = hi; i >= 0; i--)\n\t\t\t{\n\t\t\t\ta[min ((i + 1) * k, $ - 1)] = a[i * k];\n\t\t\t}\n\t\t\ta = a[1..$];\n\t\t}\n\t\ta[] += 1;\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n", "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = array (iota (n));\n\t\ta.reserve (2 * n);\n\t\tforeach (k; 2..n + 1)\n\t\t{\n\t\t\tint hi = (n - 1) / k;\n\t\t\ta.length++;\n\t\t\tfor (int i = hi; i >= 0; i--)\n\t\t\t{\n\t\t\t\ta[min ((i + 1) * k, $ - 1)] = a[i * k];\n\t\t\t}\n\t\t\ta = a[1..$];\n\t\t}\n\t\ta[] += 1;\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.exception;\nimport std.math;\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));\n\t\ta.reserve (n * 2);\n\t\tforeach (k; 2..n + 1)\n\t\t{\n\t\t\tdebug {writeln (a);}\n\t\t\tint hi = (n - 1) / k;\n\t\t\ta.length++;\n\t\t\tdebug {writeln (a);}\n\t\t\tfor (int i = hi; i >= 0; i--)\n\t\t\t{\n\t\t\t\tdebug {writefln (\"%s -> %s\", i * k,\n\t\t\t\t min ((i + 1) * k,\n\t\t\t\t a.length - 1));}\n\t\t\t\ta[min ((i + 1) * k, $ - 1)] = a[i * k];\n\t\t\t}\n\t\t\ta = a[1..$];\n\t\t}\n\t\ta[] += 1;\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n))\n\t{\n\t\tauto a = array (iota (n * 2));\n\t\tforeach (k; 1..n + 1)\n\t\t{\n\t\t\tfor (int i = (n - 1) / k; i >= 0; i--)\n\t\t\t{\n\t\t\t\ta[min ((i + 1) * k, n)] = a[i * k];\n\t\t\t}\n\t\t\ta = a[1..$];\n\t\t}\n\t\ta[] += 1;\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n))\n\t{\n\t\tauto a = array (iota (n * 2));\n\t\tforeach (k; 2..n + 1)\n\t\t{\n\t\t\ta = a[1..$];\n\t\t\tfor (int i = (n - 1) / k * k; i >= 0; i -= k)\n\t\t\t{\n\t\t\t\ta[min (i + k, n)] = a[i];\n\t\t\t}\n\t\t}\n\t\twritefln (\"%(%s %)\", a[1..$]);\n\t}\n}\n"}], "negative_code": [], "src_uid": "967cdd9d6a8a0df722e9f9e2c06af238"} {"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 int[] pos = new int[](N + 1);\r\n foreach(int i, a; A) {\r\n pos[a] = i;\r\n }\r\n\r\n int[] ans;\r\n foreach(int n; 0..N) {\r\n // [A, [n, pos[n + 1]]].deb;\r\n if (pos[n + 1] != n) {\r\n ans ~= A[0..n];\r\n ans ~= A[n..pos[n + 1] + 1].reverse.array;\r\n ans ~= A[pos[n + 1] + 1..$];\r\n break;\r\n }\r\n }\r\n\r\n if (ans.empty) ans = A;\r\n ans.toAnswerString.writeln;\r\n }\r\n\r\n foreach(i; 0..QN) {\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>>\".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.stdio, std.string, std.conv;\r\nimport std.algorithm.iteration;\r\nimport std.algorithm.searching;\r\nimport std.algorithm.mutation;\r\nimport std.range;\r\nvoid solution(ref File input, ref File output) {\r\n auto t = input.readln.chomp.to!int;\r\n while (t-- > 0) {\r\n auto _ = input.readln;\r\n auto source = input.readln.chomp\r\n .split(' ')\r\n .map!(to!int)\r\n .array;\r\n for (int i = 0; i < source.length; i++) {\r\n if (i + 1 != source[i])\r\n {\r\n for (int j = i + 1; j < source.length; j++)\r\n {\r\n if (source[j] == i + 1) {\r\n source[i .. j + 1].reverse;\r\n goto end;\r\n }\r\n }\r\n }\r\n }\r\n end:\r\n writeln(source.map!(to!string).join(' '));\r\n }\r\n}\r\nvoid main()\r\n{\r\n File input, output;\r\n debug(1) {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n solution(input, output);\r\n}\r\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.conv;\r\nimport std.algorithm.iteration;\r\nimport std.algorithm.searching;\r\nimport std.algorithm.mutation;\r\nimport std.range;\r\nvoid solution(ref File input, ref File output) {\r\n auto t = input.readln.chomp.to!int;\r\n writeln(t);\r\n while (t-- > 0) {\r\n auto _ = input.readln;\r\n auto source = input.readln.chomp\r\n .split(' ')\r\n .map!(to!int)\r\n .array;\r\n for (int i = 0; i < source.length; i++) {\r\n if (i + 1 != source[i])\r\n {\r\n for (int j = i + 1; j < source.length; j++)\r\n {\r\n if (source[j] == i + 1) {\r\n source[i .. j + 1].reverse;\r\n goto end;\r\n }\r\n }\r\n }\r\n }\r\n end:\r\n writeln(source.map!(to!string).join(' '));\r\n }\r\n}\r\nvoid main()\r\n{\r\n File input, output;\r\n debug(1) {\r\n input = File(\"input.txt\", \"r\");\r\n output = File(\"output.txt\", \"w\");\r\n } else {\r\n input = stdin;\r\n output = stdout;\r\n }\r\n solution(input, output);\r\n}\r\n"}], "src_uid": "a57823a7ca0f67a07f94175ab59d33de"} {"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 = new long[](N);\n foreach (_; 0..M) {\n s = readln.split.map!(to!int);\n auto u = s[0] - 1;\n auto v = s[1] - 1;\n auto c = s[2].to!long;\n A[u] -= c;\n A[v] += c;\n }\n\n auto plus = N.iota.filter!(i => A[i] > 0).array;\n auto minus = N.iota.filter!(i => A[i] < 0).array;\n\n int cnt = 0;\n auto G = new Tuple!(int, long)[][](N);\n\n for (int i = 0, j = 0; i < plus.length && j < minus.length; ) {\n auto u = minus[j];\n auto v = plus[i];\n auto c = min(-A[u], A[v]);\n cnt += 1;\n G[u] ~= tuple(v, c);\n A[u] += c;\n A[v] -= c;\n if (A[u] == 0) ++j;\n if (A[v] == 0) ++i;\n }\n\n cnt.writeln;\n foreach (i; 0..N) foreach (e; G[i]) writeln(i+1, \" \", e[0]+1, \" \", e[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\nvoid main ()\n{\n\tint n;\n\tint m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\tauto d = new long [n];\n\t\tforeach (j; 0..m)\n\t\t{\n\t\t\tint u;\n\t\t\tint v;\n\t\t\tlong w;\n\t\t\treadf !(\" %s %s %s\") (u, v, w);\n\t\t\tu -= 1;\n\t\t\tv -= 1;\n\t\t\td[u] += w;\n\t\t\td[v] -= w;\n\t\t}\n\n\t\tint i = 0;\n\t\tint j = 0;\n\t\tTuple !(int, int, long) [] answer;\n\t\twhile (true)\n\t\t{\n\t\t\twhile (i < n && d[i] <= 0)\n\t\t\t{\n\t\t\t\ti += 1;\n\t\t\t}\n\t\t\twhile (j < n && d[j] >= 0)\n\t\t\t{\n\t\t\t\tj += 1;\n\t\t\t}\n\t\t\tif (i == n && j == n)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tauto cur = min (+d[i], -d[j]);\n\t\t\tanswer ~= tuple (i + 1, j + 1, cur);\n\t\t\td[i] -= cur;\n\t\t\td[j] += cur;\n\t\t}\n\n\t\twriteln (answer.length);\n\t\tforeach (ref e; answer)\n\t\t{\n\t\t\twritefln !(\"%s %s %s\") (e[0], e[1], e[2]);\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 M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n auto D = new long[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n D[i] = readLong();\n }\n \n auto fs = new long[N];\n foreach (i; 0 .. M) {\n fs[U[i]] -= D[i];\n fs[V[i]] += D[i];\n }\n \n int[] us, vs;\n foreach (u; 0 .. N) {\n if (fs[u] < 0) us ~= u;\n if (fs[u] > 0) vs ~= u;\n }\n const usLen = cast(int)(us.length);\n const vsLen = cast(int)(vs.length);\n auto fus = new long[usLen];\n auto fvs = new long[vsLen];\n foreach (j; 0 .. usLen) {\n fus[j] = -fs[us[j]];\n }\n foreach (k; 0 .. vsLen) {\n fvs[k] = fs[vs[k]];\n }\n \n alias Entry = Tuple!(int, \"u\", int, \"v\", long, \"d\");\n Entry[] ans;\n for (int j = 0, k = 0; j < usLen && k < vsLen; ) {\n const t = min(fus[j], fvs[k]);\n if (t > 0) {\n fus[j] -= t;\n fvs[k] -= t;\n ans ~= Entry(us[j], vs[k], t);\n }\n if (j < usLen && fus[j] == 0) {\n ++j;\n } else if (k < vsLen && fvs[k] == 0) {\n ++k;\n } else {\n assert(false);\n }\n }\n \n writeln(ans.length);\n foreach (ref e; ans) {\n writeln(e.u + 1, \" \", e.v + 1, \" \", e.d);\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 s = readln.split.map!(to!int);\n auto N = s[0];\n auto M = s[1];\n auto G = new long[int][](N);\n auto H = new long[int][](N);\n auto inD = new int[](N);\n auto outD = new int[](N);\n auto rbt = new RedBlackTree!int;\n\n bool edge_exists(int u, int v) {\n return (v in G[u]) && G[u][v] > 0;\n }\n\n void add_edge(int u, int v, long c) {\n if (c == 0) return;\n if (edge_exists(v, u)) {\n add_edge(v, u, -c);\n } else if (edge_exists(u, v)) {\n G[u][v] += c;\n H[v][u] += c;\n if (G[u][v] == 0) {\n inD[v] -= 1;\n outD[u] -= 1;\n if (inD[v] == 0) rbt.removeKey(v);\n if (outD[u] == 0) rbt.removeKey(u);\n } else if (G[u][v] < 0) {\n auto nc = -G[u][v];\n G[u][v] = 0;\n H[v][u] = 0;\n inD[v] -= 1;\n outD[u] -= 1;\n if (inD[v] == 0) rbt.removeKey(v);\n if (outD[u] == 0) rbt.removeKey(u);\n add_edge(v, u, nc);\n }\n } else {\n if (c < 0) {\n swap(u, v);\n c *= -1;\n }\n G[u][v] = c;\n H[v][u] = c;\n inD[v] += 1;\n outD[u] += 1;\n if (inD[v] > 0 && outD[v] > 0) rbt.insert(v);\n if (inD[u] > 0 && outD[u] > 0) rbt.insert(u);\n\n }\n }\n\n foreach (_; 0..M) {\n s = readln.split.map!(to!int);\n auto u = s[0] - 1;\n auto v = s[1] - 1;\n auto c = s[2].to!long;\n add_edge(u, v, c);\n }\n\n int cnt = 0;\n while (!rbt.empty) {\n auto u = rbt.front;\n auto from = H[u].byKey.front;\n auto to = G[u].byKey.front;\n auto from_cost = H[u][from];\n auto to_cost = G[u][to];\n auto cost = min(from_cost, to_cost);\n add_edge(from, u, -cost);\n add_edge(u, to, -cost);\n add_edge(from, to, cost);\n }\n\n N.iota.map!(i => G[i].keys.filter!(j => G[i][j] > 0).sum).sum.writeln;\n foreach (i; 0..N) foreach (j; G[i].keys) {\n if (G[i][j] > 0) writeln(i+1, \" \", j+1, \" \", G[i][j]);\n }\n}\n"}], "src_uid": "6f7bee466780e6e65b2841bfccad28b0"} {"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 isValid(char[] cs) {\r\n int now;\r\n foreach (c; cs) {\r\n if (c == '(') {\r\n ++now;\r\n } else if (c == ')') {\r\n if (--now < 0) {\r\n return false;\r\n }\r\n } else {\r\n assert(false);\r\n }\r\n }\r\n return (now == 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 const N = readInt();\r\n const S = readToken();\r\n \r\n auto as = new char[N];\r\n auto bs = new char[N];\r\n \r\n const cnt1 = cast(int)(S.count('1'));\r\n int pos0, pos1;\r\n foreach (i; 0 .. N) {\r\n if (S[i] == '0') {\r\n if (pos0 % 2 == 0) {\r\n as[i] = '(';\r\n bs[i] = ')';\r\n } else {\r\n as[i] = ')';\r\n bs[i] = '(';\r\n }\r\n ++pos0;\r\n } else {\r\n if (pos1 < cnt1 / 2) {\r\n as[i] = bs[i] = '(';\r\n } else {\r\n as[i] = bs[i] = ')';\r\n }\r\n ++pos1;\r\n }\r\n }\r\n debug {\r\n writeln(\"as = \", as);\r\n writeln(\"bs = \", bs);\r\n }\r\n \r\n bool ok = true;\r\n ok = ok && isValid(as);\r\n ok = ok && isValid(bs);\r\n if (ok) {\r\n writeln(\"YES\");\r\n writeln(as);\r\n writeln(bs);\r\n } else {\r\n writeln(\"NO\");\r\n }\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;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 string[][](t, 2);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tlong cnt0, cnt1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '0')\n\t\t\t\t++cnt0;\n\t\t\telse\n\t\t\t\t++cnt1;\n\t\t}\n\n\t\tlong c0, c1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '0')\n\t\t\t{\n\t\t\t\tans[ti][0] ~= c0 % 2 ? ')' : '(';\n\t\t\t\t++c0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tans[ti][0] ~= c1 < cnt1/2 ? '(' : ')';\n\t\t\t\t++c1;\n\t\t\t}\n\t\t}\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '1')\n\t\t\t\tans[ti][1] ~= ans[ti][0][i];\n\t\t\telse\n\t\t\t\tans[ti][1] ~= ans[ti][0][i] == '(' ? ')' : '(';\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong cnt;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (ans[ti][1][i] == '(')\n\t\t\t\t++cnt;\n\t\t\telse\n\t\t\t\t--cnt;\n\t\t\tif (cnt < 0)\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 (cnt != 0)\n\t\t\tok = false;\n\t\tif (!ok)\n\t\t\tans[ti].length = 0;\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\twriteln(e[0]);\n\t\t\twriteln(e[1]);\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.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 string[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto s = RD!string;\n\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (s[i] == '1')\n\t\t\t\tans[ti] ~= i % 2 ? ')' : '(';\n\t\t\telse\n\t\t\t\tans[ti] ~= i % 2 ? '(' : ')';\n\t\t}\n\n\t\tbool ok = true;\n\t\tlong cnt;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (ans[ti][i] == '(')\n\t\t\t\t++cnt;\n\t\t\telse\n\t\t\t\t--cnt;\n\t\t\tif (cnt < 0)\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 (cnt != 0)\n\t\t\tok = false;\n\t\tif (!ok)\n\t\t\tans[ti].length = 0;\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\tforeach (i; 0..e.length)\n\t\t\t\twrite(i % 2 ? \")\" : \"(\");\n\t\t\twriteln;\n\t\t\twriteln(e);\n\t\t}\n\t}\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "f2aedd618eae5c51386525b1f76b19a6"} {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.container;\n\nimmutable int inf = cast(int)1e9 + 5;\nalias Node = Tuple!(int, \"L\", int, \"R\", long, \"cnt\", int, \"len\");\n\nNode merge(in Node a, in Node b) {\n\tNode res;\n\tres.len = a.len + b.len;\n\tres.L = (a.len == a.L ? a.len + b.L : a.L);\n\tres.R = (b.len == b.R ? b.len + a.R : b.R);\n\tres.cnt = a.cnt + b.cnt + cast(long)a.R * b.L;\n\treturn res;\n}\n\nclass IT {\n\tNode[] T;\n\tint size;\n\tthis(int _size = 0) {\n\t\tsize = _size;\n\t\tT = new Node[4 * size];\n\t\tinit(1, 1, size);\n\t}\n\tvoid init(int v, int l, int r) {\n\t\tif (l == r) { T[v].len = 1; return; }\n\t\tint mid = (l + r) >> 1;\n\t\tinit(2 * v, l, mid); init(2 * v + 1, mid + 1, r);\n\t\tT[v].len = T[2 * v].len + T[2 * v + 1].len;\n\t}\n\tvoid up(int v, int l, int r, int pos) {\n\t\tint mid = (l + r) >> 1;\n\t\tif (l > pos || r < pos) return;\n\t\tif (l == r) {\n\t\t\tT[v].L = T[v].R = T[v].cnt = T[v].len = 1; return;\n\t\t}\n\t\tup(2 * v, l, mid, pos); up(2 * v + 1, mid + 1, r, pos);\n\t\tT[v] = merge(T[2 * v], T[2 * v + 1]);\n\t}\n\tNode get(int v, int l, int r, int i, int j) {\n\t\tint mid = (l + r) >> 1;\n\t\tif (l > j || r < i) return Node();\n\t\tif (i <= l && r <= j) return T[v];\n\t\treturn merge(get(2 * v, l, mid, i, j), get(2 * v + 1, mid + 1, r, i, j));\n\t}\n}\n\nIT T;\n\nint N;\nint[] A, B;\n\nint[] leftEq, rightSm;\n\nvoid doStack() {\n\tauto st = SList!int();\n\tleftEq = new int[N + 2];\n\trightSm = new int[N + 2];\n\tB[0] = B[N + 1] = -inf;\n\tst.insertFront(0);\n\tforeach (i; 1..N + 1) {\n\t\twhile (B[i] <= B[st.front]) st.removeFront();\n\t\tleftEq[i] = st.front + 1; st.insertFront(i);\n\t}\n\tst = SList!int();\n\tst.insertFront(N + 1);\n\tfor (int i = N; i >= 1; --i) {\n\t\twhile (B[i] < B[st.front]) st.removeFront();\n\t\trightSm[i] = st.front - 1; st.insertFront(i);\n\t}\n}\n\nint[] Aidx, Bidx;\n\nlong get(int i, int k, int j) {\n\treturn T.get(1, 1, N, i, j).cnt - T.get(1, 1, N, i, k - 1).cnt - T.get(1, 1, N, k + 1, j).cnt;\n}\n\nvoid main() {\n\treadf(\"%d\", &N);\n\tA = new int[N + 2];\n\tB = new int[N + 2];\n\tAidx = new int[N + 2];\n\tBidx = new int[N + 2];\n\tT = new IT(N);\n\tforeach (i; 1..N + 1) readf(\" %d\", &A[i]);\n\tforeach (i; 1..N + 1) readf(\" %d\", &B[i]);\n\tdoStack();\n\tforeach (i; 1..N + 1) Aidx[i] = Bidx[i] = i;\n\tsort!((a, b) => (A[a] < A[b]))(Aidx[1..N+1]);\n\tsort!((a, b) => (B[a] < B[b]))(Bidx[1..N+1]);\n\tlong ans = 0; int cur = 1;\n\tfor (int i = 1; i <= N; ++i) {\n\t\tint st = i, j = i;\n\t\twhile (cur <= N && A[Aidx[cur]] < B[Bidx[st]]) T.up(1, 1, N, Aidx[cur++]);\n\t\twhile (j <= N && B[Bidx[st]] == B[Bidx[j]]) {\n\t\t\tint id = Bidx[j];\n\t\t\tans -= get(leftEq[id], id, rightSm[id]);\n\t\t\t//writeln(id, ' ', leftEq[id], ' ', rightSm[id], ' ', ans);\n\t\t\t++j;\n\t\t}\n\t\twhile (cur <= N && A[Aidx[cur]] <= B[Bidx[st]]) T.up(1, 1, N, Aidx[cur++]);\n\t\twhile (i <= N && B[Bidx[st]] == B[Bidx[i]]) {\n\t\t\tint id = Bidx[i];\n\t\t\tans += get(leftEq[id], id, rightSm[id]);\n\t\t\t//writeln(id, ' ', leftEq[id], ' ', rightSm[id], ' ', ans);\n\t\t\t++i;\n\t\t} --i;\n\t}\n\twriteln(ans);\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\nstruct SparseRMQ(int S) {\n immutable int N = 1< 1) {\n int md = (l+r)/2;\n int[2] q = sp.query(i, md);\n if (q[0] < q[1]) {\n l = md;\n } else {\n r = md;\n }\n }\n X = r;\n l = i; r = n+1;\n while (r-l > 1) {\n int md = (l+r)/2;\n int[2] q = sp.query(i, md);\n if (q[0] <= q[1]) {\n l = md;\n } else {\n r = md;\n }\n }\n Y = r;\n ans += cast(long)(Y-X);\n }\n writeln(ans);\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}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.container;\n\nimmutable int inf = cast(int)1e9;\nalias Node = Tuple!(int, \"L\", int, \"R\", long, \"cnt\", int, \"len\");\n\nNode merge(in Node a, in Node b) {\n\tNode res;\n\tres.len = a.len + b.len;\n\tres.L = (a.len == a.L ? a.len + b.L : a.L);\n\tres.R = (b.len == b.R ? b.len + a.R : b.R);\n\tres.cnt = a.cnt + b.cnt + cast(long)a.R * b.L;\n\treturn res;\n}\n\nclass IT {\n\tNode[] T;\n\tint size;\n\tthis(int _size = 0) {\n\t\tsize = _size;\n\t\tT = new Node[4 * size];\n\t\tfor (int i = 1; i < 4 * size; ++i) T[i].len = 1;\n\t}\n\tvoid up(int v, int l, int r, int pos) {\n\t\tint mid = (l + r) >> 1;\n\t\tif (l > pos || r < pos) return;\n\t\tif (l == r) {\n\t\t\tT[v].L = T[v].R = T[v].cnt = T[v].len = 1; return;\n\t\t}\n\t\tup(2 * v, l, mid, pos); up(2 * v + 1, mid + 1, r, pos);\n\t\tT[v] = merge(T[2 * v], T[2 * v + 1]);\n\t}\n\tNode get(int v, int l, int r, int i, int j) {\n\t\tint mid = (l + r) >> 1;\n\t\tif (l > j || r < i) return Node();\n\t\tif (i <= l && r <= j) return T[v];\n\t\treturn merge(get(2 * v, l, mid, i, j), get(2 * v + 1, mid + 1, r, i, j));\n\t}\n}\n\nIT T;\n\nint N;\nint[] A, B;\n\nint[] leftEq, rightSm;\n\nvoid doStack() {\n\tauto st = SList!int();\n\tleftEq = new int[N + 2];\n\trightSm = new int[N + 2];\n\tB[0] = B[N + 1] = -inf;\n\tst.insertFront(0);\n\tforeach (i; 1..N + 1) {\n\t\twhile (B[i] <= B[st.front]) st.removeFront();\n\t\tleftEq[i] = st.front + 1; st.insertFront(i);\n\t}\n\tst = SList!int();\n\tst.insertFront(N + 1);\n\tfor (int i = N; i >= 1; --i) {\n\t\twhile (B[i] < B[st.front]) st.removeFront();\n\t\trightSm[i] = st.front - 1; st.insertFront(i);\n\t}\n}\n\nint[] Aidx, Bidx;\n\nlong get(int i, int k, int j) {\n\treturn T.get(1, 1, N, i, j).cnt - T.get(1, 1, N, i, k - 1).cnt - T.get(1, 1, N, k + 1, j).cnt;\n}\n\nvoid main() {\n\treadf(\"%d\", &N);\n\tA = new int[N + 2];\n\tB = new int[N + 2];\n\tAidx = new int[N + 2];\n\tBidx = new int[N + 2];\n\tT = new IT(N);\n\tforeach (i; 1..N + 1) readf(\" %d\", &A[i]);\n\tforeach (i; 1..N + 1) readf(\" %d\", &B[i]);\n\tdoStack();\n\tforeach (i; 1..N + 1) Aidx[i] = Bidx[i] = i;\n\tsort!((a, b) => (A[a] < A[b]))(Aidx[1..N+1]);\n\tsort!((a, b) => (B[a] < B[b]))(Bidx[1..N+1]);\n\tlong ans = 0; int cur = 0;\n\tfor (int i = 1; i <= N; ++i) {\n\t\tint st = i, j = i;\n\t\twhile (cur <= N && A[Aidx[cur]] < B[Bidx[st]]) T.up(1, 1, N, Aidx[cur++]);\n\t\twhile (j <= N && B[Bidx[st]] == B[Bidx[j]]) {\n\t\t\tint id = Bidx[j];\n\t\t\tans -= get(leftEq[id], id, rightSm[id]);\n\t\t\t//writeln(id, ' ', leftEq[id], ' ', rightSm[id], ' ', ans);\n\t\t\t++j;\n\t\t}\n\t\twhile (cur <= N && A[Aidx[cur]] <= B[Bidx[st]]) T.up(1, 1, N, Aidx[cur++]);\n\t\twhile (i <= N && B[Bidx[st]] == B[Bidx[i]]) {\n\t\t\tint id = Bidx[i];\n\t\t\tans += get(leftEq[id], id, rightSm[id]);\n\t\t\t//writeln(id, ' ', leftEq[id], ' ', rightSm[id], ' ', ans);\n\t\t\t++i;\n\t\t} --i;\n\t}\n\twriteln(ans);\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.container;\n\nimmutable int inf = cast(int)1e9;\nalias Node = Tuple!(int, \"L\", int, \"R\", long, \"cnt\", int, \"len\");\n\nNode merge(in Node a, in Node b) {\n\tNode res;\n\tres.len = a.len + b.len;\n\tres.L = (a.len == a.L ? a.len + b.L : a.L);\n\tres.R = (b.len == b.R ? b.len + a.R : b.R);\n\tres.cnt = a.cnt + b.cnt + cast(long)a.R * b.L;\n\treturn res;\n}\n\nclass IT {\n\tNode[] T;\n\tint size;\n\tthis(int _size = 0) {\n\t\tsize = _size;\n\t\tT = new Node[4 * size];\n\t\tinit(1, 1, size);\n\t}\n\tvoid init(int v, int l, int r) {\n\t\tif (l == r) { T[v].len = 1; return; }\n\t\tint mid = (l + r) >> 1;\n\t\tinit(2 * v, l, mid); init(2 * v + 1, mid + 1, r);\n\t\tT[v].len = T[2 * v].len + T[2 * v + 1].len;\n\t}\n\tvoid up(int v, int l, int r, int pos) {\n\t\tint mid = (l + r) >> 1;\n\t\tif (l > pos || r < pos) return;\n\t\tif (l == r) {\n\t\t\tT[v].L = T[v].R = T[v].cnt = T[v].len = 1; return;\n\t\t}\n\t\tup(2 * v, l, mid, pos); up(2 * v + 1, mid + 1, r, pos);\n\t\tT[v] = merge(T[2 * v], T[2 * v + 1]);\n\t}\n\tNode get(int v, int l, int r, int i, int j) {\n\t\tint mid = (l + r) >> 1;\n\t\tif (l > j || r < i) return Node();\n\t\tif (i <= l && r <= j) return T[v];\n\t\treturn merge(get(2 * v, l, mid, i, j), get(2 * v + 1, mid + 1, r, i, j));\n\t}\n}\n\nIT T;\n\nint N;\nint[] A, B;\n\nint[] leftEq, rightSm;\n\nvoid doStack() {\n\tauto st = SList!int();\n\tleftEq = new int[N + 2];\n\trightSm = new int[N + 2];\n\tB[0] = B[N + 1] = -inf;\n\tst.insertFront(0);\n\tforeach (i; 1..N + 1) {\n\t\twhile (B[i] <= B[st.front]) st.removeFront();\n\t\tleftEq[i] = st.front + 1; st.insertFront(i);\n\t}\n\tst = SList!int();\n\tst.insertFront(N + 1);\n\tfor (int i = N; i >= 1; --i) {\n\t\twhile (B[i] < B[st.front]) st.removeFront();\n\t\trightSm[i] = st.front - 1; st.insertFront(i);\n\t}\n}\n\nint[] Aidx, Bidx;\n\nlong get(int i, int k, int j) {\n\treturn T.get(1, 1, N, i, j).cnt - T.get(1, 1, N, i, k - 1).cnt - T.get(1, 1, N, k + 1, j).cnt;\n}\n\nvoid main() {\n\treadf(\"%d\", &N);\n\tA = new int[N + 2];\n\tB = new int[N + 2];\n\tAidx = new int[N + 2];\n\tBidx = new int[N + 2];\n\tT = new IT(N);\n\tforeach (i; 1..N + 1) readf(\" %d\", &A[i]);\n\tforeach (i; 1..N + 1) readf(\" %d\", &B[i]);\n\tdoStack();\n\tforeach (i; 1..N + 1) Aidx[i] = Bidx[i] = i;\n\tsort!((a, b) => (A[a] < A[b]))(Aidx[1..N+1]);\n\tsort!((a, b) => (B[a] < B[b]))(Bidx[1..N+1]);\n\tlong ans = 0; int cur = 0;\n\tfor (int i = 1; i <= N; ++i) {\n\t\tint st = i, j = i;\n\t\twhile (cur <= N && A[Aidx[cur]] < B[Bidx[st]]) T.up(1, 1, N, Aidx[cur++]);\n\t\twhile (j <= N && B[Bidx[st]] == B[Bidx[j]]) {\n\t\t\tint id = Bidx[j];\n\t\t\tans -= get(leftEq[id], id, rightSm[id]);\n\t\t\t//writeln(id, ' ', leftEq[id], ' ', rightSm[id], ' ', ans);\n\t\t\t++j;\n\t\t}\n\t\twhile (cur <= N && A[Aidx[cur]] <= B[Bidx[st]]) T.up(1, 1, N, Aidx[cur++]);\n\t\twhile (i <= N && B[Bidx[st]] == B[Bidx[i]]) {\n\t\t\tint id = Bidx[i];\n\t\t\tans += get(leftEq[id], id, rightSm[id]);\n\t\t\t//writeln(id, ' ', leftEq[id], ' ', rightSm[id], ' ', ans);\n\t\t\t++i;\n\t\t} --i;\n\t}\n\twriteln(ans);\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.container;\n\nimmutable int inf = cast(int)1e9 + 5;\nalias Node = Tuple!(int, \"L\", int, \"R\", long, \"cnt\", int, \"len\");\n\nNode merge(in Node a, in Node b) {\n\tNode res;\n\tres.len = a.len + b.len;\n\tres.L = (a.len == a.L ? a.len + b.L : a.L);\n\tres.R = (b.len == b.R ? b.len + a.R : b.R);\n\tres.cnt = a.cnt + b.cnt + cast(long)a.R * b.L;\n\treturn res;\n}\n\nclass IT {\n\tNode[] T;\n\tint size;\n\tthis(int _size = 0) {\n\t\tsize = _size;\n\t\tT = new Node[4 * size];\n\t\tinit(1, 1, size);\n\t}\n\tvoid init(int v, int l, int r) {\n\t\tif (l == r) { T[v].len = 1; return; }\n\t\tint mid = (l + r) >> 1;\n\t\tinit(2 * v, l, mid); init(2 * v + 1, mid + 1, r);\n\t\tT[v].len = T[2 * v].len + T[2 * v + 1].len;\n\t}\n\tvoid up(int v, int l, int r, int pos) {\n\t\tint mid = (l + r) >> 1;\n\t\tif (l > pos || r < pos) return;\n\t\tif (l == r) {\n\t\t\tT[v].L = T[v].R = T[v].cnt = T[v].len = 1; return;\n\t\t}\n\t\tup(2 * v, l, mid, pos); up(2 * v + 1, mid + 1, r, pos);\n\t\tT[v] = merge(T[2 * v], T[2 * v + 1]);\n\t}\n\tNode get(int v, int l, int r, int i, int j) {\n\t\tint mid = (l + r) >> 1;\n\t\tif (l > j || r < i) return Node();\n\t\tif (i <= l && r <= j) return T[v];\n\t\treturn merge(get(2 * v, l, mid, i, j), get(2 * v + 1, mid + 1, r, i, j));\n\t}\n}\n\nIT T;\n\nint N;\nint[] A, B;\n\nint[] leftEq, rightSm;\n\nvoid doStack() {\n\tauto st = SList!int();\n\tleftEq = new int[N + 2];\n\trightSm = new int[N + 2];\n\tB[0] = B[N + 1] = -inf;\n\tst.insertFront(0);\n\tforeach (i; 1..N + 1) {\n\t\twhile (B[i] <= B[st.front]) st.removeFront();\n\t\tleftEq[i] = st.front + 1; st.insertFront(i);\n\t}\n\tst = SList!int();\n\tst.insertFront(N + 1);\n\tfor (int i = N; i >= 1; --i) {\n\t\twhile (B[i] < B[st.front]) st.removeFront();\n\t\trightSm[i] = st.front - 1; st.insertFront(i);\n\t}\n}\n\nint[] Aidx, Bidx;\n\nlong get(int i, int k, int j) {\n\treturn T.get(1, 1, N, i, j).cnt - T.get(1, 1, N, i, k - 1).cnt - T.get(1, 1, N, k + 1, j).cnt;\n}\n\nvoid main() {\n\treadf(\"%d\", &N);\n\tA = new int[N + 2];\n\tB = new int[N + 2];\n\tAidx = new int[N + 2];\n\tBidx = new int[N + 2];\n\tT = new IT(N);\n\tforeach (i; 1..N + 1) readf(\" %d\", &A[i]);\n\tforeach (i; 1..N + 1) readf(\" %d\", &B[i]);\n\tdoStack();\n\tforeach (i; 1..N + 1) Aidx[i] = Bidx[i] = i;\n\tsort!((a, b) => (A[a] < A[b]))(Aidx[1..N+1]);\n\tsort!((a, b) => (B[a] < B[b]))(Bidx[1..N+1]);\n\tlong ans = 0; int cur = 0;\n\tfor (int i = 1; i <= N; ++i) {\n\t\tint st = i, j = i;\n\t\twhile (cur <= N && A[Aidx[cur]] < B[Bidx[st]]) T.up(1, 1, N, Aidx[cur++]);\n\t\twhile (j <= N && B[Bidx[st]] == B[Bidx[j]]) {\n\t\t\tint id = Bidx[j];\n\t\t\tans -= get(leftEq[id], id, rightSm[id]);\n\t\t\t//writeln(id, ' ', leftEq[id], ' ', rightSm[id], ' ', ans);\n\t\t\t++j;\n\t\t}\n\t\twhile (cur <= N && A[Aidx[cur]] <= B[Bidx[st]]) T.up(1, 1, N, Aidx[cur++]);\n\t\twhile (i <= N && B[Bidx[st]] == B[Bidx[i]]) {\n\t\t\tint id = Bidx[i];\n\t\t\tans += get(leftEq[id], id, rightSm[id]);\n\t\t\t//writeln(id, ' ', leftEq[id], ' ', rightSm[id], ' ', ans);\n\t\t\t++i;\n\t\t} --i;\n\t}\n\twriteln(ans);\n}"}], "src_uid": "1ce94a8294cebbf0f1841dea8521e66e"} {"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\n\t\tauto can0 = new int [k * 2 + 2];\n\t\tauto can1 = new int [k * 2 + 2];\n\t\tforeach (i; 0..n / 2)\n\t\t{\n\t\t\tauto u = a[i];\n\t\t\tauto v = a[n - i - 1];\n\t\t\tcan0[u + v] += 1;\n\t\t\tcan1[min (u, v) + 1] += 1;\n\t\t\tcan1[max (u, v) + k + 1] -= 1;\n\t\t}\n\n\t\tauto sum1 = new int [k * 2 + 1];\n\t\tforeach (i; 1..k * 2 + 1)\n\t\t{\n\t\t\tsum1[i] = sum1[i - 1] + can1[i];\n\t\t}\n\n\t\tint res = n;\n\t\tforeach (i; 0..k * 2 + 1)\n\t\t{\n\t\t\tint cur0 = can0[i];\n\t\t\tint cur1 = sum1[i] - cur0;\n\t\t\tint cur2 = n / 2 - cur0 - cur1;\n\t\t\tres = min (res, 0 * cur0 + 1 * cur1 + 2 * cur2);\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!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA!int();\n\n\t\tauto cnt1 = new long[](k+1);\n\t\tauto cnt2 = new long[](k+1);\n\t\tauto cnt = new long[](k*2+1);\n\t\tforeach (i; 0..n/2)\n\t\t{\n\t\t\tauto x = cast(int)min(a[i], a[n-i-1]);\n\t\t\tauto y = cast(int)max(a[i], a[n-i-1]);\n\t\t\tauto z = a[i] + a[n-i-1];\n\t\t\t++cnt1[x];\n\t\t\t++cnt2[y];\n\t\t\t++cnt[z];\n\t\t}\n\n\t\tans[ti] = long.max;\n\t\t{\n\t\t\tlong c;\n\t\t\tforeach_reverse (i; 2..k+1)\n\t\t\t{\n\t\t\t\tc += cnt1[i];\n\t\t\t\tauto tmp = c*2 + ((n/2) - c - cnt[i]);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t\tdebug writeln(\"i:\", i, \" c:\", c, \" cnt[i]:\", cnt[i], \" tmp:\", tmp);\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tlong c;\n\t\t\tforeach (i; k+1..k*2+1)\n\t\t\t{\n\t\t\t\tc += cnt2[i-k-1];\n\t\t\t\tauto tmp = c*2 + ((n/2) - c - cnt[i]);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t\tdebug writeln(\"i:\", i, \" c:\", c, \" cnt[i]:\", cnt[i], \" tmp:\", tmp);\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": "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, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n auto need = new int[2*k + 2];\n \n foreach (i; 0 .. n / 2) {\n int mn = min(arr[i], arr[n-1 - i]);\n int mx = max(arr[i], arr[n-1 - i]);\n \n need[2] += 2;\n need[mn + 1] -= 1;\n need[mn + mx] -= 1;\n need[mn + mx + 1] += 1;\n need[mx + k + 1] += 1;\n }\n\n debug { need.writeln; }\n \n foreach (i; 1 .. 2*k + 1) { need[i] += need[i-1]; }\n \n auto ans = need[2 .. 2*k + 1].minElement;\n \n ans.writeln;\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!(int[]);\n auto N = nk[0];\n auto K = nk[1];\n auto as = readln.split.to!(int[]);\n\n auto ns = new int[]((K*2+2).to!size_t);\n foreach (i; 0..N/2) {\n auto x = as[i.to!size_t];\n auto y = as[(N-i-1).to!size_t];\n if (x > y) swap(x, y);\n auto p = x+y;\n ns[0] += 2;\n ns[(x+1).to!size_t] -= 1;\n ns[p.to!size_t] -= 1;\n ns[(p+1).to!size_t] += 1;\n ns[(y+K+1).to!size_t] += 1;\n }\n foreach (i; 0..ns.length-1) {\n ns[i+1] += ns[i];\n }\n\n int min_n = int.max;\n foreach (i; 0..ns.length) {\n min_n = min(min_n, ns[i]);\n }\n writeln(min_n);\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 auto as = readln.split.to!(long[]);\n\n auto ns = new long[]((N*2+2).to!size_t);\n foreach (i; 0..N/2) {\n auto x = as[i.to!size_t];\n auto y = as[(N-i-1).to!size_t];\n if (x > y) swap(x, y);\n auto p = x+y;\n ns[0] += 2;\n ns[(x+1).to!size_t] -= 1;\n ns[p.to!size_t] -= 1;\n ns[(p+1).to!size_t] += 1;\n ns[(y+K+1).to!size_t] += 1;\n }\n foreach (i; 0..(N*2+1).to!size_t) {\n ns[i+1] += ns[i];\n }\n\n long min_n = long.max;\n foreach (i; 0..(N+2+2).to!size_t) {\n min_n = min(min_n, ns[i]);\n }\n writeln(min_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 auto as = readln.split.to!(long[]);\n\n long solve(long p) {\n long r;\n foreach (i; 0..N/2) {\n auto x = as[i.to!size_t];\n auto y = as[(N-i-1).to!size_t];\n if (x > y) swap(x, y);\n if (x+y < p) {\n r += K-x >= p-x-y ? 1 : 2;\n } else if (x+y > p) {\n r += p-x > 0 ? 1 : 2;\n }\n }\n return r;\n }\n\n long[] bs;\n foreach (i; 0..N/2) {\n bs ~= as[i.to!size_t] + as[(N-i-1).to!size_t];\n }\n sort(bs);\n if ((N/2)%2 == 1) {\n writeln(solve(bs[(N/4).to!size_t]));\n } else {\n auto a = bs[(N/4-1).to!size_t];\n auto b = bs[(N/4).to!size_t];\n writeln(min(\n solve(a),\n solve(b),\n solve((a+b)/2),\n solve((a+b+1)/2)\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!int;\n\t\tauto k = RD!int;\n\t\tauto a = RDA!int();\n\n\t\tauto cnt1 = new long[](k+1);\n\t\tauto cnt2 = new long[](k+1);\n\t\tauto cnt = new long[](k*2+1);\n\t\tforeach (i; 0..n/2)\n\t\t{\n\t\t\tauto x = cast(int)min(a[i], a[n-i-1]);\n\t\t\tauto y = cast(int)max(a[i], a[n-i-1]);\n\t\t\tauto z = a[i] + a[n-i-1];\n\t\t\t++cnt1[x];\n\t\t\t++cnt2[y];\n\t\t\t++cnt[z];\n\t\t}\n\n\t\tans[ti] = long.max;\n\t\t{\n\t\t\tlong c;\n\t\t\tforeach_reverse (i; 2..k+1)\n\t\t\t{\n\t\t\t\tc += cnt1[i];\n\t\t\t\tauto tmp = c*2 + (n - c - cnt[i]);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tlong c;\n\t\t\tforeach (i; k+1..k*2+1)\n\t\t\t{\n\t\t\t\tc += cnt2[(i-1)/2-1];\n\t\t\t\tauto tmp = c*2 + ((n/2) - c - cnt[i]);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t\tdebug writeln(\"i:\", i, \" c:\", c, \" cnt[i]:\", 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}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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!int();\n\n\t\tauto cnt1 = new long[](k+1);\n\t\tauto cnt2 = new long[](k+1);\n\t\tauto cnt = new long[](k*2+1);\n\t\tforeach (i; 0..n/2)\n\t\t{\n\t\t\tauto x = cast(int)min(a[i], a[n-i-1]);\n\t\t\tauto y = cast(int)max(a[i], a[n-i-1]);\n\t\t\tauto z = a[i] + a[n-i-1];\n\t\t\t++cnt1[x];\n\t\t\t++cnt2[y];\n\t\t\t++cnt[z];\n\t\t}\n\n\t\tans[ti] = long.max;\n\t\t{\n\t\t\tlong c;\n\t\t\tforeach_reverse (i; 2..k+1)\n\t\t\t{\n\t\t\t\tc += cnt1[i];\n\t\t\t\tauto tmp = c*2 + ((n/2) - c - cnt[i]);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t\tdebug writeln(\"i:\", i, \" c:\", c, \" cnt[i]:\", cnt[i], \" tmp:\", tmp);\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tlong c;\n\t\t\tforeach (i; k+1..k*2+1)\n\t\t\t{\n\t\t\t\tc += cnt2[(i-1)/2-1];\n\t\t\t\tauto tmp = c*2 + ((n/2) - c - cnt[i]);\n\t\t\t\tans[ti].chmin(tmp);\n\t\t\t\tdebug writeln(\"i:\", i, \" c:\", c, \" cnt[i]:\", cnt[i], \" tmp:\", tmp);\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}"}], "src_uid": "ff9745ec5cc22c2ea50b6d789596f719"} {"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, c;\r\n\t\treadf !(\" %s %s %s %s\") (rows, cols, r, c);\r\n\t\treadln;\r\n\t\tr -= 1;\r\n\t\tc -= 1;\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\r\n\t\tint res = int.max;\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\tif (board[row][col] == 'B')\r\n\t\t\t\t{\r\n\t\t\t\t\tres = min (res,\r\n\t\t\t\t\t (r != row) + (c != col));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (res == int.max)\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", "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!(ubyte, \"\\n\");\n foreach (test_index; 0 .. tests) {\n immutable n = read!(ubyte, \" \");\n immutable m = read!(ubyte, \" \");\n immutable r = read!(ubyte, \" \");\n immutable c = read!(ubyte, \"\\n\");\n\n immutable data = (){\n static assert(true);\n byte[] ret = new byte[n * m];\n foreach (i; 0 .. n) {\n foreach (j; 0 .. m)\n ret[i * m + j] = read!(char, \"\");\n readf(\"\\n\");\n }\n\n return ret.assumeUnique;\n }();\n\n {\n immutable any_B = data.any!\"a == 'B'\";\n if (!any_B) {\n writeln(\"-1\");\n continue;\n }\n }\n\n auto mat = data.chunks(m);\n\n if (mat[r - 1][c - 1] == 'B') {\n writeln(\"0\");\n continue;\n }\n\n immutable on_line_or_column =\n mat[r - 1].any!\"a == 'B'\"\n || mat.transversal(c - 1).any!\"a == 'B'\";\n\n if (on_line_or_column)\n writeln(\"1\");\n else\n writeln(\"2\");\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 M = scan!int;\r\n auto R = scan!int - 1;\r\n auto C = scan!int - 1;\r\n auto G = cast(char[][])scan!string(N);\r\n\r\n if (!G.joiner.canFind('B')) {\r\n return -1;\r\n }\r\n\r\n long ans;\r\n bool[GridPoint] visited;\r\n M: for(auto q = DList!GridPoint(GridPoint(C, R)); !q.empty;) {\r\n bool[GridPoint] nex;\r\n while(!q.empty) {\r\n auto p = q.front; q.removeFront;\r\n if (p in visited) continue;\r\n\r\n visited[p] = true;\r\n if (p.of(G) == 'B') break M;\r\n\r\n foreach(d; [[1, 0], [-1, 0], [0, 1], [0, -1]]) {\r\n auto m = p;\r\n while(true) {\r\n m.x += d[0];\r\n m.y += d[1];\r\n if (m.x < 0 || m.y < 0 || m.x >= M || m.y >= N) break;\r\n\r\n if (!(m in visited)) nex[m] = true;\r\n }\r\n }\r\n }\r\n \r\n q.insert(nex.keys);\r\n ans++;\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\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>>\".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}"}], "negative_code": [], "src_uid": "4ca13794471831953f2737ca9d4ba853"} {"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 L = readln.split.map!(to!int).array;\n auto R = readln.split.map!(to!int).array;\n auto ans = new int[](N);\n\n auto LL = new int[](N);\n auto RR = new int[](N);\n\n foreach (i; 0..N) {\n if (L[i] > i) {\n writeln(\"NO\");\n return;\n }\n }\n\n foreach (i; 0..N) {\n if (R[N-i-1] > i) {\n writeln(\"NO\");\n return;\n }\n }\n\n int cnt = 0;\n foreach_reverse (k; 1..N+1) {\n int tmp = 0;\n int[] hoge;\n foreach (i; 0..N) {\n if (LL[i] == L[i] && RR[i] == R[i]) {\n ans[i] = k;\n tmp += 1;\n hoge ~= i;\n }\n }\n\n if (tmp == 0 && cnt < N) {\n writeln(\"NO\");\n return;\n }\n\n for (int i = 0, p = 0; i < N; ++i) {\n if (p < hoge.length && i == hoge[p]) {\n p += 1;\n }\n LL[i] += p;\n }\n\n for (int i = N-1, p = hoge.length.to!int - 1; i >= 0; --i) {\n if (p >= 0 && i == hoge[p]) {\n p -= 1;\n }\n RR[i] += hoge.length.to!int - p - 1;\n }\n\n cnt += tmp;\n }\n\n writeln(\"YES\");\n ans.map!(to!string).join(\" \").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;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto lo = readln.splitter.map !(to !(int)).array;\n\t\tauto hi = readln.splitter.map !(to !(int)).array;\n\t\tauto v = new int [n];\n\n\t\tint cur = n;\n\t\tint num = 0;\n\t\tbool bad = false;\n\t\twhile (!bad)\n\t\t{\n\t\t\tint prev = num;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (v[i] == 0 && lo[i] == 0 && hi[i] == 0)\n\t\t\t\t{\n\t\t\t\t\tv[i] = cur;\n\t\t\t\t\tnum += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (num == prev)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (v[i] == cur)\n\t\t\t\t{\n\t\t\t\t\tforeach (j; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (j < i && v[j] == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\thi[j] -= 1;\n\t\t\t\t\t\t\tbad |= (hi[j] < 0);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (j > i && v[j] == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlo[j] -= 1;\n\t\t\t\t\t\t\tbad |= (lo[j] < 0);\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\tcur -= 1;\n\t\t}\n\n\t\tif (!bad && num == n)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln (\"%(%s %)\", v);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\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;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto lo = readln.splitter.map !(to !(int)).array;\n\t\tauto hi = readln.splitter.map !(to !(int)).array;\n\t\tauto v = new int [n];\n\n\t\tint cur = n;\n\t\tint num = 0;\n\t\tbool bad = false;\n\t\twhile (!bad)\n\t\t{\n\t\t\tint prev = num;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (v[i] == 0 && lo[i] == 0 && hi[i] == 0)\n\t\t\t\t{\n\t\t\t\t\tv[i] = cur;\n\t\t\t\t\tnum += 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (num == prev)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (v[i] == cur)\n\t\t\t\t{\n\t\t\t\t\tforeach (j; 0..n)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (j < i && lo[j] + hi[j] > 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\thi[j] -= 1;\n\t\t\t\t\t\t\tbad |= (hi[j] < 0);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (j > i && lo[j] + hi[j] > 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlo[j] -= 1;\n\t\t\t\t\t\t\tbad |= (lo[j] < 0);\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\tcur -= 1;\n\t\t}\n\n\t\tif (!bad && num == n)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t\twritefln (\"%(%s %)\", v);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t}\n}\n"}], "src_uid": "fa531c38833907d619f1102505ddbb6a"} {"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", "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\n\nll[] arr, stat;\n\nll resett(int l, int r){\n ll take = 0;\n foreach(i; l..r+1){\n take -= arr[i]*stat[i];\n stat[i] = 0;\n }\n return take;\n}\n\nll sett(int l, int r){\n ll take = 0;\n foreach(i; l..r+1){\n if(arr[i] >= arr[i-1] && arr[i] >= arr[i+1]){\n stat[i] = 1;\n }else if(arr[i] <= arr[i-1] && arr[i] <= arr[i+1]){\n stat[i] = -1;\n }\n take += arr[i] * stat[i];\n }\n return take;\n}\n\nvoid play(){\n int n, q;\n n = rd!int;\n q = rd!int;\n\n // Reset\n arr = [];\n stat = [];\n\n arr ~= 0;\n arr ~= rdarr;\n arr ~= 0;\n stat.length = arr.length;\n /* if(n == 1){ writeln(arr[1]); return;} */\n\n ll ix = 0; ll pow = 0;\n bool side = 1, nside;\n foreach(i; 2..n+2){\n if(arr[i] > arr[i-1]){\n nside = 1;\n }else{\n nside = 0;\n }\n if(nside != side){\n if(ix % 2 == 0){\n pow += arr[i-1];\n stat[i-1] = 1;\n }else{\n pow -= arr[i-1];\n stat[i-1] = -1;\n }\n side = nside;\n ++ix;\n }\n }\n writeln(pow);\n int l, r;\n \n // Maxx.length > 1 always, was already a min\n foreach(k; 0..q){\n l = rd!int; r = rd!int;\n ll lval = arr[l]; ll rval = arr[r];\n /* show(arr, stat, pow); */\n pow += resett(max(l-1, 1), min(l+1, n));\n arr[l] = rval;\n pow += sett(max(l-1, 1), min(l+1, n));\n\n pow += resett(max(r-1, 1), min(r+1, n));\n arr[r] = lval;\n pow += sett(max(r-1, 1), min(r+1, n));\n /* show(arr, stat, pow); */\n writeln(pow);\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": "d04f34ce7c9184a5777380a2abec5c3a"} {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() { while (solve()) {} }\nbool solve() {\n\tint n;\n\tif (readf(\" %s\", &n) != 1) return false;\n\tlong r, sum;\n\treadf(\" %s %s\", &r, &sum);\n\tsum *= n;\n\n\tstruct ex {\n\t\tlong a, b;\n\t}\n\tex[] a = new ex[n];\n\tforeach (ref e; a)\n\t\treadf(\" %s %s\", &e.a, &e.b);\n\n\ta.sort!q{ a.b < b.b };\n\n\tforeach (e; a) {\n\t\tsum -= e.a;\n\t}\n\tlong ans = 0;\n\tforeach (e; a) {\n\t\tif (sum <= 0) break;\n\t\tlong can = r - e.a;\n\t\tans += e.b * min(can, sum);\n\t\tsum -= can;\n\t}\n\n\twriteln(ans);\n\n\treturn true;\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nstruct XD\n{\n int a;\n int b;\n}\n\nvoid solve(XD[] xds, int n, int r, int avg)\n{\n xds.sort!(\"a.b < b.b\");\n long sum = 0;\n foreach (i; 0 .. n)\n {\n sum += xds[i].a;\n }\n auto need = cast(long)n * avg - sum;\n if (need <= 0)\n {\n writeln(0);\n return;\n }\n long ans = 0;\n foreach (i; 0 .. n)\n {\n long d = r - xds[i].a;\n if (need <= d)\n {\n ans += need * xds[i].b;\n break;\n }\n need -= d;\n ans += d * xds[i].b;\n }\n writeln(ans);\n}\n\nint main(string[] args)\n{\n int n, r, avg;\n while (readf(\"%d %d %d\\n\", &n, &r, &avg) == 3)\n {\n auto xds = new XD[n];\n foreach (i; 0 .. n)\n {\n readf(\"%d %d\\n\", &xds[i].a, &xds[i].b);\n }\n solve(xds, n, r, avg);\n }\n return 0;\n}"}], "negative_code": [], "src_uid": "55270ee4e6aae7fc0c9bb070fcbf5560"} {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable long infinity = long.max / 2;\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 = new long [] [] (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\treadf !(\" %s\") (board[row][col]);\n\t\t\t}\n\t\t}\n\n\t\tlong solve (int rowPick, int colPick)\n\t\t{\n\t\t\tauto base = board[rowPick][colPick];\n\t\t\tbase -= rowPick + colPick;\n\t\t\tauto cost = new long [] [] (rows, cols);\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tforeach (col; 0..cols)\n\t\t\t\t{\n\t\t\t\t\tcost[row][col] = (row || col) ?\n\t\t\t\t\t infinity : 0;\n\t\t\t\t\tif (row > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row][col] = min\n\t\t\t\t\t\t (cost[row][col],\n\t\t\t\t\t\t cost[row - 1][col]);\n\t\t\t\t\t}\n\t\t\t\t\tif (col > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row][col] = min\n\t\t\t\t\t\t (cost[row][col],\n\t\t\t\t\t\t cost[row][col - 1]);\n\t\t\t\t\t}\n\t\t\t\t\tauto toDo = base + row + col;\n\t\t\t\t\tif (board[row][col] >= toDo)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row][col] +=\n\t\t\t\t\t\t board[row][col] - toDo;\n\t\t\t\t\t\tcost[row][col] = min\n\t\t\t\t\t\t (cost[row][col], infinity);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row][col] = infinity;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn cost[rows - 1][cols - 1];\n\t\t}\n\n\t\tlong res = infinity;\n\t\tforeach (rowPick; 0..rows)\n\t\t{\n\t\t\tforeach (colPick; 0..cols)\n\t\t\t{\n\t\t\t\tres = min (res, solve (rowPick, colPick));\n\t\t\t}\n\t\t}\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 long infinity = long.max / 2;\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 = new long [] [] (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\treadf !(\" %s\") (board[row][col]);\n\t\t\t}\n\t\t}\n\t\tauto cost = new long [] [] (rows, cols);\n\n\t\tlong solve (int rowPick, int colPick)\n\t\t{\n\t\t\tauto base = board[rowPick][colPick];\n\t\t\tbase -= rowPick + colPick;\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tforeach (col; 0..cols)\n\t\t\t\t{\n\t\t\t\t\tcost[row][col] = (row || col) ?\n\t\t\t\t\t infinity : 0;\n\t\t\t\t\tif (row > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row][col] = min\n\t\t\t\t\t\t (cost[row][col],\n\t\t\t\t\t\t cost[row - 1][col]);\n\t\t\t\t\t}\n\t\t\t\t\tif (col > 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row][col] = min\n\t\t\t\t\t\t (cost[row][col],\n\t\t\t\t\t\t cost[row][col - 1]);\n\t\t\t\t\t}\n\t\t\t\t\tauto toDo = base + row + col;\n\t\t\t\t\tif (board[row][col] >= toDo)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row][col] +=\n\t\t\t\t\t\t board[row][col] - toDo;\n\t\t\t\t\t\tcost[row][col] = min\n\t\t\t\t\t\t (cost[row][col], infinity);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row][col] = infinity;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn cost[rows - 1][cols - 1];\n\t\t}\n\n\t\tlong res = infinity;\n\t\tforeach (rowPick; 0..rows)\n\t\t{\n\t\t\tforeach (colPick; 0..cols)\n\t\t\t{\n\t\t\t\tres = min (res, solve (rowPick, colPick));\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;\nimport std.typecons;\n\nimmutable long infinity = long.max / 2;\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 = new long [] [] (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\treadf !(\" %s\") (board[row][col]);\n\t\t\t}\n\t\t}\n\t\tauto cost = new long [] [] (rows + 1, cols + 1);\n\n\t\tlong solve (int rowPick, int colPick)\n\t\t{\n\t\t\tauto base = board[rowPick][colPick];\n\t\t\tbase -= rowPick + colPick;\n\t\t\tforeach (ref line; cost)\n\t\t\t{\n\t\t\t\tline[] = infinity;\n\t\t\t}\n\t\t\tcost[0][1] = 0;\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tforeach (col; 0..cols)\n\t\t\t\t{\n\t\t\t\t\tauto toDo = base + row + col;\n\t\t\t\t\tif (board[row][col] >= toDo)\n\t\t\t\t\t{\n\t\t\t\t\t\tcost[row + 1][col + 1] =\n\t\t\t\t\t\t board[row][col] - toDo +\n\t\t\t\t\t\t min (cost[row][col + 1],\n\t\t\t\t\t\t cost[row + 1][col]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn cost[rows][cols];\n\t\t}\n\n\t\tlong res = infinity;\n\t\tforeach (rowPick; 0..rows)\n\t\t{\n\t\t\tforeach (colPick; 0..cols)\n\t\t\t{\n\t\t\t\tres = min (res, solve (rowPick, colPick));\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "d60181774d6e39ecc32ecddb32cedbf4"} {"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_do_h_damage(uint[] a, ulong k, ulong h)\n{\n ulong dmg, olddmg;\n foreach (i ; 1 .. a.length) {\n olddmg = dmg;\n dmg += min(cast(ulong)(a[i] - a[i - 1]), k);\n if (dmg < olddmg) // overflow\n return true;\n if (dmg >= h)\n return true;\n }\n olddmg = dmg;\n dmg += k;\n if (dmg < olddmg) // overflow\n return true;\n return dmg >= h;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n ulong n, h;\n readf!\" %d %d \"(n, h);\n auto a = readln.splitter.map!(to!uint).array;\n ulong L = 1UL, R = h + 100, mid, ans = 0;\n while (L <= R) {\n mid = L + (R - L) / 2;\n if (!can_do_h_damage(a, mid, h)) {\n ans = mid;\n L = mid + 1;\n } else {\n R = mid - 1;\n }\n }\n writeln(ans + 1);\n }\n}\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n auto n = scan!int;\n auto h = scan;\n auto a = scanArray;\n long[] b;\n for(int i = 1; i < n; ++i){\n b ~= a[i] - a[i-1];\n }\n b ~= h;\n b.sort;\n long summ = 0;\n for(int i = 0; i < n; ++i){\n long left = h - summ;\n long bucks = n - i;\n long k = left/bucks + (left % bucks != 0);\n if(b[i] >= k){\n writeln(k);\n return;\n }\n summ += b[i];\n }\n assert(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;\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 debug writeln(\"for test \", tc);\n auto n = readInt!int;\n auto h = readInt!long;\n auto a = ma(n, readInt!long);\n bool kills(long k)\n {\n debug writeln(\"kills \", k);\n long health = h;\n foreach(i, ai; a)\n {\n\tlong lastTime = ai + k;\n\tif (i + 1 < n)\n\t {\n\t lastTime = min(lastTime, a[i + 1]);\n\t }\n\tlong length = lastTime - ai;\n\tdebug writeln(\"for \", i, \" length \", length);\n\tif (length >= health) { debug writeln(\"yes\"); return true; }\n\thealth -= length;\n }\n debug writeln(\"no\"); return false;\n }\n long high = h;\n long low = 1;\n long ans = -1;\n while (low <= high)\n {\n long middle = low + (high - low)/2L;\n if (kills(middle))\n\t{\n\t ans = middle;\n\t high = middle - 1;\n\t}\n else\n\t{\n\t low = middle + 1;\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"}], "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 can_do_h_damage(uint[] a, ulong k, ulong h)\n{\n ulong dmg;\n foreach (i ; 1 .. a.length) {\n dmg += min(a[i] - a[i - 1], k);\n if (dmg >= h)\n return true;\n }\n dmg += k;\n return dmg >= h;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n ulong n, h;\n readf!\" %d %d \"(n, h);\n auto a = readln.splitter.map!(to!uint).array;\n writeln(iota(1UL, h + 1).map!(k => can_do_h_damage(a, k, h)).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\nbool can_do_h_damage(uint[] a, ulong k, ulong h)\n{\n ulong dmg;\n foreach (i ; 1 .. a.length) {\n dmg += min(a[i] - a[i - 1], k);\n }\n dmg += k;\n return dmg >= h;\n}\n\nvoid main()\n{\n foreach (casenum ; 1 .. readln.strip.to!int + 1) {\n ulong n, h;\n readf!\" %d %d \"(n, h);\n auto a = readln.splitter.map!(to!uint).array;\n writeln(iota(1UL, h + 1).map!(k => can_do_h_damage(a, k, h)).assumeSorted.lowerBound(true).length + 1);\n }\n}\n"}], "src_uid": "3d0685162fbb432c37bb6aeb5fe51f94"} {"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 (row; 0..n)\r\n\t\t{\r\n\t\t\ta ~= readln.splitter.map !(to !(int)).array;\r\n\t\t}\r\n\r\n\t\tauto c = new int [n + m - 1];\r\n\t\tauto d = new int [n + m - 1];\r\n\t\tforeach (row; 0..n)\r\n\t\t{\r\n\t\t\tforeach (col; 0..m)\r\n\t\t\t{\r\n\t\t\t\tc[row + col] += a[row][col];\r\n\t\t\t\td[row + m - col - 1] += a[row][col];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint res = 0;\r\n\t\tforeach (row; 0..n)\r\n\t\t{\r\n\t\t\tforeach (col; 0..m)\r\n\t\t\t{\r\n\t\t\t\tres = max (res, c[row + col] +\r\n\t\t\t\t d[row + m - col - 1] - a[row][col]);\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 M = scan!int;\r\n auto A = scan!long(N * M).chunks(M).array;\r\n\r\n auto lsum = new long[](N + M - 1);\r\n foreach(y; -M+1..N) {\r\n int tx = max(-y, 0);\r\n int ty = max(0, y);\r\n while(tx < M && ty < N) {\r\n lsum[y + M - 1] += A[ty++][tx++];\r\n }\r\n }\r\n\r\n auto rsum = new long[](N + M - 1);\r\n foreach(y; -M+1..N) {\r\n int tx = min(M - 1 + y , M - 1);\r\n int ty = max(0, y);\r\n while(tx >= 0 && ty < N) {\r\n rsum[y + M - 1] += A[ty++][tx--];\r\n }\r\n }\r\n\r\n // lsum.deb;\r\n // rsum.deb;\r\n long ans = 0;\r\n foreach(y; 0..N) foreach(x; 0..M) {\r\n long tans;\r\n tans += lsum[M - x + y - 1];\r\n tans += rsum[x + y];\r\n tans -= A[y][x];\r\n ans = max(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>>\".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": "module x_sum;\r\n\r\nimport 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\nint SD(int[][] matrix, int n, int m) {\r\n int sum = matrix[n][m];\r\n for ( {int i = n-1; int j = m-1; } i >= 0 && j >= 0; i--, j--)\r\n sum += matrix[i][j];\r\n for ( {int i = n+1; int j = m+1; } i < matrix.length && j < matrix[0].length; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n-1; int j = m+1; } i >= 0 && j < matrix[0].length; i--, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n+1; int j = m-1; } i < matrix.length && j >= 0; i++, j--)\r\n sum += matrix[i][j];\r\n return sum;\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 int sum = 0;\r\n readf(\"%d %d\\n\", n, m);\r\n int[][] matrix;\r\n int temp = n;\r\n while (temp--)\r\n matrix ~= rtln!int;\r\n if (m == 1)\r\n foreach (ln; matrix)\r\n sum = max(sum, ln[0]);\r\n else\r\n for (int i = 0; i < n; i++)\r\n for (int j = 0; j < m; j++)\r\n sum = max(sum, SD(matrix, i, j));\r\n writeln(sum);\r\n }\r\n}"}], "negative_code": [{"source_code": "module x_sum;\r\n\r\nimport 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\nint SD(int[][] matrix, int n, int m) {\r\n int sum = matrix[n][m];\r\n for ( {int i = n-1; int j = m-1; } i >= 0 && j >= 0; i--, j--)\r\n sum += matrix[i][j];\r\n for ( {int i = n+1; int j = m+1; } i < matrix.length && j < matrix[0].length; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n-1; int j = m+1; } i >= 0 && j < matrix[0].length; i--, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n+1; int j = m-1; } i < matrix.length && j >= 0; i++, j--)\r\n sum += matrix[i][j];\r\n return sum;\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 int sum = 0;\r\n readf(\"%d %d\\n\", n, m);\r\n int[][] matrix;\r\n int temp = n;\r\n while (temp--)\r\n matrix ~= rtln!int;\r\n if (m == 1)\r\n foreach (ln; matrix)\r\n sum = max(sum, ln[0]);\r\n else\r\n for (int i = 0; i < n; i++)\r\n for (int j = 1; j < m; j++)\r\n sum = max(sum, SD(matrix, i, j));\r\n writeln(sum);\r\n }\r\n}"}, {"source_code": "module x_sum;\r\n\r\nimport 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\nint SD(int[][] matrix, int n, int m) {\r\n int sum = -(2 * matrix[n][m]);\r\n for ( {int i = 0; int j = 0; } i < n && j < m; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i < matrix.length && j < matrix[0].length; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i >= 0 && j < matrix[0].length; i--, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i < matrix.length && j >= 0; i++, j--)\r\n sum += matrix[i][j];\r\n return sum;\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 int sum;\r\n readf(\"%d %d\\n\", n, m);\r\n int[][] matrix;\r\n int temp = n;\r\n while (temp--)\r\n matrix ~= rtln!int;\r\n if (m == 1)\r\n foreach (ln; matrix)\r\n sum = max(sum, ln[0]);\r\n else\r\n for (int i = 0; i < n; i++)\r\n for (int j = 1; j < m; j++)\r\n sum = max(sum, SD(matrix, i, j));\r\n writeln(sum);\r\n }\r\n}"}, {"source_code": "module x_sum;\r\n\r\nimport 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\nint SD(int[][] matrix, int n, int m) {\r\n int sum = -(2 * matrix[n][m]);\r\n for ( {int i = 0; int j = 0; } i < n && j < m; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i < matrix.length && j < matrix[0].length; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i >= 0 && j < matrix[0].length; i--, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i < matrix.length && j >= 0; i++, j--)\r\n sum += matrix[i][j];\r\n return sum;\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 int sum;\r\n readf(\"%d %d\\n\", n, m);\r\n int[][] matrix;\r\n int temp = n;\r\n while (temp--)\r\n matrix ~= rtln!int;\r\n for (int i = 0; i < n; i++)\r\n for (int j = 1; j < m; j++)\r\n sum = max(sum, SD(matrix, i, j));\r\n writeln(sum);\r\n }\r\n}"}, {"source_code": "module x_sum;\r\n\r\nimport 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\nint SD(int[][] matrix, int n, int m) {\r\n int sum = -(2 * matrix[n][m]);\r\n for ( {int i = 0; int j = 0; } i < n && j < m; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i < matrix.length && j < matrix[0].length; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i >= 0 && j < matrix[0].length; i--, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i < matrix.length && j >= 0; i++, j--)\r\n sum += matrix[i][j];\r\n return sum;\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 int sum;\r\n readf(\"%d %d\\n\", n, m);\r\n int[][] matrix;\r\n int temp = n;\r\n while (temp--)\r\n matrix ~= rtln!int;\r\n for (int i = 0; i < n; i++)\r\n for (int j = 0; j < m; j++)\r\n sum = max(sum, SD(matrix, i, j));\r\n writeln(sum);\r\n }\r\n}"}, {"source_code": "module x_sum;\r\n\r\nimport 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\nint SD(int[][] matrix, int n, int m) {\r\n int sum = -(2 * matrix[n][m]);\r\n for ( {int i = 0; int j = 0; } i < n && j < m; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i < matrix.length && j < matrix[0].length; i++, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i >= 0 && j < matrix[0].length; i--, j++)\r\n sum += matrix[i][j];\r\n for ( {int i = n; int j = m; } i < matrix.length && j >= 0; i++, j--)\r\n sum += matrix[i][j];\r\n return sum;\r\n}\r\n\r\nvoid main() {\r\n int t, n, m, sum;\r\n readf(\"%d\\n\", t);\r\n while(t--) {\r\n readf(\"%d %d\\n\", n, m);\r\n int[][] matrix;\r\n int temp = n;\r\n while (temp--)\r\n matrix ~= rtln!int;\r\n for (int i = 0; i < n; i++)\r\n for (int j = 0; j < m; j++)\r\n sum = max(sum, SD(matrix, i, j));\r\n writeln(sum);\r\n }\r\n}"}], "src_uid": "1b0c53ec666cdfea31a74f73d6ff70f2"} {"source_code": "import std.stdio, std.range, std.algorithm, std.conv, std.string;\n\nvoid main() {\n\n\tint n = readln.strip.to!int;\n\n\tauto t = stdin.byLine.take(n).\n\t\tmap!(a => a.split.map!(to!int).any!\"a == 1 || a == 3\").array;\n\n\tint[] idx;\n\tforeach (i, el; t) {\n\t\tif (!el) {\n\t\t\tidx ~= i + 1;\n\t\t}\n\t}\n\n\twriteln(idx.length);\n\twritefln(\"%(%s %)\", idx);\n}", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.range, std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] ans;\n foreach (i; 0..n) {\n auto row = readln.chomp.split.map!(to!int);\n if (row.any!\"a == 1 || a == 3\") {\n continue;\n }\n\n ans ~= i + 1;\n }\n\n ans.length.writeln;\n if (ans.length > 0) {\n ans.map!(to!string).join(\" \").writeln;\n }\n}\n"}, {"source_code": "import std.stdio, std.string, std.algorithm, std.conv;\n\nvoid main() {\n\n\tint sum; int[] ans;\n\tforeach (i; 1 .. readln.strip.to!int + 1) {\n\t\tif (readln.split.map!(to!int).all!\"a != 1 && a != 3\") {\n\t\t\t++sum;\n\t\t\tans ~= i;\n\t\t}\n\t}\n\n\twriteln(sum);\n\n\tif (sum > 0) {\n\t\twritefln(\"%(%s %)\", ans);\n\t}\n}"}, {"source_code": "import 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.string,\n std.numeric,\n std.variant,\n std.typecons,\n std.algorithm,\n std.typetuple,\n std.exception;\n\nvoid main() {\n\n\tint n = readln.strip.to!int;\n\n\tint[101][101] a; bool[int] hash;\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. n + 1) {\n\t\t\tscanf(\"%d\", &a[i][j]);\n\t\t\tif (a[i][j] != 0 && a[i][j] != -1) {\n\t\t\t\tif (a[i][j] == 1) {\n\t\t\t\t\thash[i] = false;\n\t\t\t\t}\n\t\t\t\tif (a[i][j] == 2) {\n\t\t\t\t\thash[j] = false;\n\t\t\t\t}\n\t\t\t\tif (a[i][j] == 3) {\n\t\t\t\t\thash[i] = hash[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\n\tint[] ans; int sum;\n\tforeach (i; 1 .. n + 1) {\n\t\tif (i !in hash) {\n\t\t\t++sum;\n\t\t\tans ~= i;\n\t\t}\n\t}\n\n\twriteln(sum);\n\tif (sum > 0) {\n\t\twritefln(\"%(%s %)\", ans);\n\t}\n}"}], "negative_code": [{"source_code": "import 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.string,\n std.numeric,\n std.variant,\n std.typecons,\n std.algorithm,\n std.typetuple,\n std.exception;\n\nvoid main() {\n\n\tint n = readln.strip.to!int;\n\n\tint[101][101] a;\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. n + 1) {\n\t\t\tscanf(\"%d\", &a[i][j]);\n\t\t}\n\t}\n\n\tbool[int] hash;\n\tforeach (i; 1 .. n) {\n\t\tif (a[i][i + 1] != 0) {\n\t\t\tif (a[i][i + 1] == 1) {\n\t\t\t\thash[i] = false;\n\t\t\t}\n\t\t\tif (a[i][i + 1] == 2) {\n\t\t\t\thash[i + 1] = false;\n\t\t\t}\n\t\t\tif (a[i][i + 1] == 3) {\n\t\t\t\thash[i] = hash[i + 1] = false;\n\t\t\t}\n\t\t}\n\t\tif (a[i + 1][i] != 0) {\n\t\t\tif (a[i + 1][i] == 1) {\n\t\t\t\thash[i + 1] = false;\n\t\t\t}\n\t\t\tif (a[i + 1][i] == 2) {\n\t\t\t\thash[i] = false;\n\t\t\t}\n\t\t\tif (a[i + 1][i] == 3) {\n\t\t\t\thash[i] = hash[i + 1] = false;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (a[1][n] != 0) {\n\t\thash[n] = false;\n\t}\n\n\tif (a[n][1] != 0) {\n\t\tif (a[n][1] == 1) {\n\t\t\thash[n] = false;\n\t\t}\n\t\tif (a[n][1] == 2) {\n\t\t\thash[1] = false;\n\t\t}\n\t\tif (a[n][1] == 3) {\n\t\t\thash[1] = hash[n] = false;\n\t\t}\n\t}\n\n\tint[] ans; int sum;\n\tforeach (i; 1 .. n + 1) {\n\t\tif (i !in hash) {\n\t\t\t++sum;\n\t\t\tans ~= i;\n\t\t}\n\t}\n\n\twriteln(sum);\n\tif (sum > 0) {\n\t\twritefln(\"%(%s %)\", ans);\n\t}\n}"}, {"source_code": "import 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.string,\n std.numeric,\n std.variant,\n std.typecons,\n std.algorithm,\n std.typetuple,\n std.exception;\n\nvoid main() {\n\n\tint n = readln.strip.to!int;\n\n\tint[101][101] a;\n\tforeach (i; 1 .. n + 1) {\n\t\tforeach (j; 1 .. n + 1) {\n\t\t\tscanf(\"%d\", &a[i][j]);\n\t\t}\n\t}\n\n\tbool[int] hash;\n\tforeach (i; 1 .. n) {\n\t\tif (a[i][i + 1] != 0) {\n\t\t\tif (a[i][i + 1] == 1) {\n\t\t\t\thash[i] = false;\n\t\t\t}\n\t\t\tif (a[i][i + 1] == 2) {\n\t\t\t\thash[i + 1] = false;\n\t\t\t}\n\t\t\tif (a[i][i + 1] == 3) {\n\t\t\t\thash[i] = hash[i + 1] = false;\n\t\t\t}\n\t\t}\n\t\tif (a[i + 1][i] != 0) {\n\t\t\tif (a[i + 1][i] == 1) {\n\t\t\t\thash[i + 1] = false;\n\t\t\t}\n\t\t\tif (a[i + 1][i] == 2) {\n\t\t\t\thash[i] = false;\n\t\t\t}\n\t\t\tif (a[i + 1][i] == 3) {\n\t\t\t\thash[i] = hash[i + 1] = false;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (a[1][n] != 0) {\n\t\tif (a[1][n] == 1) {\n\t\t\thash[1] = false;\n\t\t}\n\t\tif (a[1][n] == 2) {\n\t\t\thash[n] = false;\n\t\t}\n\t\tif (a[1][n] == 3) {\n\t\t\thash[1] = hash[n] = false;\n\t\t}\n\t}\n\n\tif (a[n][1] != 0) {\n\t\tif (a[n][1] == 1) {\n\t\t\thash[n] = false;\n\t\t}\n\t\tif (a[n][1] == 2) {\n\t\t\thash[1] = false;\n\t\t}\n\t\tif (a[n][1] == 3) {\n\t\t\thash[1] = hash[n] = false;\n\t\t}\n\t}\n\n\tint[] ans; int sum;\n\tforeach (i; 1 .. n + 1) {\n\t\tif (i !in hash) {\n\t\t\t++sum;\n\t\t\tans ~= i;\n\t\t}\n\t}\n\n\twriteln(sum);\n\tif (sum > 0) {\n\t\twritefln(\"%(%s %)\", ans);\n\t}\n}"}], "src_uid": "3fc0ac711b113fa98f41740536dad44f"} {"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\tif (a.stride (2).canFind !(q{a % 2 == 0}))\r\n\t\t{\r\n\t\t\twriteln (-1);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tint [] answer;\r\n\r\n\t\tvoid go (int pos)\r\n\t\t{\r\n\t\t\tanswer ~= pos;\r\n\t\t\treverse (a[0..pos]);\r\n\t\t}\r\n\r\n\t\tfor ( ; n > 1; n -= 2)\r\n\t\t{\r\n\t\t\tgo (a.countUntil (n).to !(int) + 1);\r\n\t\t\tgo (a.countUntil (n - 1).to !(int) + 0);\r\n\t\t\tgo (a.countUntil (n - 1).to !(int) + 2);\r\n\t\t\tgo (3);\r\n\t\t\tgo (n);\r\n\t\t\tdebug {writeln (a);}\r\n\t\t}\r\n\r\n\t\twriteln (answer.length);\r\n\t\twritefln !(\"%(%s %)\") (answer);\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 debug {\r\n for (int n = 3; n <= 7; n += 2) {\r\n writeln(\"n = \", n);\r\n int[string] vis;\r\n auto as = iota(n).array;\r\n void dfs(int last) {\r\n const key = as.to!string;\r\n if (key !in vis) {\r\n vis[key] = last;\r\n for (int m = 3; m <= n; m += 2) {\r\n as[0 .. m].reverse;\r\n dfs(m);\r\n as[0 .. m].reverse;\r\n }\r\n }\r\n }\r\n dfs(-1);\r\n foreach (key, val; vis) {\r\n writeln(key, \" \", val);\r\n }\r\n writeln(\"|vis| = \", vis.length);\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 N = readInt();\r\n auto A = new int[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readInt() - 1;\r\n }\r\n \r\n bool ok = true;\r\n foreach (i; 0 .. N) {\r\n ok = ok && ((A[i] - i) % 2 == 0);\r\n }\r\n if (ok) {\r\n auto as = A.dup;\r\n int[] ans;\r\n for (int n = N; n > 1; n -= 2) {\r\n int p = -1, q = -1;\r\n foreach (i; 0 .. n) {\r\n if (as[i] == n - 2) p = i;\r\n if (as[i] == n - 1) q = i;\r\n }\r\n \r\n void oper(int m) {\r\n assert(m % 2 != 0);\r\n ans ~= m;\r\n as[0 .. m].reverse;\r\n if (p < m) p = m - 1 - p;\r\n if (q < m) q = m - 1 - q;\r\n }\r\n oper(q + 1);\r\n oper(p);\r\n oper(n);\r\n oper(q + 1);\r\n oper(n);\r\n assert(p == n - 2);\r\n assert(q == n - 1);\r\n }\r\n \r\n const ansLen = cast(int)(ans.length);\r\n writeln(ansLen);\r\n foreach (i; 0 .. ansLen) {\r\n if (i > 0) write(\" \");\r\n write(ans[i]);\r\n }\r\n writeln;\r\n assert(2 * ansLen <= 5 * N);\r\n } else {\r\n writeln(-1);\r\n }\r\n }\r\n }\r\n } catch (EOFException e) {\r\n }\r\n}\r\n"}], "negative_code": [], "src_uid": "fa0fc36acf5a638917be7a2769cbfd80"} {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.algorithm;\nimport std.container.dlist;\n\nbool dcare(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return true;\n } else if (s[p] == 0){\n ans.insertFront(\"(0->\");\n ans.insertBack(\")\");\n dcare(s, p + 1, ans);\n return true;\n } else {\n ans.insertFront(\"(1->\");\n ans.insertBack(\")\");\n dcare(s, p + 1, ans);\n return true;\n }\n}\n\nbool exact_zero(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return false;\n } else if (s[p] == 1) {\n ans.insertFront(\"(1->\");\n ans.insertBack(\")\");\n return exact_zero(s, p + 1, ans);\n } else {\n ans.insertFront(\"(0->\");\n ans.insertBack(\")\");\n dcare(s, p + 1, ans);\n return true;\n }\n}\n\nbool one(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return true;\n } else if (s[p] == 0) {\n ans.insertBack(\"(0)\");\n if (!exact_zero(s, p + 1, ans)) {\n return false;\n }\n return true;\n } else {\n ans.insertBack(\"(1)\");\n dcare(s, p + 1, ans);\n return true;\n }\n}\n\nbool zero(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return false;\n } else if (s[p] == 1) {\n return false;\n } else {\n if (!one(s, p + 1, ans)) {\n return false;\n }\n if (p == s.length - 1) {\n ans.insertBack(\"(0)\");\n } else {\n ans.insertFront(\"(\");\n ans.insertBack(\"->0)\");\n }\n return true;\n }\n}\n\nvoid main() {\n int n = readln().strip().to!int;\n auto a = readln().split().map!(to!int).array;\n a.reverse();\n DList!string ans;\n if (zero(a, 0, ans)) {\n writeln(\"YES\");\n writeln(ans.array.join(\"\"));\n } else {\n writeln(\"NO\");\n }\n \n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.algorithm;\nimport std.range;\nimport std.container.dlist;\n\nint impl(int x, int y) {\n return (1 - x) | y;\n}\n\nstring solve(int[] a) {\n auto n = a.length;\n if (a.back() != 0) {\n return \"\";\n }\n if (n == 1) {\n return \"0\";\n }\n int val = a[n - 2];\n foreach_reverse (i; 0..n-2) {\n val = impl(a[i], val);\n }\n if (val != 1) {\n return \"\";\n }\n char[] buf;\n foreach (i; 0..n-2) {\n buf ~= \"(\" ~ to!string(a[i]) ~ \"->\";\n }\n buf ~= \"(\" ~ to!string(a[a.length-2]);\n buf ~= ')'.repeat().take(a.length - 1).array;\n buf ~= \"->0\";\n return buf.dup;\n}\n\nvoid main() {\n int n = readln().strip().to!int;\n auto a = readln().split().map!(to!int).array;\n string ans = solve(a);\n if (!ans.empty()) {\n writeln(\"YES\");\n writeln(ans);\n } else {\n writeln(\"NO\");\n }\n \n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.algorithm;\nimport std.container.dlist;\n\nbool dcare(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return true;\n } else if (s[p] == 0){\n ans.insertFront(\"(0->\");\n ans.insertBack(\")\");\n dcare(s, p + 1, ans);\n return true;\n } else {\n ans.insertFront(\"(1->\");\n ans.insertBack(\")\");\n dcare(s, p + 1, ans);\n return true;\n }\n}\n\nbool one(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return true;\n } else if (s[p] == 0) {\n if (!zero(s, p + 1, ans)) {\n return false;\n }\n ans.insertFront(\"(\");\n ans.insertBack(\"->0)\");\n return true;\n } else {\n ans.insertBack(\"(1)\");\n dcare(s, p + 1, ans);\n return true;\n }\n}\n\nbool zero(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return false;\n } else if (s[p] == 1) {\n return false;\n } else {\n if (!one(s, p + 1, ans)) {\n return false;\n }\n if (p == s.length - 1) {\n ans.insertBack(\"(0)\");\n } else {\n ans.insertFront(\"(\");\n ans.insertBack(\"->0)\");\n }\n return true;\n }\n}\n\nvoid main() {\n int n = readln().strip().to!int;\n auto a = readln().split().map!(to!int).array;\n a.reverse();\n DList!string ans;\n if (zero(a, 0, ans)) {\n writeln(\"YES\");\n writeln(ans.array.join(\"\"));\n } else {\n writeln(\"NO\");\n }\n \n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array;\nimport std.algorithm;\nimport std.container.dlist;\n\nbool dcare(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return true;\n } else if (s[p] == 0){\n ans.insertFront(\"(0->\");\n ans.insertBack(\")\");\n dcare(s, p + 1, ans);\n return true;\n } else {\n ans.insertFront(\"(1->\");\n ans.insertBack(\")\");\n dcare(s, p + 1, ans);\n return true;\n }\n}\n\nbool exact_zero(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return false;\n } else if (s[p] == 1) {\n return false;\n } else {\n ans.insertBack(\"(0)\");\n return true;\n }\n}\n\nbool one(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return true;\n } else if (s[p] == 0) {\n if (!exact_zero(s, p + 1, ans)) {\n return false;\n }\n ans.insertFront(\"(\");\n ans.insertBack(\"->0)\");\n dcare(s, p + 2, ans);\n return true;\n } else {\n ans.insertBack(\"(1)\");\n dcare(s, p + 1, ans);\n return true;\n }\n}\n\nbool zero(int[] s, int p, ref DList!string ans) {\n if (p >= s.length) {\n return false;\n } else if (s[p] == 1) {\n return false;\n } else {\n if (!one(s, p + 1, ans)) {\n return false;\n }\n if (p == s.length - 1) {\n ans.insertBack(\"(0)\");\n } else {\n ans.insertFront(\"(\");\n ans.insertBack(\"->0)\");\n }\n return true;\n }\n}\n\nvoid main() {\n int n = readln().strip().to!int;\n auto a = readln().split().map!(to!int).array;\n a.reverse();\n DList!string ans;\n if (zero(a, 0, ans)) {\n writeln(\"YES\");\n writeln(ans.array.join(\"\"));\n } else {\n writeln(\"NO\");\n }\n \n}\n"}], "src_uid": "98380bd9d6865fa9a2d100ca3484b005"} {"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\nint ceildiv (in int x, in int y) {\n return (x + y - 1) / y;\n}\n\nbool test (const int n, const int d) {\n if (n >= d) return true;\n for (int x = 1; x < 200_000 ; ++x) {\n int y = x + ceildiv (d, x + 1);\n if (y <= n) return true;\n }\n return false;\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable nt = r.next!uint ();\n foreach (tid; 0 .. nt) {\n int n = r.next!int;\n int d = r.next!int;\n writeln (test (n, d) ? \"YES\" : \"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; }\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;\n\t\tauto d = RD;\n\t\tlong last = long.max, x;\n\t\tforeach (i; 1..d+2)\n\t\t{\n\t\t\tauto y = d / i + (d % i != 0 ? 1 : 0);\n\t\t\tif (y >= last)\n\t\t\t{\n\t\t\t\tx = i-1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlast = y;\n\t\t}\n\t\tans[ti] = d / x + (d % x != 0 ? 1 : 0) + x - 1 <= n;\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.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 immutable n = e[0];\n immutable d = e[1];\n if(n>=d){\n writeln(\"YES\");\n continue;\n }\n real func(real a)\n {\n return d/real(a+1)+a;\n }\n immutable nd = ternarySearch!func(0.0, n+1);\n debugPrint!nd;\n if(n>=ceil(nd)){\n writeln(\"YES\");\n }else writeln(\"NO\");\n }\n}\n\n//辞書順順列はiota(1,N),nextPermituionを使う\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//最小を返す\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)11)debugPrint!(l,r,nl,nr,()=>FF(nl),()=>FF(nr));\n if(FF(nl)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文字のみ\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<mod(a-(1L< 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分解\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のn個上の親を返す\n //バグあるかも\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=0&&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=1&&b<=size);\n\n T vl=UNIT,vr=UNIT;\n for(long l=a+n,r=b+n;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=0 &&\n y= 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//素因数分解\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//約数をすべて列挙\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までの素数のリスト\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=d){\n writeln(\"YES\");\n continue;\n }\n real func(real a)\n {\n return d/real(a+1).to!long+a;\n }\n immutable nd = ternarySearch!func(0.0, n+1);\n debugPrint!nd;\n if(n>=ceil(nd)){\n writeln(\"YES\");\n }else writeln(\"NO\");\n }\n}\n\n//辞書順順列はiota(1,N),nextPermituionを使う\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//最小を返す\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)11)debugPrint!(l,r,nl,nr,()=>FF(nl),()=>FF(nr));\n if(FF(nl)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文字のみ\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<mod(a-(1L< 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分解\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のn個上の親を返す\n //バグあるかも\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=0&&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=1&&b<=size);\n\n T vl=UNIT,vr=UNIT;\n for(long l=a+n,r=b+n;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=0 &&\n y= 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//素因数分解\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//約数をすべて列挙\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までの素数のリスト\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=d){\n writeln(\"YES\");\n continue;\n }\n long func(long a)\n {\n return (d+a)/(a+1)+a;\n }\n auto nd = ternarySearch!func(1, 10^^9);\n if(n>=nd){\n writeln(\"YES\");\n }else writeln(\"NO\");\n }\n}\n\n//辞書順順列はiota(1,N),nextPermituionを使う\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//最小を返す\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)mod(a-(1L< 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分解\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のn個上の親を返す\n //バグあるかも\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=0&&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=1&&b<=size);\n\n T vl=UNIT,vr=UNIT;\n for(long l=a+n,r=b+n;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=0 &&\n y= 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//素因数分解\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//約数をすべて列挙\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までの素数のリスト\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=d){\n writeln(\"YES\");\n continue;\n }\n long func(long a)\n {\n return (d+a)/(a+1)+a;\n }\n immutable nd = ternarySearch!func(0, n+1);\n if(n>=nd){\n writeln(\"YES\");\n }else writeln(\"NO\");\n }\n}\n\n//辞書順順列はiota(1,N),nextPermituionを使う\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//最小を返す\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)mod(a-(1L< 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分解\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のn個上の親を返す\n //バグあるかも\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=0&&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=1&&b<=size);\n\n T vl=UNIT,vr=UNIT;\n for(long l=a+n,r=b+n;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=0 &&\n y= 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//素因数分解\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//約数をすべて列挙\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までの素数のリスト\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=d){\n writeln(\"YES\");\n continue;\n }\n long func(long a)\n {\n return ceil(d/real(a+1)).to!long+a;\n }\n immutable nd = ternarySearch!func(0, n+1);\n if(n>=nd){\n writeln(\"YES\");\n }else writeln(\"NO\");\n }\n}\n\n//辞書順順列はiota(1,N),nextPermituionを使う\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//最小を返す\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)mod(a-(1L< 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分解\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のn個上の親を返す\n //バグあるかも\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=0&&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=1&&b<=size);\n\n T vl=UNIT,vr=UNIT;\n for(long l=a+n,r=b+n;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=0 &&\n y= 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//素因数分解\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//約数をすべて列挙\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までの素数のリスト\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= 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;\n\t\tauto d = RD;\n\t\tauto c = (d+1)/2;\n\t\tauto x = d / c + (d % c != 0 ? 1 : 0);\n\t\tauto y = x + c - 1;\n\t\tans[ti] = y <= n;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e ? \"YES\" : \"NO\");\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "src_uid": "e65b2a81689bb13b90a02a9ccf1d4125"} {"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\nenum LIM = 2020;\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\nvoid main() {\n prepare;\n \n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n auto A = new string[M];\n foreach (i; 0 .. N) {\n A[i] = readToken();\n }\n \n auto bell = new Mint[M + 1];\n bell[0] = 1;\n foreach (i; 1 .. M + 1) {\n foreach (j; 0 .. i) {\n bell[i] += binom(i - 1, j) * bell[j];\n }\n }\n \n auto bs = new string[M];\n foreach (i; 0 .. N) {\n foreach (j; 0 .. M) {\n bs[j] ~= A[i][j];\n }\n }\n bs.sort;\n Mint ans = 1;\n foreach (grp; bs.group) {\n ans *= bell[grp[1]];\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "/+ dub.sdl:\n name \"E\"\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.datastructure.unionfind;\n\n// import dkh.modint;\nalias Mint = ModInt!(10^^9 + 7);\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) sc.read!true;\n\n int n, m; // for hackeres: swapped(n, m)\n sc.read(n, m);\n bool[][] g = new bool[][](n, n);\n foreach (ph; 0..m) {\n string s;\n sc.read(s);\n foreach (i; 0..n) {\n foreach (j; i+1..n) {\n if (s[i] != s[j]) {\n g[i][j] = true;\n }\n }\n }\n }\n\n auto uf = UnionFind(n);\n foreach (i; 0..n) {\n foreach (j; i+1..n) {\n if (g[i][j]) continue;\n uf.merge(i, j);\n }\n }\n\n auto fact = factTable!Mint(10000);\n auto iFac = invFactTable!Mint(10000);\n Mint C(int n, int k) {\n if (n < k || n < 0) return Mint(0);\n return fact[n] * iFac[k] * iFac[n-k];\n }\n\n Mint[] dp = new Mint[n+1];\n dp[0] = Mint(1);\n foreach (i; 1..n+1) {\n foreach (j; 0..i) {\n dp[i] += dp[i-(1+j)] * C(i-1, j);\n }\n }\n\n Mint ans = Mint(1);\n int[] ls;\n foreach (i; 0..n) {\n if (!uf.isLeader(i)) continue;\n auto l = uf.group(i).length.to!int;\n ls ~= l;\n ans *= dp[l];\n }\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/ldc/inline.d */\n// module dkh.ldc.inline;\n\nversion(LDC) {\n pragma(LDC_inline_ir) R inlineIR(string s, R, P...)(P);\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/modint.d */\n// module dkh.modint;\n\n// import dkh.numeric.primitive;\n\n \nstruct ModInt(uint MD) if (MD < int.max) {\n import std.conv : to;\n uint v;\n this(int v) {this(long(v));}\n this(long v) {this.v = (v%MD+MD)%MD;}\n static auto normS(uint x) {return (x a[n-1]*T(n)).take(length).array;\n}\n\nT[] invFactTable(T)(size_t length) if (isModInt!T) {\n import std.algorithm : map, reduce;\n import std.range : take, recurrence, iota;\n import std.array : array;\n auto res = new T[length];\n res[$-1] = T(1) / iota(1, length).map!T.reduce!\"a*b\";\n foreach_reverse (i, v; res[0..$-1]) {\n res[i] = res[i+1] * T(i+1);\n }\n return res;\n}\n\nT[] invTable(T)(size_t length) if (isModInt!T) {\n auto f = factTable!T(length);\n auto invf = invFactTable!T(length);\n auto res = new T[length];\n foreach (i; 1..length) {\n res[i] = invf[i] * f[i-1];\n }\n return res;\n}\n\n \n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/datastructure/unionfind.d */\n// module dkh.datastructure.unionfind;\n\n \nstruct UnionFind {\n private int[] id; \n private int[][] groups; \n size_t count; \n \n this(size_t n) {\n import std.algorithm : map;\n import std.range : iota, array;\n import std.conv : to;\n int _n = n.to!int;\n id = _n.iota.array;\n groups = _n.iota.map!\"[a]\".array;\n count = n;\n }\n \n void merge(size_t a, size_t b) {\n import std.algorithm : swap, each;\n if (same(a, b)) return;\n count--;\n uint 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 const(int[]) group(size_t i) const {\n return groups[id[i]];\n }\n \n bool isLeader(size_t i) const {\n return i == id[i];\n }\n \n bool same(size_t a, size_t b) const {\n return id[a] == id[b];\n }\n}\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\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/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/numeric/primitive.d */\n// module dkh.numeric.primitive;\n\nimport std.traits;\nimport std.bigint;\n\n \nUnqual!T pow(T, U)(T x, U n)\nif (!isFloatingPoint!T && (isIntegral!U || is(U == BigInt))) {\n return pow(x, n, T(1));\n}\n\n \nUnqual!T pow(T, U, V)(T x, U n, V e)\nif ((isIntegral!U || is(U == BigInt)) && is(Unqual!T == Unqual!V)) {\n Unqual!T b = x, v = e;\n Unqual!U m = n;\n while (m) {\n if (m & 1) v *= b;\n b *= b;\n m /= 2;\n }\n return v;\n}\n\n \n\n \nT powMod(T, U, V)(T x, U n, V md)\nif (isIntegral!U || is(U == BigInt)) {\n T r = T(1);\n while (n) {\n if (n & 1) r = (r*x)%md;\n x = (x*x)%md;\n n >>= 1;\n }\n return r % md;\n}\n\n// import dkh.int128;\n\n \nulong ulongPowMod(U)(ulong x, U n, ulong md)\nif (isIntegral!U || is(U == BigInt)) {\n x %= md;\n ulong r = 1;\n while (n) {\n if (n & 1) {\n r = mul128(r, x).mod128(md);\n }\n x = mul128(x, x).mod128(md);\n n >>= 1;\n }\n return r % md;\n}\n\n \nT lcm(T)(in T a, in T b) {\n import std.numeric : gcd;\n return a / gcd(a,b) * b;\n}\n\n \n \n\n \n \nT[3] extGcd(T)(in T a, in T b) \nif (!isIntegral!T || isSigned!T) \n{\n if (b==0) {\n return [T(1), T(0), a];\n } else {\n auto e = extGcd(b, a%b);\n return [e[1], e[0]-a/b*e[1], e[2]];\n }\n}\n\n \n \n/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/int128.d */\n \n\n// module dkh.int128;\n\nversion(LDC) {\n// import dkh.ldc.inline;\n}\n\nversion(LDC) version(X86_64) {\n version = LDC_IR;\n}\n\n \nulong[2] mul128(ulong a, ulong b) {\n ulong[2] res;\n version(LDC_IR) {\n ulong upper, lower;\n inlineIR!(`\n %r0 = zext i64 %0 to i128 \n %r1 = zext i64 %1 to i128\n %r2 = mul i128 %r1, %r0\n %r3 = trunc i128 %r2 to i64\n %r4 = lshr i128 %r2, 64\n %r5 = trunc i128 %r4 to i64\n store i64 %r3, i64* %2\n store i64 %r5, i64* %3`, void)(a, b, &lower, &upper);\n return [lower, upper];\n } else version(D_InlineAsm_X86_64) {\n ulong upper, lower;\n asm {\n mov RAX, a;\n mul b;\n mov lower, RAX;\n mov upper, RDX;\n }\n return [lower, upper];\n } else {\n ulong B = 2UL^^32;\n ulong[2] a2 = [a % B, a / B];\n ulong[2] b2 = [b % B, b / B];\n ulong[4] c;\n foreach (i; 0..2) {\n foreach (j; 0..2) {\n c[i+j] += a2[i] * b2[j] % B;\n c[i+j+1] += a2[i] * b2[j] / B;\n }\n }\n foreach (i; 0..3) {\n c[i+1] += c[i] / B;\n c[i] %= B;\n }\n return [c[0] + c[1] * B, c[2] + c[3] * B];\n }\n}\n\n \n\n \nulong div128(ulong[2] a, ulong b) {\n version(LDC_IR) {\n return inlineIR!(`\n %r0 = zext i64 %0 to i128\n %r1 = zext i64 %1 to i128\n %r2 = shl i128 %r1, 64\n %r3 = add i128 %r0, %r2\n %r4 = zext i64 %2 to i128\n %r5 = udiv i128 %r3, %r4\n %r6 = trunc i128 %r5 to i64\n ret i64 %r6`,ulong)(a[0], a[1], b);\n } else version(D_InlineAsm_X86_64) {\n ulong upper = a[1], lower = a[0];\n ulong res;\n asm {\n mov RDX, upper;\n mov RAX, lower;\n div b;\n mov res, RAX;\n }\n return res;\n } else {\n if (b == 1) return a[0];\n while (!(b & (1UL << 63))) {\n a[1] <<= 1;\n if (a[0] & (1UL << 63)) a[1] |= 1;\n a[0] <<= 1;\n b <<= 1;\n }\n ulong ans = 0;\n foreach (i; 0..64) {\n bool up = (a[1] & (1UL << 63)) != 0;\n a[1] <<= 1;\n if (a[0] & (1UL << 63)) a[1] |= 1;\n a[0] <<= 1;\n\n ans <<= 1;\n if (up || b <= a[1]) {\n a[1] -= b;\n ans++;\n }\n }\n return ans;\n }\n}\n\n\n \nulong mod128(ulong[2] a, ulong b) {\n version(D_InlineAsm_X86_64) {\n ulong upper = a[1], lower = a[0];\n ulong res;\n asm {\n mov RDX, upper;\n mov RAX, lower;\n div b;\n mov res, RDX;\n }\n return res;\n } else {\n return a[0] - div128(a, b) * b;\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": "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\nenum LIM = 2020;\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\nvoid main() {\n prepare;\n \n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n auto A = new string[M];\n foreach (i; 0 .. N) {\n A[i] = readToken();\n }\n \n auto bell = new Mint[M + 1];\n bell[0] = 1;\n foreach (i; 1 .. M) {\n foreach (j; 0 .. i) {\n bell[i] += binom(i - 1, j) * bell[j];\n }\n }\n \n auto bs = new string[M];\n foreach (i; 0 .. N) {\n foreach (j; 0 .. M) {\n bs[j] ~= A[i][j];\n }\n }\n bs.sort;\n Mint ans = 1;\n foreach (grp; bs.group) {\n ans *= bell[grp[1]];\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "c602545676f6388a5c5107a5d83fc2c6"} {"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\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\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n auto X = new int[M];\n auto Y = new int[M];\n foreach (i; 0 .. M) {\n X[i] = readInt();\n Y[i] = readInt();\n }\n \n const xs = X.dup.sort.uniq.array;\n const ys = Y.dup.sort.uniq.array;\n const xsLen = cast(int)(xs.length);\n const ysLen = cast(int)(ys.length);\n const V = xsLen + ysLen;\n \n auto uf = new int[V];\n uf[] = -1;\n foreach (i; 0 .. M) {\n const u = xs.lowerBound(X[i]);\n const v = xsLen + ys.lowerBound(Y[i]);\n uf.connect(u, v);\n }\n \n auto numEdges = new int[V];\n foreach (i; 0 .. M) {\n const u = xs.lowerBound(X[i]);\n ++numEdges[uf.root(u)];\n }\n \n Mint ans = 1;\n foreach (r; 0 .. V) {\n if (uf[r] < 0) {\n if (numEdges[r] == -uf[r] - 1) {\n ans *= (Mint(2)^^(-uf[r]) - 1);\n } else {\n ans *= Mint(2)^^(-uf[r]);\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;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto P = N.iota.map!(_ => readln.split.map!(to!int).array).array;\n int[][int] R;\n int[][int] C;\n foreach (i; 0..N) {\n R[P[i][0]] ~= i;\n C[P[i][1]] ~= i;\n }\n bool[int] used_r;\n bool[int] used_c;\n int[][] groups;\n\n\n foreach (i; 0..N) {\n int r = P[i][0];\n int c = P[i][1];\n if ((r in used_r) || (c in used_c)) continue;\n int[] stack = [i];\n int[] group;\n while (!stack.empty) {\n int n = stack.back;\n stack.popBack;\n int nr = P[n][0];\n int nc = P[n][1];\n if (!(nr in used_r)) foreach (m; R[nr]) if (!(P[m][1] in used_c)) stack ~= m;\n used_r[nr] = true;\n if (!(nc in used_c)) foreach (m; C[nc]) if (!(P[m][0] in used_r)) stack ~= m;\n used_c[nc] = true;\n group ~= n;\n }\n groups ~= group.sort().uniq.array;\n }\n\n\n immutable long MOD = 10^^9 + 7;\n long ans = 1;\n\n foreach (g; groups) {\n int[] rows, cols;\n foreach (i; g) rows ~= P[i][0];\n foreach (i; g) cols ~= P[i][1];\n int r = rows.sort().uniq.array.length.to!int;\n int c = cols.sort().uniq.array.length.to!int;\n int n = r + c;\n int m = g.length.to!int;\n\n long tmp = 0;\n long comb = 1;\n foreach (i; 0..m+1) {\n tmp += comb;\n tmp %= MOD;\n comb = comb * (n - i) % MOD * powmod(i + 1, MOD - 2, MOD) % MOD;\n }\n ans = ans * tmp % MOD;\n }\n\n ans.writeln;\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"}], "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 P = N.iota.map!(_ => readln.split.map!(to!int).array).array;\n int[][int] R;\n int[][int] C;\n foreach (i; 0..N) {\n R[P[i][0]] ~= i;\n C[P[i][1]] ~= i;\n }\n bool[int] used_r;\n bool[int] used_c;\n int[][] groups;\n\n\n immutable long MOD = 10^^9 + 7;\n long ans = 0;\n\n foreach (i; 0..N) {\n int r = P[i][0];\n int c = P[i][1];\n if ((r in used_r) || (c in used_c)) continue;\n int[] stack = [i];\n int[] group;\n while (!stack.empty) {\n int n = stack.back;\n stack.popBack;\n int nr = P[n][0];\n int nc = P[n][1];\n if (!(nr in used_r)) foreach (m; R[nr]) stack ~= m;\n if (!(nc in used_c)) foreach (m; C[nc]) stack ~= m;\n used_r[nr] = true;\n used_c[nc] = true;\n group ~= n;\n }\n groups ~= group.sort().uniq.array;\n }\n\n foreach (g; groups) {\n int[] rows, cols;\n foreach (i; g) rows ~= P[i][0];\n foreach (i; g) cols ~= P[i][1];\n int r = rows.sort().uniq.array.length.to!int;\n int c = cols.sort().uniq.array.length.to!int;\n int m = r + c;\n int n = g.length.to!int;\n\n long comb = 1;\n foreach (i; 0..m+1) {\n ans += comb;\n ans %= MOD;\n comb = comb * (n - i) % MOD * powmod(i + 1, MOD - 2, MOD);\n }\n }\n\n ans.writeln;\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"}, {"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 P = N.iota.map!(_ => readln.split.map!(to!int).array).array;\n int[][int] R;\n int[][int] C;\n foreach (i; 0..N) {\n R[P[i][0]] ~= i;\n C[P[i][1]] ~= i;\n }\n bool[int] used_r;\n bool[int] used_c;\n int[][] groups;\n\n\n foreach (i; 0..N) {\n int r = P[i][0];\n int c = P[i][1];\n if ((r in used_r) || (c in used_c)) continue;\n int[] stack = [i];\n int[] group;\n while (!stack.empty) {\n int n = stack.back;\n stack.popBack;\n int nr = P[n][0];\n int nc = P[n][1];\n if (!(nr in used_r)) foreach (m; R[nr]) stack ~= m;\n if (!(nc in used_c)) foreach (m; C[nc]) stack ~= m;\n used_r[nr] = true;\n used_c[nc] = true;\n group ~= n;\n }\n groups ~= group.sort().uniq.array;\n }\n\n\n immutable long MOD = 10^^9 + 7;\n long ans = 1;\n\n foreach (g; groups) {\n int[] rows, cols;\n foreach (i; g) rows ~= P[i][0];\n foreach (i; g) cols ~= P[i][1];\n int r = rows.sort().uniq.array.length.to!int;\n int c = cols.sort().uniq.array.length.to!int;\n int n = r + c;\n int m = g.length.to!int;\n\n long tmp = 0;\n long comb = 1;\n foreach (i; 0..m+1) {\n tmp += comb;\n tmp %= MOD;\n comb = comb * (n - i) % MOD * powmod(i + 1, MOD - 2, MOD);\n }\n ans = ans * tmp % MOD;\n }\n\n ans.writeln;\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"}], "src_uid": "8781003d9eea51a509145bc6db8b609c"} {"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 string s = cin.read_string;\n if (s[indexOf(s, '.') - 1] == '9') {\n writeln(\"GOTO Vasilisa.\");\n } else {\n int loc_of_dot = indexOf(s, '.');\n if (s[loc_of_dot + 1] < '5') {\n for (int i = 0; i < loc_of_dot; i++) {\n write(s[i]);\n }\n writeln();\n } else {\n for (int i = 0; i < loc_of_dot - 1; i++) {\n write(s[i]);\n }\n write(s[loc_of_dot - 1] - 47);\n writeln();\n }\n } \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 string s = cin.read_string;\n if (s[indexOf(s, '.') - 1] == '9') {\n writeln(\"GOTO Vasilisa.\");\n } else {\n int loc_of_dot = indexOf(s, '.');\n if (s[loc_of_dot + 1] < '5') {\n writeln(s[0..loc_of_dot]);\n } else {\n write(s[0..loc_of_dot - 1]);\n write(s[loc_of_dot - 1] - 47);\n writeln();\n }\n } \n } \n}"}], "negative_code": [], "src_uid": "3060ecad253a2b4d4fac39e91fcd6c95"} {"source_code": "import std;\n\nvoid main () {\n uint tests;\n readf!\"%s\\n\"(tests);\n\n foreach (_; 0 .. tests) {\n uint n, k;\n readf!\"%s %s\\n\"(n, k);\n\n uint[] a = readln().chomp\n .split(\" \")\n .to!(uint[]);\n\n uint[] b = readln().chomp\n .split(\" \")\n .to!(uint[]);\n\n auto result = zip(a, b)\n .array\n .sort!\"a[0] < b[0]\";\n\n foreach (val; result) {\n if (k >= val[0])\n k += val[1];\n else\n break;\n }\n\n writeln(k);\n }\n}\n// \"\"\n", "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid solve(){\n long n = scan;\n long k = scan;\n auto ai = scanArray;\n auto bi = scanArray;\n tup[] arr;\n for(int i = 0; i < n; ++i){\n arr ~= tup(ai[i], bi[i]);\n }\n arr.sort;\n /* show(arr); */\n for(int i = 0; i < n; ++i){\n if(arr[i][0] <= k){\n k += arr[i][1];\n }\n }\n writeln(k);\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": "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!int;\r\n auto A = scan!int(N);\r\n auto B = scan!int(N);\r\n\r\n int ram = K;\r\n foreach(req, add; zip(A, B).sort!\"a[0] < b[0]\") {\r\n if (ram >= req) ram += add;\r\n }\r\n \r\n return ram;\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\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>>\".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}"}], "negative_code": [], "src_uid": "168f2a740d21a3a916a9d560fbcffeb9"} {"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 auto n = next!long;\n auto m = next!int;\n long[2] s, f;\n s[0] = next!long; s[1] = next!long;\n f[0] = next!long; f[1] = next!long;\n long[2][] points = new long[2][](m);\n foreach(ref point; points)\n {\n point[0] = next!long; point[1] = next!long;\n }\n auto adj = new Tuple!(int, long)[][](m + 2);\n auto ix = iota(0, m).array.sort!((i, j) => points[i][0] < points[j][0]).array;\n auto iy = iota(0, m).array.sort!((i, j) => points[i][1] < points[j][1]).array;\n foreach(k, i; ix)\n {\n if (k >= 1)\n\t{\n\t adj[i] ~= tuple(ix[k - 1], abs(points[i][0] - points[ix[k - 1]][0]));\n\t}\n if (k + 1 < ix.length)\n\t{\n\t adj[i] ~= tuple(ix[k + 1], abs(points[i][0] - points[ix[k + 1]][0]));\n\t}\n }\n foreach(k, i; iy)\n {\n if (k >= 1)\n\tadj[i] ~= tuple(iy[k - 1], abs(points[i][1] - points[iy[k - 1]][1]));\n if (k + 1 < iy.length)\n\tadj[i] ~= tuple(iy[k + 1], abs(points[i][1] - points[iy[k + 1]][1]));\n }\n foreach(i; 0 .. m)\n {\n auto cost = min(abs(s[0] - points[i][0]), abs(s[1] - points[i][1]));\n adj[m] ~= tuple(i, cost);\n adj[i] ~= tuple(m, cost);\n }\n foreach(i; 0 .. m)\n {\n auto cost = abs(f[0] - points[i][0]) + abs(f[1] - points[i][1]);\n adj[m + 1] ~= tuple(i, cost);\n adj[i] ~= tuple(m + 1, cost);\n }\n adj[m] ~= tuple(m + 1, abs(s[0] - f[0]) + abs(s[1] - f[1]));\n auto pq = redBlackTree!(Tuple!(long, int))();\n auto distance = new long[](m + 2);\n distance[] = long.max / 2;\n pq.insert(tuple(cast(long)0, m));\n distance[m] = 0;\n while(!pq.empty)\n {\n auto nextnode = pq.front;\n pq.removeFront;\n if (nextnode[0] > distance[nextnode[1]]) continue;\n foreach(nei; adj[nextnode[1]])\n\t{\n\t if (distance[nextnode[1]] + nei[1] < distance[nei[0]])\n\t {\n\t distance[nei[0]] = distance[nextnode[1]] + nei[1];\n\t pq.insert(tuple(distance[nei[0]], nei[0]));\n\t }\n\t}\n }\n distance[m + 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", "positive_code": [{"source_code": "import std.algorithm;\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\tint n, m;\n\twhile (readf !(\" %s %s\") (n, m) > 0)\n\t{\n\t\talias Point = Tuple !(int, q{x}, int, q{y}, int, q{id});\n\t\tPoint s, f;\n\t\treadf !(\" %s %s\") (s.x, s.y);\n\t\ts.id = m;\n\t\treadf !(\" %s %s\") (f.x, f.y);\n\t\tf.id = m + 1;\n\t\tauto p = new Point [m];\n\t\tforeach (int i, ref c; p)\n\t\t{\n\t\t\treadf !(\" %s %s\") (c.x, c.y);\n\t\t\tc.id = i;\n\t\t}\n\t\tp ~= s;\n\t\tauto tx = redBlackTree !(Point) ();\n\t\tauto ty = redBlackTree !((p, q) =>\n\t\t p.y < q.y || (p.y == q.y && (p.x < q.x ||\n\t\t (p.x == q.x && p.id < q.id))), Point);\n\t\tforeach (ref c; p)\n\t\t{\n\t\t\ttx.insert (c);\n\t\t\tty.insert (c);\n\t\t}\n\n\t\tlong res = abs (s.x - f.x) + abs (s.y - f.y);\n\t\talias Pair = Tuple !(long, q{dist}, int, q{id});\n\t\tauto q = redBlackTree !(Pair) ();\n\t\tq.insert (Pair (0, m));\n\t\twhile (!q.empty)\n\t\t{\n\t\t\tauto cur = q.front.dist;\n\t\t\tauto id = q.front.id;\n\t\t\tq.removeFront ();\n\t\t\tres = min (res, cur + abs (p[id].x - f.x) +\n\t\t\t abs (p[id].y - f.y));\n\n\t\t\tauto x = tx.equalRange (p[id]);\n\t\t\tif (!x.empty)\n\t\t\t{\n\t\t\t\tauto lox = tx.lowerBound (p[id]);\n\t\t\t\tif (!lox.empty)\n\t\t\t\t{\n\t\t\t\t\tauto v = lox.back;\n\t\t\t\t\tq.insert (Pair (cur +\n\t\t\t\t\t abs (v.x - p[id].x), v.id));\n\t\t\t\t}\n\t\t\t\tauto hix = tx.upperBound (p[id]);\n\t\t\t\tif (!hix.empty)\n\t\t\t\t{\n\t\t\t\t\tauto v = hix.front;\n\t\t\t\t\tq.insert (Pair (cur +\n\t\t\t\t\t abs (v.x - p[id].x), v.id));\n\t\t\t\t}\n\t\t\t\ttx.removeKey (p[id]);\n\t\t\t}\n\n\t\t\tauto y = ty.equalRange (p[id]);\n\t\t\tif (!y.empty)\n\t\t\t{\n\t\t\t\tauto loy = ty.lowerBound (p[id]);\n\t\t\t\tif (!loy.empty)\n\t\t\t\t{\n\t\t\t\t\tauto v = loy.back;\n\t\t\t\t\tq.insert (Pair (cur +\n\t\t\t\t\t abs (v.y - p[id].y), v.id));\n\t\t\t\t}\n\t\t\t\tauto hiy = ty.upperBound (p[id]);\n\t\t\t\tif (!hiy.empty)\n\t\t\t\t{\n\t\t\t\t\tauto v = hiy.front;\n\t\t\t\t\tq.insert (Pair (cur +\n\t\t\t\t\t abs (v.y - p[id].y), v.id));\n\t\t\t\t}\n\t\t\t\tty.removeKey (p[id]);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\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.math;\n\nvoid main(string[] args)\n{\n auto n = next!long;\n auto m = next!int;\n long[2] s, f;\n s[0] = next!long; s[1] = next!long;\n f[0] = next!long; f[1] = next!long;\n long[2][] points = new long[2][](m);\n foreach(ref point; points)\n {\n point[0] = next!long; point[1] = next!long;\n }\n auto adj = new Tuple!(int, long)[][](m + 2);\n auto ix = iota(0, m).array.sort!((i, j) => points[i][0] < points[i][0]).array;\n auto iy = iota(0, m).array.sort!((i, j) => points[i][1] < points[i][1]).array;\n foreach(k, i; ix)\n {\n if (k >= 1)\n\t{\n\t adj[i] ~= tuple(ix[k - 1], abs(points[i][0] - points[ix[k - 1]][0]));\n\t}\n if (k + 1 < ix.length)\n\t{\n\t adj[i] ~= tuple(ix[k + 1], abs(points[i][0] - points[ix[k + 1]][0]));\n\t}\n }\n foreach(k, i; iy)\n {\n if (k >= 1)\n\tadj[i] ~= tuple(iy[k - 1], abs(points[i][1] - points[iy[k - 1]][1]));\n if (k + 1 < iy.length)\n\tadj[i] ~= tuple(iy[k + 1], abs(points[i][1] - points[iy[k + 1]][1]));\n }\n foreach(i; 0 .. m)\n {\n auto cost = min(abs(s[0] - points[i][0]), abs(s[1] - points[i][1]));\n adj[m] ~= tuple(i, cost);\n adj[i] ~= tuple(m, cost);\n }\n foreach(i; 0 .. m)\n {\n auto cost = abs(f[0] - points[i][0]) + abs(f[1] - points[i][1]);\n adj[m + 1] ~= tuple(i, cost);\n adj[i] ~= tuple(m + 1, cost);\n }\n adj[m] ~= tuple(m + 1, abs(s[0] - f[0]) + abs(s[1] - f[1]));\n auto pq = redBlackTree!(Tuple!(long, int))();\n auto distance = new long[](m + 2);\n distance[] = long.max;\n pq.insert(tuple(cast(long)0, m));\n distance[m] = 0;\n while(!pq.empty)\n {\n auto nextnode = pq.front;\n pq.removeFront;\n debug writeln(\"doing node \", nextnode);\n if (nextnode[0] > distance[nextnode[1]]) continue;\n foreach(nei; adj[nextnode[1]])\n\t{\n\t debug writeln(\"\\t with adj \", nei);\n\t if (distance[nextnode[1]] + nei[1] < distance[nei[0]])\n\t {\n\t distance[nei[0]] = distance[nextnode[1]] + nei[1];\n\t pq.insert(tuple(distance[nei[0]], nei[0]));\n\t }\n\t}\n }\n writeln(distance[0], \" \", distance[1], \" \", distance[2]);\n distance[m + 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"}, {"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 auto n = next!long;\n auto m = next!int;\n long[2] s, f;\n s[0] = next!long; s[1] = next!long;\n f[0] = next!long; f[1] = next!long;\n long[2][] points = new long[2][](m);\n foreach(ref point; points)\n {\n point[0] = next!long; point[1] = next!long;\n }\n auto adj = new Tuple!(int, long)[][](m + 2);\n auto ix = iota(0, m).array.sort!((i, j) => points[i][0] < points[i][0]).array;\n auto iy = iota(0, m).array.sort!((i, j) => points[i][1] < points[i][1]).array;\n foreach(k, i; ix)\n {\n if (k >= 1)\n\t{\n\t adj[i] ~= tuple(ix[k - 1], abs(points[i][0] - points[ix[k - 1]][0]));\n\t}\n if (k + 1 < ix.length)\n\t{\n\t adj[i] ~= tuple(ix[k + 1], abs(points[i][0] - points[ix[k + 1]][0]));\n\t}\n }\n foreach(k, i; iy)\n {\n if (k >= 1)\n\tadj[i] ~= tuple(iy[k - 1], abs(points[i][1] - points[iy[k - 1]][1]));\n if (k + 1 < iy.length)\n\tadj[i] ~= tuple(iy[k + 1], abs(points[i][1] - points[iy[k + 1]][1]));\n }\n foreach(i; 0 .. m)\n {\n auto cost = min(abs(s[0] - points[i][0]), abs(s[1] - points[i][1]));\n adj[m] ~= tuple(i, cost);\n adj[i] ~= tuple(m, cost);\n }\n foreach(i; 0 .. m)\n {\n auto cost = abs(f[0] - points[i][0]) + abs(f[1] - points[i][1]);\n adj[m + 1] ~= tuple(i, cost);\n adj[i] ~= tuple(m + 1, cost);\n }\n adj[m] ~= tuple(m + 1, abs(s[0] - f[0]) + abs(s[1] - f[1]));\n auto pq = redBlackTree!(Tuple!(long, int))();\n auto distance = new long[](m + 2);\n distance[] = long.max;\n pq.insert(tuple(cast(long)0, m));\n distance[m] = 0;\n while(!pq.empty)\n {\n auto nextnode = pq.front;\n pq.removeFront;\n debug writeln(\"doing node \", nextnode);\n if (nextnode[0] > distance[nextnode[1]]) continue;\n foreach(nei; adj[nextnode[1]])\n\t{\n\t debug writeln(\"\\t with adj \", nei);\n\t if (distance[nextnode[1]] + nei[1] < distance[nei[0]])\n\t {\n\t distance[nei[0]] = distance[nextnode[1]] + nei[1];\n\t pq.insert(tuple(distance[nei[0]], nei[0]));\n\t }\n\t}\n }\n distance[m + 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"}], "src_uid": "bd6f4859e3c3ce19b8e89c431f2e65fb"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1550/problem/A\n//\nimport std.stdio;\n\nvoid main() {\n int t;\n readf(\"%s\\n\", &t);\n\nwhile(t--) {\n int s;\n readf(\"%s\\n\", &s);\n\n int ans = 1;\n\n while(ans * ans < s) {\n ans += 1;\n }\n\n ans.writeln;\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\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n while (t--) {\n int s;\n readf!\" %d \"(s);\n int[] a;\n int x = 1;\n int sum = 0;\n int result = 0;\n while (true) {\n a ~= x;\n sum += x;\n result += 1;\n x += 2;\n if (sum >= s) {\n break;\n }\n }\n writeln(result);\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 s = RD-1;\r\n\r\n\t\t++ans[ti];\r\n\t\tlong x = 1;\r\n\t\twhile (s != 0)\r\n\t\t{\r\n\t\t\t++ans[ti];\r\n\t\t\tx += 2;\r\n\t\t\ts = max(0, s-x);\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": "322792a11d3eb1df6b54e8f89c9a0490"} {"source_code": "//ahmat\nimport std.stdio,std.string,std.math,std.algorithm,\nstd.array,std.container,std.algorithm,std.numeric,std.bitmanip,\nstd.range,std.random,std.complex,std.functional,std.typecons,\nstd.format,std.bigint,core.vararg,core.bitop,std.conv;\nint sz(T)(ref T a){return cast(int)a.length;}\nalias rbt=RedBlackTree;\nalias deq=DList;\nalias heap=BinaryHeap;\nconst long mod=1000_000_007;\n\nvoid main(){\n int n;\n readf(\"%d \",&n);\n int[] a=readln.splitter.map!(to!int).array;\n bool[int] set;\n foreach(int i;1..n+1) set[i]=true;\n foreach(int x;a) set.remove(x);\n writeln(set.byKey.array[0]);\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 - 1];\n\t\tforeach (i; 0 .. N - 1) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tbool[] app = new bool[N + 1];\n\t\tforeach (a; A) {\n\t\t\tapp[a] = true;\n\t\t}\n\t\tforeach (a; 1 .. N + 1) {\n\t\t\tif (!app[a]) {\n\t\t\t\twriteln(a);\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}, {"source_code": "import std.stdio, std.string;\n\nvoid solve(int[] arr)\n{\n bool[] flag = new bool[arr.length + 10];\n foreach (i, ref val; arr)\n {\n flag[val] = true;\n }\n foreach (i, ref val; flag)\n {\n if (i > 0 && val == false)\n {\n writeln(i);\n return;\n }\n }\n}\n\nvoid main(string[] args)\n{\n int n;\n while (scanf(\"%d\", &n) == 1)\n {\n int[] arr = new int[n - 1];\n foreach (int i; 0 .. n - 1)\n {\n scanf(\"%d\", &arr[i]);\n }\n solve(arr);\n }\n}"}], "negative_code": [], "src_uid": "0e4ff955c1e653fbeb003987fa701729"} {"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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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\tstring name=readln.strip;\n\tint n;\n\tread(&n);\n\tauto r1=regex(`(\\w+) posted on (\\w+)\\'s wall`),\n\t\tr2=regex(`(\\w+) commented on (\\w+)\\'s post`),\n\t\tr3=regex(`(\\w+) likes (\\w+)\\'s post`);\n\tint[string] q;\n\tforeach(i;0..n)\n\t{\n\t\tauto s=readln.strip;\n\t\tif(auto c=matchFirst(s,r1))\n\t\t{\n\t\t\tif(c[1]==name)\n\t\t\t{\n\t\t\t\tq[c[2]]+=15;\n\t\t\t}\n\t\t\telse if(c[2]==name)\n\t\t\t{\n\t\t\t\tq[c[1]]+=15;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tq[c[1]]+=0;\n\t\t\t\tq[c[2]]+=0;\n\t\t\t}\n\t\t}\n\t\telse if(auto c=matchFirst(s,r2))\n\t\t{\n\t\t\tif(c[1]==name)\n\t\t\t{\n\t\t\t\tq[c[2]]+=10;\n\t\t\t}\n\t\t\telse if(c[2]==name)\n\t\t\t{\n\t\t\t\tq[c[1]]+=10;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tq[c[1]]+=0;\n\t\t\t\tq[c[2]]+=0;\n\t\t\t}\n\t\t}\n\t\telse if(auto c=matchFirst(s,r3))\n\t\t{\n\t\t\tif(c[1]==name)\n\t\t\t{\n\t\t\t\tq[c[2]]+=5;\n\t\t\t}\n\t\t\telse if(c[2]==name)\n\t\t\t{\n\t\t\t\tq[c[1]]+=5;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tq[c[1]]+=0;\n\t\t\t\tq[c[2]]+=0;\n\t\t\t}\n\t\t}\n\t}\n\tpair!(int,string) a[];\n\tforeach(i,j;q)a~=mp(j,i);\n\tbool cmp(ref const pair!(int,string) x,ref const pair!(int,string) y)\n\t{\n\t\treturn x.fi>y.fi || (x.fi==y.fi && x.se1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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\tstring name=readln.strip;\n\tint n;\n\tread(&n);\n\tauto r1=ctRegex!(`(\\w+) posted on (\\w+)\\'s wall`),\n\t\tr2=ctRegex!(`(\\w+) commented on (\\w+)\\'s post`),\n\t\tr3=ctRegex!(`(\\w+) likes (\\w+)\\'s post`);\n\tint[string] q;\n\tforeach(i;0..n)\n\t{\n\t\tauto s=readln.strip;\n\t\tif(auto c=matchFirst(s,r1))\n\t\t{\n\t\t\tif(c[1]==name)\n\t\t\t{\n\t\t\t\tq[c[2]]+=15;\n\t\t\t}\n\t\t\telse if(c[2]==name)\n\t\t\t{\n\t\t\t\tq[c[1]]+=15;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tq[c[1]]+=0;\n\t\t\t\tq[c[2]]+=0;\n\t\t\t}\n\t\t}\n\t\telse if(auto c=matchFirst(s,r2))\n\t\t{\n\t\t\tif(c[1]==name)\n\t\t\t{\n\t\t\t\tq[c[2]]+=10;\n\t\t\t}\n\t\t\telse if(c[2]==name)\n\t\t\t{\n\t\t\t\tq[c[1]]+=10;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tq[c[1]]+=0;\n\t\t\t\tq[c[2]]+=0;\n\t\t\t}\n\t\t}\n\t\telse if(auto c=matchFirst(s,r3))\n\t\t{\n\t\t\tif(c[1]==name)\n\t\t\t{\n\t\t\t\tq[c[2]]+=5;\n\t\t\t}\n\t\t\telse if(c[2]==name)\n\t\t\t{\n\t\t\t\tq[c[1]]+=5;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tq[c[1]]+=0;\n\t\t\t\tq[c[2]]+=0;\n\t\t\t}\n\t\t}\n\t}\n\tpair!(int,string) a[];\n\tforeach(i,j;q)a~=mp(j,i);\n\tbool cmp(ref const pair!(int,string) x,ref const pair!(int,string) y)\n\t{\n\t\treturn x.fi>y.fi || (x.fi==y.fi && x.se= 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 abc = new int[][](3);\n\t\tabc[0] = RDA!int;\n\t\tabc[1] = RDA!int;\n\t\tabc[2] = RDA!int;\n\n\t\tint pos;\n\t\tint last = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (last == abc[pos][i])\n\t\t\t\tpos = (pos+1) % 3;\n\t\t\t\n\t\t\tans[ti] ~= abc[pos][i];\n\t\t\tlast = ans[ti][$-1];\n\t\t}\n\t\tif (ans[ti][0] == ans[ti][$-1])\n\t\t{\n\t\t\tpos = (pos+1) % 3;\n\t\t\tans[ti][$-1] = abc[pos][$-1];\n\t\t}\n\t\tif (ans[ti][$-2] == ans[ti][$-1])\n\t\t{\n\t\t\tpos = (pos+1) % 3;\n\t\t\tans[ti][$-1] = abc[pos][$-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", "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, 3);\n foreach (j; 0 .. 3) {\n foreach (i; 0 .. N) {\n A[i][j] = readInt();\n }\n }\n \n auto ans = new int[N];\n foreach (i; 0 .. N) {\n foreach (j; 0 .. 3) {\n bool ok = true;\n if (i >= 1) {\n ok = ok && (ans[i - 1] != A[i][j]);\n }\n if (i == N - 1) {\n ok = ok && (ans[0] != A[i][j]);\n }\n if (ok) {\n ans[i] = A[i][j];\n break;\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"}], "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\t\tauto abc = new int[][](3);\n\t\tabc[0] = RDA!int;\n\t\tabc[1] = RDA!int;\n\t\tabc[2] = RDA!int;\n\n\t\tint pos;\n\t\tint last = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (last == abc[pos][i])\n\t\t\t\tpos = (pos+1) % 3;\n\t\t\t\n\t\t\tans[ti] ~= abc[pos][i];\n\t\t\tlast = ans[ti][$-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"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 abc = new int[][](3);\n\t\tabc[0] = RDA!int;\n\t\tabc[1] = RDA!int;\n\t\tabc[2] = RDA!int;\n\n\t\tint pos;\n\t\tint last = -1;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (last == abc[pos][i])\n\t\t\t\tpos = (pos+1) % 3;\n\t\t\t\n\t\t\tans[ti] ~= abc[pos][i];\n\t\t\tlast = ans[ti][$-1];\n\t\t}\n\t\tif (ans[ti][0] == ans[ti][$-1])\n\t\t{\n\t\t\tpos = (pos+1) % 3;\n\t\t\tans[ti][$-1] = abc[pos][$-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"}], "src_uid": "7647528166b72c780d332ef4ff28cb86"} {"source_code": "// Vicfred\n// https://codeforces.com/contest/1398/problem/B\n// 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 while(t--) {\n string s = readln.strip;\n\n int[] moves;\n for(int i = 0; i < s.length; ++i) {\n if(s[i] == '1') {\n int j = i;\n while(j + 1 < s.length && s[j + 1] == '1')\n ++j;\n moves ~= j - i + 1;\n i = j;\n }\n }\n\n moves.sort!(\"a > b\");\n\n int ans = 0;\n for(int i = 0; i < moves.length; i += 2)\n ans += moves[i];\n ans.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 s = readln.strip;\n\t\tauto g = s.group.array;\n\t\tauto sizes = g.filter !(q{a[0] == '1'}).map !(q{a[1]}).array;\n\t\tsort !(q{a > b}) (sizes);\n\t\twriteln (sizes.stride (2).sum);\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 s = RD!string;\n\t\tint cnt;\n\t\tint[] list;\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\t++cnt;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (cnt != 0)\n\t\t\t\t\tlist ~= cnt;\n\t\t\t\tcnt = 0;\n\t\t\t}\n\t\t}\n\t\tif (cnt != 0)\n\t\t\tlist ~= cnt;\n\t\tlist.sort!\"a > b\";\n\t\tint i;\n\t\twhile (!list.empty)\n\t\t{\n\t\t\tif (i % 2 == 0)\n\t\t\t\tans[ti] += list.front;\n\t\t\tlist.popFront;\n\t\t\t++i;\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}"}], "negative_code": [], "src_uid": "ebf0bf949a29eeaba3bcc35091487199"} {"source_code": "import std.stdio;\n\nvoid main()\n{\n uint numTasks;\n readf(\"%d\\n\", &numTasks);\n\n uint time, numMessages;\n uint queue, maxQueue = 0;\n uint lastTime;\n\n foreach(i;0..numTasks)\n {\n readf(\"%d %d\\n\", &time, &numMessages);\n if (queue > 0)\n {\n uint timeDiff = time - lastTime;\n if (queue > timeDiff)\n {\n queue -= timeDiff;\n }\n else\n {\n queue = 0;\n }\n }\n lastTime = time;\n queue += numMessages;\n if (queue > maxQueue) maxQueue = queue;\n }\n writeln(lastTime + queue, \" \", maxQueue);\n}\n\n", "positive_code": [{"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\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint m = 0, c = 0, t = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tint r, k;\n\t\t\treadf (\" %s %s\", &r, &k);\n\t\t\tc = max (0, c - (r - t));\n\t\t\tc += k;\n\t\t\tm = max (m, c);\n\t\t\tt = r;\n\t\t}\n\t\twritefln (\"%s %s\", t + c, m);\n\t}\n}\n"}, {"source_code": "module sigod.codeforces.p292A;\n\nimport std.stdio;\n\nvoid main()\n{\n\tint n;\n\tstdin.readf(\" %s\", &n);\n\n\tint[] t = new int[n];\n\tint[] c = new int[n];\n\n\tforeach (i; 0 .. n) {\n\t\tstdin.readf(\" %s %s\", &t[i], &c[i]);\n\t}\n\n\tint x, y;\n\tsolve(t, c, x, y);\n\n\tstdout.writeln(x, \" \", y);\n}\n\nvoid solve(int[] time, int[] count, out int last_send_time, out int max_queue_size)\n{\n\tmax_queue_size = int.min;\n\n\tint queue_size = 0;\n\tint current_time = 0;\n\n\tforeach (i; 0 .. time.length) {\n\t\tqueue_size = max(queue_size - (time[i] - current_time), 0) + count[i];\n\n\t\tcurrent_time = time[i];\n\n\t\tif (max_queue_size < queue_size) max_queue_size = queue_size;\n\n\t\tversion (unittest) {\n\t\t\tstdout.writeln(\"queue_size: \", queue_size,\n\t\t\t\t\"; current_time: \", current_time);\n\t\t}\n\t}\n\n\tlast_send_time = current_time + queue_size;\n\n\tif (max_queue_size < queue_size) max_queue_size = queue_size;\n}\n\nunittest {\n\timport std.string;\n\n\tint x, y;\n\n\tsolve([1, 2], [1, 1], x, y);\n\tassert(x == 3 && y == 1, format(\"x: %s, y: %s\", x, y));\n\n\tsolve([1000000], [10], x, y);\n\tassert(x == 1000010 && y == 10, format(\"x: %s, y: %s\", x, y));\n\n\tsolve([3, 4, 5], [3, 3, 3], x, y);\n\tassert(x == 12 && y == 7, format(\"x: %s, y: %s\", x, y));\n}\n\nprivate pure\nint max(int a, int b)\n{\n\tif (a > b) return a;\n\telse return b;\n}"}], "negative_code": [], "src_uid": "608f8246bc6067e259898e8ed94db4c4"} {"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 str = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n\tauto T = RD!int;\n\tauto ans = new char[][][](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto r = RD!int;\n\t\tauto c = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = new string[](r);\n\t\tforeach (j; 0..r)\n\t\t\ts[j] = RD!string;\n\t\tans[i] = new char[][](r, c);\n\n\t\tint rice;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tforeach (x; 0..c)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t++rice;\n\t\t\t}\n\t\t}\n\t\tauto cnt1 = rice / k;\n\t\tauto cnt2 = rice % k;\n\t\tint cnt;\n\t\tint num;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tif (y % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt > cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tans[i][y][x] = str[num];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach_reverse (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt > cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tans[i][y][x] = str[num];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (y; 0..e.length)\n\t\t{\n\t\t\twriteln(e[y]);\n\t\t}\n\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(); }\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 r = rint, c = rint, k = rint;\n\t\tbool[][] uf;\n\t\tchar[][] ansf = new char[][](r, c);\n\t\tforeach(i; 0 .. r) uf ~= readln.chomp.to!(char[]).map!(c => c == 'R').array;\n\t\t\n\t\tint sum;\n\t\tforeach(i; 0 .. r) foreach(j; 0 .. c) if(uf[i][j]) sum += 1;\n\t\t\n\t\tint h = 0;\n\t\tchar[] symbols = (\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\" ~ \n\t\t\"abcdefghijklmnopqrstuvwxyz\" ~ \"0123456789\").to!(char[]);\n\t\tint cnt;\n\t\tint[] quota;\n\t\tforeach(x; 0 .. k){\n\t\t\tif(x < sum % k) quota ~= sum / k + 1;\n\t\t\telse quota ~= sum / k;\n\t\t}\n\t\tlog(\"quota:\", quota);\n\t\tforeach(i; 0 .. r){\n\t\t\tif(i % 2 == 0) foreach(j; 0 .. c){\n\t\t\t\tif(uf[i][j]) cnt += 1;\n\t\t\t\tif(cnt > quota[h]) cnt = 1, h += 1;\n\t\t\t\tansf[i][j] = symbols[h];\n\t\t\t}\n\t\t\telse foreach_reverse(j; 0 .. c){\n\t\t\t\tif(uf[i][j]) cnt += 1;\n\t\t\t\tif(cnt > quota[h]) cnt = 1, h += 1;\n\t\t\t\tansf[i][j] = symbols[h];\n\t\t\t}\n\t\t}\n\t\tforeach(i; 0 .. r) ansf[i].writeln;\n\t}\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.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\nchar tr(int x) {\n if (x < 10) return cast(char)('0' + x);\n if (x < 36) return cast(char)('A' + (x - 10));\n if (x < 62) return cast(char)('a' + (x - 36));\n assert(false);\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const numCases = readInt();\n foreach (caseId; 0 .. numCases) {\n const M = readInt();\n const N = readInt();\n const K = readInt();\n auto A = new string[M];\n foreach (x; 0 .. M) {\n A[x] = readToken();\n }\n \n int rice;\n foreach (x; 0 .. M) {\n rice += A[x].count('R');\n }\n const q = rice / K, r = rice % K;\n \n alias Pt = Tuple!(int, \"x\", int, \"y\");\n Pt[] ps;\n foreach (x; 0 .. M) {\n if (x % 2 == 0) {\n foreach (y; 0 .. N) {\n ps ~= Pt(x, y);\n }\n } else {\n foreach_reverse (y; 0 .. N) {\n ps ~= Pt(x, y);\n }\n }\n }\n const psLen = cast(int)(ps.length);\n \n auto ans = new int[][](M, N);\n int pos;\n foreach (k; 0 .. K) {\n int need = q + ((k < r) ? 1 : 0);\n int cnt;\n for (; cnt < need; ++pos) {\n const x = ps[pos].x, y = ps[pos].y;\n ans[x][y] = k;\n if (A[x][y] == 'R') {\n ++cnt;\n }\n }\n }\n for (; pos < psLen; ++pos) {\n const x = ps[pos].x, y = ps[pos].y;\n ans[x][y] = K - 1;\n }\n \n foreach (x; 0 .. M) {\n foreach (y; 0 .. N) {\n write(tr(ans[x][y]));\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\tstring names;\n\tforeach (c; 'a'..'z' + 1)\n\t{\n\t\tnames ~= cast (char) (c);\n\t}\n\tforeach (c; 'A'..'Z' + 1)\n\t{\n\t\tnames ~= cast (char) (c);\n\t}\n\tforeach (c; '0'..'9' + 1)\n\t{\n\t\tnames ~= cast (char) (c);\n\t}\n\tdebug {writeln (names);}\n\n\tint tests;\n\treadf !(\" %s\") (tests);\n\tforeach (test; 0..tests)\n\t{\n\t\tint r, c, k;\n\t\treadf !(\" %s %s %s\") (r, c, k);\n\t\treadln;\n\n\t\tauto board = new string [r];\n\t\tint num = 0;\n\t\tforeach (row; 0..r)\n\t\t{\n\t\t\tboard[row] = readln.strip;\n\t\t\tnum += board[row].count ('R');\n\t\t}\n\t\tint part = num / k;\n\t\tauto give = new int [k];\n\t\tforeach (i; 0..num)\n\t\t{\n\t\t\tgive[i % k] += 1;\n\t\t}\n\n\t\tauto ans = new char [] [] (r, c);\n\t\tint cur = 0;\n\t\tint team = 0;\n\t\tforeach (row; 0..r)\n\t\t{\n\t\t\tforeach (col0; 0..c)\n\t\t\t{\n\t\t\t\tauto col = (row & 1) ? col0 : c - col0 - 1;\n\t\t\t\tans[row][col] = names[team];\n\t\t\t\tdebug {writeln (row, \" \", col, \" \", team);}\n\t\t\t\tcur += (board[row][col] == 'R');\n\t\t\t\tif (cur >= give[team])\n\t\t\t\t{\n\t\t\t\t\tcur = 0;\n\t\t\t\t\tteam = min (team + 1, k - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twritefln !(\"%-(%s\\n%)\") (ans);\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 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 r = rint, c = rint, k = rint;\n\t\tbool[][] uf;\n\t\tchar[][] ansf = new char[][](r, c);\n\t\tforeach(i; 0 .. r) uf ~= readln.chomp.to!(char[]).map!(c => c == 'R').array;\n\t\t\n\t\tint sum;\n\t\tforeach(i; 0 .. r) foreach(j; 0 .. c) if(uf[i][j]) sum += 1;\n\t\t\n\t\tint h = 0;\n\t\tchar[] symbols = (\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\" ~ \n\t\t\"abcdefghijklmnopqrstuvwxyz\" ~ \"0123456789\").to!(char[]);\n\t\tint cnt;\n\t\tint[] quota;\n\t\tforeach(x; 0 .. k){\n\t\t\tif(x < sum % k) quota ~= sum / k + 1;\n\t\t\telse quota ~= sum / k;\n\t\t}\n\t\tforeach(i; 0 .. r){\n\t\t\tif(i % 2 == 0) foreach(j; 0 .. c){\n\t\t\t\tif(uf[i][j]) cnt += 1;\n\t\t\t\tansf[i][j] = symbols[h];\n\t\t\t\tif(cnt >= quota[h]) cnt = 0, h += 1;\n\t\t\t}\n\t\t\telse foreach_reverse(j; 0 .. c){\n\t\t\t\tif(uf[i][j]) cnt += 1;\n\t\t\t\tansf[i][j] = symbols[h];\n\t\t\t\tif(cnt >= quota[h]) cnt = 0, h += 1;\n\t\t\t}\n\t\t}\n\t\tforeach(i; 0 .. r) ansf[i].writeln;\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 str = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n\tauto T = RD!int;\n\tauto ans = new char[][][](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto r = RD!int;\n\t\tauto c = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = new string[](r);\n\t\tforeach (j; 0..r)\n\t\t\ts[j] = RD!string;\n\t\tans[i] = new char[][](r, c);\n\n\t\tint rice;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tforeach (x; 0..c)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t++rice;\n\t\t\t}\n\t\t}\n\t\tauto cnt1 = rice / k;\n\t\tauto cnt2 = rice % k;\n\t\tint cnt;\n\t\tint num;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tif (y % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tans[i][y][x] = str[num];\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\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\telse\n\t\t\t{\n\t\t\t\tforeach_reverse (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tans[i][y][x] = str[num];\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\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}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (y; 0..e.length)\n\t\t{\n\t\t\twriteln(e[y]);\n\t\t}\n\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 char[][][](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto r = RD!int;\n\t\tauto c = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = new string[](r);\n\t\tforeach (j; 0..r)\n\t\t\ts[j] = RD!string;\n\t\tans[i] = new char[][](r, c);\n\n\t\tint rice;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tforeach (x; 0..c)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t++rice;\n\t\t\t}\n\t\t}\n\t\tauto cnt1 = rice / k;\n\t\tauto cnt2 = rice % k;\n\t\tint cnt;\n\t\tint num;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tif (y % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tans[i][y][x] = cast(char)(('0'+num)%256);\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\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\telse\n\t\t\t{\n\t\t\t\tforeach_reverse (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tans[i][y][x] = cast(char)(('0'+num)%256);\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\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}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (y; 0..e.length)\n\t\t{\n\t\t\twriteln(e[y]);\n\t\t}\n\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 str = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n\tauto T = RD!int;\n\tauto ans = new char[][][](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto r = RD!int;\n\t\tauto c = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = new string[](r);\n\t\tforeach (j; 0..r)\n\t\t\ts[j] = RD!string;\n\t\tans[i] = new char[][](r, c);\n\n\t\tint rice;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tforeach (x; 0..c)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t++rice;\n\t\t\t}\n\t\t}\n\t\tauto cnt1 = rice / k;\n\t\tauto cnt2 = rice % k;\n\t\tint cnt;\n\t\tint num;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tif (y % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt > cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tans[i][y][x] = str[num];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach_reverse (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt > cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tans[i][y][x] = str[num];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (y; 0..e.length)\n\t\t{\n\t\t\twriteln(e[y]);\n\t\t}\n\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 char[][][](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto r = RD!int;\n\t\tauto c = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = new string[](r);\n\t\tforeach (j; 0..r)\n\t\t\ts[j] = RD!string;\n\t\tans[i] = new char[][](r, c);\n\n\t\tint rice;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tforeach (x; 0..c)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t++rice;\n\t\t\t}\n\t\t}\n\t\tauto cnt1 = rice / k;\n\t\tauto cnt2 = rice % k;\n\t\tint cnt;\n\t\tint num;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tif (y % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tans[i][y][x] = num.to!string[0];\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\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\telse\n\t\t\t{\n\t\t\t\tforeach_reverse (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tans[i][y][x] = num.to!string[0];\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\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}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (y; 0..e.length)\n\t\t{\n\t\t\twriteln(e[y]);\n\t\t}\n\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 str = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n\tauto T = RD!int;\n\tauto ans = new char[][][](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto r = RD!int;\n\t\tauto c = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = new string[](r);\n\t\tforeach (j; 0..r)\n\t\t\ts[j] = RD!string;\n\t\tans[i] = new char[][](r, c);\n\n\t\tint rice;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tforeach (x; 0..c)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t++rice;\n\t\t\t}\n\t\t}\n\t\tauto cnt1 = rice / k;\n\t\tauto cnt2 = rice % k;\n\t\tint cnt;\n\t\tint num;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tif (y % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tans[i][y][x] = str[num];\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tforeach_reverse (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tans[i][y][x] = str[num];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (y; 0..e.length)\n\t\t{\n\t\t\twriteln(e[y]);\n\t\t}\n\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.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 char[][][](T);\n\tforeach (i; 0..T)\n\t{\n\t\tauto r = RD!int;\n\t\tauto c = RD!int;\n\t\tauto k = RD!int;\n\t\tauto s = new string[](r);\n\t\tforeach (j; 0..r)\n\t\t\ts[j] = RD!string;\n\t\tans[i] = new char[][](r, c);\n\n\t\tint rice;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tforeach (x; 0..c)\n\t\t\t{\n\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t++rice;\n\t\t\t}\n\t\t}\n\t\tauto cnt1 = rice / k;\n\t\tauto cnt2 = rice % k;\n\t\tint cnt;\n\t\tint num;\n\t\tforeach (y; 0..r)\n\t\t{\n\t\t\tif (y % 2 == 0)\n\t\t\t{\n\t\t\t\tforeach (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tans[i][y][x] = cast(char)(('a'+num)%256);\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\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\telse\n\t\t\t{\n\t\t\t\tforeach_reverse (x; 0..c)\n\t\t\t\t{\n\t\t\t\t\tans[i][y][x] = cast(char)(('a'+num)%256);\n\t\t\t\t\tif (s[y][x] == 'R')\n\t\t\t\t\t{\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t\tif (cnt >= cnt1+(num < cnt2 ? 1 : 0))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t++num;\n\t\t\t\t\t\t\tcnt = 0;\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}\n\n\tforeach (e; ans)\n\t{\n\t\tforeach (y; 0..e.length)\n\t\t{\n\t\t\twriteln(e[y]);\n\t\t}\n\t}\n\t\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "dc0acf5347fba3c211ebaca7c9475bf5"} {"source_code": "import std.stdio;\nimport std.exception;\nimport std.algorithm;\nimport std.math;\n\nint gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); }\n\nvoid main() { while (solve()) {} }\n\nenum N = 100500;\n\nstruct node {\n\tint g;\n\tint mn, cntmn;\n\tint len;\n\tthis(int val) {\n\t\tthis.g = val;\n\t\tthis.mn = val;\n\t\tthis.cntmn = 1;\n\t\tthis.len = 1;\n\t}\n\tint ans() {\n\t\tif (mn != g) return len;\n\t\treturn len - cntmn;\n\t}\n}\n\nnode merge(node a, node b) {\n\tnode res;\n\tres.len = a.len + b.len;\n\tres.g = gcd(a.g, b.g);\n\tres.mn = min(a.mn, b.mn);\n\tres.cntmn = 0;\n\tif (res.mn == a.mn) res.cntmn += a.cntmn;\n\tif (res.mn == b.mn) res.cntmn += b.cntmn;\n\treturn res;\n}\n\nnode[4 * N] t;\nint[N] a;\n\nvoid build(size_t v, size_t lf, size_t rg) {\n\tif (lf + 1 == rg) {\n\t\tt[v] = node(a[lf]);\n\t\treturn;\n\t}\n\tsize_t mid = (lf + rg) / 2;\n\tbuild(v * 2 + 1, lf, mid);\n\tbuild(v * 2 + 2, mid, rg);\n\tt[v] = merge(t[v * 2 + 1], t[v * 2 + 2]);\n}\n\nnode get(size_t from, size_t to, size_t v, size_t lf, size_t rg) {\n\tif (from == lf && to == rg) return t[v];\n\tsize_t mid = (lf + rg) / 2;\n\tif (to <= mid) return get(from, to, v * 2 + 1, lf, mid);\n\tif (from >= mid) return get(from, to, v * 2 + 2, mid, rg);\n\treturn merge(get(from, mid, v * 2 + 1, lf, mid),\n\t\tget(mid, to, v * 2 + 2, mid, rg));\n}\n\nsize_t n;\n\nbool solve() {\n\tif (!readf(\" %s\", &n)) return false;\n\tforeach (i; 0..n)\n\t\tenforce(readf(\" %s\", &a[i]));\n\tbuild(0, 0, n);\n\tsize_t m;\n\tenforce(readf(\" %s\", &m));\n\tforeach (i; 0..m) {\n\t\tsize_t lf, rg;\n\t\tenforce(readf(\" %s %s\", &lf, &rg));\n\t\tlf--;\n\t\tnode res = get(lf, rg, 0, 0, n);\n\t\twriteln(res.ans);\n\t}\n\treturn true;\n}\n", "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\n\nimmutable N = 100001;\n\nint[N] a;\nint[4*N] tree;\nint[][int] mapper;\n\nint gcd(int a, int b) {\n while (b != 0) {\n int t = a % b;\n a = b;\n b = t;\n }\n return a;\n}\n\nvoid build(int x, int l, int r) {\n if (l == r) {\n tree[x] = a[l];\n } else {\n int mid = (l + r) >> 1;\n build(x << 1, l, mid);\n build(x << 1 | 1, mid + 1, r);\n tree[x] = gcd(tree[x << 1], tree[x << 1 | 1]);\n }\n}\n\nint query(int x, int l, int r, int ql, int qr) {\n if (l > qr || r < ql) {\n return 0;\n } else if (l >= ql && r <= qr) {\n return tree[x];\n } else {\n int mid = (l + r) >> 1;\n return gcd(query(x << 1, l, mid, ql, qr), query(x << 1 | 1, mid + 1, r, ql, qr));\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n mapper[a[i]] ~= i;\n }\n build(1, 0, n - 1);\n int t; readf(\" %s\", &t);\n while (t--) {\n int l, r; readf(\" %s %s\", &l, &r); l--; r--;\n int g = query(1, 0, n - 1, l, r);\n if (g in mapper) {\n int ll, rr;\n int lo = -1, hi = to!(int)(mapper[g].length);\n while (lo + 1 < hi) {\n int mid = (lo + hi) >> 1;\n if (mapper[g][mid] < l) lo = mid;\n else hi = mid;\n }\n ll = hi;\n lo = -1; hi = to!(int)(mapper[g].length);\n while (lo + 1 < hi) {\n int mid = (lo + hi) >> 1;\n if (mapper[g][mid] > r) hi = mid;\n else lo = mid;\n }\n rr = lo;\n writeln((r - l + 1) - (rr - ll + 1));\n } else {\n writeln(r - l + 1);\n }\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\n\nimmutable N = 100001;\n\nint[N] a;\nint[4*N] tree;\nint[][int] mapper;\n\nint gcd(int a, int b) {\n while (b != 0) {\n int t = a % b;\n a = b;\n b = t;\n }\n return a;\n}\n\nvoid build(int x, int l, int r) {\n if (l == r) {\n tree[x] = a[l];\n } else {\n int mid = (l + r) >> 1;\n build(x << 1, l, mid);\n build(x << 1 | 1, mid + 1, r);\n tree[x] = gcd(tree[x << 1], tree[x << 1 | 1]);\n }\n}\n\nint query(int x, int l, int r, int ql, int qr) {\n if (l > qr || r < ql) {\n return 0;\n } else if (l >= ql && r <= qr) {\n return tree[x];\n } else {\n int mid = (l + r) >> 1;\n return gcd(query(x << 1, l, mid, ql, qr), query(x << 1 | 1, mid + 1, r, ql, qr));\n }\n}\n\nvoid main() {\n int n; readf(\" %s\", &n);\n for (int i = 0; i < n; i++) {\n readf(\" %s\", &a[i]);\n mapper[a[i]] ~= i;\n }\n build(1, 0, n - 1);\n int t; readf(\" %s\", &t);\n while (t--) {\n int l, r; readf(\" %s %s\", &l, &r); l--; r--;\n int g = query(1, 0, n - 1, l, r);\n if (g in mapper) {\n int ll, rr;\n int lo = -1, hi = to!(int)(mapper[g].length);\n while (lo + 1 < hi) {\n int mid = (lo + hi) >> 1;\n if (mapper[g][mid] < l) lo = mid;\n else hi = mid;\n }\n ll = hi;\n lo = -1; hi = to!(int)(mapper[g].length);\n while (lo + 1 < hi) {\n int mid = (lo + hi) >> 1;\n if (mapper[g][mid] > r) hi = mid;\n else lo = mid;\n }\n rr = lo;\n writeln((r - l + 1) - (rr - ll + 1));\n } else {\n writeln(0);\n }\n }\n}\n"}], "src_uid": "f7f1d57921fe7b7a697967dcfc8f0169"} {"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 a = new long[][](N);\n\tforeach (i; 0..N)\n\t{\n\t\ta[i] = RDR.ARR;\n\t}\n\n\tlong x = a[0][0];\n\tforeach (i; 1..N)\n\t{\n\t\tx ^= a[i][0];\n\t\tdebug writeln(x);\n\t}\n\n\tuint pos_i = N, pos_j;\n\t(){\n\tforeach (i; 0..N)\n\t{\n\t\tforeach (j; 1..M)\n\t\t{\n\t\t\tif (x != 0) return;\n\t\t\tx ^= a[i][j-1];\n\t\t\tx ^= a[i][j];\n\t\t\tpos_i = i;\n\t\t\tpos_j = j;\n\t\t}\n\t}}();\n\n\tif (x == 0)\n\t\twriteln(\"NIE\");\n\telse\n\t{\n\t\twriteln(\"TAK\");\n\t\tif (pos_i == 0)\n\t\t\twrite(pos_j+1);\n\t\telse\n\t\t\twrite(1);\n\t\tforeach (i; 1..N)\n\t\t{\n\t\t\tif (i == pos_i)\n\t\t\t\twrite(\" \", pos_j+1);\n\t\t\telse\n\t\t\t\twrite(\" \", 1);\n\t\t}\n\t\twriteln();\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, std.bigint;\n\nint[500][500] IS;\nint[10][500] BS;\n\nvoid main()\n{\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n foreach (i; 0..N) {\n int[10] ds;\n foreach (j, n; readln.split.to!(int[])) {\n IS[i][j] = n;\n foreach (d; 0..10) {\n auto x = (n>>d)&1;\n if (!j) {\n ds[d] = x;\n } else if (ds[d] != x) {\n ds[d] = 2;\n }\n }\n }\n BS[i] = ds;\n }\n int targ_d = -1, one_cnt;\n foreach (d; 0..10) {\n one_cnt = 0;\n foreach (i; 0..N) {\n if (BS[i][d] == 2) {\n targ_d = d;\n } else if (BS[i][d] == 1) {\n ++one_cnt;\n }\n }\n if (one_cnt%2 == 1) targ_d = d;\n if (targ_d != -1) break;\n }\n if (targ_d == -1) {\n writeln(\"NIE\");\n return;\n }\n one_cnt = one_cnt%2 == 1 ? 0 : 1;\n int[] r;\n foreach (j, ns; IS[0..N]) {\n if (BS[j][targ_d] != 2) {\n r ~= 1;\n } else {\n foreach (int i, n; ns[0..M]) {\n auto x = (n>>targ_d)&1;\n if (one_cnt && x) {\n --one_cnt;\n r ~= i+1;\n break;\n } else if (!one_cnt && !x) {\n r ~= i+1;\n break;\n }\n }\n }\n }\n writeln(\"TAK\");\n writeln(r.to!(string[]).join(\" \"));\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\nvoid solve(){\n\t\n\tint n = read!int;\n\tint m = read!int;\n\tint[][] as = read!int(n, m);\n\t\n\tint i1 = 0, j1 = 0;\n\tbool f = 0;\nA:\n\tforeach(i; 0 .. n){\n\t\tint[] q = as[i];\n\t\tforeach(j; 0 .. m){\n\t\t\tif(q[j] != q[0]){\n\t\t\t\ti1 = i;\n\t\t\t\tj1 = j;\n\t\t\t\tf = 1;\n\t\t\t\tbreak A;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tint ansj = 0;\n\tint xor;\n\tforeach(i; 0 .. n) xor ^= as[i][0];\n\tif(xor == 0){\n\t\tif(j1 != 0) ansj = j1;\n\t\telse{\n\t\t\t\"NIE\".writeln;\n\t\t\treturn;\n\t\t}\n\t}\n\t\n\t\"TAK\".writeln;\n\tint[] ans;\n\tforeach(i; 0 .. n) ans ~= 1;\n\tans[i1] = ansj + 1;\n\tans.map!(to!string).join(\" \").writeln;\n\t\n\t\n\t\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln, write;\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, m;\n\n readf(\" %s %s\\n\", n, m);\n\n auto a = new int[][n];\n uint saver = 100000000;\n uint x1 = 0;\n uint x2 = 0;\n uint pos2 = 0;\n uint pos1 = 0;\n bool flag = false;\n foreach (i; 0 .. n) {\n a[i] = new int[m];\n foreach (j; 0 .. m)\n readf(\" %s\", a[i][j]);\n\n auto ma = a[i].enumerate.maxElement!\"a.value\";\n auto mi = a[i].enumerate.minElement!\"a.value\";\n if (ma[1] != mi[1] && !flag) {\n saver = i;\n x1 ^= ma[1];\n x2 ^= mi[1];\n pos1 = ma[0];\n pos2 = mi[0];\n flag = true;\n }\n else {\n x1 ^= a[i][0];\n x2 ^= a[i][0];\n }\n }\n\n if (x1 == 0 && x2 == 0) {\n writeln(\"NIE\");\n }\n else {\n writeln(\"TAK\");\n foreach (i; 0 .. n) {\n if (i != saver)\n write(1, \" \");\n else {\n if (x1 != 0)\n write(pos1 + 1, \" \");\n else if (x2 != 0)\n write(pos2 + 1, \" \");\n }\n }\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.string;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto H = s[0];\n auto W = s[1];\n auto A = H.iota.map!(_ => readln.split.map!(to!int).array).array;\n\n auto x = A.map!(a => a.front).reduce!\"a ^ b\";\n int r = -1, c = -1;\n\n if (x == 0) {\n outer: foreach (i; 0..H) {\n foreach (j; 1..W) {\n if (A[i][j] != A[i][0]) {\n r = i;\n c = j;\n break outer;\n }\n }\n }\n if (r == -1) {\n writeln(\"NIE\");\n return;\n }\n }\n\n writeln(\"TAK\");\n H.iota.map!(i => i == r ? c + 1 : 1).map!(to!string).join(\" \").writeln;\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\nint[500][500] IS;\nint[10][500] BS;\n\nvoid main()\n{\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n foreach (i; 0..N) {\n int[10] ds;\n foreach (j, n; readln.split.to!(int[])) {\n IS[i][j] = n;\n foreach (d; 0..10) {\n auto x = (n>>d)&1;\n if (!j) {\n ds[d] = x;\n } else if (ds[d] != x) {\n ds[d] = 2;\n }\n }\n }\n BS[i] = ds;\n }\n int targ_d = -1, free_cnt, one_cnt;\n foreach (d; 0..10) {\n one_cnt = 0;\n foreach (i; 0..N) {\n if (BS[i][d] == 2) {\n targ_d = d;\n ++free_cnt;\n } else if (BS[i][d] == 1) {\n ++one_cnt;\n }\n }\n if (one_cnt%2 == 1) targ_d = d;\n }\n if (targ_d == -1) {\n writeln(\"NIE\");\n return;\n }\n one_cnt = one_cnt%2 == 1 ? 0 : 1;\n int[] r;\n foreach (j, ns; IS[0..N]) {\n if (BS[j][targ_d] != 2) {\n r ~= 1;\n } else {\n foreach (int i, n; ns[0..M]) {\n auto x = (n>>targ_d)&1;\n if (one_cnt && x) {\n --one_cnt;\n r ~= i+1;\n } else if (!one_cnt && !x) {\n r ~= i+1;\n }\n }\n }\n }\n writeln(\"TAK\");\n writeln(r.to!(string[]).join(\" \"));\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;\n\nint[500][500] IS;\nint[10][500] BS;\n\nvoid main()\n{\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n foreach (i; 0..N) {\n int[10] ds;\n foreach (j, n; readln.split.to!(int[])) {\n IS[i][j] = n;\n foreach (d; 0..10) {\n auto x = (n>>d)&1;\n if (!j) {\n ds[d] = x;\n } else if (ds[d] != x) {\n ds[d] = 2;\n }\n }\n }\n BS[i] = ds;\n }\n int targ_d = -1, free_cnt, one_cnt;\n foreach (d; 0..10) {\n one_cnt = 0;\n foreach (i; 0..N) {\n if (BS[i][d] == 2) {\n targ_d = d;\n ++free_cnt;\n } else if (BS[i][d] == 1) {\n ++one_cnt;\n }\n }\n if (one_cnt%2 == 1) targ_d = d;\n if (targ_d != -1) break;\n }\n if (targ_d == -1) {\n writeln(\"NIE\");\n return;\n }\n one_cnt = one_cnt%2 == 1 ? 0 : 1;\n int[] r;\n foreach (j, ns; IS[0..N]) {\n if (BS[j][targ_d] != 2) {\n r ~= 1;\n } else {\n foreach (int i, n; ns[0..M]) {\n auto x = (n>>targ_d)&1;\n if (one_cnt && x) {\n --one_cnt;\n r ~= i+1;\n } else if (!one_cnt && !x) {\n r ~= i+1;\n }\n }\n }\n }\n writeln(\"TAK\");\n writeln(r.to!(string[]).join(\" \"));\n}"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.bigint;\n\nint[500][500] IS;\nint[10][500] BS;\n\nvoid main()\n{\n auto nm = readln.split.to!(int[]);\n auto N = nm[0];\n auto M = nm[1];\n foreach (i; 0..N) {\n int[10] ds;\n foreach (j, n; readln.split.to!(int[])) {\n IS[i][j] = n;\n foreach (d; 0..10) {\n auto x = (n>>d)&1;\n if (!j) {\n ds[d] = x;\n } else if (ds[d] != x) {\n ds[d] = 2;\n }\n }\n }\n BS[i] = ds;\n }\n int targ_d = -1, targ_i, free_cnt, one_cnt;\n foreach (d; 0..10) {\n one_cnt = 0;\n foreach (i; 0..N) {\n if (BS[i][d] == 2) {\n targ_d = d;\n ++free_cnt;\n } else if (BS[i][d] == 1) {\n ++one_cnt;\n }\n }\n if (one_cnt%2 == 1) targ_d = d;\n }\n if (targ_d == -1) {\n writeln(\"NIE\");\n return;\n }\n one_cnt = one_cnt%2 == 1 ? 0 : 1;\n int[] r;\n foreach (j, ns; IS[0..N]) {\n if (BS[j][targ_d] != 2) {\n r ~= 1;\n } else {\n foreach (int i, n; ns[0..M]) {\n auto x = (n>>targ_d)&1;\n if (one_cnt && x) {\n --one_cnt;\n r ~= i+1;\n } else if (!one_cnt && !x) {\n r ~= i+1;\n }\n }\n }\n }\n writeln(r.to!(string[]).join(\" \"));\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\nvoid solve(){\n\t\n\tint n = read!int;\n\tint m = read!int;\n\tint[][] as = read!int(n, m);\n\t\n\tint i1, j1;\n\tbool f = 0;\nA:\n\tforeach(i; 0 .. n){\n\t\tint[] q = as[i];\n\t\tforeach(j; 0 .. m){\n\t\t\tif(q[j] != q[0]){\n\t\t\t\ti1 = i;\n\t\t\t\tj1 = j;\n\t\t\t\tf = 1;\n\t\t\t\tbreak A;\n\t\t\t}\n\t\t}\n\t}\n\tif(! f){\n\t\t\"NIE\".writeln;\n\t\treturn;\n\t}\n\t\n\tint xor;\n\tforeach(i; 0 .. n) xor ^= as[i][0];\n\tint ansj;\n\tif(xor != 0) ansj = 0; else ansj = j1;\n\t\n\t\"TAK\".writeln;\n\tint[] ans;\n\tforeach(i; 0 .. n) ans ~= 1;\n\tans[i1] = ansj + 1;\n\tans.map!(to!string).join(\" \").writeln;\n\t\n\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 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!int;\n\tint m = read!int;\n\tint[][] as = read!int(n, m);\n\t\n\tint i1, j1;\n\tbool f = 0;\nA:\n\tforeach(i; 0 .. n){\n\t\tint[] q = as[i];\n\t\tforeach(j; 0 .. m){\n\t\t\tif(q[j] != q[0]){\n\t\t\t\ti1 = i;\n\t\t\t\tj1 = j;\n\t\t\t\tf = 1;\n\t\t\t\tbreak A;\n\t\t\t}\n\t\t}\n\t}\n\tif(! f){\n\t\t\"NIE\".writeln;\n\t\treturn;\n\t}\n\t\n\tint xor;\n\tforeach(i; 0 .. n){\n\t\tif(i != i1) xor ^= as[i][0];\n\t}\n\tint ansj;\n\tif((xor ^ as[i1][0]) != 0) ansj = 0; else ansj = j1;\n\t\n\t\"TAK\".writeln;\n\tint[] ans;\n\tforeach(i; 0 .. n){\n\t\tif(i != i1) ans ~= 1;\n\t\telse ans ~= ansj + 1;\n\t}\n\tans.map!(to!string).join(\" \").writeln;\n\t\n\t\n\t\n}\n"}, {"source_code": "import std.stdio : writef, readf, readln, writeln, writefln, write;\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, m;\n\n readf(\" %s %s\\n\", n, m);\n\n auto a = new int[][n];\n uint saver = 100000000;\n\n uint x1 = 0;\n uint x2 = 0;\n bool flag = false;\n uint pos2 = 0;\n uint pos1 = 0;\n foreach (i; 0 .. n) {\n a[i] = new int[m];\n foreach (j; 0 .. m)\n readf(\" %s\", a[i][j]);\n\n auto ma = a[i].enumerate.maxElement!\"a.value\";\n auto mi = a[i].enumerate.minElement!\"a.value\";\n if (ma[1] != mi[1] && !flag) {\n saver = i;\n flag = true;\n x1 ^= ma[1];\n x2 ^= mi[1];\n pos1 = ma[0];\n pos2 = mi[0];\n }\n else {\n x1 ^= a[i][0];\n x2 ^= a[i][0];\n }\n }\n\n if (x1 == 0 && x2 == 0) {\n writeln(\"NIE\");\n }\n else {\n writeln(\"TAK\");\n foreach (i; 0 .. n) {\n if (i != saver)\n write(1, \" \");\n else {\n if (x1 != 0)\n write(pos1 + 1, \" \");\n if (x2 != 0)\n write(pos2 + 1, \" \");\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.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 a = new long[][](N);\n\tforeach (i; 0..N)\n\t{\n\t\ta[i] = RDR.ARR;\n\t}\n\n\tlong x = a[0][0];\n\tforeach (i; 1..N)\n\t{\n\t\tx ^= a[i][0];\n\t\tdebug writeln(x);\n\t}\n\n\tuint pos_i = N, pos_j;\n\t(){\n\tforeach (j; 1..M)\n\t{\n\t\tforeach (i; 0..N)\n\t\t{\n\t\t\tif (x != 0) return;\n\t\t\tif (a[i][j] == a[i][j-1]) continue;\n\t\t\tx ^= a[i][j];\n\t\t\tpos_i = i;\n\t\t\tpos_j = j;\n\t\t}\n\t}}();\n\n\tif (x == 0)\n\t\twriteln(\"NIE\");\n\telse\n\t{\n\t\twriteln(\"TAK\");\n\t\twrite(pos_j+1);\n\t\tforeach (i; 1..pos_i+1)\n\t\t{\n\t\t\twrite(\" \", pos_j+1);\n\t\t}\n\t\tforeach (i; pos_i+1..N)\n\t\t{\n\t\t\twrite(\" \", pos_j);\n\t\t}\n\t\twriteln();\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; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); 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 a = new long[][](N);\n\tforeach (i; 0..N)\n\t{\n\t\ta[i] = RDR.ARR;\n\t}\n\n\tlong x = a[0][0];\n\tforeach (i; 1..N)\n\t{\n\t\tx ^= a[i][0];\n\t\tdebug writeln(x);\n\t}\n\n\tuint pos_i = N, pos_j;\n\t(){\n\tforeach (j; 1..M)\n\t{\n\t\tforeach (i; 0..N)\n\t\t{\n\t\t\tif (x != 0) return;\n\t\t\tx ^= a[i][j-1];\n\t\t\tx ^= a[i][j];\n\t\t\tpos_i = i;\n\t\t\tpos_j = j;\n\t\t}\n\t}}();\n\n\tif (x == 0)\n\t\twriteln(\"NIE\");\n\telse\n\t{\n\t\twriteln(\"TAK\");\n\t\twrite(pos_j+1);\n\t\tforeach (i; 1..pos_i+1)\n\t\t{\n\t\t\twrite(\" \", pos_j+1);\n\t\t}\n\t\tforeach (i; pos_i+1..N)\n\t\t{\n\t\t\twrite(\" \", pos_j);\n\t\t}\n\t\twriteln();\n\t}\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "3efc451a0fd5b67d58812eff774b3c6a"} {"source_code": "import std.stdio;\n\nvoid main(){\n int n;\n readf(\"%s\",&n);\n\n for(int i = 0; i < n; i++){\n for(int j = 0; j < n; j++){\n int k = i;\n if (i > n/2){\n k = n - i -1;\n }\n if(j <= n/2+k && j >= n/2-k){\n write(\"D\");\n } else {\n write(\"*\");\n }\n }\n writeln();\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;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\t\n\t\tchar[][] cs = new char[][](N, N);\n\t\tforeach (x; 0 .. N) foreach (y; 0 .. N) {\n\t\t\tcs[x][y] = (abs(x - N / 2) + abs(y - N / 2) <= N / 2) ? 'D' : '*';\n\t\t}\n\t\tforeach (x; 0 .. N) {\n\t\t\twriteln(cs[x].to!string);\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "a003d645999934c255f7b05d8494fa40"} {"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 [] a)\r\n{\r\n\tauto m = 1 << n;\r\n\r\n\tfor (int s = 0; s < m; s++)\r\n\t{\r\n\t\tint r = m - 1 - s;\r\n\t\tint t = r;\r\n\t\tdo\r\n\t\t{\r\n\t\t\tint cur = 0;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (s & (1 << i))\r\n\t\t\t\t{\r\n\t\t\t\t\tcur += a[i];\r\n\t\t\t\t}\r\n\t\t\t\tif (t & (1 << i))\r\n\t\t\t\t{\r\n\t\t\t\t\tcur -= a[i];\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (cur == 0 && !(s == 0 && t == 0))\r\n\t\t\t{\r\n\t\t\t\treturn true;\r\n\t\t\t}\r\n\r\n\t\t\tt = (t - 1) & r;\r\n\t\t}\r\n\t\twhile (t != r);\r\n\t}\r\n\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 n = readln.strip.to !(int);\r\n\t\tauto a = readln.splitter.map !(to !(int)).array;\r\n\t\twriteln (solve (n, a) ? \"YES\" : \"NO\");\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\nint N = 10000000 + 32;\nint[] gdiffmap;\n\nvoid update_diffmap(int[] b, int bs, int delta)\n{\n int bj = b[bs - 1];\n int diffbase = N;\n int *diffmap = &gdiffmap[diffbase];\n foreach (bii ; 0 .. bs) {\n int bi = b[bii];\n diffmap[bi - bj] += delta;\n diffmap[bj - bi] += delta;\n }\n}\n\nbool solve(int[] a, int i, int[] b, int bs)\n{\n int[] diffmap = gdiffmap;\n int diffbase = N;\n if (i == a.length)\n return false;\n\n update_diffmap(b, bs, 1);\n if (diffmap[diffbase + a[i]] > 0) {\n update_diffmap(b, bs, -1);\n return true;\n }\n\n foreach (bii ; 0 .. bs) {\n b[bs] = b[bii] + a[i];\n if (solve(a, i + 1, b, bs + 1)) {\n update_diffmap(b, bs, -1);\n return true;\n }\n }\n\n update_diffmap(b, bs, -1);\n return false;\n}\n\nvoid main()\n{\n int t;\n readf!\" %d \"(t);\n gdiffmap = new int[](2 * N);\n while (t--) {\n int n;\n readf!\" %d \"(n);\n auto a = readln.strip.split.map!(to!int).array;\n auto b = new int[](n + 1);\n writeln(solve(a, 0, b, 1) ? \"YES\" : \"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.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 bool ans;\n void dfs(int i, bool any, int sum) {\n ans = ans || (any && sum == 0);\n if (i == N) {\n return;\n }\n dfs(i + 1, any, sum);\n dfs(i + 1, true, sum + A[i]);\n dfs(i + 1, true, sum - A[i]);\n }\n \n dfs(0, false, 0);\n writeln(ans ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "e8e32f179080f9d12bb1e4df303ea124"} {"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;\n\nvoid main()\n{\n\tauto n = readln().chomp().to!int();\n\tauto input = readln().chomp();\n\tint[] len;\n\n\tforeach (sentence; splitter(input, regex(r\"[.!?][ ]?\"))) {\n\t\tif (sentence.length) {\n\t\t\tlen ~= sentence.length + 2;\n\t\t} else {\n\t\t\tlen[0]--;\n\t\t}\n\t}\n\tlen ~= 0;\n\t\n\tauto cnt = 1;\n\tfor (int i = 0; i < len.length - 1; i++) {\n\t\tif (len[i] > n) {\n\t\t\tcnt = 0;\n\t\t\tbreak;\n\t\t}\n\t\tif (len[i] + len[i+1] > n) {\n\t\t\tlen[i+1]--;\n\t\t\tcnt++;\n\t\t}\n\t\telse len[i+1] += len[i];\n\t}\n\n\tif (cnt) writeln(cnt);\n\telse writeln(\"Impossible\");\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;\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\tloop:while(read(&n))\n\t{\n\t\tauto a=readln.strip.splitter(regex(\"[.?!]+\")).map!(a => a.length+1).array[0..$-1];\n\t\tdebug writeln(a);\n\t\tint pos=0,len,ans;\n\t\twhile(posn)\n\t\t\t{\n\t\t\t\twriteln(\"Impossible\");\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t\twhile(pos1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\tloop:while(read(&n))\n\t{\n\t\tauto a=readln.splitter(regex(\"[.?!\\n]+\")).map!(a => a.length+1).array;\n\t\tint pos=0,len,ans;\n\t\twhile(posn)\n\t\t\t{\n\t\t\t\twriteln(\"Impossible\");\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t\twhile(pos1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\tloop:while(read(&n))\n\t{\n\t\tauto a=readln.splitter(regex(\"[.?!\\n]+\")).map!(a => a.length+1).array;\n\t\tint pos=0,len,ans;\n\t\twhile(posn)\n\t\t\t{\n\t\t\t\twriteln(\"Impossible\");\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t\twhile(pos n) {\n\t\t\tcnt = 0;\n\t\t\tbreak;\n\t\t}\n\t\tif (len[i] + len[i+1] > n) cnt++;\n\t\telse len[i+1] += len[i];\n\t}\n\n\tif (cnt) writeln(cnt);\n\telse writeln(\"Impossible\");\n}"}], "src_uid": "12b64f77fc9dd44a7e0287ff0a716a6a"} {"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 i = readNums!ulong;\n auto x = i[0];\n auto y = i[1];\n auto z = i[2];\n\n auto buy = (x / z) + (y / z);\n\n x %= z;\n y %= z;\n\n ulong give;\n if(x + y >= z){\n give = min(z - x, z - y);\n buy += (x + y) / z;\n }\n\n writeln(buy, \" \", give);\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 long x, y, z;\n readf(\" %s %s %s\", x, y, z);\n\n long tt = 0;\n tt += x / z;\n tt += y / z;\n long rx = x % z;\n long ry = y % z;\n long ex = 0;\n\n if (rx + ry >= z) {\n ex = z - max(rx, ry);\n tt++;\n }\n\n writef(\"%s %s\\n\", tt, ex);\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 int[] i = readNums!int;\n int x = i[0];\n int y = i[1];\n int z = i[2];\n\n int buy = (x + y) / z;\n\n x %= z;\n y %= z;\n\n int give;\n if(x + y >= z) give = min(x, y);\n\n writeln(buy, \" \", give);\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 int[] i = readNums!int;\n int x = i[0];\n int y = i[1];\n int z = i[2];\n\n int buy = (x / z) + (y / z);\n\n x %= z;\n y %= z;\n\n int give;\n if(x + y >= z){\n give = min(x, y);\n buy += (x + y) / z;\n }\n\n writeln(buy, \" \", give);\n}\n"}], "src_uid": "863a8124d46bb09b49fc88939fb5f364"} {"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\nchar[100_001] _a, _b;\nbool[100_000] used;\n\nvoid main() {\n while (true) {\n version (LocalProject)\n memset(used.ptr, 0x00, used.sizeof);\n auto a = _a[ ];\n auto b = _b[ ];\n readln(a);\n if (a.empty)\n break;\n readln(b);\n a = a[0 .. $ - 1];\n b = b[0 .. $ - 1];\n const n = cast(int)a.length;\n const m = cast(int)b.length;\n //b[0 .. lb] ~ b[rb .. m]\n int la = 0, lb = 0, ra = n, rb = m;\n while (la < n && lb < m) {\n while (la < n && a[la] != b[lb])\n la++;\n if (la == n)\n break;\n used[la] = true;\n debug writeln(\"Left-using \", la);\n la++;\n lb++;\n }\n int lres = lb, rres = m;\n while (ra && rb) {\n ra--;\n rb--;\n int passed = 0;\n while (ra >= 0 && a[ra] != b[rb])\n if (used[ra--])\n passed++;\n if (ra < 0)\n break;\n if (used[ra])\n passed++;\n debug writeln(\"Right-using \", ra);\n while (passed-- > 0 || lb > rb) {\n lb--;\n if (lb) {\n while (a[--la] != b[lb]) { }\n do\n used[la--] = false;\n while (a[la] != b[lb - 1]);\n la++;\n } else\n la = 0;\n }\n if (lb + m - rb > lres + m - rres) {\n lres = lb;\n rres = rb;\n }\n }\n if (!lres && rres == m)\n writeln('-');\n else\n writeln(b[0 .. lres], b[rres .. m]);\n }\n}\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 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;\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\tstring a,b;\n\tloop:while((a=readln.strip)!=\"\")\n\t{\n\t\tb=readln.strip;\n\t\tint[] p,s;\n\t\ts.length=p.length=b.length;\n\t\tp[]=int.max/4;\n\t\ts[]=int.min/4;\n\t\tint pos=0;\n\t\tfor(int i=0;i=0 && pos>=0;i--)\n\t\t{\n\t\t\twhile(pos>=0 && a[pos]!=b[i])pos--;\n\t\t\tif(pos<0)break;\n\t\t\ts[i]=pos--;\n\t\t}\n\t\tdebug writeln(p);\n\t\tdebug writeln(s);\n\t\tint ans=p.countUntil!\"a==int.max/4\",p1=ans,p2=b.length;\n\t\tforeach_reverse(i;0..b.length)\n\t\t{\n\t\t\tif(s[i]==int.min/4)break;\n\t\t\tint h=lowb(p,s[i]);\n\t\t\tint l=b.length-i;\n\t\t\tl+=h;\n\t\t\tif(l>ans)\n\t\t\t{\n\t\t\t\tans=l;\n\t\t\t\tp1=h;\n\t\t\t\tp2=i;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(ans);\n\t\tdebug writeln(p1,' ',p2);\n\t\tif(ans==0)writeln('-');\n\t\telse if(ans>=b.length)writeln(b);\n\t\telse writeln(b[0..p1],b[p2..$]);\n\t}\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 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;\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\tstring a,b;\n\tloop:while((a=readln.strip)!=\"\")\n\t{\n\t\tb=readln.strip;\n\t\tint[] p,s;\n\t\ts.length=p.length=b.length;\n\t\tp[]=int.max/4;\n\t\ts[]=int.min/4;\n\t\tint pos=0;\n\t\tfor(int i=0;i=0 && pos>=0;i--)\n\t\t{\n\t\t\twhile(pos>=0 && a[pos]!=b[i])pos--;\n\t\t\tif(pos<0)break;\n\t\t\ts[i]=pos--;\n\t\t}\n\t\tdebug writeln(p);\n\t\tdebug writeln(s);\n\t\tint ans=p.countUntil!\"a==int.max/4\",p1=ans-1,p2=b.length;\n\t\tforeach_reverse(i;0..b.length)\n\t\t{\n\t\t\tif(s[i]==int.min/4)break;\n\t\t\tint h=lowb(p,s[i]);\n\t\t\tint l=b.length-i;\n\t\t\tl+=max(h-1,0);\n\t\t\tif(l>ans)\n\t\t\t{\n\t\t\t\tans=l;\n\t\t\t\tp1=max(0,h-1);\n\t\t\t\tp2=i;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(ans);\n\t\tdebug writeln(p1,' ',p2);\n\t\tif(ans==0)writeln('-');\n\t\telse writeln(b[0..p1+1],b[p2..$]);\n\t}\n\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 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;\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\tstring a,b;\n\tloop:while((a=readln.strip)!=\"\")\n\t{\n\t\tb=readln.strip;\n\t\tint[] p,s;\n\t\ts.length=p.length=b.length;\n\t\tp[]=int.max/4;\n\t\ts[]=int.min/4;\n\t\tint pos=0;\n\t\tfor(int i=0;i=0 && pos>=0;i--)\n\t\t{\n\t\t\twhile(pos>=0 && a[pos]!=b[i])pos--;\n\t\t\tif(pos<0)break;\n\t\t\ts[i]=pos--;\n\t\t}\n\t\tdebug writeln(p);\n\t\tdebug writeln(s);\n\t\tint ans=p.countUntil!\"a==int.max/4\",p1=ans-1,p2=b.length;\n\t\tforeach_reverse(i;0..b.length)\n\t\t{\n\t\t\tif(s[i]==int.min/4)break;\n\t\t\tint h=lowb(p,s[i]);\n\t\t\tint l=b.length-i;\n\t\t\tl+=max(h-1,0);\n\t\t\tif(l>ans)\n\t\t\t{\n\t\t\t\tans=l;\n\t\t\t\tp1=h-1;\n\t\t\t\tp2=i;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(ans);\n\t\tdebug writeln(p1,' ',p2);\n\t\tif(ans==0)writeln('-');\n\t\telse writeln(b[0..p1+1],b[p2..$]);\n\t}\n\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 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;\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(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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-----------------------------------------------------------------\n\nvoid main()\n{\n\tstring a,b;\n\tloop:while((a=readln.strip)!=\"\")\n\t{\n\t\tb=readln.strip;\n\t\tint[] p,s;\n\t\ts.length=p.length=b.length;\n\t\tp[]=int.max/4;\n\t\ts[]=int.min/4;\n\t\tint pos=0;\n\t\tfor(int i=0;i=0 && pos>=0;i--)\n\t\t{\n\t\t\twhile(pos>=0 && a[pos]!=b[i])pos--;\n\t\t\tif(pos<0)break;\n\t\t\ts[i]=pos--;\n\t\t}\n\t\tdebug writeln(p);\n\t\tdebug writeln(s);\n\t\tint ans=p.countUntil!\"a==int.max/4\",p1=ans-1,p2=b.length;\n\t\tforeach_reverse(i;0..b.length)\n\t\t{\n\t\t\tif(s[i]==int.min/4)break;\n\t\t\tint h=lowb(p,s[i]);\n\t\t\tint l=b.length-i;\n\t\t\tl+=max(h-1,0);\n\t\t\tif(l>ans)\n\t\t\t{\n\t\t\t\tans=l;\n\t\t\t\tp1=h-1;\n\t\t\t\tp2=i;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(ans);\n\t\tdebug writeln(p1,' ',p2);\n\t\tif(ans==0)writeln('-');\n\t\telse if(ans>=b.length)writeln(b);\n\t\telse writeln(b[0..p1+1],b[p2..$]);\n\t}\n\n}"}], "src_uid": "89aef6720eac7376ce0a657d46c3c5b7"} {"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = 1;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto Q = scan!int;\r\n auto A = scan!long(N);\r\n\r\n long ans = A.sum;\r\n\r\n alias QV = Tuple!(int, \"qi\", long, \"v\");\r\n auto arr = new QV[](N + 1);\r\n foreach(i; 0..N) arr[i].v = A[i];\r\n\r\n foreach(qi; 1..Q + 1) {\r\n auto q = scan!int;\r\n if (q == 1) {\r\n auto i = scan!int - 1;\r\n auto v = scan!long;\r\n auto currentValue = arr[i].qi >= arr[N].qi ? arr[i].v : arr[N].v;\r\n ans += v - currentValue;\r\n arr[i] = QV(qi, v);\r\n } else {\r\n auto v = scan!long;\r\n ans = v * N;\r\n arr[N] = QV(qi, v);\r\n }\r\n\r\n ans.writeln;\r\n }\r\n }\r\n\r\n foreach(i; 0..QN) {\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>>\".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 n, q;\r\n scanf(\"%d %d\", &n, &q);\r\n getchar();\r\n long[] arr = readln.split.to!(long[]);\r\n long sum = arr.sum;\r\n long[long] xch;\r\n long def_value;\r\n bool not_rewrited = true;\r\n outer: foreach(_; 0..q)\r\n {\r\n long[] query = readln.split.to!(long[]);\r\n if (query[0] == 1) {\r\n if (not_rewrited)\r\n sum += query[2] - xch.get(query[1], arr[cast(size_t)query[1] - 1]);\r\n else\r\n sum += query[2] - xch.get(query[1], def_value);\r\n xch[query[1]] = query[2];\r\n }\r\n else {\r\n not_rewrited = false;\r\n sum = n * query[1];\r\n def_value = query[1];\r\n xch.clear;\r\n }\r\n writeln(sum);\r\n }\r\n}\r\n"}], "negative_code": [{"source_code": "void main() { runSolver(); }\r\n\r\nvoid problem() {\r\n auto QN = 1;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto Q = scan!int;\r\n auto A = scan!long(N);\r\n\r\n long ans = A.sum;\r\n\r\n alias QV = Tuple!(int, \"qi\", long, \"v\");\r\n auto arr = new QV[](N + 1);\r\n foreach(i; 0..N) arr[i].v = A[i];\r\n\r\n foreach(qi; 0..Q) {\r\n auto q = scan!int;\r\n if (q == 1) {\r\n auto i = scan!int - 1;\r\n auto v = scan!long;\r\n auto currentValue = arr[i].qi >= arr[N].qi ? arr[i].v : arr[N].v;\r\n ans += v - currentValue;\r\n arr[i] = QV(qi, v);\r\n } else {\r\n auto v = scan!long;\r\n ans = v * N;\r\n arr[N] = QV(qi, v);\r\n }\r\n\r\n ans.writeln;\r\n }\r\n }\r\n\r\n foreach(i; 0..QN) {\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>>\".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 = 1;\r\n\r\n auto solve() {\r\n auto subSolve() {\r\n auto N = scan!int;\r\n auto Q = scan!int;\r\n auto A = scan!long(N);\r\n\r\n long ans = A.sum;\r\n\r\n alias QV = Tuple!(int, \"qi\", long, \"v\");\r\n auto arr = new QV[](N + 1);\r\n foreach(i; 0..N) arr[i].v = A[i];\r\n\r\n foreach(qi; 0..Q) {\r\n auto q = scan!int;\r\n if (q == 1) {\r\n auto i = scan!int - 1;\r\n auto v = scan!long;\r\n auto currentValue = arr[i].qi >= arr[N].qi ? arr[i].v : arr[N].v;\r\n ans += v - currentValue;\r\n arr[i] = QV(qi, v);\r\n } else {\r\n auto v = scan!long;\r\n ans = v * N;\r\n arr[N] = QV(qi, v);\r\n }\r\n\r\n ans.writeln;\r\n }\r\n }\r\n\r\n foreach(i; 0..QN) {\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>>\".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": "b9771f941967b030aa13d0bfcc4d0a61"} {"source_code": "import std.ascii;\nimport std.conv;\nimport std.exception;\nimport std.stdio;\n\nimmutable int MAX_N = 52;\nimmutable int MOD = 1_000_000_007;\n\nstruct Z_P (T, int MOD)\n{\nprivate:\n\tstatic if (is (T == int))\n\t{\n\t\talias long T2;\n\t}\n\telse static if (is (T == uint))\n\t{\n\t\talias ulong T2;\n\t}\n\telse\n\t{\n\t\tstatic assert (false);\n\t}\n\n\tT value;\n\n\tvoid conv (T nvalue)\n\t{\n\t\tif (nvalue < 0)\n\t\t{\n\t\t\tvalue = ((nvalue % MOD) + MOD) % MOD;\n\t\t}\n\t\telse if (nvalue >= MOD)\n\t\t{\n\t\t\tvalue = nvalue % MOD;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tvalue = nvalue;\n\t\t}\n\t}\n\npublic:\n\tthis (T nvalue)\n\t{\n\t\tconv (nvalue);\n\t}\n\n\tZ_P opBinary (string op) (Z_P other)\n\t\tif (op == \"+\")\n\t{\n\t\tauto temp = value + other.value;\n\t\tif (temp >= MOD)\n\t\t{\n\t\t\ttemp -= MOD;\n\t\t}\n\t\treturn Z_P (temp);\n\t}\n\n\tref Z_P opBinary (string op) (T other)\n\t\tif (op == \"+\")\n\t{\n\t\tauto temp = this + Z_P (other);\n\t\tthis = temp;\n\t\treturn this;\n\t}\n\n\tZ_P opBinary (string op) (Z_P other)\n\t\tif (op == \"*\")\n\t{\n\t\tauto temp = (cast (T2) value * other.value) % MOD;\n\t\treturn Z_P (cast (T) temp);\n\t}\n\n\tref Z_P opAssign (Z_P other)\n\t{\n\t\tvalue = other.value;\n\t\treturn this;\n\t}\n\n\tref Z_P opAssign (T nvalue)\n\t{\n\t\tconv (nvalue);\n\t\treturn this;\n\t}\n\n\tref opOpAssign (string op) (Z_P other)\n\t\tif (op == \"+\")\n\t{\n\t\tthis = this + other;\n\t\treturn this;\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn to!string (value);\n\t}\n}\n\nstruct Matrix (T)\n{\nprivate:\n\tT [] a;\n\tint w, h;\n\npublic:\n\tthis (this)\n\t{\n\t\ta = a.dup;\n\t}\n\n\tthis (int nw, int nh)\n\t{\n\t\tw = nw;\n\t\th = nh;\n\t\ta.length = w * h;\n\t}\n\n\tref Matrix opAssign (Matrix other)\n\t{\n\t\tdebug {writeln (\"!\");}\n\t\ta = other.a.dup;\n\t\tw = other.w;\n\t\th = other.h;\n\t\treturn this;\n\t}\n\n\tref Matrix opOpAssign (string op) (Matrix other)\n\t\tif (op == \"*\")\n\t{\n\t\tenforce (h == other.w);\n\t\tdebug {writeln (this, \" * \", other);}\n\t\tauto res = Matrix (w, other.h);\n\t\tforeach (i; 0..w)\n\t\t{\n\t\t\tforeach (j; 0..other.h)\n\t\t\t{\n\t\t\t\tforeach (k; 0..h)\n\t\t\t\t{\n\t\t\t\t\tres[i, j] += this[i, k] * other[k, j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (this, \" * \", other, \" = \", res);}\n\t\tthis = res;\n\t\treturn this;\n\t}\n\n\tref T opIndex (int p, int q)\n\t{\n\t\treturn a[p * w + q];\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn \"[\" ~ to!string (w) ~ \" x \" ~ to!string (h) ~\n\t\t \": \" ~ to!string (a) ~ \"]\";\n\t}\n\n\t@property Matrix unity ()\n\t{\n\t\tenforce (w == h);\n\t\tMatrix res;\n\t\tforeach (i; 0..w)\n\t\t{\n\t\t\tres[i, i] = 1;\n\t\t}\n\t\treturn res;\n\t}\n}\n\nT pow (T, P) (T a, P b, T UNITY)\n{\n\tauto res = UNITY;\n\tdebug {writeln (\"res = \", res);}\n\tauto temp = a;\n\twhile (b > 0)\n\t{\n\t\tdebug {writeln (\"b = \", b);}\n\t\tif (b & 1)\n\t\t{\n\t\t\tres *= temp;\n\t\t\tdebug {writeln (\"res = \", res);}\n\t\t}\n\t\ttemp *= temp;\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nint conv (char c)\n{\n\tif (isLower (c))\n\t{\n\t\treturn c - 'a';\n\t}\n\tif (isUpper (c))\n\t{\n\t\treturn c - 'A' + 26;\n\t}\n\tassert (false);\n}\n\nvoid main ()\n{\n\tlong n;\n\tint m, k;\n\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\talias Z_P !(int, MOD) EType;\n\t\talias Matrix !(EType) MType;\n\t\tauto a = MType (m, m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\ta[i, j] = 1;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tchar u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\ta[conv (u), conv (v)] = 0;\n\t\t}\n\t\tdebug {writeln (\"a: \", a);}\n\t\tauto unity = MType (m, m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tunity[i, i] = 1;\n\t\t}\n\t\tdebug {writeln (\"unity: \", unity);}\n\t\tauto b = pow (a, n - 1, unity);\n\t\tEType res;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tres += b[i, j];\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\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\nconst MOD = 1000000007;\n\nint[][] modMul(in int[][] A, in int[][] B) {\n assert(A[0].length == B.length);\n auto H = A.length, W = B[0].length;\n auto ret = new int[][](H, W);\n foreach (i; 0 .. H) {\n foreach (j; 0 .. W) {\n foreach (k; 0 .. A[0].length) {\n long t = ret[i][j] + cast(long)(A[i][k]) * B[k][j];\n ret[i][j] = cast(int)(t % MOD);\n }\n }\n }\n return ret;\n}\n\nint[][] E(in int[][] M) {\n assert(M.length == M[0].length);\n auto N = M.length;\n auto ret = new int[][](N, N);\n foreach (i; 0 .. N) {\n ret[i][i] = 1;\n }\n return ret;\n}\n\nint[][] modPow(in int[][] M, long x) {\n if (x == 0) return M.E;\n if (x & 1) {\n return M.modMul(modPow(M, x - 1));\n } else {\n auto M1 = modPow(M, x / 2);\n return M1.modMul(M1);\n }\n}\n\nvoid main() {\n long N; int M, K;\n scanf(\"%lld %d %d\\n\", &N, &M, &K);\n auto B = new string[K];\n foreach (k; 0 .. K) {\n B[k] = readln.chomp;\n }\n\n auto x = new int[][](M, M);\n foreach (ref l; x) l[] = 1;\n foreach (s; B) {\n int begin = cast(int)(s[0].isLower ? s[0] - 'a' : s[0] - 'A' + 26),\n end = cast(int)(s[1].isLower ? s[1] - 'a' : s[1] - 'A' + 26);\n x[begin][end] = 0;\n }\n auto y = x.modPow(N - 1);\n int ans = 0;\n foreach (i; 0 .. M) {\n foreach (j; 0 .. M) {\n ans = (ans + y[i][j]) % MOD;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.ascii;\nimport std.conv;\nimport std.exception;\nimport std.stdio;\n\nimmutable int MAX_N = 52;\nimmutable int MOD = 1_000_000_007;\n\nstruct Z_P (T, int MOD)\n{\nprivate:\n\tstatic if (is (T == int))\n\t{\n\t\talias long T2;\n\t}\n\telse static if (is (T == uint))\n\t{\n\t\talias ulong T2;\n\t}\n\telse\n\t{\n\t\tstatic assert (false);\n\t}\n\n\tT value;\n\n\tvoid conv (T nvalue)\n\t{\n\t\tif (nvalue < 0)\n\t\t{\n\t\t\tvalue = ((nvalue % MOD) + MOD) % MOD;\n\t\t}\n\t\telse if (nvalue >= MOD)\n\t\t{\n\t\t\tvalue = nvalue % MOD;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tvalue = nvalue;\n\t\t}\n\t}\n\npublic:\n\tthis (T nvalue)\n\t{\n\t\tconv (nvalue);\n\t}\n\n\tZ_P opBinary (string op) (Z_P other)\n\t\tif (op == \"+\")\n\t{\n\t\tauto temp = value + other.value;\n\t\tif (temp >= MOD)\n\t\t{\n\t\t\ttemp -= MOD;\n\t\t}\n\t\treturn Z_P (temp);\n\t}\n\n\tref Z_P opBinary (string op) (T other)\n\t\tif (op == \"+\")\n\t{\n\t\tauto temp = this + Z_P (other);\n\t\tthis = temp;\n\t\treturn this;\n\t}\n\n\tZ_P opBinary (string op) (Z_P other)\n\t\tif (op == \"*\")\n\t{\n\t\tauto temp = (cast (T2) value * other.value) % MOD;\n\t\treturn Z_P (cast (T) temp);\n\t}\n\n\tref Z_P opAssign (Z_P other)\n\t{\n\t\tvalue = other.value;\n\t\treturn this;\n\t}\n\n\tref Z_P opAssign (T nvalue)\n\t{\n\t\tconv (nvalue);\n\t\treturn this;\n\t}\n\n\tref opOpAssign (string op) (Z_P other)\n\t\tif (op == \"+\")\n\t{\n\t\tthis = this + other;\n\t\treturn this;\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn to!string (value);\n\t}\n}\n\nstruct Matrix (T)\n{\nprivate:\n\tT [] a;\n\tint w, h;\n\npublic:\n\tthis (this)\n\t{\n\t\ta = a.dup;\n\t}\n\n\tthis (int nw, int nh)\n\t{\n\t\tw = nw;\n\t\th = nh;\n\t\ta.length = w * h;\n\t}\n\n\tref Matrix opAssign (Matrix other)\n\t{\n\t\tdebug {writeln (\"!\");}\n\t\ta = other.a.dup;\n\t\tw = other.w;\n\t\th = other.h;\n\t\treturn this;\n\t}\n\n\tref Matrix opOpAssign (string op) (Matrix other)\n\t\tif (op == \"*\")\n\t{\n\t\tenforce (h == other.w);\n\t\tdebug {writeln (this, \" * \", other);}\n\t\tauto res = Matrix (w, other.h);\n\t\tforeach (i; 0..w)\n\t\t{\n\t\t\tforeach (j; 0..other.h)\n\t\t\t{\n\t\t\t\tres[i, j] = 0;\n\t\t\t}\n\t\t\tforeach (k; 0..h)\n\t\t\t{\n\t\t\t\tforeach (j; 0..other.h)\n\t\t\t\t{\n\t\t\t\t\tres[i, j] += this[i, k] * other[k, j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (this, \" * \", other, \" = \", res);}\n\t\tthis = res;\n\t\treturn this;\n\t}\n\n\tref T opIndex (int p, int q)\n\t{\n\t\treturn a[p * w + q];\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn \"[\" ~ to!string (w) ~ \" x \" ~ to!string (h) ~\n\t\t \": \" ~ to!string (a) ~ \"]\";\n\t}\n\n\t@property Matrix unity ()\n\t{\n\t\tenforce (w == h);\n\t\tMatrix res;\n\t\tforeach (i; 0..w)\n\t\t{\n\t\t\tres[i, i] = 1;\n\t\t}\n\t\treturn res;\n\t}\n}\n\nT pow (T, P) (T a, P b, T UNITY)\n{\n\tauto res = UNITY;\n\tdebug {writeln (\"res = \", res);}\n\tauto temp = a;\n\twhile (b > 0)\n\t{\n\t\tdebug {writeln (\"b = \", b);}\n\t\tif (b & 1)\n\t\t{\n\t\t\tres *= temp;\n\t\t\tdebug {writeln (\"res = \", res);}\n\t\t}\n\t\ttemp *= temp;\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nint conv (char c)\n{\n\tif (isLower (c))\n\t{\n\t\treturn c - 'a';\n\t}\n\tif (isUpper (c))\n\t{\n\t\treturn c - 'A' + 26;\n\t}\n\tassert (false);\n}\n\nvoid main ()\n{\n\tlong n;\n\tint m, k;\n\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\talias Z_P !(int, MOD) EType;\n\t\talias Matrix !(EType) MType;\n\t\tauto a = MType (m, m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\ta[i, j] = 1;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tchar u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\ta[conv (u), conv (v)] = 0;\n\t\t}\n\t\tdebug {writeln (\"a: \", a);}\n\t\tauto unity = MType (m, m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tunity[i, i] = 1;\n\t\t}\n\t\tdebug {writeln (\"unity: \", unity);}\n\t\tauto b = pow (a, n - 1, unity);\n\t\tEType res;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tres += b[i, j];\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.ascii;\nimport std.conv;\nimport std.exception;\nimport std.stdio;\n\nimmutable int MAX_N = 52;\nimmutable int MOD = 1_000_000_007;\n\nstruct Z_P (T, int MOD)\n{\nprivate:\n\tstatic if (is (T == int))\n\t{\n\t\talias long T2;\n\t}\n\telse static if (is (T == uint))\n\t{\n\t\talias ulong T2;\n\t}\n\telse\n\t{\n\t\tstatic assert (false);\n\t}\n\n\tT value;\n\n\tvoid conv (T nvalue)\n\t{\n\t\tif (nvalue < 0)\n\t\t{\n\t\t\tvalue = ((nvalue % MOD) + MOD) % MOD;\n\t\t}\n\t\telse if (nvalue >= MOD)\n\t\t{\n\t\t\tvalue = nvalue % MOD;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tvalue = nvalue;\n\t\t}\n\t}\n\npublic:\n\tthis (T nvalue)\n\t{\n\t\tconv (nvalue);\n\t}\n\n\tZ_P opBinary (string op) (Z_P other)\n\t\tif (op == \"+\")\n\t{\n\t\tauto temp = value + other.value;\n\t\tif (temp >= MOD)\n\t\t{\n\t\t\ttemp -= MOD;\n\t\t}\n\t\treturn Z_P (temp);\n\t}\n\n\tref Z_P opBinary (string op) (T other)\n\t\tif (op == \"+\")\n\t{\n\t\tauto temp = this + Z_P (other);\n\t\tthis = temp;\n\t\treturn this;\n\t}\n\n\tZ_P opBinary (string op) (Z_P other)\n\t\tif (op == \"*\")\n\t{\n\t\tauto temp = (cast (T2) value * other.value) % MOD;\n\t\treturn Z_P (cast (T) temp);\n\t}\n\n\tref Z_P opAssign (Z_P other)\n\t{\n\t\tvalue = other.value;\n\t\treturn this;\n\t}\n\n\tref Z_P opAssign (T nvalue)\n\t{\n\t\tconv (nvalue);\n\t\treturn this;\n\t}\n\n\tref opOpAssign (string op) (Z_P other)\n\t\tif (op == \"+\")\n\t{\n\t\tthis = this + other;\n\t\treturn this;\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn to!string (value);\n\t}\n}\n\nstruct Matrix (T)\n{\nprivate:\n\tT [] a;\n\tint w, h;\n\npublic:\n\tthis (this)\n\t{\n\t\ta = a.dup;\n\t}\n\n\tthis (int nw, int nh)\n\t{\n\t\tw = nw;\n\t\th = nh;\n\t\ta.length = w * h;\n\t}\n\n\tref Matrix opAssign (Matrix other)\n\t{\n\t\tdebug {writeln (\"!\");}\n\t\ta = other.a.dup;\n\t\tw = other.w;\n\t\th = other.h;\n\t\treturn this;\n\t}\n\n\tref Matrix opOpAssign (string op) (Matrix other)\n\t\tif (op == \"*\")\n\t{\n\t\tenforce (w == other.h);\n\t\tdebug {writeln (this, \" * \", other);}\n\t\tauto res = Matrix (h, other.w);\n\t\tforeach (i; 0..h)\n\t\t{\n\t\t\tres[i][] = cast (T) 0;\n\t\t\tforeach (k; 0..w)\n\t\t\t{\n//\t\t\t\tres[i][] += other[k][] * this[i, k];\n\t\t\t\tforeach (j; 0..other.w)\n\t\t\t\t{\n\t\t\t\t\tres[i][j] += this[i][k] * other[k][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (this, \" * \", other, \" = \", res);}\n\t\tthis = res;\n\t\treturn this;\n\t}\n\n\tT [] opIndex (int p)\n\t{\n\t\treturn a[p * w..p * w + w];\n\t}\n\n\tref T opIndex (int p, int q)\n\t{\n\t\treturn a[p * w + q];\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn \"[\" ~ to!string (w) ~ \" x \" ~ to!string (h) ~\n\t\t \": \" ~ to!string (a) ~ \"]\";\n\t}\n\n\t@property Matrix unity ()\n\t{\n\t\tenforce (w == h);\n\t\tMatrix res;\n\t\tforeach (i; 0..w)\n\t\t{\n\t\t\tres[i, i] = 1;\n\t\t}\n\t\treturn res;\n\t}\n}\n\nT pow (T, P) (T a, P b, T UNITY)\n{\n\tauto res = UNITY;\n\tdebug {writeln (\"res = \", res);}\n\tauto temp = a;\n\twhile (b > 0)\n\t{\n\t\tdebug {writeln (\"b = \", b);}\n\t\tif (b & 1)\n\t\t{\n\t\t\tres *= temp;\n\t\t\tdebug {writeln (\"res = \", res);}\n\t\t}\n\t\ttemp *= temp;\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nint conv (char c)\n{\n\tif (isLower (c))\n\t{\n\t\treturn c - 'a';\n\t}\n\tif (isUpper (c))\n\t{\n\t\treturn c - 'A' + 26;\n\t}\n\tassert (false);\n}\n\nvoid main ()\n{\n\tlong n;\n\tint m, k;\n\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\talias Z_P !(int, MOD) EType;\n\t\talias Matrix !(EType) MType;\n\t\tauto a = MType (m, m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\ta[i, j] = 1;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tchar u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\ta[conv (u), conv (v)] = 0;\n\t\t}\n\t\tdebug {writeln (\"a: \", a);}\n\t\tauto unity = MType (m, m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tunity[i, i] = 1;\n\t\t}\n\t\tdebug {writeln (\"unity: \", unity);}\n\t\tauto b = pow (a, n - 1, unity);\n\t\tEType res;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tres += b[i, j];\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\nconst MOD = 1000000007;\n\nint[][] modMul(in int[][] A, in int[][] B) {\n assert(A[0].length == B.length);\n auto H = A.length, W = B[0].length;\n auto ret = new int[][](H, W);\n foreach (i; 0 .. H) {\n foreach (j; 0 .. W) {\n foreach (k; 0 .. A[0].length) {\n ret[i][j] = (ret[i][j] + A[i][k] * B[k][j]) % MOD;\n }\n }\n }\n return ret;\n}\n\nint[][] E(in int[][] M) {\n assert(M.length == M[0].length);\n auto N = M.length;\n auto ret = new int[][](N, N);\n foreach (i; 0 .. N) {\n ret[i][i] = 1;\n }\n return ret;\n}\n\nint[][] modPow(in int[][] M, long x) {\n if (x == 0) return M.E;\n if (x & 1) {\n return M.modMul(modPow(M, x - 1));\n } else {\n auto M1 = modPow(M, x / 2);\n return M1.modMul(M1);\n }\n}\n\nvoid main() {\n long N; int M, K;\n scanf(\"%lld %d %d\\n\", &N, &M, &K);\n auto B = new string[K];\n foreach (k; 0 .. K) {\n B[k] = readln.chomp;\n }\n\n auto x = new int[][](M, M);\n foreach (ref l; x) l[] = 1;\n foreach (s; B) {\n int begin = cast(int)(s[0].isLower ? s[0] - 'a' : s[0] - 'A'),\n end = cast(int)(s[1].isLower ? s[1] - 'a' : s[1] - 'A');\n x[begin][end] = 0;\n }\n auto y = x.modPow(N - 1);\n int ans = 0;\n foreach (i; 0 .. M) {\n foreach (j; 0 .. M) {\n ans = (ans + y[i][j]) % MOD;\n }\n }\n writeln(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\nconst MOD = 1000000007;\n\nint[][] modMul(in int[][] A, in int[][] B) {\n assert(A[0].length == B.length);\n auto H = A.length, W = B[0].length;\n auto ret = new int[][](H, W);\n foreach (i; 0 .. H) {\n foreach (j; 0 .. W) {\n foreach (k; 0 .. A[0].length) {\n long t = ret[i][j] + A[i][k] * B[k][j];\n ret[i][j] = cast(int)(t % MOD);\n }\n }\n }\n return ret;\n}\n\nint[][] E(in int[][] M) {\n assert(M.length == M[0].length);\n auto N = M.length;\n auto ret = new int[][](N, N);\n foreach (i; 0 .. N) {\n ret[i][i] = 1;\n }\n return ret;\n}\n\nint[][] modPow(in int[][] M, long x) {\n if (x == 0) return M.E;\n if (x & 1) {\n return M.modMul(modPow(M, x - 1));\n } else {\n auto M1 = modPow(M, x / 2);\n return M1.modMul(M1);\n }\n}\n\nvoid main() {\n long N; int M, K;\n scanf(\"%lld %d %d\\n\", &N, &M, &K);\n auto B = new string[K];\n foreach (k; 0 .. K) {\n B[k] = readln.chomp;\n }\n\n auto x = new int[][](M, M);\n foreach (ref l; x) l[] = 1;\n foreach (s; B) {\n int begin = cast(int)(s[0].isLower ? s[0] - 'a' : s[0] - 'A' + 26),\n end = cast(int)(s[1].isLower ? s[1] - 'a' : s[1] - 'A' + 26);\n x[begin][end] = 0;\n }\n auto y = x.modPow(N - 1);\n int ans = 0;\n foreach (i; 0 .. M) {\n foreach (j; 0 .. M) {\n ans = (ans + y[i][j]) % MOD;\n }\n }\n writeln(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\nconst MOD = 1000000007;\n\nint[][] modMul(in int[][] A, in int[][] B) {\n assert(A[0].length == B.length);\n auto H = A.length, W = B[0].length;\n auto ret = new int[][](H, W);\n foreach (i; 0 .. H) {\n foreach (j; 0 .. W) {\n foreach (k; 0 .. A[0].length) {\n ret[i][j] = (ret[i][j] + A[i][k] * B[k][j]) % MOD;\n }\n }\n }\n return ret;\n}\n\nint[][] E(in int[][] M) {\n assert(M.length == M[0].length);\n auto N = M.length;\n auto ret = new int[][](N, N);\n foreach (i; 0 .. N) {\n ret[i][i] = 1;\n }\n return ret;\n}\n\nint[][] modPow(in int[][] M, long x) {\n if (x == 0) return M.E;\n if (x & 1) {\n return M.modMul(modPow(M, x - 1));\n } else {\n auto M1 = modPow(M, x / 2);\n return M1.modMul(M1);\n }\n}\n\nvoid main() {\n long N; int M, K;\n scanf(\"%lld %d %d\\n\", &N, &M, &K);\n auto B = new string[K];\n foreach (k; 0 .. K) {\n B[k] = readln.chomp;\n }\n\n auto x = new int[][](M, M);\n foreach (ref l; x) l[] = 1;\n foreach (s; B) {\n int begin = cast(int)(s[0].isLower ? s[0] - 'a' : s[0] - 'A' + 26),\n end = cast(int)(s[1].isLower ? s[1] - 'a' : s[1] - 'A' + 26);\n x[begin][end] = 0;\n }\n auto y = x.modPow(N - 1);\n int ans = 0;\n foreach (i; 0 .. M) {\n foreach (j; 0 .. M) {\n ans = (ans + y[i][j]) % MOD;\n }\n }\n writeln(ans);\n}\n"}, {"source_code": "import std.ascii;\nimport std.conv;\nimport std.exception;\nimport std.stdio;\n\nimmutable int MAX_N = 52;\nimmutable int MOD = 1_000_000_007;\n\nstruct Z_P (T, int MOD)\n{\nprivate:\n\tstatic if (is (T == int))\n\t{\n\t\talias long T2;\n\t}\n\telse static if (is (T == uint))\n\t{\n\t\talias ulong T2;\n\t}\n\telse\n\t{\n\t\tstatic assert (false);\n\t}\n\n\tT value;\n\n\tvoid conv (T nvalue)\n\t{\n\t\tif (nvalue < 0)\n\t\t{\n\t\t\tvalue = ((nvalue % MOD) + MOD) % MOD;\n\t\t}\n\t\telse if (nvalue >= MOD)\n\t\t{\n\t\t\tvalue = nvalue % MOD;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tvalue = nvalue;\n\t\t}\n\t}\n\npublic:\n\tthis (T nvalue)\n\t{\n\t\tconv (nvalue);\n\t}\n\n\tZ_P opBinary (string op) (Z_P other)\n\t\tif (op == \"+\")\n\t{\n\t\tauto temp = value + other.value;\n\t\tif (temp >= MOD)\n\t\t{\n\t\t\ttemp -= MOD;\n\t\t}\n\t\treturn Z_P (temp);\n\t}\n\n\tref Z_P opBinary (string op) (T other)\n\t\tif (op == \"+\")\n\t{\n\t\tauto temp = this + Z_P (other);\n\t\tthis = temp;\n\t\treturn this;\n\t}\n\n\tZ_P opBinary (string op) (Z_P other)\n\t\tif (op == \"*\")\n\t{\n\t\tauto temp = (cast (T2) value * other.value) % MOD;\n\t\treturn Z_P (cast (T) temp);\n\t}\n\n\tref Z_P opAssign (T nvalue)\n\t{\n\t\tconv (nvalue);\n\t\treturn this;\n\t}\n\n\tref opOpAssign (string op) (Z_P other)\n\t\tif (op == \"+\")\n\t{\n//\t\tthis = this + other;\n\t\treturn this + other;\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn to!string (value);\n\t}\n}\n\nstruct Matrix (T)\n{\nprivate:\n\tT [] a;\n\tint w, h;\n\npublic:\n\tthis (this)\n\t{\n\t\ta = a.dup;\n\t}\n\n\tthis (int nw, int nh)\n\t{\n\t\tw = nw;\n\t\th = nh;\n\t\ta.length = w * h;\n\t}\n\n\tref Matrix opAssign (Matrix other)\n\t{\n\t\tdebug {writeln (\"!\");}\n\t\ta = other.a.dup;\n\t\tw = other.w;\n\t\th = other.h;\n\t\treturn this;\n\t}\n\n\tref Matrix opOpAssign (string op) (Matrix other)\n\t\tif (op == \"*\")\n\t{\n\t\tenforce (h == other.w);\n\t\tdebug {writeln (this, \" * \", other);}\n\t\tauto res = Matrix (w, other.h);\n\t\tforeach (i; 0..w)\n\t\t{\n\t\t\tforeach (j; 0..other.h)\n\t\t\t{\n\t\t\t\tforeach (k; 0..h)\n\t\t\t\t{\n\t\t\t\t\tres[i, j] += this[i, k] * other[k, j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (this, \" * \", other, \" = \", res);}\n\t\tthis = res;\n\t\treturn this;\n\t}\n\n\tref T opIndex (int p, int q)\n\t{\n\t\treturn a[p * w + q];\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn \"[\" ~ to!string (w) ~ \" x \" ~ to!string (h) ~\n\t\t \": \" ~ to!string (a) ~ \"]\";\n\t}\n\n\t@property Matrix unity ()\n\t{\n\t\tenforce (w == h);\n\t\tMatrix res;\n\t\tforeach (i; 0..w)\n\t\t{\n\t\t\tres[i, i] = 1;\n\t\t}\n\t\treturn res;\n\t}\n}\n\nT pow (T, P) (T a, P b, T UNITY)\n{\n\tauto res = UNITY;\n\tdebug {writeln (\"res = \", res);}\n\tauto temp = a;\n\twhile (b > 0)\n\t{\n\t\tdebug {writeln (\"b = \", b);}\n\t\tif (b & 1)\n\t\t{\n\t\t\tres *= temp;\n\t\t\tdebug {writeln (\"res = \", res);}\n\t\t}\n\t\ttemp *= temp;\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nint conv (char c)\n{\n\tif (isLower (c))\n\t{\n\t\treturn c - 'a';\n\t}\n\tif (isUpper (c))\n\t{\n\t\treturn c - 'A' + 26;\n\t}\n\tassert (false);\n}\n\nvoid main ()\n{\n\tlong n;\n\tint m, k;\n\twhile (readf (\" %s %s %s\", &n, &m, &k) > 0)\n\t{\n\t\talias Z_P !(int, MOD) EType;\n\t\talias Matrix !(EType) MType;\n\t\tauto a = MType (m, m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\ta[i, j] = 1;\n\t\t\t}\n\t\t}\n\t\tforeach (i; 0..k)\n\t\t{\n\t\t\tchar u, v;\n\t\t\treadf (\" %s %s\", &u, &v);\n\t\t\ta[conv (u), conv (v)] = 0;\n\t\t}\n\t\tdebug {writeln (\"a: \", a);}\n\t\tauto unity = MType (m, m);\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tunity[i, i] = 1;\n\t\t}\n\t\tdebug {writeln (\"unity: \", unity);}\n\t\tauto b = pow (a, n - 1, unity);\n\t\tEType res;\n\t\tforeach (i; 0..m)\n\t\t{\n\t\t\tforeach (j; 0..m)\n\t\t\t{\n\t\t\t\tres += b[i, j];\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "11031ad43c34d4dca79eddab2342dce0"} {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(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 a = RDA(-1);\n\t\t\n\t\tauto cnt = new long[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\t++cnt[a[i]];\n\t\t}\n\n\t\tlong c1, c2;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (cnt[i] > 0)\n\t\t\t\t++c1;\n\t\t\tc2.chmax(cnt[i]);\n\t\t}\n\n\t\tif (c1 > c2)\n\t\t\tans[ti] = c2;\n\t\telse if (c1 == c2)\n\t\t\tans[ti] = c2-1;\n\t\telse\n\t\t\tans[ti] = c1;\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 (_; 0..T) {\n auto N = readln.chomp.to!int;\n auto ns = new int[](N);\n foreach (a; readln.split.to!(int[])) ++ns[a-1];\n int cnt, max_n;\n foreach (n; ns) if (n > 0) {\n ++cnt;\n max_n = max(max_n, n);\n }\n if (cnt < max_n) {\n writeln(cnt);\n } else if (max_n < cnt) {\n writeln(max_n);\n } else {\n writeln(cnt-1);\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\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint [int] d;\n\t\tforeach (ref c; a)\n\t\t{\n\t\t\td[c] += 1;\n\t\t}\n\t\tauto p = d.byValue.array;\n\t\tsort (p);\n\t\tint one = p.back;\n\t\tint two = p.length.to !(int);\n\t\tint res = min (one, two) - (one == two);\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) { 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(-1);\n\t\t\n\t\tauto cnt = new long[](n);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\t++cnt[a[i]];\n\t\t}\n\n\t\tlong c1, c2;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (cnt[i] > 0)\n\t\t\t\t++c1;\n\t\t\tc2.chmax(cnt[i]);\n\t\t}\n\n\t\tif (c1 > c2)\n\t\t\tans[ti] = c2;\n\t\telse\n\t\t\tans[ti] = c2-1;\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}"}], "src_uid": "a1951e7d11b504273765fc9fb2f18a5e"} {"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 G = new int[][](M, N);\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n G[x][y] = readInt();\n }\n \n int ans = int.max;\n int am = -1;\n \n foreach (a; 0 .. G[0][0] + 1) {\n auto rows = new int[M];\n auto cols = new int[N];\n rows[0] = a;\n cols[0] = G[0][0] - a;\n foreach (x; 1 .. M) {\n rows[x] = G[x][0] - cols[0];\n }\n foreach (y; 1 .. N) {\n cols[y] = G[0][y] - rows[0];\n }\n if (rows.all!\"a >= 0\" && cols.all!\"a >= 0\") {\n bool ok = true;\n foreach (x; 0 .. M) foreach (y; 0 .. N) {\n ok = ok && (G[x][y] == rows[x] + cols[y]);\n }\n if (ok) {\n const cost = rows.sum + cols.sum;\n if (chmin(ans, cost)) {\n am = a;\n }\n }\n }\n }\n \n if (am == -1) {\n writeln(-1);\n } else {\n auto rows = new int[M];\n auto cols = new int[N];\n rows[0] = am;\n cols[0] = G[0][0] - am;\n foreach (x; 1 .. M) {\n rows[x] = G[x][0] - cols[0];\n }\n foreach (y; 1 .. N) {\n cols[y] = G[0][y] - rows[0];\n }\n writeln(ans);\n foreach (x; 0 .. M) {\n foreach (_; 0 .. rows[x]) {\n writeln(\"row \", x + 1);\n }\n }\n foreach (y; 0 .. N) {\n foreach (_; 0 .. cols[y]) {\n writeln(\"col \", y + 1);\n }\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n", "positive_code": [{"source_code": "import std.stdio, std.algorithm;\n\nvoid main()\n{\n int n, m;\n readf(\"%d %d\", &n, &m);\n \n int[][] a = new int[][n];\n \n foreach (ref aa; a)\n {\n aa = new int[m];\n foreach (ref t; aa) readf(\" %d\", &t);\n }\n \n struct Result {bool row; int num; int count;}\n \n Result[] r = [];\n \n void f(bool row)\n {\n if (row)\n {\n for (int i = 0; i < n; i++)\n {\n int mn = int.max;\n \n for (int j = 0; j < m; j++) mn = min(a[i][j], mn);\n \n for (int j = 0; j < m; j++) a[i][j] -= mn;\n \n r ~= Result(row, i, mn);\n }\n }\n else\n {\n for (int i = 0; i < m; i++)\n {\n int mn = int.max;\n \n for (int j = 0; j < n; j++) mn = min(a[j][i], mn);\n \n for (int j = 0; j < n; j++) a[j][i] -= mn;\n \n r ~= Result(row, i, mn);\n }\n }\n }\n \n f(n <= m);\n f(!(n <= m));\n \n bool happened = true;\n \n loop: foreach (aa; a)\n {\n foreach (t; aa)\n {\n if (t != 0)\n {\n happened = false;\n break loop;\n }\n }\n }\n \n if (happened)\n {\n int count = 0;\n \n foreach (rr; r) count += rr.count;\n \n writeln(count);\n \n foreach (rr; r)\n {\n for (int i = 0; i < rr.count; i++)\n {\n writeln(rr.row ? \"row\" : \"col\", \" \", rr.num+1);\n }\n }\n }\n else\n {\n writeln(-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;\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.split.map!(to!int).array).array;\n auto C = new int[][](W, H);\n foreach (j; 0..W) foreach (i; 0..H) C[j][i] = B[i][j];\n\n int ans1 = 0;\n string[] ans1s;\n foreach (i; 0..H) {\n int m = B[i].reduce!min;\n ans1 += m;\n foreach (j; 0..W) B[i][j] -= m;\n foreach (_; 0..m) ans1s ~= \"row \" ~ (i + 1).to!string;\n }\n foreach (j; 0..W) {\n int m = 1 << 29;\n foreach (i; 0..H) m = min(m, B[i][j]);\n ans1 += m;\n foreach (i; 0..H) B[i][j] -= m;\n foreach (_; 0..m) ans1s ~= \"col \" ~ (j + 1).to!string;\n }\n\n foreach (i; 0..H) foreach (j; 0..W) if (B[i][j] != 0) ans1 = 1 << 29;\n\n swap(H, W);\n int ans2 = 0;\n string[] ans2s;\n foreach (i; 0..H) {\n int m = C[i].reduce!min;\n ans2 += m;\n foreach (j; 0..W) C[i][j] -= m;\n foreach (_; 0..m) ans2s ~= \"col \" ~ (i + 1).to!string;\n }\n foreach (j; 0..W) {\n int m = 1 << 29;\n foreach (i; 0..H) m = min(m, C[i][j]);\n ans2 += m;\n foreach (i; 0..H) C[i][j] -= m;\n foreach (_; 0..m) ans2s ~= \"row \" ~ (j + 1).to!string;\n }\n foreach (i; 0..H) foreach (j; 0..W) if (C[i][j] != 0) ans2 = 1 << 29;\n\n int ans;\n string[] anss;\n if (ans1 <= ans2) ans = ans1, anss = ans1s;\n else ans = ans2, anss = ans2s;\n\n if (ans == 1 << 29) {\n writeln(-1);\n return;\n }\n\n ans.writeln;\n foreach (i; 0..ans) anss[i].writeln;\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons;\n\nimmutable int inf = 10^^9 + 7;\n\nint n, m;\nint[][] g;\n\nvoid main() {\n scan(n, m);\n\n g = new int[][](n, m);\n iota(n).each!(i => g[i][] = readln.split.to!(int[]));\n\n int itrmax = g[0].reduce!min;\n\n int minm = inf;\n int[] rmmin = new int[](n), cmmin = new int[](m);\n\n foreach (k ; 0 .. itrmax + 1) {\n int move;\n int[] rm = new int[](n), cm = new int[](m);\n\n move = k;\n rm[0] = k;\n\n foreach (j ; 0 .. m) {\n move += g[0][j] - k;\n cm[j] = g[0][j] - k;\n }\n\n foreach (i ; 1 .. n) {\n int v = g[i][0] - cm[0];\n\n if (v < 0) {\n move = inf;\n break;\n }\n\n bool flag;\n\n foreach (j ; 1 .. m) {\n if (v != g[i][j] - cm[j]) {\n move = inf;\n flag = 1;\n break;\n }\n }\n\n if (flag) break;\n\n move += v;\n rm[i] = v;\n }\n\n debug {\n writeln(\"k:\", k);\n writeln(\"move:\", move);\n }\n\n if (move < minm) {\n minm = move;\n rmmin = rm.dup;\n cmmin = cm.dup;\n }\n }\n\n debug {\n }\n\n if (minm == inf) {\n writeln(-1);\n return;\n }\n\n writeln(minm);\n\n foreach (i ; 0 .. n) {\n foreach (k ; 0 .. rmmin[i]) {\n writefln(\"row %s\", i + 1);\n }\n }\n\n foreach (j ; 0 .. m) {\n foreach (k ; 0 .. cmmin[j]) {\n writefln(\"col %s\", j + 1);\n }\n }\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}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\nimport std.format;\n\nimmutable int max = 2 * 10^^5 + 10;\n\nint n, m;\nint[][] g;\n\nvoid main() {\n scan(n, m);\n\n bool swapped;\n\n if (n <= m) {\n g = new int[][](n, m);\n iota(n).each!(i => g[i][] = readln.split.to!(int[]));\n }\n else {\n swap(n, m);\n swapped = 1;\n\n g = new int[][](n, m);\n\n foreach (i ; 0 .. m) {\n auto line = readln.split.to!(int[]);\n\n foreach (j, e ; line) {\n g[j][i] = e;\n }\n }\n }\n\n debug {\n writeln(n, \" \", m);\n stderr.writefln(\"%(%(%s %)\\n%)\", g);\n }\n\n string[] ans;\n string i_s, con;\n\n foreach (i ; 0 .. n) {\n int x = g[i].reduce!min;\n g[i][] -= x;\n i_s = (i + 1).to!string;\n\n if (!swapped) con = \"row \" ~ i_s;\n else con = \"col \" ~ i_s;\n\n ans ~= repeat(con, x).array;\n }\n\n debug {\n writefln(\"%(%(%s %)\\n%)\", g);\n writeln(\"ans\", ans);\n }\n\n int x;\n\n foreach (j ; 0 .. m) {\n x = g[0][j];\n\n foreach (i ; 1 .. n) {\n if (x != g[i][j]) {\n writeln(-1);\n return;\n }\n }\n\n if (!swapped) con = \"col \" ~ (j + 1).to!string;\n else con = \"row \" ~ (j + 1).to!string;\n\n ans ~= repeat(con, x).array;\n }\n\n int k = ans.length.to!int;\n\n writeln(k);\n\n foreach (move ; ans) {\n writeln(move);\n }\n\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\nint n, m;\nint[][] g;\n\nvoid main() {\n scan(n, m);\n\n bool swapped;\n \n if (n <= m) {\n g = new int[][](n, m);\n iota(n).each!(i => g[i][] = readln.split.to!(int[]));\n }\n else {\n swap(n, m);\n swapped = 1;\n\n int[] line;\n\n g = new int[][](n, m);\n\n foreach (j ; 0 .. m) {\n line = readln.split.to!(int[]);\n\n foreach (i, e; line) {\n g[i][j] = e;\n }\n }\n }\n\n debug {\n writefln(\"n:%d, m:%d\", n, m);\n writefln(\"%(%(%s %)\\n%)\", g);\n }\n\n string[] ans;\n string rc;\n\n foreach (i ; 0 .. n) {\n int x = g[i].reduce!min;\n g[i][] -= x;\n\n if (!swapped) rc = \"row \";\n else rc = \"col \";\n\n ans ~= repeat(rc ~ (i + 1).to!string, x).array;\n }\n\n foreach (j ; 0 .. m) {\n int x = g[0][j];\n\n if (!(iota(n).map!(i => g[i][j] == x).reduce!\"a && b\")) {\n writeln(-1);\n return;\n }\n\n if (!swapped) rc = \"col \";\n else rc = \"row \";\n\n ans ~= repeat(rc ~ (j + 1).to!string, x).array;\n }\n\n writeln(ans.length);\n\n foreach (move ; ans) {\n writeln(move);\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 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, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n int[][] arr;\n foreach (_; 0 .. n) arr ~= readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n Tuple!(string, int)[] ans;\n \n void go(string descr) {\n foreach (i; 0 .. arr.length) {\n int ops = 500;\n foreach (j; 0 .. arr[i].length) {\n ops = min(ops, arr[i][j]);\n }\n foreach (_; 0 .. ops) ans ~= tuple(descr, cast(int)i+1);\n foreach (j; 0 .. arr[i].length) arr[i][j] -= ops;\n }\n }\n \n auto transposer = (int[][] arr) => arr.transposed().map!(t => t.array).array;\n \n if (n < m) {\n go(\"row\");\n arr = transposer(arr);\n go(\"col\");\n } else {\n arr = transposer(arr);\n go(\"col\");\n arr = transposer(arr);\n go(\"row\");\n }\n \n bool ok = arr.all!(r => r.all!(x => x == 0));\n if (!ok) {\n writeln(\"-1\");\n return;\n }\n \n ans.length.writeln;\n foreach (t; ans) {\n writeln(t[0], ' ', t[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\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n\n int[][] arr;\n foreach (_; 0 .. n) arr ~= readln.chomp.split.map!(to!int).array;\n \n debug { arr.writeln; }\n \n Tuple!(string, int)[] ans;\n \n void go(string descr) {\n foreach (i; 0 .. arr.length) {\n int ops = arr[i].minElement;\n ans ~= tuple(descr, cast(int)i+1).repeat(ops).array;\n arr[i][] -= ops;\n }\n }\n \n auto transposer = (int[][] arr) => arr.transposed().map!(t => t.array).array;\n \n if (n < m) {\n go(\"row\");\n arr = transposer(arr);\n go(\"col\");\n } else {\n arr = transposer(arr);\n go(\"col\");\n arr = transposer(arr);\n go(\"row\");\n }\n \n bool ok = arr.all!(r => r.all!(x => x == 0));\n if (!ok) {\n writeln(\"-1\");\n return;\n }\n \n ans.length.writeln;\n foreach (t; ans) {\n writeln(t[0], ' ', t[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\nvoid main ()\n{\n\tint rows, cols;\n\twhile (readf (\" %s %s\", &rows, &cols) > 0)\n\t{\n\t\treadln;\n\t\tint [] [] a;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\ta ~= readln.splitter.map !(to !(int)).array;\n\t\t}\n\t\tint w = a.map !(line => line.reduce !(min)).reduce !(min);\n\t\tforeach (ref line; a)\n\t\t{\n\t\t\tline[] -= w;\n\t\t}\n\n\t\tint [] rAdd;\n\t\tint [] cAdd;\nsolution_loop:\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] == 0)\n\t\t\t\t{\n\t\t\t\t\trAdd = a.transversal (col).array;\n\t\t\t\t\tcAdd = a[row].dup;\n\t\t\t\t\tbreak solution_loop;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tassert (rAdd.length == rows);\n\t\tassert (cAdd.length == cols);\n\n\t\tbool ok = true;\n\t\tforeach (row; 0..rows)\n\t\t{\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tok &= (a[row][col] == rAdd[row] + cAdd[col]);\n\t\t\t}\n\t\t}\n\n\t\tif (ok)\n\t\t{\n\t\t\twriteln (w * min (rows, cols) + rAdd.sum + cAdd.sum);\n\t\t\tif (rows < cols)\n\t\t\t{\n\t\t\t\trAdd[] += w;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcAdd[] += w;\n\t\t\t}\n\t\t\tforeach (row; 0..rows)\n\t\t\t{\n\t\t\t\tforeach (i; 0..rAdd[row])\n\t\t\t\t{\n\t\t\t\t\twriteln (\"row \", row + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tforeach (col; 0..cols)\n\t\t\t{\n\t\t\t\tforeach (i; 0..cAdd[col])\n\t\t\t\t{\n\t\t\t\t\twriteln (\"col \", col + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons;\n\nimmutable int inf = 10^^9 + 7;\n\nint n, m;\nint[][] g;\n\nvoid main() {\n scan(n, m);\n\n g = new int[][](n, m);\n iota(n).each!(i => g[i][] = readln.split.to!(int[]));\n\n int itrmax = g[0].reduce!min;\n\n int minm = inf;\n int[] rmmin = new int[](n), cmmin = new int[](m);\n\n foreach (k ; 0 .. itrmax + 1) {\n int move;\n int[] rm = new int[](n), cm = new int[](m);\n\n move = k;\n rm[0] = k;\n\n foreach (j ; 0 .. m) {\n move += g[0][j] - k;\n cm[j] = g[0][j] - k;\n }\n\n foreach (i ; 1 .. n) {\n int v = g[i][0] - cm[0];\n\n if (v < 0) {\n move = inf;\n break;\n }\n\n bool flag;\n\n foreach (j ; 1 .. m) {\n if (v != g[i][j] - cm[j]) {\n move = inf;\n flag = 1;\n break;\n }\n }\n\n if (flag) break;\n\n move += v;\n rm[i] = v;\n }\n\n debug {\n writeln(\"k:\", k);\n writeln(\"move:\", move);\n }\n\n if (move < minm) {\n minm = move;\n rmmin = rm.dup;\n cmmin = cm.dup;\n }\n }\n\n debug {\n }\n\n if (minm == inf) {\n writeln(-1);\n return;\n }\n\n writeln(minm);\n\n foreach (i ; 0 .. n) {\n foreach (k ; 0 .. rmmin[i]) {\n writefln(\"row %s\", i + 1);\n }\n }\n\n foreach (j ; 0 .. m) {\n foreach (k ; 0 .. cmmin[j]) {\n writefln(\"col %s\", j + 1);\n }\n }\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}"}], "negative_code": [], "src_uid": "b19ab2db46484f0c9b49cf261502bf64"} {"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\nint[] inv(int[] p) {\r\n auto inv_p = new int[p.length];\r\n foreach(i; 0 .. p.length) {\r\n inv_p[p[i]] = i;\r\n }\r\n return inv_p;\r\n}\r\n\r\nvoid main() {\r\n\r\n immutable mod = 10 ^^ 9 + 7;\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).map!(x => x - 1).array;\r\n int[] b = readln.splitter.map!(to!int).map!(x => x - 1).array;\r\n int[] ra = inv(a), rb = inv(b);\r\n int[] r = new int[n];\r\n foreach(i; 0 .. n) {\r\n\t\t\tr[i] = ra[b[i]];\r\n\t\t}\r\n\t\tbool[] vis = new bool[n];\r\n\t\tint ans = 1;\r\n\t\tforeach(i; 0 .. n) {\r\n\t\t\tif(!vis[i]) {\r\n\t\t\t\tint j = i;\r\n\t\t\t\tdo {\r\n\t\t\t\t\tvis[j] = true;\r\n\t\t\t\t\tj = r[j];\r\n\t\t\t\t} while (!vis[j]);\r\n\t\t\t\tans = (ans << 1) % mod;\r\n\t\t\t}\r\n\t\t}\r\n ans.writeln;\r\n }\r\n\r\n} // main", "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random, std.math, std.range;\n\nulong p = 1000000007;\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!(x => x.to!int - 1).array;\n auto b = readln.chomp.split.map!(x => x.to!int - 1).array;\n auto c = zip(a, b).sort!((x, y) => x[0] < y[0]);\n bool[] flag = new bool[](c.length);\n ulong result = 0;\n\n foreach (i ; 0 .. c.length) {\n if (!flag[i])\n result += 1;\n size_t j = i;\n while (!flag[j]) {\n flag[j] = true;\n j = c[j][1];\n }\n }\n writeln(powmod(2UL, result, p));\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 mod = 10 ^^ 9 + 7;\r\n\r\nint [] inv (int [] p)\r\n{\r\n\tauto res = new int [p.length];\r\n\tforeach (i; 0..p.length)\r\n\t{\r\n\t\tres[p[i]] = i;\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\tauto n = readln.strip.to !(int);\r\n\r\n\t\tauto p = readln.splitter.map !(to !(int)).array;\r\n\t\tp[] -= 1;\r\n\t\tauto rp = inv (p);\r\n\r\n\t\tauto q = readln.splitter.map !(to !(int)).array;\r\n\t\tq[] -= 1;\r\n\t\tauto rq = inv (q);\r\n\r\n\t\tauto r = new int [n];\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tr[i] = rp[q[i]];\r\n\t\t}\r\n\r\n\t\tauto vis = new bool [n];\r\n\t\tint res = 1;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (!vis[i])\r\n\t\t\t{\r\n\t\t\t\tint j = i;\r\n\t\t\t\tdo\r\n\t\t\t\t{\r\n\t\t\t\t\tvis[j] = true;\r\n\t\t\t\t\tj = r[j];\r\n\t\t\t\t}\r\n\t\t\t\twhile (!vis[j]);\r\n\t\t\t\tres = (res << 1) % mod;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\twriteln (res);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "3f1e2549d7342364b08f976fcbb7b1fa"} {"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\nalias Coord = Tuple !(int, q{r}, int, q{c});\r\n\r\nbool solve (int n, Coord a, Coord b, Coord c, Coord z)\r\n{\r\n\tif (a == z || b == z || c == z)\r\n\t{\r\n\t\treturn true;\r\n\t}\r\n\tauto d = Coord (a.r ^ b.r ^ c.r, a.c ^ b.c ^ c.c);\r\n\tif (d.r % 2 == z.r % 2 && d.c % 2 == z.c % 2)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tCoord e;\r\n\te.r = (a.r == b.r) ? a.r : (b.r == c.r) ? b.r : c.r;\r\n\te.c = (a.c == b.c) ? a.c : (b.c == c.c) ? b.c : c.c;\r\n\tbool corner = (e.r == 1 || e.r == n) && (e.c == 1 || e.c == n);\r\n\tif (corner)\r\n\t{\r\n\t\treturn (z.r == e.r || z.c == e.c);\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\tint n;\r\n\t\tCoord a, b, c, z;\r\n\t\treadf !(\" %s\") (n);\r\n\t\treadf !(\" %s %s\") (a.r, a.c);\r\n\t\treadf !(\" %s %s\") (b.r, b.c);\r\n\t\treadf !(\" %s %s\") (c.r, c.c);\r\n\t\treadf !(\" %s %s\") (z.r, z.c);\r\n\t\twriteln (solve (n, a, b, c, z) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "positive_code": [{"source_code": "import std.stdio;\r\nimport std.math;\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 = readln.chomp.to!int;\r\n auto cs = readln.chomp.split(\" \").map!(to!int).array;\r\n int[] ys = [cs[0], cs[2], cs[4]];\r\n int[] xs = [cs[1], cs[3], cs[5]];\r\n\r\n int Y, X; readf(\"%d %d\\n\", &Y, &X);\r\n\r\n int find_d(int[] ys) {\r\n int[int] cy;\r\n foreach (y; ys) {\r\n cy[y] = cy.get(y, 0) + 1;\r\n }\r\n foreach (k, v; cy) {\r\n if (v == 2) return k;\r\n }\r\n assert(false);\r\n }\r\n int y = find_d(ys);\r\n int x = find_d(xs);\r\n\r\n if ( (y == 1 || y == N) && (x == 1 || x == N) ) {\r\n // L-corner is at the corner of the board\r\n writeln(Y == y || X == x ? \"YES\" : \"NO\");\r\n } else {\r\n writeln( abs(Y - y) % 2 == 0 || abs(X - x) % 2 == 0 ? \"YES\" : \"NO\" );\r\n }\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": "e5a0005e0832e2ca3dd248f6aefb2238"} {"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 (_; 0 .. numCases) {\r\n const N = readInt();\r\n auto A = new long[N];\r\n foreach (i; 0 .. N) {\r\n A[i] = readLong();\r\n }\r\n \r\n bool ans = true;\r\n foreach (i; 0 .. N) {\r\n bool ok;\r\n for (long x = 2; x <= 2 + i && x <= 30; ++x) {\r\n ok = ok || (A[i] % x != 0);\r\n }\r\n ans = ans && ok;\r\n }\r\n writeln(ans ? \"YES\" : \"NO\");\r\n }\r\n }\r\n } catch (EOFException e) {\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 a = ma(n, readInt!int);\n\tlong m = 1;\n\tbool can = true;\n\tforeach(i, ai; a)\n\t{\n\t\tif (m <= 1_000_000_000L) m = m * (cast(long)i + 2) / gcd(m, cast(long)i + 2);\n\t\tcan = can && (ai % m != 0);\n\t}\n\tif (can) writeln(\"YES\"); else writeln(\"NO\");\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;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\n\r\nbool solve (int n, int [] a)\r\n{\r\n\tn = min (n, 30);\r\n\ta = a[0..n];\r\nremove_loop:\r\n\twhile (!a.empty)\r\n\t{\r\n\t\tforeach_reverse (i; 0..n)\r\n\t\t{\r\n\t\t\tif (a[i] % (i + 2) != 0)\r\n\t\t\t{\r\n\t\t\t\ta = a[0..i] ~ a[i + 1..$];\r\n\t\t\t\tn -= 1;\r\n\t\t\t\tcontinue remove_loop;\r\n\t\t\t}\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\twriteln (solve (n, a) ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\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 int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n if (i == n-1) readf!\"%d\\n\"(a[i]);\n else readf!\"%d \"(a[i]);\n }\n\n if (n == 1) {\n // writeln(a);\n if (a[0] % 2 != 0) writeln(\"YES\");\n else writeln(\"NO\");\n continue;\n }\n\n int[] m = new int[n];\n for (int i = 0; i < n; i++) {\n m[i] = a[i] % (i + 2);\n }\n\n bool possible = true;\n while (a.length > 0) {\n bool marked = false;\n // writeln(a);\n for (int i = cast(int) (a.length-1); i >= 0; i--) {\n if (a[i] % (i + 2) != 0) {\n a = a.remove(i);\n marked = true;\n break;\n }\n }\n if (!marked) {\n possible = false;\n break;\n }\n }\n\n if (possible) writeln(\"YES\");\n else writeln(\"NO\");\n }\n}\n\n/*\nthere exists a combination where\n\n\n\n*/\n"}], "negative_code": [], "src_uid": "080f29d4e2aa5bb9ee26d882362c8cd7"} {"source_code": "// https://codeforces.com/problemset/problem/115/A\nimport std.algorithm;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n\n int[] graph = new int[n+1];\n\n foreach(i; 1..n+1)\n graph[i] = readln.chomp.to!int;\n\n int[] depths = new int[n+1];\n\n foreach(i; 1..n+1) {\n int parent = graph[i];\n int depth = 1;\n\n while(parent != -1) {\n parent = graph[parent];\n depth += 1;\n }\n\n depths[i] = depth;\n }\n\n int maxima = -1;\n foreach(item; depths)\n maxima = max(maxima,item);\n maxima.writeln;\n}\n\n", "positive_code": [{"source_code": "// https://codeforces.com/problemset/problem/115/A\nimport std.algorithm;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n\n int[] graph = new int[n+1];\n\n foreach(i; 1..n+1)\n graph[i] = readln.chomp.to!int;\n\n int[] depths = new int[n+1];\n\n foreach(i; 1..n+1) {\n int parent = graph[i];\n int depth = 1;\n\n if(parent != -1 && depths[parent] != 0) {\n depths[i] = depths[parent]+1;\n continue;\n }\n\n while(parent != -1) {\n parent = graph[parent];\n depth += 1;\n }\n\n depths[i] = depth;\n }\n\n int maxima = maxElement(depths);\n maxima.writeln;\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/115/A\nimport std.algorithm;\nimport std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n\n int[] graph = new int[n+1];\n\n foreach(i; 1..n+1)\n graph[i] = readln.chomp.to!int;\n\n int[] depths = new int[n+1];\n\n foreach(i; 1..n+1) {\n int parent = graph[i];\n int depth = 1;\n\n if(parent != -1 && depths[parent] != 0) {\n depths[i] = depths[parent]+1;\n continue;\n }\n\n while(parent != -1) {\n parent = graph[parent];\n depth += 1;\n }\n\n depths[i] = depth;\n }\n\n int maxima = -1;\n foreach(item; depths)\n maxima = max(maxima,item);\n maxima.writeln;\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 auto n = readln.chomp.to!int;\n auto child = new int[][](n);\n auto roots = new int[](0);\n\n foreach(i ; 0 .. n){\n int pi = readln.chomp.to!int;\n\n if (pi == -1) roots ~= i;\n else child[pi - 1] ~= i;\n }\n\n int ans;\n\n foreach (root ; roots) {\n ans = max(ans, dfs(n, child, root));\n }\n\n writeln(ans + 1);\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}"}], "negative_code": [], "src_uid": "8d911f79dde31f2c6f62e73b925e6996"} {"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; readf!\"%s\\n\"(n);\r\n long ans, p = 2;\r\n foreach(d; [2, 3, 2, 5, 1, 7, 2, 3, 1, 11, 1, 13, 1, 1, 2, 17, 1, 19, 1, 1, 1, 23, 1, 5, 1, 3, 1, 29, 1, 31, 2, 1, 1, 1, 1, 37, 1, 1, 1, 41, 1, 43, 1, 1, 1, 47, 1, 7, 1, 1, 1, 53, 1, 1, 1, 1, 1, 59, 1, 61, 1, 1, 2, 1, 1, 67, 1, 1, 1, 71, 1, 73, 1, 1, 1, 77, 1, 79, 1]) {\r\n long q = n / d;\r\n ans = (ans + (n - q) * p) % mod;\r\n n = q;\r\n ++p;\r\n }\r\n ans.writeln;\r\n }\r\n\r\n} // main\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;\r\n\t\t\r\n\t\tlong x = 1;\r\n\t\tlong last = n;\r\n\t\tforeach (i; 2..n+10)\r\n\t\t{\r\n\t\t\tx = lcm(x, i);\r\n\t\t\tauto tmp = last - n / x;\r\n\t\t\ttmp.modm(i);\r\n\t\t\tans[ti].moda(tmp);\r\n\t\t\tlast = n / x;\r\n\t\t\tif (last == 0) break;\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": "2b15a299c25254f265cce106dffd6174"} {"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.random;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable double maxR = 1_500_000.0 - 1.0;\n\nalias Vector = Tuple !(double, q{x}, double, q{y});\n\nbool less (int a, int b)\n{\n\tauto at = atan2 (v[a].y, v[a].x);\n\tauto bt = atan2 (v[b].y, v[b].x);\n\tif (at != bt)\n\t{\n\t\treturn at < bt;\n\t}\n\treturn a < b;\n}\n\n__gshared Vector [] v;\n__gshared Vector total;\n__gshared int [] b;\n__gshared RedBlackTree !(int, less) t;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tv = new Vector [n + 1];\n\t\tforeach (ref c; v[0..n])\n\t\t{\n\t\t\tint x, y;\n\t\t\treadf (\" %s %s\", &x, &y);\n\t\t\tc = Vector (x, y);\n\t\t}\n\n\t\tb = new int [n];\n\t\tb[] = 1;\n\t\tt = redBlackTree !(less, int) ();\n\t\tv[n] = Vector (0, 0);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tif (uniform (0, 2))\n\t\t\t{\n\t\t\t\tb[i] *= -1;\n\t\t\t\tv[i].x *= -1;\n\t\t\t\tv[i].y *= -1;\n\t\t\t}\n\t\t\tv[n].x += v[i].x;\n\t\t\tv[n].y += v[i].y;\n\t\t\tt.insert (i);\n\t\t}\n\n\t\tbool relax (int cur)\n\t\t{\n\t\t\tauto next = v[n];\n\t\t\tnext.x -= 2 * v[cur].x;\n\t\t\tnext.y -= 2 * v[cur].y;\n\t\t\tdebug {writefln (\"relax %s %.0f %.0f %.0f %.0f \" ~\n\t\t\t \"%.10f %.10f\", cur, v[cur].x, v[cur].y,\n\t\t\t next.x, next.y, hypot (next.y, next.x),\n\t\t\t hypot (v[n].y, v[n].x)); stdout.flush;}\n\t\t\tif (hypot (next.y, next.x) < hypot (v[n].y, v[n].x))\n\t\t\t{\n\t\t\t\tt.removeKey (cur);\n\t\t\t\tb[cur] *= -1;\n\t\t\t\tv[cur].x *= -1;\n\t\t\t\tv[cur].y *= -1;\n\t\t\t\tt.insert (cur);\n\t\t\t\tv[n] = next;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\twhile (hypot (v[n].y, v[n].x) > maxR)\n\t\t{\n\t\t\tdebug {writefln (\"%.0f %.0f %.10f\", v[n].x, v[n].y,\n\t\t\t hypot (v[n].y, v[n].x)); stdout.flush;}\n\n\t\t\tauto lo = t.lowerBound (n);\n\t\t\tdebug {writeln (lo.empty);}\n\t\t\tif (relax (!lo.empty ? lo.back : t.back))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tauto hi = t.upperBound (n);\n\t\t\tdebug {writeln (hi.empty);}\n\t\t\tif (relax (!hi.empty ? hi.front : t.front))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tauto me = t.equalRange (n);\n\t\t\tdebug {writeln (me.empty);}\n\t\t\tif (relax (!me.empty ? me.front : t.back))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tassert (false);\n\t\t}\n\n\t\tdebug {writefln (\"%.0f %.0f %.10f\", v[n].x, v[n].y,\n\t\t hypot (v[n].y, v[n].x)); stdout.flush;}\n\t\twritefln (\"%(%s %)\", 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\nalias Pt = Tuple!(long, \"x\", long, \"y\", int, \"id\");\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto V = new Pt[N];\n foreach (i; 0 .. N) {\n V[i].x = readLong();\n V[i].y = readLong();\n V[i].id = i;\n }\n V.sort!((a, b) => (a.x^^2 + a.y^^2 < b.x^^2 + b.y^^2));\n debug {\n writeln(\"V = \", V);\n }\n \n auto ans = new int[N];\n \n ans[V[0].id] = +1;\n long x = V[0].x, y = V[0].y;\n if (N % 2 == 0) {\n foreach (s; [+1, -1]) {\n const xx = x + s * V[1].x;\n const yy = y + s * V[1].y;\n if (xx^^2 + yy^^2 <= 2 * (V[1].x^^2 + V[1].y^^2)) {\n debug {\n writeln(s, \" \", V[1]);\n writeln(xx, \" \", yy);\n }\n ans[V[1].id] = s;\n x = xx;\n y = yy;\n goto found2;\n }\n }\n assert(false);\n found2:\n }\n for (int i = (N % 2 == 0) ? 2 : 1; i < N; i += 2) {\n foreach (s; [+1, -1]) foreach (t; [+1, -1]) {\n const xx = x + s * V[i].x + t * V[i + 1].x;\n const yy = y + s * V[i].y + t * V[i + 1].y;\n if (xx^^2 + yy^^2 <= 2 * (V[i + 1].x^^2 + V[i + 1].y^^2)) {\n debug {\n writeln(s, \" \", V[i], \", \", t, \" \", V[i + 1]);\n writeln(xx, \" \", yy);\n }\n ans[V[i].id] = s;\n ans[V[i + 1].id] = t;\n x = xx;\n y = yy;\n goto found;\n }\n }\n assert(false);\n found:\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": "a37a92db3626b46c7af79e3eb991983a"} {"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 m = RD!int;\n\tauto a = RDA;\n\ta.sort();\n\n\tauto b = new long[](n+m);\n\tforeach (i; 0..n)\n\t{\n\t\tb[m+i] = b[i] + a[i];\n\t}\n\tauto ans = new long[](n+1);\n\tforeach (i; 0..n)\n\t{\n\t\tans[i+1] = ans[i] + a[i];\n\t\tans[i+1] += b[i];\n\t}\n\t\n\tans[1..$].map!(to!string).join(\" \").writeln;\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 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 A.sort();\n auto B = new long[](M);\n\n long ans = 0;\n\n foreach (i; 0..N) {\n ans += B[i % M] + A[i];\n B[i % M] += A[i];\n write(ans, \" \");\n }\n\n writeln;\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\tlong[] as = rlong(n);\n\tas.sort();\n\t\n\tlong[] sums = new long[](n);\n\tlong an;\n\tlong[] ans;\n\tforeach(k; 0 .. n){\n\t\tsums[k % m] += as[k];\n\t\tan += sums[k % m];\n\t\tans ~= an;\n\t}\n\t\n\tans.map!(to!string).array.join(\" \").writeln;\n}\n\n/*\n(k - 1 => k)\n\nsome sweets move from day d to day d + 1.\nthey are that of ( ~= k % m)-th order.\n\nus[k % m] = sum of ...\n\n\n\n*/\n"}], "negative_code": [], "src_uid": "af8ac55aa2594350226653c8d5ff47e4"} {"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 foreach (casenum ; 1 .. t + 1) {\n auto s = readln.strip;\n if ((s[$ - 1] - '0') % 2 == 0)\n writeln(0);\n else if ((s[0] - '0') % 2 == 0)\n writeln(1);\n else {\n bool good = false;\n foreach (ch ; s) {\n if ((ch - '0') % 2 == 0) {\n good = true;\n break;\n }\n }\n writeln(good ? 2 : -1);\n }\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\twriteln (s.back % 2 == 0 ? 0 :\r\n\t\t s.front % 2 == 0 ? 1 :\r\n\t\t s.canFind !(x => x % 2 == 0) ? 2 :\r\n\t\t -1);\r\n\t}\r\n}\r\n"}], "negative_code": [], "src_uid": "03e5f71810b10318fed344878d226a10"} {"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\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\nimmutable 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)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 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;}\nint sz(T)(T a) if(hasLength!T)\n{\n\treturn cast(int)a.length;\n}\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;\n\t//writeln(\"hello\");\nloop:while(read(n))\n\t{\n\t\tauto a=arread!int;\n\t\tsort(a);\n\t\tint pos=sz(a)-1;\n\t\tlong s=0,m=0;\n\t\twhile(pos>=0 && a[pos]>0)\n\t\t{\n\t\t\ts+=a[pos];\n\t\t\tif(a[pos]&1)m=a[pos];\n\t\t\tpos--;\n\t\t}\n\t\twhile(pos>=0 && a[pos]%2==0)pos--;\n\t\tif(pos<0)\n\t\t{\n\t\t\tif(s&1)writeln(s);\n\t\t\telse writeln(s-m);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(s&1)writeln(s);\n\t\t\telse writeln(max(s-(m==0?int.max:m),s+a[pos]));\n\t\t}\n\t}\n\t//debug system(\"pause\");\n}\n", "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.functional;\n\nimmutable int inf = 10^^9 + 7;\nint n;\nint[] a;\n\nvoid main() {\n scan(n);\n a = readln.split.to!(int[]);\n\n auto dp = new int[][](n + 1, 2);\n dp[0][0] = 0, dp[0][1] = -inf;\n\n foreach (i ; 0 .. n) {\n if (a[i] & 1) {\n dp[i + 1][0] = max(dp[i][0], dp[i][1] + a[i]);\n dp[i + 1][1] = max(dp[i][1], dp[i][0] + a[i]);\n }\n else {\n dp[i + 1][0] = max(dp[i][0], dp[i][0] + a[i]);\n dp[i + 1][1] = max(dp[i][1], dp[i][1] + a[i]);\n }\n }\n\n writeln(dp[n][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}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.functional;\n\nimmutable int inf = 10^^9 + 7;\nimmutable int c = 10^^4;\n\nint n;\nint[] a;\n\nvoid main() {\n scan(n);\n a = readln.split.to!(int[]);\n\n int e_max = 0, o_max = -inf;\n\n foreach (i ; 0 .. n) {\n int t_emax = e_max, t_omax = o_max;\n\n if ((a[i] + c) % 2 == 0) {\n e_max = max(e_max, e_max + a[i]);\n o_max = max(o_max, o_max + a[i]);\n }\n else {\n e_max = max(e_max, t_omax + a[i]);\n o_max = max(o_max, t_emax + a[i]);\n }\n\n debug {\n writeln(\"e_max:\", e_max);\n writeln(\"o_max:\", o_max);\n }\n }\n\n writeln(o_max);\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": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.functional;\n\nimmutable int inf = 10^^9 + 7;\nimmutable int c = 10^^4;\n\nint n;\nint[] a;\n\nvoid main() {\n scan(n);\n a = readln.split.to!(int[]);\n\n int e_max = 0, o_max = -inf;\n\n foreach (i ; 0 .. n) {\n if ((a[i] + c) % 2 == 0) {\n e_max = max(e_max, e_max + a[i]);\n o_max = max(o_max, o_max + a[i]);\n }\n else {\n e_max = max(e_max, o_max + a[i]);\n o_max = max(o_max, e_max + a[i]);\n }\n\n debug {\n writeln(\"e_max:\", e_max);\n writeln(\"o_max:\", o_max);\n }\n }\n\n writeln(o_max);\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}"}], "src_uid": "76dd49c5545770a1dfbb2da4140199c1"} {"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 Info {\n int sz;\n int[2][2] a;\n Info opBinary(string op)(Info f) const if (op == \"*\") {\n Info g;\n g.sz = sz + f.sz;\n foreach (x; 0 .. 2) foreach (y; 0 .. 2) {\n foreach (xx; 0 .. 2 - x) foreach (yy; 0 .. 2 - y) {\n g.a[x + xx][y + yy] += a[x][y] * f.a[xx][yy];\n }\n }\n return g;\n }\n Info up() const {\n Info f;\n f.sz = 1 + sz;\n f.a[0][1] += a[0][0];\n f.a[1][0] += a[0][0];\n f.a[1][1] += a[0][1];\n f.a[0][0] += a[1][0];\n f.a[0][1] += a[1][1];\n return f;\n }\n}\nInfo identity() {\n Info f;\n f.a[0][0] = 1;\n return f;\n}\n\nint N;\nint[] A, B;\n\nint[][] G;\nint[] par;\nInfo[] dp, DP;\n\nvoid dfs(int u, int p) {\n par[u] = p;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n dfs(v, u);\n }\n }\n Info f = identity;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n f = f * dp[v];\n }\n }\n dp[u] = f.up;\n}\n\nvoid DFS(int u, int p) {\n int[] vs;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n vs ~= v;\n }\n }\n const len = cast(int)(vs.length);\n auto ls = new Info[len + 1];\n auto rs = new Info[len + 1];\n ls[0] = rs[len] = identity;\n if (p != -1) {\n rs[len] = DP[u];\n }\n foreach (j; 0 .. len) {\n ls[j + 1] = ls[j] * dp[vs[j]];\n }\n foreach_reverse (j; 0 .. len) {\n rs[j] = dp[vs[j]] * rs[j + 1];\n }\n foreach (j; 0 .. len) {\n DP[vs[j]] = (ls[j] * rs[j + 1]).up;\n }\n foreach (j; 0 .. len) {\n DFS(vs[j], u);\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n N = 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 par = new int[N];\n dp = new Info[N];\n DP = new Info[N];\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 long ans;\n foreach (u; 0 .. N) {\n if (u != rt) {\n if (dp[u].a[0][0] && DP[u].a[0][0]) {\n ans += 1L * dp[u].sz * DP[u].sz;\n } else {\n ans += 1L * dp[u].a[0][1] * DP[u].a[0][1];\n }\n }\n }\n writeln(ans);\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 Info {\n int sz;\n int[2][2] a;\n Info opBinary(string op)(Info f) const if (op == \"*\") {\n Info g;\n g.sz = sz + f.sz;\n foreach (x; 0 .. 2) foreach (y; 0 .. 2) {\n foreach (xx; 0 .. 2 - x) foreach (yy; 0 .. 2 - y) {\n g.a[x + xx][y + yy] += a[x][y] * f.a[xx][yy];\n }\n }\n return g;\n }\n Info up() const {\n Info f;\n f.sz = 1 + sz;\n f.a[0][1] += a[0][0];\n f.a[1][0] += a[0][0];\n f.a[1][1] += a[0][1];\n f.a[0][0] += a[1][0];\n f.a[0][1] += a[1][1];\n return f;\n }\n}\nInfo identity() {\n Info f;\n f.a[0][0] = 1;\n return f;\n}\n\nint N;\nint[] A, B;\n\nint[][] G;\nint[] par;\nInfo[] dp, DP;\n\nvoid dfs(int u, int p) {\n par[u] = p;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n dfs(v, u);\n }\n }\n Info f = identity;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n f = f * dp[v];\n }\n }\n dp[u] = f.up;\n}\n\nInfo[] ls, rs;\nvoid DFS(int u, int p) {\n int[] vs;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n vs ~= v;\n }\n }\n const len = cast(int)(vs.length);\n ls[0] = rs[len] = identity;\n if (p != -1) {\n rs[len] = DP[u];\n }\n foreach (j; 0 .. len) {\n ls[j + 1] = ls[j] * dp[vs[j]];\n }\n foreach_reverse (j; 0 .. len) {\n rs[j] = dp[vs[j]] * rs[j + 1];\n }\n foreach (j; 0 .. len) {\n DP[vs[j]] = (ls[j] * rs[j + 1]).up;\n }\n foreach (j; 0 .. len) {\n DFS(vs[j], u);\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n N = 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 par = new int[N];\n dp = new Info[N];\n DP = new Info[N];\n const rt = 0;\n ls = new Info[N + 1];\n rs = new Info[N + 1];\n dfs(rt, -1);\n DFS(rt, -1);\n debug {\n writeln(\"rt = \", rt);\n writeln(\"dp = \", dp);\n writeln(\"DP = \", DP);\n }\n long ans;\n foreach (u; 0 .. N) {\n if (u != rt) {\n if (dp[u].a[0][0] && DP[u].a[0][0]) {\n ans += 1L * dp[u].sz * DP[u].sz;\n } else {\n ans += 1L * dp[u].a[0][1] * DP[u].a[0][1];\n }\n }\n }\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\nstruct Info {\n int sz;\n // int[2][2] a;\n int a00, a01, a10, a11;\n Info opBinary(string op)(Info f) const if (op == \"*\") {\n Info g;\n g.sz = sz + f.sz;\n /*\n foreach (x; 0 .. 2) foreach (y; 0 .. 2) {\n foreach (xx; 0 .. 2 - x) foreach (yy; 0 .. 2 - y) {\n g.a[x + xx][y + yy] += a[x][y] * f.a[xx][yy];\n }\n }\n */\n g.a00 += a00 * f.a00;\n g.a01 += a00 * f.a01;\n g.a10 += a00 * f.a10;\n g.a11 += a00 * f.a11;\n g.a01 += a01 * f.a00;\n g.a11 += a01 * f.a10;\n g.a10 += a10 * f.a00;\n g.a11 += a10 * f.a01;\n g.a11 += a11 * f.a00;\n return g;\n }\n Info up() const {\n Info f;\n f.sz = 1 + sz;\n // f.a[0][1] += a[0][0];\n // f.a[1][0] += a[0][0];\n // f.a[1][1] += a[0][1];\n // f.a[0][0] += a[1][0];\n // f.a[0][1] += a[1][1];\n f.a01 += a00;\n f.a10 += a00;\n f.a11 += a01;\n f.a00 += a10;\n f.a01 += a11;\n return f;\n }\n}\nInfo identity() {\n Info f;\n // f.a[0][0] = 1;\n f.a00 = 1;\n return f;\n}\n\nint N;\nint[] A, B;\n\nint[][] G;\nint[] par;\nInfo[] dp, DP;\n\nvoid dfs(int u, int p) {\n par[u] = p;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n dfs(v, u);\n }\n }\n Info f = identity;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n f = f * dp[v];\n }\n }\n dp[u] = f.up;\n}\n\nvoid DFS(int u, int p) {\n int[] vs;\n foreach (i; G[u]) {\n const v = A[i] ^ B[i] ^ u;\n if (v != p) {\n vs ~= v;\n }\n }\n const len = cast(int)(vs.length);\n auto ls = new Info[len + 1];\n auto rs = new Info[len + 1];\n ls[0] = rs[len] = identity;\n if (p != -1) {\n rs[len] = DP[u];\n }\n foreach (j; 0 .. len) {\n ls[j + 1] = ls[j] * dp[vs[j]];\n }\n foreach_reverse (j; 0 .. len) {\n rs[j] = dp[vs[j]] * rs[j + 1];\n }\n foreach (j; 0 .. len) {\n DP[vs[j]] = (ls[j] * rs[j + 1]).up;\n }\n foreach (j; 0 .. len) {\n DFS(vs[j], u);\n }\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n N = 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 par = new int[N];\n dp = new Info[N];\n DP = new Info[N];\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 long ans;\n foreach (u; 0 .. N) {\n if (u != rt) {\n // if (dp[u].a[0][0] && DP[u].a[0][0]) {\n if (dp[u].a00 && DP[u].a00) {\n ans += 1L * dp[u].sz * DP[u].sz;\n } else {\n ans += 1L * dp[u].a01 * DP[u].a01;\n }\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "afdd617d7231daa7e07e6dfca44e5adf"} {"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\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 if (uf[u] != r) {\n history ~= KV(u, uf[u]);\n uf[u] = r;\n }\n return 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 history ~= KV(v, uf[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 N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n auto W = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n W[i] = readInt();\n }\n const Q = readInt();\n auto K = new int[Q];\n auto E = new int[][Q];\n foreach (q; 0 .. Q) {\n K[q] = readInt();\n E[q] = new int[K[q]];\n foreach (k; 0 .. K[q]) {\n E[q][k] = readInt() - 1;\n }\n }\n \n const limW = W.maxElement + 1;\n auto edgess = new int[][limW];\n foreach (i; 0 .. M) {\n edgess[W[i]] ~= i;\n }\n alias QK = Tuple!(int, \"q\", int, \"k\");\n auto qkss = new QK[][limW];\n foreach (q; 0 .. Q) {\n foreach (k; 0 .. K[q]) {\n qkss[W[E[q][k]]] ~= QK(q, k);\n }\n }\n \n auto ans = new bool[Q];\n ans[] = true;\n auto uf = new int[N];\n uf[] = -1;\n foreach (w; 0 .. limW) {\n auto qks = qkss[w];\n const len = cast(int)(qks.length);\n for (int j = 0, k; j < len; j = k) {\n for (k = j; k < len && qks[j].q == qks[k].q; ++k) {}\n history = [];\n foreach (l; j .. k) {\n const e = E[qks[l].q][qks[l].k];\n if (!uf.connect(U[e], V[e])) {\n ans[qks[l].q] = false;\n }\n }\n foreach_reverse (kv; history) {\n uf[kv.key] = kv.val;\n }\n }\n foreach (i; edgess[w]) {\n uf.connect(U[i], V[i]);\n }\n }\n \n foreach (q; 0 .. Q) {\n writeln(ans[q] ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\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;\nimport std.typecons;\n\nimmutable int maxW = 500_009;\n\nalias Edge = Tuple !(int, q{u}, int, q{v}, int, q{w});\nalias Record = Tuple !(int, q{v}, int, q{p}, int, q{r});\n\nvoid solve (int n, int m, Edge [] e, int qn, int [] [] q)\n{\n\tauto order = m.iota.array;\n\tmakeIndex !((a, b) => a.w < b.w) (e, order);\n\n\tforeach (ref query; q)\n\t{\n\t\tschwartzSort !(a => e[a].w) (query);\n\t}\n\n\tauto hasW = new int [] [maxW];\n\tforeach (k, ref query; q)\n\t{\n\t\tint [] d;\n\t\tforeach (c; query)\n\t\t{\n\t\t\td ~= e[c].w;\n\t\t}\n//\t\tsort (d);\n\t\tforeach (w; uniq (d))\n\t\t{\n\t\t\thasW[w] ~= k;\n\t\t}\n\t}\n\tdebug\n\t{\n\t\tforeach (w; 0..maxW)\n\t\t{\n\t\t\tif (!hasW[w].empty)\n\t\t\t{\n\t\t\t\twriteln (w, \": \", hasW[w]);\n\t\t\t}\n\t\t}\n\t}\n\n\tauto p = n.iota.array;\n\tauto r = new int [n];\n\n\tint root (int v)\n\t{\n\t\twhile (v != p[v])\n\t\t{\n\t\t\tv = p[v];\n\t\t}\n\t\treturn v;\n\t}\n\n\tRecord [] backups;\n\n\tbool unite (int u, int v, bool doBackup)\n\t{\n\t\tu = root (u);\n\t\tv = root (v);\n\t\tif (u == v)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t\tif (r[u] > r[v])\n\t\t{\n\t\t\tswap (u, v);\n\t\t}\n\t\tif (doBackup)\n\t\t{\n\t\t\tbackups ~= Record (u, p[u], r[u]);\n\t\t\tbackups ~= Record (v, p[v], r[v]);\n\t\t}\n\t\tp[u] = v;\n\t\tif (r[u] == r[v])\n\t\t{\n\t\t\tr[v] += 1;\n\t\t}\n\t\treturn true;\n\t}\n\n\tvoid restoreBackups ()\n\t{\n\t\tforeach_reverse (backup; backups)\n\t\t{\n\t\t\tp[backup.v] = backup.p;\n\t\t\tr[backup.v] = backup.r;\n\t\t}\n\t\tbackups.length = 0;\n\t}\n\n\tauto res = new bool [qn];\n\tres[] = true;\n\n\tint prevW = -1;\n\tforeach (j; 0..m)\n\t{\n\t\tint y = order[j];\n\t\tint curW = e[y].w;\n\t\tif (prevW != curW)\n\t\t{\n\t\t\tforeach (k; hasW[curW])\n\t\t\t{\n\t\t\t\twhile (!q[k].empty && e[q[k].front].w == curW)\n\t\t\t\t{\n\t\t\t\t\tint x = q[k].front;\n\t\t\t\t\tq[k].popFront ();\n\t\t\t\t\tif (!unite (e[x].u, e[x].v, true))\n\t\t\t\t\t{\n\t\t\t\t\t\tres[k] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\trestoreBackups ();\n\t\t\t}\n\t\t\tprevW = curW;\n\t\t}\n\t\tunite (e[y].u, e[y].v, false);\n\t}\n\n\tforeach (c; res)\n\t{\n\t\twriteln (c ? \"YES\" : \"NO\");\n\t}\n}\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\tauto e = new Edge [m];\n\t\tforeach (ref edge; e)\n\t\t{\n\t\t\treadf (\" %s %s %s\", &edge.u, &edge.v, &edge.w);\n\t\t\tedge.u -= 1;\n\t\t\tedge.v -= 1;\n\t\t}\n\n\t\tint qn;\n\t\treadf (\" %s\", &qn);\n\t\treadln;\n\t\tauto q = new int [] [qn];\n\t\tforeach (ref query; q)\n\t\t{\n\t\t\tquery = readln.splitter.drop (1)\n\t\t\t .map !(to !(int)).array;\n\t\t\tquery[] -= 1;\n\t\t}\n\n\t\tsolve (n, m, e, qn, q);\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\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 N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n auto W = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n W[i] = readInt();\n }\n const Q = readInt();\n auto K = new int[Q];\n auto E = new int[][Q];\n foreach (q; 0 .. Q) {\n K[q] = readInt();\n E[q] = new int[K[q]];\n foreach (k; 0 .. K[q]) {\n E[q][k] = readInt() - 1;\n }\n }\n \n const limW = W.maxElement + 1;\n auto edgess = new int[][limW];\n foreach (i; 0 .. M) {\n edgess[W[i]] ~= i;\n }\n alias QK = Tuple!(int, \"q\", int, \"k\");\n auto qkss = new QK[][limW];\n foreach (q; 0 .. Q) {\n foreach (k; 0 .. K[q]) {\n qkss[W[E[q][k]]] ~= QK(q, k);\n }\n }\n \n auto ans = new bool[Q];\n ans[] = true;\n auto uf = new int[N];\n uf[] = -1;\n auto saves = new int[N];\n foreach (w; 0 .. limW) {\n auto qks = qkss[w];\n const len = cast(int)(qks.length);\n for (int j = 0, k; j < len; j = k) {\n for (k = j; k < len && qks[j].q == qks[k].q; ++k) {}\n foreach (l; j .. k) {\n const e = E[qks[l].q][qks[l].k];\n saves[U[e]] = uf[U[e]];\n saves[V[e]] = uf[V[e]];\n }\n foreach (l; j .. k) {\n const e = E[qks[l].q][qks[l].k];\n if (!uf.connect(U[e], V[e])) {\n ans[qks[l].q] = false;\n }\n }\n foreach (l; j .. k) {\n const e = E[qks[l].q][qks[l].k];\n uf[U[e]] = saves[U[e]];\n uf[V[e]] = saves[V[e]];\n }\n }\n foreach (i; edgess[w]) {\n uf.connect(U[i], V[i]);\n }\n }\n \n foreach (q; 0 .. Q) {\n writeln(ans[q] ? \"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\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 if (uf[u] != r) {\n history ~= KV(u, r);\n uf[u] = r;\n }\n return 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 history ~= KV(v, uf[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 N = readInt();\n const M = readInt();\n auto U = new int[M];\n auto V = new int[M];\n auto W = new int[M];\n foreach (i; 0 .. M) {\n U[i] = readInt() - 1;\n V[i] = readInt() - 1;\n W[i] = readInt();\n }\n const Q = readInt();\n auto K = new int[Q];\n auto E = new int[][Q];\n foreach (q; 0 .. Q) {\n K[q] = readInt();\n E[q] = new int[K[q]];\n foreach (k; 0 .. K[q]) {\n E[q][k] = readInt() - 1;\n }\n }\n \n const limW = W.maxElement + 1;\n auto edgess = new int[][limW];\n foreach (i; 0 .. M) {\n edgess[W[i]] ~= i;\n }\n alias QK = Tuple!(int, \"q\", int, \"k\");\n auto qkss = new QK[][limW];\n foreach (q; 0 .. Q) {\n foreach (k; 0 .. K[q]) {\n qkss[W[E[q][k]]] ~= QK(q, k);\n }\n }\n \n auto ans = new bool[Q];\n ans[] = true;\n auto uf = new int[N];\n uf[] = -1;\n foreach (w; 0 .. limW) {\n auto qks = qkss[w];\n const len = cast(int)(qks.length);\n for (int j = 0, k; j < len; j = k) {\n for (k = j; k < len && qks[j].q == qks[k].q; ++k) {}\n history = [];\n foreach (l; j .. k) {\n const e = E[qks[l].q][qks[l].k];\n if (!uf.connect(U[e], V[e])) {\n ans[qks[l].q] = false;\n }\n }\n foreach_reverse (kv; history) {\n uf[kv.key] = kv.val;\n }\n }\n foreach (i; edgess[w]) {\n uf.connect(U[i], V[i]);\n }\n }\n \n foreach (q; 0 .. Q) {\n writeln(ans[q] ? \"YES\" : \"NO\");\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "21a1aada3570f42093c7ed4e06f0766d"} {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main() {\n int M;\n readf(\" %s\", &M);\n int[] Q = new int[M];\n foreach (ref q; Q) \n readf(\" %s\", &q);\n int use = reduce!(min)(Q);\n\n int N;\n readf(\" %s\", &N);\n int[] A = new int[N];\n foreach (ref a; A)\n readf(\" %s\", &a);\n sort!(\"a > b\")(A);\n\n long ans = 0;\n foreach (i, a; A) {\n auto m = i % (use + 2);\n if (m < use)\n ans += a;\n }\n writeln(ans);\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 m;\nint[] q;\nint n;\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\tm.next;\n\tq = q.init;\n\tforeach(i; m.iota){\n\t\tq ~= next!int();\n\t}\n\tn.next;\n\ta = a.init;\n\tforeach(i; n.iota){\n\t\ta ~= next!int();\n\t}\n\n\tq = q.sort;\n\ta = a.sort.retro.array;\n\t\n\tint cnt;\n\tint sum;\n\tfor(int i=0; i= q[0] ){\n\t\t\t++i;\n\t\t\tcnt = 0;\n\t\t}else{\n\t\t\tsum += a[i];\n\t\t\t++cnt;\n\t\t}\n\t}\n\t\n\tsum.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.algorithm;\nimport std.stdio;\n\nvoid main() {\n int M;\n readf(\" %s\", &M);\n int[] Q = new int[M];\n foreach (ref q; Q) \n readf(\" %s\", &q);\n int use = reduce!(min)(Q);\n\n int N;\n readf(\" %s\", &N);\n int[] A = new int[N];\n foreach (ref a; A)\n readf(\" %s\", &a);\n sort!(\"a > b\")(A);\n\n long ans = 0;\n foreach (i, a; A) {\n auto m = i % (use + 2);\n if (m < use)\n ans += a;\n }\n writeln(ans);\n}\n"}], "negative_code": [], "src_uid": "08803b63ae803e4a76afe7258a4004aa"} {"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 [int] cnt;\n arr.each!(x => ++cnt[x]);\n \n debug { cnt.writeln; }\n \n auto vals = cnt.values.sort().retro().array;\n \n auto ans = 0, cur = int.max;\n foreach (i, v; vals) {\n if (cur == 1) break;\n \n auto nxt = min(v, cur / 2);\n auto now = (2^^(i+1) - 1) * nxt;\n \n debug { writeln(nxt, ' ', now); }\n \n ans = max(ans, now.to!int);\n cur = nxt;\n }\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.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 [int] cnt;\n arr.each!(x => ++cnt[x]);\n \n debug { cnt.writeln; }\n \n auto vals = cnt.values.sort().retro().array;\n \n auto ans = 0, cur = int.max;\n foreach (i, v; vals.enumerate(1)) {\n if (cur == 1) break;\n \n auto nxt = min(v, cur / 2);\n auto now = i.iota.map!(x => nxt * 2^^x).sum;\n \n debug { writeln(nxt, ' ', now); }\n \n ans = max(ans, now);\n cur = nxt;\n }\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 arr = readln.chomp.split.map!(to!int).array;\n \n int [int] cnt;\n arr.each!(x => ++cnt[x]);\n \n debug { cnt.writeln; }\n \n auto vals = cnt.values.sort().retro().array;\n \n auto ans = 0, cur = int.max;\n foreach (i, v; vals.enumerate(1)) {\n if (cur == 1) break;\n \n auto nxt = min(v, cur / 2);\n auto now = (2^^i - 1) * nxt;\n \n debug { writeln(nxt, ' ', now); }\n \n ans = max(ans, now);\n cur = nxt;\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "7b12845f668e28b7f18019d5ab5eaec7"} {"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.front == a.minElement ? \"Yes\" : \"No\");\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 auto n = readln.strip.to!long;\n auto a = readln.splitter.map!(to!long).array;\n writeln (a[0] == 1 ? \"Yes\" : \"No\");\n }\n}\n"}], "negative_code": [], "src_uid": "76b3667cce9e23675e21caf6926f608d"} {"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 notestcases = next!int;\n testcaseloop:foreach(testcase; 0 .. notestcases)\n {\n auto n = next!int;\n auto m = next!int;\n auto a = next!int;\n auto b = next!int;\n if (a * n != b * m)\n\t{\n\t println(\"NO\");\n\t continue testcaseloop;\n\t}\n println(\"YES\");\n auto res = new int[][](n, m);\n foreach(row; 0 .. n)\n\t{\n\t auto startcol = (row * a) % m;\n\t foreach(delta; 0 .. a)\n\t res[row][(startcol + delta) % m] = 1;\n\t}\n foreach(row; res)\n\t{\n\t foreach(element; row)\n\t write(element);\n\t writeln;\n\t}\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.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 notestcases = next!int;\n testcaseloop:foreach(testcase; 0 .. notestcases)\n {\n auto n = next!int;\n auto m = next!int;\n auto a = next!int;\n auto b = next!int;\n if (a * n != b * m)\n\t{\n\t println(\"NO\");\n\t continue testcaseloop;\n\t}\n println(\"YES\");\n auto res = new int[][](n, m);\n int col = 0;\n foreach(row; 0 .. n)\n\t{\n\t foreach(d; 0 .. a)\n\t {\n\t res[row][col] = 1;\n\t col++; if (col == m) col = 0;\n\t }\n\t}\n foreach(row; res)\n\t{\n\t foreach(element; row)\n\t write(element);\n\t writeln;\n\t}\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"}], "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;\n\nvoid main(string[] args)\n{\n auto notestcases = next!int;\n testcaseloop:foreach(testcase; 0 .. notestcases)\n {\n auto n = next!int;\n auto m = next!int;\n auto a = next!int;\n auto b = next!int;\n if (a * n != b * m)\n\t{\n\t println(\"NO\");\n\t continue testcaseloop;\n\t}\n println(\"YES\");\n auto res = new int[][](n, m);\n foreach(row; 0 .. n)\n\t{\n\t auto startcol = (row * a) % m;\n\t res[row][startcol .. startcol + a] = 1;\n\t}\n foreach(row; res)\n\t{\n\t foreach(element; row)\n\t write(element);\n\t writeln;\n\t}\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;\n\nvoid main(string[] args)\n{\n auto notestcases = next!int;\n testcaseloop:foreach(testcase; 0 .. notestcases)\n {\n auto n = next!int;\n auto m = next!int;\n auto a = next!int;\n auto b = next!int;\n if (a * n != b * m)\n\t{\n\t println(\"NO\");\n\t continue testcaseloop;\n\t}\n println(\"YES\");\n auto res = new int[][](n, m);\n foreach(row; 0 .. n)\n\t{\n\t auto startcol = (row * a) % m;\n\t res[row][startcol .. startcol + a] = 1;\n\t}\n foreach(row; res)\n\tprintln(row);\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.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, a, b;\n\n void solve(long tc = -1)\n {\n if (m % a != 0 || n % b != 0 || m / a != n / b)\n {\n writeln(\"NO\");\n return;\n }\n auto t = m / a;\n auto sol = makeSlice!long(n, m);\n foreach(ti; 0 .. t)\n {\n foreach(ai; 0 .. a)\n foreach(bi; 0 .. b)\n {\n sol.at(ti * b + bi).at(ti * a + ai) = 1;\n }\n }\n writeln(\"YES\");\n foreach(row; sol)\n {\n foreach(bit; row)\n write(bit);\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"}, {"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, a, b;\n\n void solve(long tc = -1)\n {\n if (m % a != 0 || n % b != 0 || m / a != n / b)\n {\n writeln(\"NO\");\n return;\n }\n auto t = m / a;\n auto sol = makeSlice!long(n, m);\n foreach(ti; 0 .. t)\n {\n foreach(ai; 0 .. a)\n foreach(bi; 0 .. b)\n {\n sol.at(ti * b + bi).at(ti * a + ai) = 1;\n }\n }\n writeln(\"YES\");\n foreach(row; sol)\n {\n foreach(bit; row)\n write(bit, \" \");\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"}], "src_uid": "8aa648ff5adc0cf7b20fea52d2c34759"} {"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, q;\r\n\t\treadf !(\" %s %s\") (n, q);\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\t\tauto s = [0];\r\n\t\tforeach (ref c; a)\r\n\t\t{\r\n\t\t\ts ~= s.back + c;\r\n\t\t}\r\n\t\tauto t = s.assumeSorted ();\r\n\t\tforeach (j; 0..q)\r\n\t\t{\r\n\t\t\tauto cur = readln.strip.to !(int);\r\n\t\t\tauto len = t.lowerBound (cur).length.to !(int);\r\n\t\t\twriteln ((t.back < cur) ? -1 : len);\r\n\t\t}\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 QN = scan!int;\r\n auto A = scan!long(N);\r\n auto Q = scan!long(QN);\r\n\r\n A.sort!\"a > b\";\r\n auto acc = A.cumulativeFold!\"a + b\".array.assumeSorted;\r\n // acc.deb;\r\n\r\n foreach(q; Q) {\r\n auto l = acc.upperBound(q - 1);\r\n // l.deb;\r\n writefln(\"%s\", l.empty ? -1 : N - l.length.signed + 1);\r\n }\r\n }\r\n\r\n foreach(i; 0..QN) {\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, 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>>\".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": "a3df5d51538658e8c9356f9e848debcf"}