{"source_code": "import std.stdio;\n\nimmutable int MOD = 1_000_000_007;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m))\n\t{\n\t\tauto f = new long [] [n + 1];\n\t\tforeach (p; 0..n + 1)\n\t\t{\n\t\t\tf[p] = new long [m + 1];\n\t\t}\n\t\tforeach (p; 1..n + 1)\n\t\t{\n\t\t\tlong cur;\n\t\t\tforeach (d; 2..m + 1)\n\t\t\t{\n\t\t\t\tcur += f[p - 1][d];\n\t\t\t\tf[p][d] = f[p][d - 1] + cur;\n\t\t\t\tif (d == 2)\n\t\t\t\t{\n\t\t\t\t\tf[p][d] += 1;\n\t\t\t\t}\n\t\t\t\tf[p][d] %= MOD;\n\t\t\t}\n\t\t}\n\n\t\tlong res;\n\t\tforeach (d; 2..m + 1)\n\t\t{\n\t\t\tlong cur;\n\t\t\tforeach (p; 1..n + 1)\n\t\t\t{\n\t\t\t\tcur += f[p][d] *\n\t\t\t\t       (f[n - p + 1][d] - f[n - p][d]);\n\t\t\t\tcur %= MOD;\n\t\t\t}\n\t\t\tcur *= m - d + 1;\n\t\t\tres += cur;\n\t\t}\n\n\t\twriteln (res % MOD);\n\t}\n}\n", "src_uid": "9ca1ad2fa16ca81e9ab5eba220b162c1"}
{"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.numeric;\n\nimmutable long inf = 10L^^13;\nlong x, y;\n\nvoid main() {\n    scan(x, y);\n\n    auto xf = factrize(x);\n\n    debug {\n        writeln(\"xf:\", xf);\n    }\n\n    long ans;\n\n    while (y > 0) {\n        long g = gcd(x, y);\n\n        if (g == x) {\n            ans += y / g;\n            break;\n        }\n        \n        long m = inf;\n\n        foreach (p ; xf) {\n            long mp = (y - (y / (p * g)) * p * g) / g;\n            if (0 < mp && mp < m) {\n                m = mp;\n            }\n        }\n\n        ans += m;\n        y = y - m * g;\n    }\n\n    writeln(ans);\n}\n\nauto factrize(long x) {\n    auto res = new long[](0);\n\n    for (long p = 2; p*p <= x; p++) {\n        if (x % p == 0) {\n            res ~= p;\n            while (x % p == 0) {\n                x /= p;\n            }\n        }\n    }\n\n    if (x > 1) {\n        res ~= x;\n    }\n\n    return res;\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": "ea92cd905e9725e7fcb87b9ed4f64c2e"}
{"source_code": "import std.stdio;\n\nvoid main()\n{\n    int h, m;\n    readf(\"%d%*c%d\", &h, &m);\n    \n    int r = 0;\n    \n    while (h / 10 != m % 10 || h % 10 != m / 10)\n    {\n        m++;\n        \n        if (m == 60)\n        {\n            m = 0;\n            h++;\n            h %= 24;\n        }\n        \n        r++;\n    }\n    \n    writeln(r);\n}", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"}
{"source_code": "import std.stdio,std.algorithm,std.range,std.conv;\n\nauto lines(dstring[] f){\n\tdstring[] r;\n\tforeach(i;0..10){\n\t\tforeach(j;0..10){\n\t\t\tif(j+5<=10) r~=f[i][j..j+5];\n\t\t\tif(i+5<=10) r~=f[i..i+5].map!(x=>x[j]).to!dstring;\n\t\t\tif(i+5<=10&&j+5<=10)\n\t\t\t\tr~=iota(5).map!(x=>f[i+x][j+x]).to!dstring;\n\t\t\tif(i+5<=10&&j>=4)\n\t\t\t\tr~=iota(5).map!(x=>f[i+x][j-x]).to!dstring;\n\t\t}\n\t}\n\treturn r;\n}\n\nvoid main(){\n\tauto field=stdin.byLineCopy.map!(to!dstring).array;\n\twriteln(field.lines.any!(r=>r.count('X')==4&&r.count('.')==1)?\"YES\":\"NO\");\n}\n", "src_uid": "d5541028a2753c758322c440bdbf9ec6"}
{"source_code": "import std.stdio, std.string, std.math;\n\nint check(long num, long n, long m, long k)\n{\n    long cnt = 0, i;\n    for (i = 1; i <= n && i <= num; ++ i)\n    {\n        cnt += fmin(num / i, m);\n    }\n    for (i = 1; i <= m && i <= num; ++ i)\n    {\n        cnt += fmin(num / i, n);\n    }\n    cnt >>= 1;\n    /*\n    if (cnt > k) return 1;\n    if (cnt == k) return 0;\n    return -1;\n    */\n    if (cnt >= k) return 1;\n    return 0;\n}\n\nvoid solve(int n, int m, long k)\n{\n    long left = 1, right = cast(long)n * m;\n    long ans = -1;\n    while (left <= right)\n    {\n        auto mid = (left + right) >> 1;\n        auto res = check(mid, n, m, k);\n        /*\n        if (res == 0)\n        {\n            writeln(mid);\n            return;\n        }\n        else if (res < 0)\n        {\n            left = mid + 1;\n        }\n        else\n        {\n            ans = mid;\n            right = mid - 1;\n        }\n        */\n        if (res)\n        {\n            ans = mid;\n            right = mid - 1;\n        }\n        else\n        {\n            left = mid + 1;\n        }\n    }\n    writeln(ans);\n}\n\nvoid main(string[] args)\n{\n    int n, m;\n    long k;\n    while (scanf(\"%d%d%lld\", &n, &m, &k) == 3)\n    {\n        solve(n, m, k);\n    }\n}\n", "src_uid": "13a918eca30799b240ceb9de47507a26"}
{"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint c=0;\n\twhile(a!=0)\n\t{\n\t\tif (a>=100)\n\t\t{\n\t\t\ta=a-100;\n\t\t\tc=c+1;\n\t\t}\n\t\telse if (a>=20)\n\t\t{\n\t\t\ta=a-20;\n\t\t\tc=c+1;\n\t\t}\n\t\telse if (a>=10)\n\t\t{\n\t\t\ta=a-10;\n\t\t\tc=c+1;\n\t\t}\n\t\telse if (a>=5)\n\t\t{\n\t\t\ta=a-5;\n\t\t\tc=c+1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\ta=a-1;\n\t\t\tc=c+1;\n\t\t}\n\t}\n\twriteln(c);\n\treturn 0;\n}", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"}
{"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;\n\nvoid add (ref int a, int b)\n{\n\ta += b;\n\tif (a >= mod)\n\t{\n\t\ta -= mod;\n\t}\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.map !(q{a == '('}).array;\n\t\tauto k = s.length.to !(int);\n\t\tauto p = new int [2] [k + 1];\n\t\tforeach (i; 0..k + 1)\n\t\t{\n\t\t\tforeach (bool v; 0..2)\n\t\t\t{\n\t\t\t\tauto t = s[0..i] ~ v;\n\t\t\t\twhile (t.length > k || t != s[0..t.length])\n\t\t\t\t{\n\t\t\t\t\tt = t[1..$];\n\t\t\t\t}\n\t\t\t\tp[i][v] = t.length.to !(int);\n\t\t\t}\n\t\t}\n\t\tdebug {writeln (p.map !(q{a[0]}));}\n\t\tdebug {writeln (p.map !(q{a[1]}));}\n\n\t\tauto f = new int [2] [] [] [] (n * 2 + 1, n + 1, k + 1);\n\t\tf[0][0][0][0] = 1;\n\t\tforeach (i; 0..n * 2)\n\t\t{\n\t\t\tforeach (b; 0..n + 1)\n\t\t\t{\n\t\t\t\tforeach (x; 0..k + 1)\n\t\t\t\t{\n\t\t\t\t\tforeach (j; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (v; 0..2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tauto c = b + v * 2 - 1;\n\t\t\t\t\t\t\tif (c < 0 || c > n)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tauto y = p[x][v];\n\t\t\t\t\t\t\tauto m = j | (y == k);\n\t\t\t\t\t\t\tadd (f[i + 1][c][y][m],\n\t\t\t\t\t\t\t    f[i][b][x][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\twriteln (sum (f[n * 2][0].map !(q{a[1]}), 0L) % mod);\n\t}\n}\n", "src_uid": "590a49a7af0eb83376ed911ed488d7e5"}
{"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 dchar c){\n    return c=='a'||c=='o'||c=='y'||c=='e'||c=='u'||c=='i';\n}\nvoid main(){\n    auto s=readln.strip\n                 .map!(toLower)\n                 .filter!((x)=>!isv(x));\n    foreach(ref x;s)\n        write(\".\",x);\n    writeln;\n}\n\n", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"}
{"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 da = RD!int;\n\tauto db = RD!int;\n\n\tif (da+1 == db)\n\t{\n\t\twriteln(da, \"9 \", db, \"0\");\n\t}\n\telse if (da == db)\n\t{\n\t\twriteln(da, \"0 \", db, \"1\");\n\t}\n\telse if (da == 9 && db == 1)\n\t{\n\t\twriteln(da, \" \", db, \"0\");\n\t}\n\telse\n\t{\n\t\twriteln(-1);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}", "src_uid": "3eff6f044c028146bea5f0dfd2870d23"}
{"source_code": "module Solution;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n  auto a = readln.stripRight.to!(dchar[]);\n  sort (a);\n  writeln(uniq (a).walkLength % 2 ? \"IGNORE HIM!\" : \"CHAT WITH HER!\");\n}\n\n", "src_uid": "a8c14667b94b40da087501fd4bdd7818"}
{"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\tlong n, k;\n\tscanf(\"%lld %lld\", &n, &k);\n\tlong half = n / 2;\n\thalf += (n - half * 2);\n\tlong num = (k <= half ? 1 + (k-1)*2 : 2 + (k-half-1)*2);\n\tprintf(\"%lld\", num);\n\treturn 0;\n}\n\n", "src_uid": "1f8056884db00ad8294a7cc0be75fe97"}
{"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 = 1; n > 0; i <<= 1) {\n        int l = n % 10;\n\n        if (l == 4) {\n            result += i;\n        } else {\n            result += i << 1;\n        }\n\n        n /= 10;\n    }\n\n    writeln(result);\n}\n", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"}
{"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\tlong k, l, m, n, d;\n\tscanf(\"%d %d %d %d %d\", &k, &l, &m, &n, &d);\n\td++;\n\tlong count = 0;\n\tforeach (long i; 1..d)\n\t{\n\t\tif (i % k == 0\n\t\t || i % l == 0\n\t     || i % m == 0\n\t\t || i % n == 0)\n\t\t{\n\t\t\tcount++;\n\t\t}\n\t}\n\tprintf(\"%d\", count);\n\treturn 0;\n}\n\n", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"}
{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] 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 K = readInt();\n      const PA = readInt();\n      const PB = readInt();\n      \n      const A = Mint(PA) / (PA + PB);\n      const B = Mint(PB) / (PA + PB);\n      const BInv = B.inv;\n      \n      // a, ab\n      auto dp = new Mint[][](K + 1, K);\n      foreach_reverse (i; 0 .. K + 1) foreach_reverse (j; 0 .. K) {\n        if (i + j >= K) {\n          // a...ab: (i + l, j + (i + l))\n          dp[i][j] = j + i + BInv - 1;\n        } else {\n          // a: (i + 1, j)\n          // b: (i, j + i)\n          if (i == 0) {\n            // dp[0][j] = A * dp[1][j] + B * dp[0][j];\n            dp[0][j] = dp[1][j];\n          } else {\n            if (j + i >= K) {\n              dp[i][j] = A * dp[i + 1][j] + B * (j + i);\n            } else {\n              dp[i][j] = A * dp[i + 1][j] + B * dp[i][j + i];\n            }\n          }\n        }\n      }\n      writeln(dp[0][0]);\n    }\n  } catch (EOFException e) {\n  }\n}\n", "src_uid": "0dc9f5d75143a2bc744480de859188b4"}
{"source_code": "module main;\n\nimport std.stdio, std.string, std.algorithm, std.conv;\n\nstatic bool greater(T)(T a, T b)\n{\n    return a > b;\n}\n\nvoid solve(char[] s)\n{\n    //writeln(s);\n    int[] d;\n    foreach (i, val; s)\n    {\n        d ~= val - '0';\n    }\n    //auto d = to!(int[])(s);\n    //sort!(greater)(s);\n    sort!(greater)(d);\n    /*foreach (i, val; d)\n    {\n        writeln(val);\n    }*/\n    int[10] cnt;\n    auto t = [[-1], [-1], [2], [3], [2, 2, 3], [5], [3, 5], [7], [2, 2, 2, 7], [2, 3, 3, 7]];\n    foreach (i, val; d)\n    {\n        if (val <= 1) break;\n        foreach (j; 0 .. t[val].length)\n        {\n            ++ cnt[t[val][j]];\n        }\n    }\n    for (int i = 7; i > 1; -- i)\n    {\n        foreach (j; 0 .. cnt[i])\n        {\n            writef(\"%d\", i);\n        }\n    }\n    writef(\"\\n\");\n}\n\nint main(string[] args)\n{\n    int n;\n    char[] buf;\n    while (scanf(\"%d\", &n) == 1)\n    {\n        stdin.readln(buf);\n        stdin.readln(buf);\n        solve(chomp(buf));\n    }\n    return 0;\n}", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"}
{"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    uint n, m; ulong k;\n    readf (\"%s %s %s\", &n, &m, &k);\n    \n    if (k < n) {\n        writeln(1 + k, ' ', 1);\n        return;\n    } else if (k == n) {\n        writeln(n, ' ', 2);\n        return;\n    }\n    \n    k -= n;\n    debug { writeln(k); }\n    --m;\n    auto rows = k / m;\n    auto cols = k % m;\n    auto row = n - rows;\n    auto col = 1 + (rows % 2 == 0 ? 1 + cols : m - cols);\n    writeln(row, ' ', col);\n}", "src_uid": "e88bb7621c7124c54e75109a00f96301"}
{"source_code": "import std.stdio, std.conv, std.algorithm, std.array;\n\nvoid main() {\n    long n, k;\n    readf(\"%d %d\\n\", n, k);\n    auto arr = map!(el => to!long(el))(readln.split);\n    long maxDiv = 0;\n    foreach (a; arr) {\n        if (k % a == 0 && a > maxDiv)\n            maxDiv = a;\n    }\n    writeln(k / maxDiv);\n}", "src_uid": "80520be9916045aca3a7de7bc925af1f"}
{"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\tint[] n = new int[a];\n\tint[] m = new int[b];\n\tfor (int i=0; i<a; i++)\n\t{\n\t\treadf(\" %d\", &n[i]);\n\t}\n\tfor (int i=0; i<b; i++)\n\t{\n\t\treadf(\" %d\", &m[i]);\n\t}\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tfor (int j=0; j<b; j++)\n\t\t{\n\t\t\tif (n[i]==m[j])\n\t\t\t{\n\t\t\t\twriteln(n[i]);\n\t\t\t}\n\t\t}\n\t}\n\treturn 0;\n}", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"}
{"source_code": "import std.stdio, std.conv, std.string, std.algorithm, std.range;\n\nvoid main() {\n    int n = readln.chomp.to!int;\n    int[] ans;\n    for (int i = 0; n > 0; i++) {\n        if ((n & 1) == 1) {\n            ans ~= (i + 1);\n        }\n\n        n = n >> 1;\n    }\n\n    ans.map!(to!string).array.reverse.join(\" \").writeln;\n}", "src_uid": "757cd804aba01dc4bc108cb0722f68dc"}
{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\n\nstring readline()\n{\n\tstring result = readln();\n\tif (result[result.length - 1] == '\\n') result.length--;\n\treturn result;\n}\n\nint main(string[] argv)\n{\n\tstring word = readline();\n\tstring drow = readline();\n\tif (word.dup.reverse == drow)\n\t{\n\t\twrite(\"YES\");\n\t} else {\n\t\twrite(\"NO\");\n\t}\n\treturn 0;\n}\n", "src_uid": "35a4be326690b58bf9add547fb63a5a5"}
{"source_code": "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\nauto pmod(T)(T a, T m)\n{\n  return (a%m + m)%m;\n}\n\nstruct Interval\n{\n  long l, h;\n}\nInterval intersect(Interval a, Interval b)\n{\n  return Interval(max(a.l, b.l), min(a.h, b.h));\n}\nbool empty(Interval i)\n{\n  with(i)\n    return l > h;\n}\nlong len(Interval i)\n{\n  return i.h - i.l + 1;\n}\n\nvoid main(string[] args)\n{\n  inputFile = stdin;\n  debug inputFile = File(args[1]);\n  auto la = next!long;\n  auto ra = next!long;\n  auto ta = next!long;\n  auto lb = next!long;\n  auto rb = next!long;\n  auto tb = next!long;\n  auto g = gcd(ta, tb);\n  long best = 0;\n  foreach(s; [lb + pmod(la - lb, g), lb - pmod(lb - la, g)])\n    best = max(best, Interval(s, s + ra - la).intersect(Interval(lb, rb)).len);\n  foreach(e; [rb + pmod(ra - rb, g), rb - pmod(rb - ra, g)])\n    best = max(best, Interval(e - (ra - la), e).intersect(Interval(lb, rb)).len);\n  best.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", "src_uid": "faa75751c05c3ff919ddd148c6784910"}
{"source_code": "import std.stdio : readf, writeln;\nimport std.exception : enforce, ConvException;\n\nbool solve() {\n\tenum n = 6;\n\tint[n] a;\n\tforeach (i; 0..n)\n\t\tif (!readf(\" %s\", &a[i]))\n\t\t\treturn false;\n\tforeach (i; 0..n)\n\t\tinner: foreach (j; 0..i) {\n\t\t\tint[] other;\n\t\t\tforeach (t; 0..n)\n\t\t\t\tif (t != i && t != j)\n\t\t\t\t\tother ~= a[t];\n\t\t\tforeach (t; 1..other.length) {\n\t\t\t\tif (other[t] != other[0])\n\t\t\t\t\tcontinue inner;\n\t\t\t}\n\t\t\tif (a[i] == a[j]) {\n\t\t\t\twriteln(\"Elephant\");\n\t\t\t\treturn true;\n\t\t\t} else {\n\t\t\t\twriteln(\"Bear\");\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\twriteln(\"Alien\");\n\treturn true;\n}\n\nvoid main() {\n\twhile (solve()) {}\n}\n", "src_uid": "43308fa25e8578fd9f25328e715d4dd6"}
{"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %x\",&a);\n\tfor (int i=0; i<a; i++)\n\t{\n\t\tint b=0;\n\t\treadf(\" %x\", &b);\n\t\tif (b==1)\n\t\t{\n\t\t\twriteln(\"HARD\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\twriteln(\"EASY\");\n\treturn 0;\n}", "src_uid": "060406cd57739d929f54b4518a7ba83e"}
{"source_code": "import std.algorithm,std.ascii,std.stdio;void main(){auto s=readln;writeln(s.length>5&&s.any!isLower&s.any!isUpper&s.any!isDigit?\"Correct\":\"Too weak\");}", "src_uid": "42a964b01e269491975965860ec92be7"}
{"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                int[][] mat = new int[][n];\n                int sum = 0;\n                for (int i = 0; i < n; i++) {\n                        mat[i] = new int[n];\n                        for (int j = 0; j < n; j++) {\n                                mat[i][j] = cin.read_int;\n                                if (i == j || i + j == n - 1 || i == n / 2 || j == n / 2) {\n                                        sum += mat[i][j];\n                                }\n                        }\n                }\n                writeln(sum);\n        }        \n}", "src_uid": "5ebfad36e56d30c58945c5800139b880"}
{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.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 m = read.to!int;\n\tint r = read.to!int;\n\t\n\tint a = 9999;\n\tforeach(i; 0 .. n) a = min(a, read.to!int);\n\t\n\tint b = -1;\n\tforeach(j; 0 .. m) b = max(b, read.to!int);\n\t\n\tint x;\n\tif(a > b) x = 0;\n\telse x = r / a;\n\t\n\tint ans = (r - x * a) + (x * b);\n\tans.writeln;\n\t\n}\n", "src_uid": "42f25d492bddc12d3d89d39315d63cb9"}
{"source_code": "import std.conv, 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 A = 5 - 1, B = 10 - 1, C = 50 - 1;\n\nvoid main() {\n  try {\n    for (; ; ) {\n      const N = readLong();\n      \n      alias Entry = Tuple!(long, \"key\", int, \"val\");\n      auto ess = new Entry[][C];\n      foreach (x; 0 .. C) foreach (y; 0 .. C) {\n        if (x + y <= N) {\n          const r = cast(int)((A * x + B * y) % C);\n          const mn = A * x + B * y;\n          const mx = A * x + B * y + C * (N - x - y);\n          ess[r] ~= Entry((mn - r) / C, +1);\n          ess[r] ~= Entry((mx - r) / C + 1, -1);\n        }\n      }\n      long ans;\n      foreach (r; 0 .. C) {\n        ess[r].sort;\n        int now;\n        foreach (j; 0 .. cast(int)(ess[r].length) - 1) {\n          now += ess[r][j].val;\n          if (now > 0) {\n            ans += ess[r][j + 1].key - ess[r][j].key;\n          }\n        }\n      }\n      writeln(ans);\n    }\n  } catch (EOFException e) {\n  }\n}\n", "src_uid": "75ec99318736a8a1b62a8d51efd95355"}
{"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 n = nm[0], m = nm[1];\n  int d=1;\n  while(n>0) {\n    if (d%m==0) n++;\n    n--;\n    d++;\n  } \n  writeln(d-1);\n}", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"}
{"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 rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nstatic long PRIME = 10^^9 + 7;\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\n\nvoid play(){\n    int n, m, k;\n    n = rd!int; m = rd!int; k = rd!int;\n    ll res = 1;\n    int tim = 0;\n    if(k == 1 || k > n){\n        tim = n;\n    }else if (k == n){\n        tim = (k + 1)/2;\n    }else if(k % 2){\n        tim = 2;\n    }else{\n        tim = 1;\n    }\n    foreach(i; 0..tim){\n        res *= m;\n        res %= PRIME;\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", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d"}
{"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 x = cast(int)sqrt(cast(double)k);\n\tlong ans;\n\tforeach (i; x..n+2)\n\t{\n\t\tauto j = cast(long)i;\n\t\tauto j2 = cast(long)(i-1);\n\t\tauto y = j * j2 / 2;\n\t\tif (j * j2 < k) continue;\n\t\tif (y - k == n - j2)\n\t\t{\n\t\t\tdebug writeln(i);\n\t\t\tans = n - j2;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"}
{"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip;\nimport std.algorithm.iteration : map, sum;\nimport std.algorithm.searching: until;\nimport std.regex;\nimport std.range;\nimport std.array;\nimport std.conv;\nimport std.typecons;\n\nvoid main()\n{\n  auto h = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n  auto a=h[0], b=h[1];\n  auto c=tuple(a,0);\n  writeln(a + generate!(()=>c=tuple((c[0]+c[1])/b, (c[0]+c[1])%b)).map!\"a[0]\".until!\"a==0\".sum);\n}", "src_uid": "a349094584d3fdc6b61e39bffe96dece"}
{"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  auto a = r.nextA!int (n);\n  int res;\n  foreach (i; 1 .. n) {\n    auto x = a[i - 1], y = a[i];\n    if (x == 2 && y == 3 || x == 3 && y == 2) {\n      writeln (\"Infinite\");\n      return;\n    }\n    if (x == 1 && y == 2) {\n      res += 3;\n      if (i >= 2 && a[i - 2] == 3) --res;\n    } else if (x == 1 && y == 3) {\n      res += 4;\n    } else if (x == 2 && y == 1) {\n      res += 3;\n    } else if (x == 3 && y == 1) {\n      res += 4;\n    } \n    /*\n    else if (x == 3 && y == 2) {\n      res += 4;\n    }\n    */\n    debug stderr.writeln (x, \" \", y, \" \", res);\n  }\n  writeln (\"Finite\");\n  writeln (res);\n}\n\n", "src_uid": "6c8f028f655cc77b05ed89a668273702"}
{"source_code": "void main(){\n  import std.stdio, std.string, std.conv, std.algorithm;\n  import std.random;\n\n  if(false){\n    auto rnd=Random(unpredictableSeed);\n    int n=50;\n    auto ans=new int[][](n);\n    foreach(i; 0..n){\n      int[] ks;\n      foreach(__; 0..3) ks~=uniform!\"[]\"(2, 10, rnd);\n      // ks~=2; ks~=2; ks~=3; -> yes\n      if(check(ks)){\n        ans[i]~=ks;\n      }\n    }\n    foreach(i; 0..n)if(ans[i].length>0) writeln(ans[i]);\n  }\n\n  auto d=readln.split.to!(int[]);\n  if(count(d, 1)){writeln(\"YES\"); return;}\n  if(count(d, 2)>=2){writeln(\"YES\"); return;}\n\n  sort(d);\n  if(d[0]==2 && d[1]==d[2] && d[2]==4){writeln(\"YES\"); return;}\n  if(d[0]==d[1] && d[1]==d[2] && d[2]==3){writeln(\"YES\"); return;}\n\n  writeln(\"NO\");\n}\n\nbool check(int[] ks){\n  import std.algorithm;\n  foreach(x1; 0..10)foreach(x2; 0..10)foreach(x3; 0..10){\n    auto ok=new bool[](300);\n    for(int i=x1; i<300; i+=ks[0]) ok[i]=true;\n    for(int i=x2; i<300; i+=ks[1]) ok[i]=true;\n    for(int i=x3; i<300; i+=ks[2]) ok[i]=true;\n    bool yes=true;\n    for(int i=max(x1, x2, x3); i<300; i++) yes&=ok[i];\n    if(yes) return true;\n  }\n  return false;\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){\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}", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"}
{"source_code": "import std.stdio;\n\nvoid main() {\n\tint[12] array;\n\tint n;\n\treadf(\" %s\", &n);\n\tfor (int i = 0; i < 12; i++)\n\t\treadf(\" %s\", &array[i]);\n\n\tarray.sort;\n\n\tint counter = 0;\n\tint count = 0;\t\n\tforeach_reverse(e; array) {\n\t\tif (counter >= n) {\n\t\t\tbreak;\n\t\t}\n\t\tcounter += e;\n\t\tcount++;\n\t\t\n\t}\n\n\tif (n > counter)\n\t\twriteln(-1);\n\telse\n\t\twriteln(count);\n}", "src_uid": "59dfa7a4988375febc5dccc27aca90a8"}
{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio      : readln, writeln;\nimport std.string     : chomp;\nimport std.array      : split;\nimport std.conv       : to;\nimport std.algorithm  : min;\n\nauto gets() { return readln.chomp; }\nauto getV(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n    auto nkt = getVals!int;\n    auto n = nkt[0], k = nkt[1], t = nkt[2];\n    if (t <= k) {\n        writeln(t);\n        return;\n    }\n    if (t <= n) {\n        writeln(k);\n        return;\n    }\n    writeln(k - (t - n));\n}", "src_uid": "7e614526109a2052bfe7934381e7f6c2"}
{"source_code": "import std.stdio;\n\nvoid main() {\n    int n, cnt = 0;\n    string s;\n    readf(\"%d\\n\", &n);\n    char oldc;\n    for (int i = 0; i < n; ++i) {\n        char c;\n        readf(\" %c\", &c);\n        if (i != 0 && c == oldc) {\n            cnt++;\n        }\n        oldc = c;\n    }\n    writefln(\"%d\", cnt);\n}", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"}
{"source_code": "import std.stdio;\nimport std.math;\nimport std.string;\t\nimport std.conv;\n\nvoid main()\n{\n\tauto a = split(strip(readln));\n\tint n = to!int(a[0]);\n\tint b = to!int(a[1]);\n\tint p = to!int(a[2]);\n\n\tauto xn = n;\n\tint bo;\n\twhile (n >= 2)\n\t{\n\t\tauto po = to!int(log2(n));\n\t\tauto k = pow(2, po);\n\t\tbo += (k / 2) * (2 * b + 1);\n\t\tn = n - k + (k / 2);\n\t\t//writeln(k, \"\\t\", n);\n\t}\n\n\twriteln(bo, \" \", p * xn);\n}\n\n\n", "src_uid": "eb815f35e9f29793a120d120968cfe34"}
{"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 k, r;\n\tscanf(\"%d %d\", &k, &r);\n\tint cr = k % 10;\n\tint num = 1;\n\twhile (cr != 0 && cr != r)\n\t{\n\t\tcr += k % 10; cr %= 10;\n\t\tnum++;\n\t}\n\tprintf(\"%d\", num);\n\treturn 0;\n}", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"}
{"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,a,b;\n    scan(n,a,b);\n\n    int ans;\n\n    foreach (i ; 1 .. n) {\n        ans = max(ans, min(a/i, b/(n-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}", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e"}
{"source_code": "import std.stdio, std.array, std.string, 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 = readln.chomp.to!long;\n\n    foreach (a; 1..X+1) {\n        foreach (b; 1..X+1) {\n            if (a % b == 0 && a * b > X && a < b * X) {\n                writeln(a, \" \", b);\n                return;\n            }\n        }\n    }\n\n    writeln(-1);\n}\n", "src_uid": "883f67177474d23d7a320d9dbfa70dd3"}
{"source_code": "#!/usr/bin/rdmd\n\nimport std.stdio;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.regex;\nimport std.math;\nimport std.bigint;\nimport std.numeric;\nimport std.container;\nimport std.typecons;\nimport std.algorithm;\nimport std.range;\n\nvoid main() {\n  int n = readln().chomp().to!int();\n  int[] x = readln().split().map!(to!int)().array();\n  bool flag = false;\n  for (int i = 0; i < n-1; i++) {\n    int a = x[i], b = x[i+1];\n    if (a > b) swap(a, b);\n    for (int j = 0; j < n-1; j++) {\n      int c = x[j], d = x[j+1];\n      if (c > d) swap(c, d);\n      if (a < c && c < b && b < d) flag = true;\n      if (c < a && a < d && d < b) flag = true;\n    }\n  }\n  if (flag) writeln(\"yes\");\n  else writeln(\"no\");\n}\n", "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"}
{"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\nbyte tie(short a, short b, short c, short d) {\n\n\tint sum1 = max(3 * a / 10, a - a / 250 * c);\n\tint sum2 = max(3 * b / 10, b - b / 250 * d);\n\n\tif (sum1 < sum2)\n\t\treturn 1;\n\telse if (sum1 > sum2)\n\t\treturn 2;\n\telse\n\t\treturn 0;\n}\n\nvoid main() {\n\n\tshort a, b, c, d;\n\n\tscanf(\"%hd%hd%hd%hd\", &a, &b, &c, &d);\n\n\tbyte ans = tie(a, b, c, d);\n\n\tif (ans == 1)\n\t\twriteln(\"Vasya\");\n\telse if (ans == 2)\n\t\twriteln(\"Misha\");\n\telse\n\t\twriteln(\"Tie\");\n}", "src_uid": "95b19d7569d6b70bd97d46a8541060d0"}
{"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 r = () => readln.chomp.split.map!(to!int);\n    \n    auto s1 = r().sum;\n    auto s2 = r().sum;\n    \n    writeln(s1 >= s2 ? \"Yes\" : \"No\");\n}", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"}
{"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 x1 = cin.read_int;\n                int y1 = cin.read_int;\n                int x2 = cin.read_int;\n                int y2 = cin.read_int;\n\n                writeln(max(abs(x2 - x1), abs(y2 - y1)));\n        }        \n}", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"}
{"source_code": "import std.stdio, std.string, std.math;\n\nbool check(int x, int y, long t, int cnt1, int cnt2)\n{\n    auto b = x * y;\n    auto cnt = t / b, left = t % b;\n    auto no1 = y - 1, no2 = x - 1;\n    auto sub1 = (x - 1) * cnt + left / y;\n    auto sub2 = (y - 1) * cnt + left / x;\n    cnt1 -= sub1;\n    cnt2 -= sub2;\n    if (cnt1 < 0) cnt1 = 0;\n    if (cnt2 < 0) cnt2 = 0;\n    if (t - cnt - sub1 - sub2 >= cnt1 + cnt2) return true;\n    return false;\n}\n\nvoid solve(int cnt1, int cnt2, int x, int y)\n{\n    long left = 1, right = 1L << 60;\n    long ans = -1;\n    while (left <= right)\n    {\n\tauto mid = (left + right) >> 1;\n\tif (check(x, y, mid, cnt1, cnt2))\n\t{\n\t    ans = mid;\n\t    right = mid - 1;\n\t}\n\telse\n\t{\n\t    left = mid + 1;\n\t}\n    }\n    writefln(\"%d\", ans);\n}\n\nvoid main(string[] args)\n{\n    int cnt1, cnt2, x, y;\n    while (scanf(\"%d%d%d%d\", &cnt1, &cnt2, &x, &y) == 4)\n    {\n\tsolve(cnt1, cnt2, x, y);\n    }\n}\n", "src_uid": "ff3c39b759a049580a6e96c66c904fdc"}
{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.numeric;\n\nvoid read_vars(Args...)(out Args args) {\n  auto tokens = readln.idup.split;\n  foreach (i, ref arg; args) {\n    arg = tokens[i].to!(typeof(arg));\n  }\n}\n\nvoid main() {\n  int n;\n  read_vars(n);\n  int x, y;\n  for (int i = 0; i * 2 < n; ++i) {\n    int j = n - i;\n    if (gcd(i, j) == 1) {\n      x = i;\n      y = j;\n    }\n  }\n  writefln!\"%d %d\"(x, y);\n}\n", "src_uid": "0af3515ed98d9d01ce00546333e98e77"}
{"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\nvoid main() {\n    int n;\n    while (read(&n)) {\n        int a, b;\n        foreach (i; 0 .. n) {\n            int x;\n            read(&x);\n            if (x == 1)\n                a = i;\n            else if (x == n)\n                b = i;\n        }\n        if (a > b)\n            swap(a, b);\n        writeln(max(b, n - a - 1));\n    }\n}\n", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4"}
{"source_code": "import std.algorithm;\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 Exam = Tuple\n\t\t    !(int, q{s}, int, q{d}, int, q{c}, int, q{num});\n\t\tauto exams = new Exam [m];\n\t\tforeach (i, ref exam; exams)\n\t\t{\n\t\t\treadf (\" %s %s %s\", &exam.s, &exam.d, &exam.c);\n\t\t\texam.num = i + 1;\n\t\t}\n\t\texams.schwartzSort !(exam => exam.d);\n\n\t\tauto res = new int [n + 1];\n\t\tforeach (const ref exam; exams)\n\t\t{\n\t\t\tres[exam.d] = m + 1;\n\t\t}\n\n\t\tforeach (day; 1..n + 1)\n\t\t{\n\t\t\tforeach (ref exam; exams)\n\t\t\t{\n\t\t\t\tif (res[day] == 0 && exam.c > 0 &&\n\t\t\t\t    exam.s <= day && day < exam.d)\n\t\t\t\t{\n\t\t\t\t\tres[day] = exam.num;\n\t\t\t\t\texam.c -= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (exams.any !(exam => exam.c > 0))\n\t\t{\n\t\t\twriteln (-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twritefln (\"%(%s %)\", res.drop (1));\n\t\t}\n\t}\n}\n", "src_uid": "02d8d403eb60ae77756ff96f71b662d3"}
{"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, t;\n    scan(s,t);\n\n    string ans = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\";\n\n    foreach (i ; 1 .. s.length + 1) {\n        foreach (j ; 1 .. t.length + 1) {\n            string tmp = s[0 .. i] ~ t[0 .. j];\n            if (tmp < ans) {\n                ans = tmp;\n            }\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}", "src_uid": "aed892f2bda10b6aee10dcb834a63709"}
{"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    long n; int m;\n    readf(\"%s %s\", &n, &m);\n    readln;\n    \n    auto mtrx = new int[][] (m, m);\n    mtrx[0][0] = 1;\n    mtrx[0][$-1] = 1;\n    \n    for (int i = 1; i < m; ++i) mtrx[i][i-1] = 1;\n    \n    auto orig = new int[][] (m, m);\n    for (int i = 0; i < m; ++i) orig[i][] = mtrx[i][];\n    auto tmp = new int[][] (m, m);\n    \n    debug { mtrx.writeln; }\n    \n    void multMtrx(int[][] mtrx1, int[][] mtrx2) {\n        debug { tmp.writeln; mtrx2.writeln; }\n        \n        for (int i = 0; i < m; ++i) {\n            for (int j = 0; j < m; ++j) {\n                int cur = 0;\n                for (int k = 0; k < m; ++k) {\n                    cur = (cur + (mtrx1[i][k].to!long * mtrx2[k][j] % MD)) % MD;\n                }\n                tmp[i][j] = cur;\n            }\n        }\n        \n        for (int i = 0; i < m; ++i) mtrx1[i][] = tmp[i][];\n    }\n    \n    \n    void calcPow(long p) {\n        if (p == 1) return;\n        \n        calcPow(p/2);\n        multMtrx(mtrx, mtrx);\n        \n        if (p % 2 == 1) {\n            multMtrx(mtrx, orig);\n        }\n    }\n    \n    calcPow(n);\n    \n    debug { mtrx.writeln; }\n    \n    auto ans = 0;\n    for (int i = 0; i < m; ++i) ans = (ans + mtrx[$-1][i]) % MD;\n    \n    ans.writeln;\n}", "src_uid": "e7b9eec21d950f5d963ff50619c6f119"}
{"source_code": "import std.stdio, std.conv, std.range, std.algorithm, std.string;\nimport std.math;\n\nvoid main() {\n    int n, m;\n    readf(\"%d %d\\n\", &n, &m);\n    int[] a = readln.chomp.split.map!(\n        a => (a.to!int / cast(double)m).ceil.to!int\n        ).array;\n\n    int ma = 0;\n    int ans = 0;\n    foreach (int i, e; a) {\n        if (e >= ma) {\n            ans = i + 1;\n            ma = e;\n        }\n    }\n\n    ans.writeln;\n}\n", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c"}
{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main() {\n\tint c = readln.chomp.split.map!(to!int).reduce!(\"a + b\");\n\tif (c > 0 && c % 5 == 0) {\n\t\twriteln(c / 5);\n\t} else {\n\t\twriteln(-1);\n\t}\n}\n", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"}
{"source_code": "import std.stdio;\nimport std.string;\n\nint main()\n{\n\tint a=0;\n\tint b=0;\n\tint c=0;\n\tint d=0;\n\tint e=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\treadf(\" %d\", &c);\n\treadf(\" %d\", &d);\n\treadf(\" %d\", &e);\n\tif (2*d+a*b>2*e+a*c)\n\t{\n\t\twriteln(\"Second\");\n\t}\n\telse if (2*d+a*b<2*e+a*c)\n\t{\n\t\twriteln(\"First\");\n\t}\n\telse\n\t{\n\t\twriteln(\"Friendship\");\n\t}\n\treturn 0;\n}", "src_uid": "10226b8efe9e3c473239d747b911a1ef"}
{"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\n\nvoid main() {\n    auto spinner = \"v<^>\";\n\n    char s, t;\n    int n;\n\n    scan(s, t);\n    scan(n);\n\n    n %= 4;\n\n    int b = spinner.countUntil(s);\n\n    bool cw, ccw;\n\n    if (spinner[(b + n) % 4] == t) {\n        cw = true;\n    }\n\n    if (spinner[(b - n + 4) % 4] == t) {\n        ccw = true;\n    }\n\n    if (cw && ccw) {\n        writeln(\"undefined\");\n    }\n    else if (cw) {\n        writeln(\"cw\");\n    }\n    else if (ccw) {\n        writeln(\"ccw\");\n    }\n    else {\n        assert(0);\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": "fb99ef80fd21f98674fe85d80a2e5298"}
{"source_code": "import std.stdio, std.array, 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!BigInt);\n    auto N = s[0];\n    auto K = s[1];\n\n    BigInt hi = N + 1;\n    BigInt lo = 0;\n    while (hi - lo > 1) {\n        auto mid = (hi + lo) / 2;\n        if (mid + mid * K > N / 2) hi = mid;\n        else lo = mid;\n    }\n\n    writeln(lo, \" \", lo * K, \" \", N - lo * K - lo);\n}\n", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80"}
{"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    int a, b;\n    readf(\"%s %s\", &a, &b);\n    readln;\n    \n    auto starts = make!(RedBlackTree!int)([1 + a, k+1 - a]);\n    auto afterStep = make!(RedBlackTree!long);\n    \n    foreach (i; 0 .. n) {\n        afterStep.insert(k.to!long*i + 1 + b);\n        afterStep.insert(k.to!long*(i+1) + 1 - b);\n    }\n    \n    //debug { starts.writeln; afterStep.writeln; }\n    \n    long tot = n.to!long * k;\n    long mn = tot, mx = 1;\n    \n    long Calc(long step, long tot) {\n        if (step == 0) { step = tot; }\n        return tot / gcd(tot, step); \n    }\n    \n    foreach (start; starts) {\n        foreach (nxt; afterStep) {\n            long step = abs(start - nxt);\n            long cur = Calc(step, tot);\n            mn = min(mn, cur);\n            mx = max(mx, cur);\n            \n            step = tot - abs(start - nxt);\n            cur = Calc(step, tot);\n            mn = min(mn, cur);\n            mx = max(mx, cur);\n        }\n    }\n    \n    writeln(mn, ' ', mx);\n}", "src_uid": "5bb4adff1b332f43144047955eefba0c"}
{"source_code": "import std.stdio, std.string;\n\nvoid solve(int c, int d, int n, int m, int k)\n{\n    int ans = 1 << 30;\n    for (int i = 0; ; ++ i)\n    {\n        int j = m * n - i * n - k;\n        if (j < 0)\n        {\n            j = 0;\n        }\n        int total = i * c + j * d;\n        ans = total < ans ? total : ans;\n        if (i * n + k >= m * n)\n        {\n            break;\n        }\n    }\n    printf(\"%d\\n\", ans);\n}\n\nvoid main(string[] args)\n{\n    int c, d, m, n, k;\n    while (scanf(\"%d%d%d%d%d\", &c, &d, &n, &m, &k) == 5)\n    {\n        solve(c, d, n, m, k);\n    }\n}", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb"}
{"source_code": "// https://codeforces.com/problemset/problem/478/B\nimport std.stdio;\n\nvoid main() {\n    ulong n, m;\n    readf(\"%s %s\\n\", &n, &m);\n    ulong j = n-m;\n    ulong maxima = j*(j+1)/2;\n    ulong perteam = n/m;\n    ulong minima = (m-n%m)*(perteam*(perteam-1)/2) + (n%m)*(perteam*(perteam+1)/2);\n    writefln(\"%s %s\", minima, maxima);\n}\n\n", "src_uid": "a081d400a5ce22899b91df38ba98eecc"}
{"source_code": "import std.stdio, std.array, 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!long);\n    auto A = s[0];\n    auto B = s[1];\n    auto D = abs(A - B);\n    \n    long ansv = A * B;\n    long ansk = 0;\n\n    long[] cand;\n\n    for (long i = 1; i * i <= D; ++i) {\n        if (D % i == 0) {\n            cand ~= i;\n            cand ~= D / i;\n        }\n    }\n\n    foreach (g; cand) {\n        long diff = (g - A % g) % g;\n        long val = (A + diff) * (B + diff) / g;\n        if (val < ansv || (val == ansv && diff < ansk)) {\n            ansv = val;\n            ansk = diff;\n        }\n    }\n\n    writeln(ansk);\n}\n", "src_uid": "414149fadebe25ab6097fc67663177c3"}
{"source_code": "import std.c.stdio;\nimport std.stdio;\nvoid main() {\n long a,b,c,t=0;\n    scanf(\"%lld%lld\",&a,&b);\n    while(a!=0){\n        if(a<b){\n            c=a;\n            a=b;\n            b=c;\n        }\n        c=a/b;\n        a=a-c*b;\n        t=t+c;\n    }\n    printf(\"%lld\\n\",t);\n}", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"}
{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n    int n;\n    n = rd!int;\n    ll res = 1;\n    for(int i = n-1; i > n/2; --i){\n        res *= i;\n    }\n    foreach(i; 1..(n/2)){\n        res *= i;\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;\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": "ad0985c56a207f76afa2ecd642f56728"}
{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nlong calc(long h, long n, long side) {\n\tif (h == 0) {\n\t\treturn 0;\n\t}\n\tconst mid = 1L << (h - 1);\n\tlong ret = 1;\n\tswitch (side) {\n\t\tcase 0: {\n\t\t\tif (n < mid) {\n\t\t\t\tret += calc(h - 1, n, 1);\n\t\t\t} else {\n\t\t\t\tret += (1L << h) - 1;\n\t\t\t\tret += calc(h - 1, n - mid, 0);\n\t\t\t}\n\t\t} break;\n\t\tcase 1: {\n\t\t\tif (n >= mid) {\n\t\t\t\tret += calc(h - 1, n - mid, 0);\n\t\t\t} else {\n\t\t\t\tret += (1L << h) - 1;\n\t\t\t\tret += calc(h - 1, n, 1);\n\t\t\t}\n\t\t} break;\n\t\tdefault: assert(false);\n\t}\n\treturn ret;\n}\n\nlong H, N;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tH = readLong;\n\t\tN = readLong - 1;\n\t\t\n\t\tconst res = calc(H, N, 0);\n\t\twriteln(res);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781"}
{"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 k = cin.readInt;\n                int[10] c = 0;\n                for (int i = 0; i < 4; i++) {\n                        string s = cin.readString;\n                        for (int j = 0; j < 4; j++) \n                                if (s[j] != '.') c[s[j] - '0']++;\n                }\n                \n                for (int i = 0; i < c.length; i++) {\n                        if (c[i] > 2 * k) {\n                                writeln(\"NO\");\n                                return;\n                        }\n                }\n                writeln(\"YES\");\n        }        \n}", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16"}
{"source_code": "import std.stdio;\n\nlong M;\n\nlong cnt(long x) {\n\tlong ans = 0;\n\tforeach (long i; 2..cast(long)1e6 + 1) {\n\t\tans += x / (i ^^ 3);\n\t}\n\treturn ans;\n}\n\nvoid main() {\n\treadf(\"%d\", &M);\n\tlong low = 1, hi = cast(long)1e18;\n\twhile (low != hi) {\n\t\tlong mid = (low + hi) >> 1;\n\t\tif (cnt(mid) < M) low = mid + 1; else hi = mid;\n\t}\n\tif (cnt(low) == M) writeln(low); else writeln(-1);\n}", "src_uid": "602deaad5c66e264997249457d555129"}
{"source_code": "/+ dub.sdl:\n    name \"A\"\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[] res;\n    foreach (i; 0..300) {\n        int m = n-i;\n        int k = m;\n        if (m <= 0) break;\n        string s = m.to!string;\n        foreach (c; s) {\n            m += c - '0';\n        }\n        if (n == m) {\n            res ~= k;\n        }\n    }\n    res.sort!\"a<b\";\n    writeln(res.length);\n    foreach (d; res) {\n        writeln(d);\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", "src_uid": "ae20ae2a16273a0d379932d6e973f878"}
{"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 arr = readln.chomp.split.map!(to!int).array;\n    \n    RedBlackTree!int[] nrs;\n    foreach (_; 0 .. 2) { nrs ~= make!(RedBlackTree!int); }\n    \n    debug { nrs.writeln; }\n\n    void go(RedBlackTree!int rbt, int[] arr) {\n        rbt.insert(0);\n        foreach (e; arr) {\n            auto old = rbt.array;\n            \n            foreach (v; old) { rbt.insert((v + e) % m); }\n        }\n    }\n    \n    go(nrs[0], arr[0 .. n/2]);\n    go(nrs[1], arr[n/2 .. $]);\n    \n    debug { writeln(nrs[0], ' ', nrs[1]); }\n    \n    int ans = 0;\n    foreach (e; nrs[0]) {\n        while (e + nrs[1].back >= m) { nrs[1].removeBack(); }\n        \n        ans = max(ans, e + nrs[1].back);\n    }\n    \n    ans.writeln;\n}", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a"}
{"source_code": "import std.stdio;\nimport std.bigint;\n\nint main(string[] argv)\n{\n\tint n, t;\n\treadf(\"%d %d\", &n, &t);\n\tstring num = \"\";\n\tforeach (int i; 0..n)\n\t{\n\t\tnum ~= \"9\";\n\t}\n\tBigInt number = num;\n\tint k = number % t;\n\tnumber -= k;\n\tif (number != 0)\n\t{\n\t\twrite(number);\n\t\treturn 0;\n\t}\n\twrite(-1);\n\treturn 0;\n}", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"}
{"source_code": "import std.stdio;\n\nvoid write_chars(char[] cs) {\n  foreach(c; cs) {\n    write(c);\n  }\n}\n\nchar[] chars(string s) {\n  char[] cs;\n  foreach(c; s) {\n    cs ~= c;\n  }\n  return cs;\n}\n\nvoid swap(char *first, char *second) {\n  char t = *first;\n  *first = *second;\n  *second = t;\n}\n\nchar[] after_wait(char[] queue) {\n  for (int i=0; i < queue.length - 1; i++) {\n    if (queue[i] == 'B' && queue[i+1] == 'G') {\n      swap(&queue[i], &queue[i+1]);\n      i++;\n    }\n  }\n  return queue;\n}\n\nvoid main() {\n  int n, t;\n  string queue;\n  readf(\"%s %s\", &n, &t);\n  readf(\" %s\", &queue);\n  auto chars = chars(queue);\n  while (t > 0) {\n    chars = after_wait(chars);\n    t--;\n  }\n  write_chars(chars);\n}", "src_uid": "964ed316c6e6715120039b0219cc653a"}
{"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\n\nvoid main() \n{\n    auto ilkSatir = stdin.readln.strip.split().map!(a => to!int(a)).array();\n\n\tauto minumumSayi = min( ilkSatir[0], ilkSatir[1]);\n\tint sonuc = 1;\n\twhile ( minumumSayi )\n\t{\n\t\tsonuc *= (minumumSayi--);\t\n\t}\n\twriteln(sonuc);\n}", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"}
{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(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 ans = (N % 2 != 0 && A[0] % 2 != 0 && A[N - 1] % 2 != 0);\n      writeln(ans ? \"Yes\" : \"No\");\n    }\n  } catch (EOFException e) {\n  }\n}\n", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"}
{"source_code": "import std.stdio;\nimport std.string;\nimport std.uni;\n\nvoid main() {\n\tint ans = 0;\n\treadln();\n\tstring[] input = readln().split();\n\tforeach (string word; input) {\n\t\tint counter = 0;\n\t\tforeach (char c; word) if (isUpper(c)) counter++;\n\t\tif (counter > ans) ans = counter;\n\t}\n\twriteln(ans);\n}", "src_uid": "d3929a9acf1633475ab16f5dfbead13c"}
{"source_code": "import std.stdio, std.array, std.string, 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!int).array;\n    auto K = A.sum;\n    auto DT = iota(M).map!(_ => readln.split.map!(to!int).array).array;\n    DT.sort!\"a[0] < b[0]\";\n    \n    bool check(int x) {\n        auto lb = DT.assumeSorted!\"a[0] < b[0]\".lowerBound([x+1, 0]).length.to!int;\n        if (lb == 0) {\n            return x >= 2 * K;\n        }\n        int day = x;\n        int money = x;\n        int unused_money = 0;\n        int sale = 0;\n        auto B = A.dup;\n        foreach_reverse (i; 0..lb) {\n            day = DT[i][0];\n            money = min(day, money);\n            if (money && B[DT[i][1]-1] > 0) {\n                int amount = min(money, B[DT[i][1]-1]);\n                B[DT[i][1]-1] -= amount;\n                money -= amount;\n                sale += amount;\n            }\n        }\n        \n        return sale + (x - sale) / 2 >= K;\n    }\n\n    int ok = 5 * 10^^5;\n    int ng = 0;\n    while (ok - ng > 1) {\n        int mid = (ok + ng) / 2;\n        (check(mid) ? ok : ng) = mid;\n    }\n\n    ok.writeln;\n}\n", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d"}
{"source_code": "import std.stdio;\n\nvoid main()\n{\n    int n, k;\n    readf(\" %s %s\", n, k);\n\n    while (k > 0)\n    {\n        k--;\n\n        if (n % 10)\n        {\n            n--;\n        }\n        else\n        {\n            n /= 10;\n        }\n    }\n\n    writeln(n);\n}", "src_uid": "064162604284ce252b88050b4174ba55"}
{"source_code": "//rextester.com:dmd64 2.072.2--codeforces.com:dmd32 2.071.2\nimport std.stdio,std.math;\nvoid main(){\n    double a;readf(\"%f\",&a);a*=2;bool b=false;\n    for(int i=1;i<cast(int)sqrt(a);i++){\n        double c=a-i*i-i;double d=cast(int)sqrt(c);\n        if(d*(d+1)==c)b=true;\n    }\n    write(b?\"YES\":\"NO\");\n}", "src_uid": "245ec0831cd817714a4e5c531bffd099"}
{"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        writeln(100/gcd(n, 100));\r\n    }\r\n}", "src_uid": "19a2bcb727510c729efe442a13c2ff7c"}
{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nvoid calc(int bound, int n, int[] dp)\n{\n    static const int mod = 998244353;\n    long sum = 0;\n    dp[0] = 1;\n    foreach (i; 1 .. bound + 1)\n    {\n        sum += dp[i - 1];\n        sum %= mod;\n        dp[i] = cast(int)sum;\n    }\n    foreach (i; bound + 1 .. n + 1)\n    {\n        sum -= dp[i - bound - 1];\n        if (sum < 0) sum += mod;\n        sum += dp[i - 1];\n        sum %= mod;\n        dp[i] = cast(int)sum;\n    }\n}\n\nvoid solve(int n, int k)\n{\n    static const int mod = 998244353;\n    auto rdp = new int[n + 1];\n    auto cdp = new int[n + 1];\n    auto ans = 0;\n    auto last = 0;\n    for (int num = 1; num < k && num <= n; ++ num)\n    {\n        calc(num, n, rdp);\n        auto bound = k / num;\n        if (bound > 0 && k % num == 0) -- bound;\n        if (bound > n) bound = n;\n        calc(bound, n, cdp);\n        long cnt = rdp[n] - last;\n        if (cnt < 0) cnt += mod;\n        cnt <<= 1;\n        cnt %= mod;\n        cnt *= cdp[n];\n        cnt %= mod;\n        ans += cnt;\n        ans %= mod;\n        last = rdp[n];\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        solve(n, k);\n    }\n    return 0;\n}", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b"}
{"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        auto row1 = readln.split.to!(int[]);\r\n        auto row2 = readln.split.to!(int[]);\r\n\r\n        if (sum(row1) == 0 && sum(row2) == 0)\r\n            writeln(0);\r\n        else if (sum(row1) + sum(row2) == 4)\r\n            writeln(2);\r\n        else\r\n            writeln(1);\r\n    }\r\n}\r\n\r\n", "src_uid": "7336b8becd2438f0439240ee8f9610ec"}
{"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\tauto s = readln.strip;\n\n\tuint c;\n\n\twhile(s.length)\n\t{\n\t\tif(s.startsWith(`RU`) || s.startsWith(`UR`))\n\t\t{\n\t\t\ts = s[2..$];\n\t\t}\n\t\telse\n\t\t{\n\t\t\ts = s[1..$];\n\t\t}\n\n\t\tc++;\n\t}\n\n\tc.writeln;\n}\n", "src_uid": "986ae418ce82435badadb0bd5588f45b"}
{"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 a;\n    sc.read(a);\n\n    writeln(2*(a-1)+1, \" \", 2);\n    writeln(1, \" \", 2);\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": "5c000b4c82a8ecef764f53fda8cee541"}
{"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\tint b=0;\n\tint c=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\treadf(\" %d\", &c);\n\tint res=0;\n\tif (a>=b+c)\n\t{\n\t\tres=res+(a-b-c+1);\n\t}\n\tif (b>=a+c)\n\t{\n\t\tres=res+(b-a-c+1);\n\t}\n\tif (c>=a+b)\n\t{\n\t\tres=res+(c-a-b+1);\n\t}\n\twriteln(res);\n\treturn 0;\n}", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09"}
{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(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 = readToken();\n      \n      int[char] freq;\n      foreach (c; S) {\n        ++freq[c];\n      }\n      bool ans = true;\n      foreach (c, f; freq) {\n        ans = ans && (f <= K);\n      }\n      writeln(ans ? \"YES\" : \"NO\");\n    }\n  } catch (EOFException e) {\n  }\n}\n", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"}
{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T 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 n = RD!int;\n\n\tauto dp = new long[](n+1);\n\tdp[0] = 1;\n\tdp[1] = 1;\n\tforeach (i; 2..n)\n\t{\n\t\tdp[i] = dp[i-1];\n\t\tdp[i].moda(dp[i-2]);\n\t}\n\n\tauto ans = dp[n-1];\n\tlong m = 2;\n\tm.modpow(n);\n\tans.modd(m);\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n", "src_uid": "cec37432956bb0a1ce62a0188fe2d805"}
{"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 = 3000;\n\nvoid main()\n{\n    int n, k, M;\n    readf(\"%s %s %s\", &n, &k, &M);\n    readln;\n\n    auto t = readln.chomp.split.map!(to!int).array;\n    t.sort();\n    \n    int tsum = t.sum;\n    \n    int ans = 0;\n    foreach (tot; 0 .. n+1) {\n        long need = tsum.to!long * tot;\n        if (need > M) { break; }\n        \n        int cur = tot * (k + 1);\n        \n        int lfttm = M - need.to!int;\n        int lftprobs = n - tot;\n        \n        foreach (e; t) {\n            int subs = min(lftprobs, lfttm / e);\n            cur += subs;\n            lfttm -= subs * e;\n        }\n        \n        ans = max(ans, cur);\n    }\n    \n    ans.writeln;\n}", "src_uid": "d659e92a410c1bc836be64fc1c0db160"}
{"source_code": "module main;\nimport std.c.stdio;\nimport std.algorithm;\n\n\nint n, a, b;\n\n\nchar getc() {\n    char ch;\n    do { scanf(\"%c\", &ch); } while (ch <= ' ');\n    return ch;\n}\n\nint main(string[] argv) {\n    scanf(\"%d%d%d\", &n, &a, &b);\n    int mx = 0;\n    for (int i = 0; i < n; ++i) {\n        char ch = getc();\n        if (ch == '1') ++mx;\n    }\n \n    long res = -1;\n    for (int i = 1; i <= mx; ++i) {\n        long sz = n/i, cnt = n-i*sz;\n        long cost = (i-cnt) * (a + b*(sz-1)*(sz-1));\n        cost += cnt * (a + b*sz*sz);\n\t    if (res == -1) res = cost;\n\t    res = min(res, cost);\n    }\n    printf(\"%lld\\n\", res);\n    \n    return 0;\n}", "src_uid": "78d013b01497053b8e321fe7b6ce3760"}
{"source_code": "import std.stdio;\n\nbool solve() {\n\tlong n;\n\tif (!readf(\" %s\", &n)) return false;\n\tlong ans = 0;\n\tlong lev = 0;\n\tlong cur = 0;\n\twhile (true) {\n\t\tlev++;\n\t\tcur += lev * 3 - 1;\n\t\tif (cur > n) break;\n\t\tif ((n - cur) % 3 == 0) {\n\t\t\t//writeln(lev);\n\t\t\tans++;\n\t\t}\n\t}\n\twriteln(ans);\n\treturn true;\n}\nvoid main() {\n\twhile (solve()) {}\n}\n", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de"}
{"source_code": "import std.stdio;\nimport std.algorithm.sorting;\nimport std.algorithm.comparison;\n\nuint min_distance(uint[] pieces, uint n) {\n  auto sorted_pieces = sort(pieces);\n  uint min_distance = 1000;\n  for (int i = 0; i < sorted_pieces.length - n + 1; i++) {\n    auto distance = sorted_pieces[i+n-1] - sorted_pieces[i];\n    min_distance = min(distance, min_distance);\n  }\n  return min_distance;\n}\n\nvoid main() {\n  uint n, m, p;\n  uint[] pieces;\n  readf(\"%s %s\", &n, &m);\n  for (int i = 0; i < m; i++) {\n    readf(\" %s\", &p);\n    pieces ~= p;\n  }\n  write(min_distance(pieces, n));\n}", "src_uid": "7830aabb0663e645d54004063746e47f"}
{"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 m = cin.read_int;\n                \n                char c;\n                char[3] colors = ['M', 'C', 'Y'];\n                bool bnw = true;\n\n                for (int i = 0; i < n; i++) {\n                        for (int j = 0; j < m; j++) {\n                                readf(\" %s\", c);\n                                if (canFind(colors[0..3], c)) bnw = false; \n                        }\n                }\n                if (bnw) writeln(\"#Black&White\");\n                else writeln(\"#Color\");\n        }        \n}", "src_uid": "19c311c02380f9a73cd477e4fde27454"}
{"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\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tint fact = 1;\n\t\tforeach (i; 1..n + 1)\n\t\t{\n\t\t\tfact = (fact * 1L * i) % mod;\n\t\t}\n\t\tint pow2 = 1;\n\t\tforeach (i; 0..n - 1)\n\t\t{\n\t\t\tpow2 = (pow2 << 1) % mod;\n\t\t}\n\t\twriteln ((fact - pow2 + mod) % mod);\n\t}\n}\n", "src_uid": "3dc1ee09016a25421ae371fa8005fce1"}
{"source_code": "import std.stdio;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n  auto s = readln().strip().map!(c => c - '0').array;\n  auto n = s.length;\n  s.reverse();\n  int r = -1;\n  foreach (i; 0..n) {\n    auto t = s[i];\n    if (t % 8 == 0) {\n      r = t;\n    }\n  }\n  foreach (i; 0..n) {\n    if (s[i] == 0) continue;\n    foreach (j; 0..i) {\n      auto t = 10 * s[i] + s[j];\n      if (t % 8 == 0) {\n        r = t;\n      }\n    }\n  }\n  foreach (i; 0..n) {\n    if (s[i] == 0) continue;\n    foreach (j; 0..i) {\n      foreach (k; 0..j) {\n        auto t = 100 * s[i] + 10 * s[j] + s[k];\n        if (t % 8 == 0) {\n          r = t;\n        }\n      }\n    }\n  }\n  if (r == -1) {\n    writeln(\"NO\");\n  } else {\n    writeln(\"YES\");\n    writeln(r);\n  }\n}\n", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"}
{"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 a = r.next!int;\n  auto b = r.next!int;\n  auto c = r.next!int;\n  long s;\n  int k = min (a, b);\n  //ab\n  a -= k;\n  s += k;\n  b -= k;\n  s += k;\n  s += 2 * c;\n  if (a || b) s++;\n  writeln (s);\n}\n\n", "src_uid": "609f131325c13213aedcf8d55fc3ed77"}
{"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    readln;\n    auto os = readln.chomp;\n    int n;\n    foreach (o; os) {\n        if (o == '+') {\n            ++n;\n        } else if (o == '-' && n > 0) {\n            --n;\n        }\n    }\n    writeln(n);\n}", "src_uid": "a593016e4992f695be7c7cd3c920d1ed"}
{"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    long n, k;\n    readf(\"%s %s\", &n, &k);\n    readln;\n    \n    if (n < k/2 + 1) {\n        writeln(0);\n        return;\n    }\n    \n    auto lst = min(k-1, n);\n    auto frst = k/2 + 1;\n    \n    auto ans = lst - frst + 1;\n    \n    ans.writeln;\n}", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"}
{"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 long LIM = 100000;\n\nlong A, B, K;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tA = readLong;\n\t\tB = readLong;\n\t\tK = readLong;\n\t\t\n\t\tlong ans = -1;\n\t\t\n\t\t// foreach (phase; 0 .. 2) {\n\t\t\tforeach (x; 0 .. LIM) {\n\t\t\t\t//\t[A / (x + 1)] + [B / (y + 1)]\n\t\t\t\tconst y = K - x;\n\t\t\t\tif (0 <= x && x < A && 0 <= y && y < B) {\n\t\t\t\t\tchmax(ans, (A / (x + 1)) * (B / (y + 1)));\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tforeach (a; 1 .. LIM) {\n\t\t\t\t//\t[A / (x + 1)] = a\n\t\t\t\t/*\n\t\t\t\t\twant x to be large\n\t\t\t\t\ta <= A / (x + 1) < a + 1\n\t\t\t\t\ta (x + 1) <= A < (a + 1) (x + 1)\n\t\t\t\t\tA / (a + 1) < x + 1 <= A / a\n\t\t\t\t*/\n\t\t\t\tconst x = min(A / a - 1, K);\n\t\t\t\tconst y = K - x;\n\t\t\t\tif (0 <= x && x < A && 0 <= y && y < B) {\n\t\t\t\t\tchmax(ans, (A / (x + 1)) * (B / (y + 1)));\n\t\t\t\t}\n\t\t\t}\n\t\t\t// swap(A, B);\n\t\t// }\n\t\t\n\t\twriteln(ans);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "src_uid": "bb453bbe60769bcaea6a824c72120f73"}
{"source_code": "import std.stdio;\n\nvoid main() {\n    long l, r;\n    scanf(\"%ld%ld\", &l, &r);\n\n    auto ans = 0;\n    for (long a2=1; a2<=r; a2*=2) {\n        for (long a3=1; a3<=r/a2; a3*=3) {\n            if (a2 * a3 >= l) ans++;\n        }\n    }\n    writeln(ans);\n}", "src_uid": "05fac54ed2064b46338bb18f897a4411"}
{"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 x, y;\n\treadln.chomp.split.tie(x, y);\n\tif (x == y) {\n\t\twriteln = \"=\";\n\t} else {\n\t\treal a = y * log10(cast(real)x);\n\t\treal b = x * log10(cast(real)y);\n\t\tdebug verbose(a, b);\n\t\tif (abs(a - b) < 1e-9) {\n\t\t\twriteln = \"=\";\n\t\t} else {\n\t\t\twriteln = a < b ? \"<\" : \">\";\n\t\t}\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", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"}
{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tlong a, b;\n\twhile (readf (\" %s %s\", &a, &b) > 0)\n\t{\n\t\tlong res = 1;\n\t\tforeach (c; a + 1..b + 1)\n\t\t{\n\t\t\tres *= c;\n\t\t\tres %= 10;\n\t\t\tif (res == 0)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"}
{"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 A, B, C;\n\nvoid main () {\n    A = readInt();\n    B = readInt();\n    C = readInt();\n\n    bool ok = false;\n\n    foreach(int X; 0 .. A + 1) {\n        int Y = B - X;\n        int Z = C - Y;\n\n        if (Y < 0 || Z < 0) continue;\n\n        if (X + Y == B && X + Z == A && Y + Z == C) {\n            writefln(\"%s %s %s\", X, Y, Z);\n            ok = true;\n            break;\n        }\n    }\n\n    if (!ok) {\n        writeln(\"Impossible\");\n    }\n}", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"}
{"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.modint;\n\nalias Mint = ModInt!(998244353);\n\nint main() {\n    Scanner sc = new Scanner(stdin);\n    scope(exit) assert(!sc.hasNext);\n\n    int w, h;\n    sc.read(w, h);\n\n    writeln(Mint(2) ^^ (w + h));\n    return 0;\n}\n/* IMPORT /home/yosupo/Programs/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<MD)?x:x-MD;}\n    static auto make(uint x) {ModInt m; m.v = x; return m;}\n     \n    auto opBinary(string op:\"+\")(ModInt r) const {return make(normS(v+r.v));}\n     \n    auto opBinary(string op:\"-\")(ModInt r) const {return make(normS(v+MD-r.v));}\n     \n    auto opBinary(string op:\"*\")(ModInt r) const {return make((ulong(v)*r.v%MD).to!uint);}\n     \n    auto opBinary(string op:\"/\")(ModInt r) const {return this*inv(r);}\n     \n    auto opBinary(string op:\"^^\", T)(T r) const {return pow(this, r, ModInt(1));}\n    auto opOpAssign(string op)(ModInt r) {return mixin (\"this=this\"~op~\"r\");}\n     \n    static ModInt inv(ModInt x) {return x^^(MD-2);};\n    string toString() const {return v.to!string;}\n}\n\n \n \n\n \n\n \nstruct DModInt(string name) {\n    import std.conv : to;\n    static uint MD;\n    uint v;\n    this(int v) {this(long(v));}\n    this(long v) {this.v = ((v%MD+MD)%MD).to!uint;}\n    static auto normS(uint x) {return (x<MD)?x:x-MD;}\n    static auto make(uint x) {DModInt m; m.MD = MD; m.v = x; return m;}\n     \n    auto opBinary(string op:\"+\")(DModInt r) const {return make(normS(v+r.v));}\n     \n    auto opBinary(string op:\"-\")(DModInt r) const {return make(normS(v+MD-r.v));}\n     \n    auto opBinary(string op:\"*\")(DModInt r) const {return make((ulong(v)*r.v%MD).to!uint);}\n     \n    auto opBinary(string op:\"/\")(DModInt r) const {return this*inv(r);}\n    auto opOpAssign(string op)(DModInt r) {return mixin (\"this=this\"~op~\"r\");}\n     \n    static DModInt inv(DModInt x) {\n        return DModInt(extGcd!int(x.v, MD)[0]);\n    }\n    string toString() {return v.to!string;}\n}\n\n \n \n\n \n\ntemplate isModInt(T) {\n    const isModInt =\n        is(T : ModInt!MD, uint MD) || is(T : DModInt!S, string S);\n}\n\n \nT[] factTable(T)(size_t length) if (isModInt!T) {\n    import std.range : take, recurrence;\n    import std.array : array;\n    return T(1).recurrence!((a, n) => a[n-1]*T(n)).take(length).array;\n}\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\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 /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/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/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", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"}
{"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\nbool isPrime (int n)\r\n{\r\n\tif (n < 2)\r\n\t{\r\n\t\treturn false;\r\n\t}\r\n\tfor (int d = 2; d * d <= n; d++)\r\n\t{\r\n\t\tif (n % d == 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\tint n;\r\n\tlong m;\r\n\twhile (readf !(\" %s %s\") (n, m) > 0)\r\n\t{\r\n\t\tint mMod = m % mod;\r\n\t\tint mPowN = 1;\r\n\t\tint whole = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tmPowN = (mPowN * 1L * mMod) % mod;\r\n\t\t\twhole = (whole + mPowN) % mod;\r\n\t\t}\r\n\r\n\t\tint res = 1;\r\n\t\tlong cur = 1;\r\n\t\tint total = 0;\r\n\t\tforeach (i; 0..n)\r\n\t\t{\r\n\t\t\tif (isPrime (i + 1))\r\n\t\t\t{\r\n\t\t\t\tcur *= i + 1;\r\n\t\t\t}\r\n\t\t\tauto good = m / cur;\r\n\t\t\tres = (res * 1L * (good % mod)) % mod;\r\n\t\t\ttotal = (total + res) % mod;\r\n\t\t\tif (good == 0)\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\ttotal = (whole - total + mod) % mod;\r\n\t\twriteln (total);\r\n\t}\r\n}\r\n", "src_uid": "0fdd91ed33431848614075ebe9d2ee68"}
{"source_code": "import std.stdio;\nimport std.string;\n\nvoid main() {\n  int n;\n  readf(\" %s\", &n);\n  readln;\n  auto s = readln.strip;\n  auto rCount = s.count('R'), gCount = s.count('G'), bCount = s.count('B');\n  auto reach = new bool[201][201][201];\n  reach[rCount][gCount][bCount] = true;\n  foreach_reverse (total; 0..201) {\n    foreach (i; 0..total + 1) {\n      foreach (j; 0..total + 1 - i) {\n        int k = total - i - j;\n        if (reach[i][j][k]) {\n          if (i >= 1 && j >= 1) reach[i - 1][j - 1][k + 1] = true;\n          if (i >= 1 && k >= 1) reach[i - 1][j + 1][k - 1] = true;\n          if (j >= 1 && k >= 1) reach[i + 1][j - 1][k - 1] = true;\n          if (i >= 2) reach[i - 1][j][k] = true;\n          if (j >= 2) reach[i][j - 1][k] = true;\n          if (k >= 2) reach[i][j][k - 1] = true;\n        }\n      }\n    }\n  }\n  if (reach[0][0][1]) write('B');\n  if (reach[0][1][0]) write('G');\n  if (reach[1][0][0]) write('R');\n  writeln;\n}\n\n", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"}
{"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 l, r; get(l, r);\n  for(int candidate = l; candidate <= r; candidate++)\n    {\n      int[10] count;\n      int c = candidate;\n      while(c)\n\t{\n\t  count[c % 10]++;\n\t  c /= 10;\n\t}\n      bool issol = true;\n      foreach(cn; count)\n\t{\n\t  if (cn > 1)\n\t    {\n\t      issol = false;\n\t      break;\n\t    }\n\t}\n      if (issol)\n\t{\n\t  ans(candidate);\n\t}\n    }\n  ans(-1);\n}\n", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"}
{"source_code": "import std.stdio, std.conv, std.functional, std.string;\r\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\r\nimport std.bigint, std.numeric, std.math, std.random;\r\nimport core.bitop;\r\n\r\nstring FMT_F = \"%.10f\";\r\n\r\nstatic File _f;\r\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\r\nstatic string[] s_rd;\r\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\r\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\r\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\r\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }\r\n\r\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\r\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\r\n\r\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\r\nbool inside(T)(T x, 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\tauto index = a.MAKE_IDX;\r\n\t\r\n\tauto tot = a.sum;\r\n\tif (tot % 2)\r\n\t\twriteln(0);\r\n\telse\r\n\t{\r\n\t\tauto dp = new bool[](cast(size_t)(tot/2+1));\r\n\t\tdp[0] = true;\r\n\t\tforeach (i; index)\r\n\t\t{\r\n\t\t\tforeach_reverse (j; 0..dp.length)\r\n\t\t\t{\r\n\t\t\t\tif (dp[j] == false) continue;\r\n\t\t\t\tauto x = cast(int)(a[i] + j);\r\n\t\t\t\tif (x > tot/2) continue;\r\n\t\t\t\tdp[x] = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (dp[$-1] == false)\r\n\t\t\twriteln(0);\r\n\t\telse\r\n\t\t{\r\n\t\t\tlong pos = -1;\r\n\t\t\tforeach (i; 0..n)\r\n\t\t\t{\r\n\t\t\t\tif (a[i] % 2)\r\n\t\t\t\t{\r\n\t\t\t\t\tpos = i;\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (pos != -1)\r\n\t\t\t{\r\n\t\t\t\twriteln(1);\r\n\t\t\t\twriteln(pos+1);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tforeach (i; 0..n)\r\n\t\t\t\t{\r\n\t\t\t\t\tauto nTot = cast(int)(tot - a[i]);\r\n\t\t\t\t\tif (dp[nTot/2] == false)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tpos = i;\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 (pos == -1)\r\n\t\t\t\t\tassert(0);\r\n\t\t\t\twriteln(1);\r\n\t\t\t\twriteln(pos+1);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstdout.flush;\r\n\tdebug readln;\r\n}", "src_uid": "29063ad54712b4911c6bf871969ee147"}
{"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\t\n\tlong f(long x)\n\t{\n\t\tif (x < 10) return 9;\n\n\n\t\tlong ans = 1;\n\t\t++x;\n\t\twhile (x % 10 == 0)\n\t\t{\n\t\t\tx /= 10;\n\t\t}\n\t\treturn ans + f(x);\n\t}\n\t\n\twriteln(f(N));\n\tstdout.flush();\n\tdebug readln();\n}", "src_uid": "055fbbde4b9ffd4473e6e716da6da899"}
{"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 res = 1;\n\t\tint total = 1;\n\t\twhile (total < n)\n\t\t{\n\t\t\ttotal += total + 1;\n\t\t\tres += 1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "src_uid": "95cb79597443461085e62d974d67a9a0"}
{"source_code": "static immutable uint PRIMES_NUM = 16;\nstatic immutable uint MAX_MASK = 1 << (PRIMES_NUM + 1);\nstatic immutable uint MAX_NUM = 101;\nstatic immutable uint MAXN = 58 + 1;\nstatic immutable uint[] PRIME_DECOMP_MASKS = [0, 0, 1, 2, 1, 4, 3,  8, 1, 2,  5, 16, 3, 32,  9,  6, 1,  64, 3, 128,  5, 10, 17, 256, 3, 4, 33, 2,  9,  512,  7, 1024, 1, 18,  65, 12, 3, 2048, 129, 34,  5, 4096, 11,  8192, 17,  6, 257, 16384, 3,  8,  5,  66, 33, 32768, 3, 20,  9, 130,  513];\n\npure uint subabs(const uint a, const uint b) {\n\treturn (a > b) ? a - b : b - a;\n}\n\npure void solvedp(const uint[] as, out uint[] bs) {\n\timport std.typecons;\n\n\talias Node = Tuple!(uint, \"ind\", uint, \"mask\");\n\talias PrevNode = Tuple!(uint, \"u\", Node, \"prev\");\n\n\tpure bool nodeEq(const Node a, const Node b) {\n\t\treturn (a.ind == b.ind) && (a.mask == b.mask);\n\t}\n\n\tPrevNode[][] prev = new PrevNode[][](MAX_NUM, MAX_MASK);\n\tauto cost = new uint[][](MAX_NUM, MAX_MASK);\n\n\n\tcost[0][] = uint.max;\n\tforeach(uint u; 1..59) {\n\t\tauto maskjoined = PRIME_DECOMP_MASKS[u];\n\t\tif (cost[0][maskjoined] > subabs(as[0], u)) {\n\t\t\tcost[0][maskjoined] = subabs(as[0], u);\n\t\t\tprev[0][maskjoined] = PrevNode(u, Node(0, maskjoined));\n\t\t}\n\t}\n\tforeach (i; 1..as.length) {\n\t\tcost[i][] = uint.max;\n\t\tforeach (mask, c; cost[i - 1]) {\n\t\t\tif (c == uint.max) {continue;}\n\t\t\tforeach (uint u; 1..MAXN) {\n\t\t\t\tauto umask = PRIME_DECOMP_MASKS[u];\n\t\t\t\tif (0 != (umask & mask)) {continue;}\n\t\t\t\tauto maskjoined = umask | mask;\n\t\t\t\tif (cost[i][maskjoined] > c + subabs(as[i], u)) {\n\t\t\t\t\tcost[i][maskjoined] = c + subabs(as[i], u);\n\t\t\t\t\tprev[i][maskjoined] = PrevNode(u, Node(i - 1, mask));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tauto minCost = uint.max;\n\tuint minMask = 0;\n\tforeach (mask, c; cost[as.length - 1]) {\n\t\tif (c < minCost) {\n\t\t\tminCost = c;\n\t\t\tminMask = mask;\n\t\t}\n\t}\n\n\t{\n\t\tbs.length = as.length;\n\t\tuint ind = as.length - 1;\n\t\tauto next = prev[ind][minMask];\n\t\tauto oldNext = next;\n\t\tdo {\n\t\t\tbs[ind--] = next.u;\n\t\t\toldNext = next;\n\t\t\tnext = prev[next.prev.ind][next.prev.mask];\n\t\t} while(false == nodeEq(oldNext.prev, next.prev));\n\t\tif (0 == ind) {bs[ind] = next.u;}\n\t}\n}\n\nint main(string[] argv) {\n    import std.stdio;\n\n\tuint n = 0;\n\tuint[] as;\n\n\treadf(\" %s\", &n);\n\tas.length = n;\n\tforeach (i; 0..n) {\n\t\treadf(\" %s\", &as[i]);\n\t}\n\n\tuint[] bs;\n\tsolvedp(as, bs);\n\n\tforeach (b; bs) {\n\t\twrite(b, ' ');\n\t}\n\n    return 0;\n}\n", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6"}
{"source_code": "import std.stdio, std.string, std.algorithm, std.conv, std.range, std.math;\n\nvoid main() {\n  string s1 = readln.chomp.toLower;\n  string s2 = readln.chomp.toLower;\n\n  if (s1 > s2) { \"1\".writeln; }\n  else if (s1 == s2) { \"0\".writeln; }\n  else { \"-1\".writeln; }\n}\n", "src_uid": "ffeae332696a901813677bd1033cf01e"}
{"source_code": "import std.stdio;\n\nvoid main() {\n    int n;\n    scanf(\"%d\", &n);\n    int ans = 1;\n    int x = 4;\n    for (int i = 2; i <= n; ++i) {\n        ans += x;\n        x += 4;\n    }\n    printf(\"%d\\n\", ans);\n}\n", "src_uid": "758d342c1badde6d0b4db81285be780c"}
{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.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\tlong n = rlong, m = rlong;\n\tFinite.mod = m;\n\tFinite ans = Finite(0);\n\tforeach(i; 1 .. n + 1){\n\t\tlog(\"i:\", i, \"n+1-i:\", n + 1 - i,  \"perm(i):\", perm(i), \"perm(n-i):\", perm(n - i));\n\t\tans += Finite(n + 1 - i) * (n + 1 - i) * perm(i) * perm(n - i);\n\t}\n\tans.writeln;\n}\n\nimport std.conv;\nstruct Finite{\n\tlong value; static long mod = 1_000_000_007;\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\n// ---以下はユーティリティ--- //\n\n/// mod p における階乗\n/// 例 perm(6) = Finite(120)\n/// オーダーはプログラム全体で出てくる最大の引数Nに対してO(N)\nFinite perm(long x){\n\tstatic Finite[] _perm = [];\n\tif(_perm.length == 0) _perm ~= Finite(1);\n\tx = Finite.val(x);\n\twhile(x >= _perm.length)\n\t\t\t_perm ~= _perm[$ - 1] * _perm.length;\n\treturn _perm[x.to!int];\n}\n\n/// mod p における階乗の逆元\n/// 例 invperm(6) = Finite(1) / Finite(120)\n/// オーダーはプログラム全体で出てくる最大の引数Nに対してO(N)\n/// ※ invperm(x) と inv(perm(x)) は同じ値だが、後者は計算量が O(mod) になる\nFinite invperm(long x){\n\tstatic Finite[] _invperm = [];\n\tif(_invperm.length == 0) _invperm ~= Finite(1);\n\tx = Finite.val(x);\n\twhile(x >= _invperm.length)\n\t\t\t_invperm ~= _invperm[$ - 1] / _invperm.length;\n\treturn _invperm[x.to!int];\n}\n\n/// mod p における二項係数(定義に注意:(a + b)! / a! / b! )\n/// 例 pascal(3, 2) = Finite(10)\n/// ただし、「a < 0 または b < 0」のとき答えは 0 を返します。\nFinite pascal(long a, long b){\n\tif(a < 0 || b < 0) return Finite(0);\n\tFinite res = perm(a + b) * invperm(a) * invperm(b);\n\treturn res;\n}\n", "src_uid": "020d5dae7157d937c3f58554c9b155f9"}
{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tint k = readln.split[1].to!int;\n\tint [] v;\n\tforeach (c; readln.strip.map!\"a - 96\".array.sort) if (v.empty || c > v.back + 1) v ~= c;\n\twriteln (v.length >= k ? v[0..k].sum : -1);\n}\n", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"}
{"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;\nstring S;\n\nvoid main() {\n  try {\n    for (; ; ) {\n      S = readToken();\n      N = cast(int)(S.length);\n      \n      const a = S.count('a');\n      \n      int ans = a;\n      foreach (x; a .. N + 1) {\n        if (2 * a > x) {\n          chmax(ans, x);\n        }\n      }\n      writeln(ans);\n    }\n  } catch (EOFException e) {\n  }\n}\n", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"}
{"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 = 54;\nimmutable int MOD = 1_000_000_007;\n\nlong [MAX_N] [MAX_N] c;\n\nvoid main ()\n{\n    foreach (i; 0..MAX_N)\n    {\n        c[i][0] = 1;\n        foreach (j; 1..i + 1)\n        {\n            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;\n        }\n    }\n\n    int n, k;\n    while (readf (\" %s %s\", &n, &k) > 0)\n    {\n        auto a = new int [n];\n        k /= 50;\n        int x = 0;\n        int y = 0;\n        foreach (i; 0..n)\n        {\n            readf (\" %s\", &a[i]);\n            a[i] /= 50;\n            if (a[i] == 1)\n            {\n                x++;\n            }\n            else if (a[i] == 2)\n            {\n                y++;\n            }\n            else\n            {\n                enforce (false);\n            }\n        }\n\n        alias Tuple !(int, \"b\", int, \"x\", int, \"y\") state;\n        alias Tuple !(int, \"dist\", int, \"num\") value;\n        state [] q;\n        q.reserve (2 * (x + 1) * (y + 1));\n        auto f = new value [] [] [] (2, x + 1, y + 1);\n        foreach (b; 0..2)\n        {\n            foreach (cx; 0..x + 1)\n            {\n                f[b][cx][] = value (int.max, 0);\n            }\n        }\n\n        f[0][0][0] = value (0, 1);\n        q ~= state (0, 0, 0);\n        while (q.length > 0)\n        {\n            state cur = q[0];\n            q = q[1..$];\n            int cb = cur.b;\n            int cx = cur.x;\n            int cy = cur.y;\n            int cd = f[cb][cx][cy].dist + 1;\n            int cn = f[cb][cx][cy].num;\n            debug {writefln (\"%s %s %s\", cb, cx, cy);}\n            int nb = 1 - cb;\n            foreach (dx; 0..x + 1)\n            {\n                foreach (dy; 0..y + 1)\n                {\n                    if (!dx && !dy)\n                    {\n                        continue;\n                    }\n                    if (dx + dy * 2 > k)\n                    {\n                        break;\n                    }\n                    int nx, ny;\n                    long mult;\n                    if (cb) // back\n                    {\n                        nx = cx - dx;\n                        ny = cy - dy;\n                        mult = (c[cx][dx] *\n                                c[cy][dy]) % MOD;\n                        if (nx < 0 || ny < 0)\n                        {\n                            continue;\n                        }\n                    }\n                    else // forward\n                    {\n                        nx = cx + dx;\n                        ny = cy + dy;\n                        mult = (c[x - cx][dx] *\n                                c[y - cy][dy]) % MOD;\n                        if (nx > x || ny > y)\n                        {\n                            continue;\n                        }\n                    }\n                    if (f[nb][nx][ny].dist == int.max)\n                    {\n                        f[nb][nx][ny].dist = cd;\n                        q ~= state (nb, nx, ny);\n                    }\n                    if (f[nb][nx][ny].dist != cd)\n                    {\n                        continue;\n                    }\n                    f[nb][nx][ny].num =\n                      (f[nb][nx][ny].num +\n                       mult * cn) % MOD;\n                }\n            }\n        }\n\n        writefln (\"%s\", f[1][x][y].dist == int.max ?\n                  -1 : f[1][x][y].dist);\n        writefln (\"%s\", f[1][x][y].num);\n    }\n}\n", "src_uid": "ebb0323a854e19794c79ab559792a1f7"}
{"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 t = readln.split;\n\t\tbool ok = t.any !(r => r[0] == s[0] || r[1] == s[1]);\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n", "src_uid": "699444eb6366ad12bc77e7ac2602d74b"}
{"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\ta.sort();\n\t\n\tlong ans = 1;\n\tforeach (i; 1..a.length)\n\t{\n\t\tbool ok;\n\t\tforeach (j; 0..i)\n\t\t{\n\t\t\tif (a[i] % a[j] == 0)\n\t\t\t{\n\t\t\t\tok = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (!ok)\n\t\t\t++ans;\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"}
{"source_code": "import std.stdio;\n\nversion (D_LP64)\n{\n  alias ulong sint;\n}\nelse\n{\n  alias uint sint;\n}\n\nunittest {\n  assert(solve(2,3,3) == 1,\"Test 1\");\n  assert(solve(0,-1,2) == 1000000006,\"Test 2\");\n  assert(solve(-9,-11,12345) == 1000000005,\"Test 3\");\n}\n\nlong solve(long x0, long x1, sint i){\n  long[] f = [x0,x1,x1-x0,-x0,-x1,-x1+x0];\n  auto index = ((i-1) % 6);\n  long x = f[index];\n  long r = x % (1000000000 + 7);\n  //writeln(r);\n  if (r < 0)\n    r = 1000000000 + 7 + r;\n  //writeln(x);\n  //writeln(r);\n  return r;\n}\n\nvoid main(){\n  auto x0 = 0;\n  auto x1 = 0;\n  auto n = 0;\n\n  readf(\" %s \",&x0);\n  readf(\" %s \",&x1);\n  readf(\" %s \",&n);\n\n  writeln(solve(x0,x1,n));\n}\n\n//5,2,-3,-5,-2,3,5,2  [5,3]\n//3,-2,-5,-3,2,5,3,   [3,5]\n//a,b,b-a,-a,-b,-b+a\n", "src_uid": "2ff85140e3f19c90e587ce459d64338b"}
{"source_code": "import\n\t\tstd.math,\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\tauto arr = readln.splitter.map!(to!int).array;\n\n\tauto l = arr[0], r = arr[1], a = arr[2];\n\n\tauto need = max(l, r) - min(l, r);\n\tauto rest = a - need;\n\tauto ans = min(l, r) + (rest < 0 ? a : need + rest / 2);\n\n\twriteln(ans * 2);\n}\n", "src_uid": "e8148140e61baffd0878376ac5f3857c"}
{"source_code": "module main;\n\nimport core.stdc.stdio;\n\nchar[101] s;\n\nint main(string[] argv)\n{\n\tint n,want;\n\tscanf(\"%d%d\",&n,&want);\n\tscanf(\"%s\",&s);\n\n\tint mx=0;\n\tfor(int at=0,to=at;at<n;at=to) {\n\t    while(to<n&&s[to]!='N') ++to;\n\t    if(s[at]!='N') continue;\n\t    while(to<n&&s[to]=='N') ++to;\n\t    int cur=to-at; if(cur>mx) mx=cur;\n\t}\n\t\n\tbool can=false; int nerr=0;\n\tfor(int i=0;i<want;++i) if(s[i]=='Y') ++nerr;\n\tfor(int i=0;i<=n-want;++i) {\n\t    if(nerr==0&&(i==0||s[i-1]!='N')&&(i==n-want||s[i+want]!='N')) can=true;\n\t    if(i==n-want) break;\n\t    if(s[i]=='Y') --nerr;\n\t    if(s[i+want]=='Y') ++nerr;\n\t}\n\n\tif(want>=mx&&can) printf(\"YES\\n\"); else printf(\"NO\\n\");\n\treturn 0;\n}", "src_uid": "5bd578d3da5837c259b222336a194d12"}
{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\n\n\nvoid main()\n{\n    string[] lines;\n    while(true)\n    {\n        string line = stdin.readln().strip();\n        if (line == \"\") break;\n        lines ~= [line];\n    }\n    auto result = process(lines);\n    foreach (line; result)\n    {\n        write(line);\n    }\n}\n\nstring[] process(string[] lines)\n{\n    auto parts = split(lines[0], ' ');\n    auto n = to!long(parts[0]);\n    auto m = to!long(parts[1]);\n    auto a = to!long(parts[2]);\n    auto n_tiles = n % a == 0 ? n/a : n/a+1;\n    auto m_tiles = m % a == 0 ? m/a : m/a+1;\n    auto result = n_tiles*m_tiles;\n    return [to!string(result)];\n}\n\n\nunittest\n{\n    auto expected = [\"4\"];\n    auto actual = process([\"6 6 4\"]);\n    writefln(\"expected: %s\", expected[0]);\n    writefln(\"actual: %s\", actual[0]);\n    assert(expected == actual);\n}\n\nunittest\n{\n    auto expected = [\"27126743055556\"];\n    auto actual = process([\"1000000000 1000000000 192\"]);\n    writefln(\"expected: %s\", expected[0]);\n    writefln(\"actual: %s\", actual[0]);\n    assert(expected == actual);\n}\n\n", "src_uid": "ef971874d8c4da37581336284b688517"}
{"source_code": "import std.stdio;\nimport std.string;\n\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tfor (int i=0; i<t; i++)\n\t{\n\t\tint a=0;\n\t\treadf(\" %d\", &a);\n\t\tif (a%7==0)\n\t\t{\n\t\t\twriteln(a/7);\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln(a/7+1);\n\t\t}\n\t}\n\treturn 0;\n}", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c"}
{"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 medN = 150;\nimmutable int maxN = medN * 2 + 1;\nimmutable int dirs = 8;\nimmutable int [dirs] dRow = [-1, -1, -1,  0, +1, +1, +1,  0];\nimmutable int [dirs] dCol = [-1,  0, +1, +1, +1,  0, -1, -1];\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto t = readln.split.map !(to !(int)).array;\n\n\t\tubyte [maxN] [maxN] [3] f;\n\t\tint b = 0;\n\t\tf[b][medN][medN] |= 1 << 1;\n\t\tforeach (ct; t)\n\t\t{\n\t\t\tforeach (j; 0..ct)\n\t\t\t{\n\t\t\t\tb ^= 1;\n\t\t\t\tforeach (ref g; f[b][])\n\t\t\t\t{\n\t\t\t\t\tg[] = 0;\n\t\t\t\t}\n\t\t\t\tforeach (row; 0..maxN)\n\t\t\t\t{\n\t\t\t\t\tforeach (col; 0..maxN)\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach (dir; 0..dirs)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (f[!b][row][col] & (1 << dir))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tint nrow = row + dRow[dir];\n\t\t\t\t\t\t\t\tint ncol = col + dCol[dir];\n\t\t\t\t\t\t\t\tf[b][nrow][ncol] |= 1 << dir;\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\n\t\t\t\tforeach (row; 0..maxN)\n\t\t\t\t{\n\t\t\t\t\tforeach (col; 0..maxN)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[2][row][col] |= f[b][row][col];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tb ^= 1;\n\t\t\tforeach (ref g; f[b][])\n\t\t\t{\n\t\t\t\tg[] = 0;\n\t\t\t}\n\t\t\tforeach (row; 0..maxN)\n\t\t\t{\n\t\t\t\tforeach (col; 0..maxN)\n\t\t\t\t{\n\t\t\t\t\tforeach (dir; 0..dirs)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (f[!b][row][col] & (1 << dir))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tf[b][row][col] |= 1 << ((dir + 1) & 7);\n\t\t\t\t\t\t\tf[b][row][col] |= 1 << ((dir + 7) & 7);\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\tlong res = 0;\n\t\tforeach (row; 0..maxN)\n\t\t{\n\t\t\tforeach (col; 0..maxN)\n\t\t\t{\n\t\t\t\tres += (f[2][row][col] != 0);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9"}
{"source_code": "import std.stdio;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.typecons;\nimport std.range;\nimport std.random;\nimport std.math;\nimport std.container;\nimport std.numeric;\nimport std.bigint;\n\n\nbool is_prime(long x) {\n  if (x <= 1 || x % 2 == 0) return false;\n  long i = 3;\n  while (i*i <= x) {\n    if (x % i == 0)\n      return false;\n    i += 2;\n  }\n  return true;\n}\n\n\nvoid main() {\n  auto N = readln.chomp.to!long;\n  if (N == 2) writeln(1);\n  else if (N == 3) writeln(1);\n  else if (N == 5) writeln(1);\n  else if (N % 2 == 0) writeln(2);\n  else if (is_prime(N)) writeln(1);\n  else if (is_prime(N-2)) writeln(2);\n  else writeln(3);\n}\n", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b"}
{"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.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\treadln;\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//\t\trandomShuffle (a);\n\n\t\tint [] ans;\n\t\tforeach (i; 0..n)\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 (i == j)\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\tif (i == k)\n\t\t\t\t\t{\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint v = 0;\n\t\t\t\t\tv += (a[i][0] - a[j][0]) *\n\t\t\t\t\t    (a[i][0] - a[k][0]);\n\t\t\t\t\tv += (a[i][1] - a[j][1]) *\n\t\t\t\t\t    (a[i][1] - a[k][1]);\n\t\t\t\t\tv += (a[i][2] - a[j][2]) *\n\t\t\t\t\t    (a[i][2] - a[k][2]);\n\t\t\t\t\tv += (a[i][3] - a[j][3]) *\n\t\t\t\t\t    (a[i][3] - a[k][3]);\n\t\t\t\t\tv += (a[i][4] - a[j][4]) *\n\t\t\t\t\t    (a[i][4] - a[k][4]);\n\t\t\t\t\tif (v > 0)\n\t\t\t\t\t{\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}\n\t\t\tif (ok)\n\t\t\t{\n\t\t\t\tans ~= i + 1;\n\t\t\t}\n\t\t}\n\n\t\twriteln (ans.length);\n\t\tforeach (c; ans)\n\t\t{\n\t\t\twriteln (c);\n\t\t}\n\t}\n}\n", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9"}
{"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tlong n1, n2, k1, k2;\n\tscanf(\"%d %d %d %d\", &n1, &n2, &k1, &k2);\n\tif (n1 > n2)\n\t{\n\t\tprintf(\"First\");\n\t} else {\n\t\tprintf(\"Second\");\n\t}\n\treturn 0;\n}", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b"}
{"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  char[2] lastChar = [0, 0];\n  auto color = new bool[n.ind];\n  foreach(i, c; s)\n    {\n      if (c >= lastChar[0])\n        {\n          color[i] = 0;\n          lastChar[0] = c;\n        }\n      else if (c >= lastChar[1])\n        {\n          color[i] = 1;\n          lastChar[1] = c;\n        }\n      else\n        {\n          writeln(\"NO\");\n          return;\n        }\n    }\n  writeln(\"YES\");\n  foreach(b; color)\n    write(cast(int)b);\n  writeln;\n}\n", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b"}
{"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 = 10 ^^ 9 + 7;\nimmutable long oneHalf = mod / 2 + 1;\n\n// x -> a1x + a0\n// b1(a1x + a0) + b0 = b1a1x + b1a0+b0\nlong [2] apply (long [2] a, long [2] b)\n{\n\treturn [(b[1] * a[0] + b[0]) % mod, (b[1] * a[1]) % mod];\n}\n\nlong [2] gen (long k)\n{\n\tif (k == 0)\n\t{\n\t\treturn [0L, 1];\n\t}\n\tif (k == 1)\n\t{\n\t\treturn [mod - oneHalf, 2L];\n\t}\n\tauto res = gen (k / 2);\n\tres = apply (res, res);\n\tif (k & 1)\n\t{\n\t\tres = apply (res, gen (1));\n\t}\n\treturn res;\n}\n\nlong solve (long x, long k)\n{\n\tif (x == 0)\n\t{\n\t\treturn 0;\n\t}\n\tx %= mod;\n\tauto a = gen (k);\n\ta = apply (a, [0L, 2]);\n\treturn (a[1] * x + a[0]) % mod;\n}\n\nvoid main ()\n{\n\tlong x, k;\n\twhile (readf (\" %s %s\", &x, &k) > 0)\n\t{\n\t\twriteln (solve (x, k));\n\t}\n}\n", "src_uid": "e0e017e8c8872fc1957242ace739464d"}
{"source_code": "import std.stdio;\nimport std.math;\nint main()\n{\n\tint[5][5] m;\n\tfor (int i=0; i<5; i++)\n\t{\n\t\tfor (int j=0; j<5; j++)\n\t\t{\n\t\t\treadf(\" %d\", &m[i][j]);\n\t\t}\n\t}\n\tint x=0;\n\tint y=0;\n\tfor (int i=0; i<5; i++)\n\t{\n\t\tfor (int j=0; j<5; j++)\n\t\t{\n\t\t\tif (m[i][j]==1)\n\t\t\t{\n\t\t\t\tx=i;\n\t\t\t\ty=j;\n\t\t\t}\n\t\t}\n\t}\n\twriteln(abs(x-2)+abs(y-2));\n\treturn 0;\n}", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9"}
{"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\n\nvoid main() {\n  int n;\n  readf! \" %d\" (n);\n  ulong res;\n  if (!(n & 1)) {\n    res = 1 << (n / 2);\n  }\n  writeln (res);\n}\n\n", "src_uid": "4b7ff467ed5907e32fd529fb39b708db"}
{"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.strip) != \"\")\n\t{\n\t\tlong nb, ns, nc;\n\t\treadf (\" %s %s %s \", &nb, &ns, &nc);\n\t\tlong pb, ps, pc;\n\t\treadf (\" %s %s %s \", &pb, &ps, &pc);\n\t\tlong kb, ks, kc;\n\t\tkb = count (s, 'B');\n\t\tks = count (s, 'S');\n\t\tkc = count (s, 'C');\n\t\tlong r;\n\t\treadf (\" %s \", &r);\n\n\t\tbool go (long num)\n\t\t{\n\t\t\tlong d = r;\n\n\t\t\tlong gb = num * kb - nb;\n\t\t\tif (gb > 0)\n\t\t\t{\n\t\t\t\td -= gb * pb;\n\t\t\t}\n\n\t\t\tlong gs = num * ks - ns;\n\t\t\tif (gs > 0)\n\t\t\t{\n\t\t\t\td -= gs * ps;\n\t\t\t}\n\n\t\t\tlong gc = num * kc - nc;\n\t\t\tif (gc > 0)\n\t\t\t{\n\t\t\t\td -= gc * pc;\n\t\t\t}\n\n\t\t\treturn d >= 0;\n\t\t}\n\n\t\tlong lo = 0L;\n\t\tlong hi = 1L << 42;\n\t\twhile (lo < hi)\n\t\t{\n\t\t\tlong me = lo + ((hi - lo + 1) >> 1);\n\t\t\tif (go (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", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"}
{"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    string k = readln.chomp;\n    \n    ulong ans = 0;\n    ulong pw = 1;\n    int right = k.length.to!int - 1;\n    while (right >= 0) {\n        ulong cur = 0;\n        int lft = right;\n        ulong m = 1;\n        while (lft >= 0 && cur + m * (k[lft] - '0') < n) {\n            cur += m * (k[lft] - '0');\n            m *= 10;\n            --lft;\n        }\n        \n        while (lft+1 < right && k[lft+1] == '0') { ++lft; }\n        \n        debug { writeln(cur, ' ', pw); }\n        \n        ans += cur * pw;\n        right = lft;\n        pw *= n;\n    }\n    \n    ans.writeln;\n}", "src_uid": "be66399c558c96566a6bb0a63d2503e5"}
{"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, i, j, a, b;\n    readf(\"%s %s %s %s %s %s\", &n, &m, &i, &j, &a, &b);\n    readln;\n    \n    immutable int INF = 10 ^^ 9 + 7;\n    \n    int Steps(int tox, int toy) {\n        if ((tox - i) % a != 0 || (toy - j) % b != 0) { return INF; }\n        \n        int xd = abs(tox - i) / a, yd = abs(toy - j) / b;\n        \n        if (xd % 2 != yd % 2) { return INF; }\n        \n        if (xd < yd && (n - 1) < a) { return INF; }\n        if (yd < xd && (m - 1) < b) { return INF; }\n        \n        return max(xd, yd);\n    }\n    \n    int ans = INF;\n    auto x = [1, n], y = [1, m];\n    foreach (ex; x) {\n        foreach (ey; y) {\n            ans = min(ans, Steps(ex, ey));\n        }\n    }\n    \n    if (ans == INF) {\n        writeln(\"Poor Inna and pony!\");\n        return;\n    }\n    \n    ans.writeln;\n}", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862"}
{"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\tstring a = readln.chomp;\n\tstring b = readln.chomp;\n\tforeach(e; zip(a, b)) {\n\t\tif (e[0] == e[1]) {\n\t\t\twrite(0);\n\t\t} else {\n\t\t\twrite(1);\n\t\t}\n\t}\n\twriteln;\n}\n", "src_uid": "3714b7596a6b48ca5b7a346f60d90549"}
{"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\nBigInt R, X0, Y0, X1, Y1;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tR = readLong;\n\t\tX0 = readLong;\n\t\tY0 = readLong;\n\t\tX1 = readLong;\n\t\tY1 = readLong;\n\t\t\n\t\tconst d2 = (X1 - X0)^^2 + (Y1 - Y0)^^2;\n\t\t/*\n\t\t\t2 R x >= sqrt(d2)\n\t\t*/\n\t\t\n\t\tBigInt lo = -1, ho = d2 + 1;\n\t\tfor (; lo + 1 < ho; ) {\n\t\t\tconst mo = (lo + ho) / 2;\n\t\t\t((2 * R * mo)^^2 >= d2) ? (ho = mo) : (lo = mo);\n\t\t}\n\t\twriteln(ho);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "src_uid": "698da80c7d24252b57cca4e4f0ca7031"}
{"source_code": "import std.stdio;\nimport std.random;\n\nstatic immutable N = 50;\n\nint n, sum, now;\nint[N + 1] a, b;\nint[N + 1][N + 1] w;\n\nint main() {\n  auto input = stdin;\n  auto output = stdout;\n  input.readf(\" %d\", &n);\n  for (int i = 1; i <= n; ++ i)\n    input.readf(\" %d\", &a[i]), sum += a[i];\n  for (int i = 1; i <= n; ++ i)\n    for (int j = 1; j <= n - i + 1; ++ j)\n      input.readf(\" %d\", &w[i][j]);\n  int T = 100000;\n  while (T --) {\n    b = a, now = sum;\n    for (int i = 1; i < n; ++ i) {\n      int t = n - i + 1;\n      for (int j = 1; j <= t; ++ j) {\n        if (b[j] < w[i][j]) {\n          now -= b[j], b[j] = 0;\n          if (now < w[n][1]) break;\n        } else if (j == n - i + 1) b[j - 1] += b[j], b[j] = 0;\n        else if (j != 1)\n          if (b[j - 1] + b[j] >= w[i + 1][j - 1])\n            if ((uniform(0, 2) || T == 99999) && T != 99998) b[j - 1] += b[j], b[j] = 0;\n      }\n      if (now < w[n][1]) break;\n    }\n    if (now >= w[n][1] && b[1] >= w[n][1]) {\n      output.writeln(\"Cerealguy\");\n      return 0;\n    }\n  }\n  output.writeln(\"Fat Rat\");\n  return 0;\n}\n", "src_uid": "0a77937c01ac69490f8b478eae77de1d"}
{"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.chomp;\n    if (a == \"0\") {\n        writeln(a);\n        return;\n    }\n    \n    auto zrs = a.count!(c => c == '0');\n    auto ans = \"1\" ~ '0'.repeat(zrs).array;\n    writeln(ans);\n}", "src_uid": "ac244791f8b648d672ed3de32ce0074d"}
{"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 readInts() {\n\treturn array(map!(to!int)(readln().strip().split()));\n}\nauto readInt() {\n\treturn readInts()[0];\n}\nauto readLongs() {\n\treturn array(map!(to!long)(readln().strip().split()));\n}\nauto readLong() {\n\treturn readLongs()[0];\n}\n\nvoid readlnTo(T...)(ref T t) {\n    auto s = readln().split();\n    assert(s.length == t.length);\n    foreach(ref ti; t) {\n        ti = s[0].to!(typeof(ti));\n        s = s[1..$];\n    }\n}\n\nconst real eps = 1e-10;\n\nvoid main(){\n    auto n = readInt();\n    writeln(n/7 * 2 + max(0, n%7-5), \" \", n/7*2+min(2, n%7));\n}\n\n", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"}
{"source_code": "import std.stdio: readln, writeln;\nimport std.string: strip;\nimport std.array: split;\nimport std.conv: to;\nimport std.algorithm: min, count;\n\n/**\n * User: Jior\n * Date: 03.06.13\n * Time: 13:13\n */\n\nvoid main() {\n    auto rgb = strip(readln()).split().to!(int[]);\n    int result = 0;\n   \tforeach(ref color; rgb) {   \t\t\n   \t\tif(color) {\n   \t\t\tif (color % 3) {\n   \t\t\t\tresult += color / 3;\n   \t\t\t\tcolor %= 3;\t\n\t\t\t} else {\n\t\t\t\tresult += color / 3 - 1;\n\t\t\t\tcolor = 3;\n\t\t\t}\n   \t\t}\n   \t}\n \t\n \tswitch(rgb.count(3)) {\n \t\tcase 2: \n \t\t\tresult += 2;\n \t\t\tbreak;\n \t\tcase 3:\n \t\t\tresult += 3;\n \t\t\tbreak;\n \t\tdefault:\n \t\t\tresult += min(rgb[0], rgb[1], rgb[2]);\t\n \t}\n\n   \twriteln(result);\n}", "src_uid": "acddc9b0db312b363910a84bd4f14d8e"}
{"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                char[2] pos = cin.read_string.dup;\n                int x = pos[0] - 'a';\n                int y = pos[1] - '0';\n                y--;\n                int count = 0;\n                \n                for (int i = -1; i <= 1; i++) {\n                        for (int j = -1; j <= 1; j++) {\n                                if (x + i < 8 && x + i >= 0 && y + j >= 0 && y - j < 8)\n                                    count++;\n                        }\n                }\n                writeln(count - 1);\n        }        \n}", "src_uid": "6994331ca6282669cbb7138eb7e55e01"}
{"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\tint a, b, s;\n\n\treadf(\" %s %s %s\", &a, &b, &s);\n\n\tif (abs(a) + abs(b) == s)\n\t\twriteln(\"Yes\");\n\telse\n\t\tif ((abs(a) + abs(b) > s))\n\t\t\twriteln(\"No\");\n\t\telse\n\t\t\tif ((abs(a) + abs(b) < s) && !((abs(a) + abs(b) - s) % 2))\n\t\t\t\twriteln(\"Yes\");\n\t\t\telse\n\t\t\t\twriteln(\"No\");\n}", "src_uid": "9a955ce0775018ff4e5825700c13ed36"}
{"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 = 1_000_000_007;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tlong a = readLong;\n\t\tlong b = readLong;\n\t\t\n\t\tlong ans = 1;\n\t\t(ans *= a) %= MO;\n\t\t(ans *= (-1 + b)) %= MO;\n\t\t(ans *= b) %= MO;\n\t\t(ans *= ((2 + b + a * b) % MO)) %= MO;\n\t\tfor (; ans % 4 != 0; ans += MO) {}\n\t\tans /= 4;\n\t\t\n\t\tans = (ans % MO + MO) % MO;\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f"}
{"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\n    while (n--) {\n        int x;\n        scan(x);\n        writeln(judge(x) ? \"YES\" : \"NO\");\n    }\n}\n\nbool judge(int x) {\n    foreach (i ; 0 .. 100) {\n        int d = x - 3*i;\n        if (d >= 0 && d % 7 == 0) {\n            return true;\n        }\n    }\n\n    return false;\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}", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"}
{"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}", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"}
{"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[] 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\tauto ps = new Pair!(int, int)[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tps[i] = pair(A[i], i);\n\t\t}\n\t\tps.sort();\n\t\t\n\t\tint k = K;\n\t\tint[] ans;\n\t\tforeach (p; ps) {\n\t\t\tconst i = p.y;\n\t\t\tif (k >= A[i]) {\n\t\t\t\tk -= A[i];\n\t\t\t\tans ~= i + 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(ans.length);\n\t\twriteln(ans.to!string.removechars(\"[],\"));\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n", "src_uid": "dbb164a8dd190e63cceba95a31690a7c"}
{"source_code": "module main;\n__gshared:\nimport std.bigint, std.container, std.array, std.algorithm, std.conv,\n\tstd.parallelism, std.functional, std.math, std.string, std.range,\n\tstd.complex, std.bitmanip, std.typecons, std.regex, std.random, std.uni,\n\tstd.traits, std.stdio, std.variant, core.bitop, std.meta, std.datetime,\n\tcore.stdc.stdio : freopen;\nimport std.numeric : fft, Fft, gcd, inverseFft;\n\nalias big = BigInt;\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\npublic const int mod = 10 ^^ 9 + 7;\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///big greatest common divizor\n\t\tbig gcd(big a, big 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 = ' ')\n\t\t\tif (isInputRange!X && !isInputRange!(ElementEncodingType!X))\n\t{\n\t\tforeach (const ref i; a)\n\t\t\twrite(i, ch);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementEncodingType!X))\n\t{\n\t\tforeach (ref const i; a)\n\t\t{\n\t\t\tforeach (ref const j; i)\n\t\t\t\twrite(j, ' ');\n\t\t\twriteln;\n\t\t}\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//compilation ldc2 -d-debug -d-version=home main.d\n//------------------------------------------program beginning--------------------------\npublic\n{\n\n}\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tfreopen(\"input.txt\", \"r\", core.stdc.stdio.stdin);\n\t\t//assert(freopen(\"output.txt\", \"w\", core.stdc.stdio.stdout));\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(\"\\nTime: %d ms\", sw.peek.msecs);\n\t\t}\n\t}\n\tlint n, s;\n\tloop: while (read(n, s))\n\t{\n\t\tlong l=1,r=n+1;\n\t\tlint check(lint k)\n\t\t{\n\t\t\tlint x,d=k;\n\t\t\twhile(d>0)\n\t\t\t{\n\t\t\t\tx+=d%10;\n\t\t\t\td/=10;\n\t\t\t}\n\t\t\treturn k-x;\n\t\t}\n\t\twhile(r-l>0)\n\t\t{\n\t\t\tlong m=(l+r)/2;\n\t\t\tif(check(m)<s)l=m+1;\n\t\t\telse r=m;\n\t\t}\n\t\twriteln(n-l+1);\n\t}\n\n}\n", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b"}
{"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;\n\tlong k;\n\n\treadf(\" %s %s\", &n, &k);\n\t--k;\n\n\tk <<= 1;\n\tint[] a, b;\n\n\tforeach_reverse (i; 0 .. n)\n\t\tif ((k >> i) % 2L)\n\t\t\tb ~= n - i;\n\t\telse\n\t\t\ta ~= n - i;\n\n\twritefln(\"%(%s %)\", a ~ b.reverse);\n}", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"}
{"source_code": "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!long;\n  auto s = next!string;\n  auto uniqsubs = new long[][](n + 1, n);\n  auto uniqsubsacc = new long[][](n + 1, n);\n  void calcacc(int size)\n  {\n    uniqsubsacc[size][0] = uniqsubs[size][0];\n    foreach(i; 1 .. n)\n      uniqsubsacc[size][i] = uniqsubsacc[size][i - 1] + uniqsubs[size][i];\n  }\n  auto getacc(int size, int i)\n  {\n    if (i < 0)\n      return 0;\n    if (i >= n)\n      return uniqsubsacc[size][$ - 1];\n    return uniqsubsacc[size][i];\n  }\n  uniqsubs[0][0] = 1;\n  uniqsubs[0][1 .. $] = 0;\n  calcacc(0);\n  bool[char] seen;\n  foreach(i; 0 .. n)\n    {\n      uniqsubs[1][i] = s[i] !in seen;\n      seen[s[i]] = true;\n    }\n  calcacc(1);\n  foreach(size; 2 .. n + 1)\n    {\n      int[char] lastpos;\n      foreach(i; 0 .. n)\n        {\n          if (s[i] in lastpos)\n            uniqsubs[size][i] = getacc(size - 1, i - 1) - getacc(size - 1, lastpos[s[i]] - 1);\n          else\n            uniqsubs[size][i] = getacc(size - 1, i - 1);\n          lastpos[s[i]] = i;\n        }\n      calcacc(size);\n    }\n  auto totalcost = long(0);\n  foreach_reverse(size; 0 .. n + 1)\n    {\n      if (k == 0)\n        break;\n      debug uniqsubsacc[size].writeln;\n      auto toremove = min(k, uniqsubsacc[size][$ - 1]);\n      totalcost += toremove * (n - size);\n      k -= toremove;\n    }\n  if (k > 0)\n    {\n      writeln(-1);\n    }\n  else\n    {\n      writeln(totalcost);\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": "ae5d21919ecac431ea7507cb1b6dc72b"}
{"source_code": "import std.stdio, std.string, core.stdc.stdio, std.math, std.range, std.algorithm;\n\nint main(string[] argv)\n{\n    int n;\n    scanf(\"%d\", &n);\n\n    foreach (int i; 1000..10000)\n    {\n        int d1 = (i / 1000) % 10;\n        int d2 = (i / 100) % 10;\n        int d3 = (i / 10) % 10;\n        int d4 = (i % 10);\n        if (!(d1 != d2 && d1 != d3 && d1 != d4 && d2 != d3 && d2 != d4 && d3 != d4))\n            continue;\n\n        if (i > n)\n        {\n            writeln(i);\n            break;\n        }\n    }\n    return 0;\n}\n", "src_uid": "d62dabfbec52675b7ed7b582ad133acd"}
{"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 le, r, x, y;\n    readf(\"%s %s %s %s\", &le, &r, &x, &y);\n    readln;\n    \n    if (y % x != 0) {\n        writeln(0);\n        return;\n    }\n    \n    int g = y / x;\n    \n    int[] dvs;\n    int k = 2;\n    while (g > 1 && k <= g / k) {\n        while (g % k == 0) {\n            dvs ~= k;\n            g /= k;\n        }\n        k += 1;\n    }\n    if (g > 1) dvs ~= g;\n    \n    int mx = 1 << dvs.length;\n    bool[int] chckd;\n    int ans = 0;\n    for (int i = 0; i < mx; ++i) {\n        int a = x, b = x;\n        for (int j = 0; j < dvs.length; ++j) {\n            if (i & (1 << j)) {\n                a *= dvs[j];\n            } else {\n                b *= dvs[j];\n            }\n        }\n        \n        if (chckd.get(a, false)) continue;\n        if (a < le || a > r) continue;\n        if (b < le || b > r) continue;\n        if (gcd(a, b) != x) continue;\n        \n        ++ans;\n        chckd[a] = true;\n        debug { writeln(a, ' ', b); }\n    }\n    \n    ans.writeln;\n}", "src_uid": "d37dde5841116352c9b37538631d0b15"}
{"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\tint n = readln.chomp.to!int;\n\twriteln = (n + 2) / 2;\n}\n\n\n", "src_uid": "5551742f6ab39fdac3930d866f439e3e"}
{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.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\tbool[int] ans;\n\tint i = 1;\n\twhile(i < n * 2 + 10){\n\t\tans[i] = 1, ans[i + 1] = 1;\n\t\tif(i % 2) i = (i + 1) * 2;\n\t\telse i = i * 2 + 1;\n\t}\n\tlog(\"ans:\", ans.keys);\n\t\n\tif(n in ans) 1.writeln;\n\telse 0.writeln;\n\t\n}\n", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501"}
{"source_code": "import std.stdio, std.array, std.string, 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\n    if (M == 0) {\n        writeln(1);\n        return;\n    } else if (M == N) {\n        writeln(0);\n        return;\n    }\n\n    auto used = new bool[](N);\n    used[] = true;\n\n    for (int i = 0; M > 0 && i < N; i += 2, M -= 1) {\n        used[i] = false;\n    }   \n     for (int i = 1; M > 0 && i < N; i += 2, M -= 1) {\n        used[i] = false;\n    }\n\n    int ans = 0;\n    foreach (i; 0..N) if (used[i] && !used[(i+1)%N]) ans += 1;\n    ans.writeln;\n}", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648"}
{"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;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tA = readToken;\n\t\t\n\t\tint ans = N;\n\t\tforeach (i, c; A) {\n\t\t\tif (c == '0') {\n\t\t\t\tans = i + 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"}
{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n  try {\n    for (; ; ) {\n      auto X = new long[3];\n      auto Y = new long[3];\n      foreach (i; 0 .. 3) {\n        X[i] = readLong();\n        Y[i] = readLong();\n      }\n      \n      bool ans = true;\n      ans = ans && ((X[1] - X[0])^^2 + (Y[1] - Y[0])^^2 == (X[2] - X[1])^^2 + (Y[2] - Y[1])^^2);\n      ans = ans && !(X[0] + X[2] == 2 * X[1] && Y[0] + Y[2] == 2 * Y[1]);\n      writeln(ans ? \"Yes\" : \"No\");\n    }\n  } catch (EOFException e) {\n  }\n}\n", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab"}
{"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                auto s = readln();\n                int n = s.parse!int;\n                string s1 = s.strip;\n                if (s1 == \"of week\") {\n                        if (n == 5 || n == 6) writeln(53);\n                        else writeln(52); \n                        return;\n                }\n                if (s1 == \"of month\") {\n                        if (n >= 1 && n <= 29) writeln(12);\n                        else if (n == 30) writeln(11);\n                        else writeln(7);\n                }\n        }        \n}", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"}
{"source_code": "import std.stdio, std.array, std.string, 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    int calc(int x, int y) {\n        return min(abs(x - y), 26 - abs(x - y));\n    }\n\n    string ACTG = \"ACTG\";\n    int ans = 1 << 29;\n    \n    foreach (i; 0..N-3) {\n        ans = min(ans, 4.iota.map!(j => calc(S[i+j].to!int, ACTG[j].to!int)).sum);\n    }\n\n    ans.writeln;\n}", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543"}
{"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\nenum x=1234567,y=123456,z=1234;\nvoid main(){\n    int n=readln.chomp.to!int;\n    for(int a=0;a<=n;a+=x){\n        for(int b=0;b<=n-a;b+=y){\n            if((n-a-b)%z==0){\n                writeln(\"YES\");\n                return;\n            } \n        }\n    }\n    writeln(\"NO\");\n}\n\n", "src_uid": "72d7e422a865cc1f85108500bdf2adf2"}
{"source_code": "import std.stdio, std.string;\nimport std.regex;\n\nimmutable pat = \"^(14{0,2})+$\";\n\nvoid main() {\n    string s = stdin.readln.chomp;\n    writeln(s.match(pat).empty ? \"NO\" : \"YES\");\n}\n", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"}
{"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 long MO = 1_000_000_007;\n\nstruct Mint {\n\tlong v;\n\tthis(long v = 0) {\n\t\tif ((this.v = v % MO) < 0) this.v += MO;\n\t}\n\tMint opUnary(string op)() {\n\t\tstatic if (op == \"-\" || op == \"+\") {\n\t\t\treturn mixin(op ~ \"v\");\n\t\t} else static if (op == \"++\" || op == \"--\") {\n\t\t\treturn this = mixin(op ~ \"v\");\n\t\t}\n\t}\n\tMint opBinary(string op)(const Mint a) const {\n\t\tstatic if (op == \"+\" || op == \"-\" || op == \"*\") {\n\t\t\treturn Mint(mixin(\"v\" ~ op ~ \"a.v\"));\n\t\t} else static if (op == \"/\") {\n\t\t\tassert(a.v != 0);\n\t\t\treturn this * a ^^ (MO - 2);\n\t\t}\n\t}\n\tMint opBinary(string op)(long a) const {\n\t\tstatic if (op == \"^^\") {\n\t\t\tMint ret = 1, x = this;\n\t\t\tfor (; a; a >>= 1, x *= x) if (a & 1) ret *= x;\n\t\t\treturn ret;\n\t\t} else {\n\t\t\treturn mixin(\"this\" ~ op ~ \"Mint(a)\");\n\t\t}\n\t}\n\tMint opAssign(long v) {\n\t\treturn this = Mint(v);\n\t}\n\tMint opOpAssign(string op)(const Mint a) {\n\t\tstatic if (op == \"+\" || op == \"-\" || op == \"*\" || op == \"/\") {\n\t\t\treturn this = mixin(\"this\" ~ op ~ \"a\");\n\t\t}\n\t}\n\tMint opOpAssign(string op)(long a) {\n\t\treturn this = mixin(\"this\" ~ op ~ \"a\");\n\t}\n\tstring toString() const {\n\t\treturn v.to!string;\n\t}\n\tunittest {\n\t\tMint a = -1;\n\t\tassert(a.v == MO - 1);\n\t\t++a;\n\t\tassert(a.v == 0);\n\t\t--a;\n\t\tassert(a.v == MO - 1);\n\t\tMint b = 1_000_000_000;\n\t\tb += 1_000_000_000;\n\t\tassert(b.v == 2_000_000_000 % MO);\n\t\tb = 2;\n\t\tb -= 4;\n\t\tassert(b.v == MO - 2);\n\t\tb = 1_000_000_000;\n\t\tb *= 1_000_000_000;\n\t\tassert(b.v == 1_000_000_000_000_000_000 % MO);\n\t\tMint c = -10;\n\t\tc /= 14;\n\t\tc *= 7;\n\t\tassert(c.v == MO - 5);\n\t}\n}\n\nimmutable LIM = 25;\nlong[] inv;\n\nint N;\nlong S;\nlong[] F;\n\nvoid main(string[] args) {\n\tinv = new long[LIM];\n\tinv[1] = 1;\n\tforeach (i; 2 .. LIM) {\n\t\tinv[i] = MO - MO / i * inv[MO % i] % MO;\n\t}\n\t\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tS = readLong;\n\t\tF = new long[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tF[i] = readLong;\n\t\t}\n\t\tMint ans;\n\t\tforeach (h; 0 .. 1 << N) {\n\t\t\tMint sig = +1;\n\t\t\tforeach (i; 0 .. N) if (h & 1 << i) {\n\t\t\t\tsig *= -1;\n\t\t\t}\n\t\t\tlong s = S;\n\t\t\tforeach (i; 0 .. N) if (h & 1 << i) {\n\t\t\t\ts -= (F[i] + 1);\n\t\t\t}\n\t\t\tif (s >= 0) {\n\t\t\t\t//\tH(N, s) = C(N + s - 1, s) = C(N + s - 1, N - 1)\n\t\t\t\tMint tmp = 1;\n\t\t\t\tforeach (k; 0 .. N - 1) {\n\t\t\t\t\ttmp *= (N + s - 1 - k);\n\t\t\t\t\t// tmp /= (1 + k);\n\t\t\t\t\ttmp *= inv[1 + k];\n\t\t\t\t}\n// writeln(s,\" : \",tmp);\n\t\t\t\tans += sig * tmp;\n\t\t\t}\n\t\t}\n\t\twriteln(ans);\n\t}\n\t} catch (EOFException) {}\n}\n\n", "src_uid": "8b883011eba9d15d284e54c7a85fcf74"}
{"source_code": "import std.stdio;\nvoid main () {\n\tlong p, k, d = 0, y = 1, r = 1;\n\treadf (\" %s %s\", &p, &k);\n\tlong res = 1;\n\tif (k == 0) d = p - 1;\n\telse {\n\t\tdo y = (y * 1L * k) % p, d++; while (y > 1);\n\t\td = p / d;\n\t}\n\tforeach (i; 0..d) r = (r * p) % 1_000_000_007;\n\tr.writeln;\n}\n", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e"}
{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.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\tlong x = rlong;\n\tlong a, b;\n\tfor(long d = 1; d * d <= x; d ++){\n\t\tif(x % d) continue;\n\t\tif(gcd(d, x / d) > 1) continue;\n\t\ta = d, b = x / d;\n\t}\n\twriteln(a, \" \", b);\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": "e504a04cefef3da093573f9df711bcea"}
{"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 a,b,c;\n    scanf(\"%d %d %d\",&a,&b,&c); \n    writeln(7*min(a,b/2,c/4));\n}\n\n", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"}
{"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", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8"}
{"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 = 10 ^^ 9 + 7;\n    \n    auto s = readln.chomp;\n    \n    auto t = readln.chomp;\n    \n    auto ps = new int[] (t.length + 2);\n    ps[0] = 0;\n    ps[t.length + 1] = s.length.to!int + 1;\n    int j = 0;\n    foreach (i, e; s) {\n        if (j >= t.length) { break; }\n        \n        if (e == t[j]) {\n            ps[j+1] = i.to!int + 1;\n            ++j;\n        }\n    }\n    \n    auto sf = new int[] (t.length + 2);\n    sf[0] = 0;\n    sf[t.length+1] = s.length.to!int + 1;\n    j = t.length.to!int - 1;\n    foreach_reverse (i, e; s) {\n        if (j < 0) { break; }\n        \n        if (e == t[j]) {\n            sf[j+1] = i.to!int + 1;\n            --j;\n        }\n    }\n    \n    debug { ps.writeln; sf.writeln; }\n    \n    int ans = 0;\n    foreach (i; 0 .. t.length + 1) {\n        ans = max(ans, sf[i+1] - ps[i] - 1);\n    }\n    \n    ans.writeln;\n}", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"}
{"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 scoreW = 0;\n                int scoreB = 0;\n                for (int i = 0; i < 8; i++) {\n                        string s = cin.readString;\n                        for (int j = 0; j < 8; j++) {\n                                if (s[j] == 'Q') scoreW += 9;\n                                if (s[j] == 'q') scoreB += 9;\n                                if (s[j] == 'R') scoreW += 5;\n                                if (s[j] == 'r') scoreB += 5;\n                                if (s[j] == 'B') scoreW += 3;\n                                if (s[j] == 'b') scoreB += 3;\n                                if (s[j] == 'N') scoreW += 3;\n                                if (s[j] == 'n') scoreB += 3;\n                                if (s[j] == 'P') scoreW += 1;\n                                if (s[j] == 'p') scoreB += 1;\n                        }\n                }\n                if (scoreW > scoreB) writeln(\"White\");\n                else if (scoreB > scoreW) writeln(\"Black\");\n                else writeln(\"Draw\");\n                        \n        }        \n}", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"}
{"source_code": "import core.stdc.stdio;\nimport core.stdc.stdlib;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.mutation;\nimport std.stdio;\n\n\nint[200010] b;\nint[200010] b1;\nint[200010] b2;\nint[200010] b3;\n\nextern(C) int comp(scope const void* a, scope const void* b) {\n  return *cast(const int*)a - *cast(const int*)b;\n}\n\nint main()\n{\n  \n  int n, k;\n  scanf(\"%d%d\", &n, &k);\n  for (int i = 0; i < n; i++) {\n    scanf(\"%d\", &b[i]);\n  }\n  readln();\n  string c = readln();\n\n  int n1 = 0, n2 = 0, n3 = 0;\n  for (int i = 0; i < n; i++) {\n\t  if (c[i] == 'W') {\n\t\t  b1[n1++] = b[i];\n\t  }\n\t  if (c[i] == 'R') {\n\t\t  b2[n2++] = b[i];\n\t  }\n\t  if (c[i] == 'O') {\n\t\t  b3[n3++] = b[i];\n\t  }\n  }\n  qsort(b1.ptr, n1, b1[0].sizeof, &comp);\n  qsort(b2.ptr, n2, b2[0].sizeof, &comp);\n  qsort(b3.ptr, n3, b3[0].sizeof, &comp);\n  for (int i = 0; i < n1 / 2; i++) {\n    int t = b1[i];\n    b1[i] = b1[n1 - i - 1];\n    b1[n1 - i - 1] = t;\n  }\n  for (int i = 0; i < n2 / 2; i++) {\n    int t = b2[i];\n    b2[i] = b2[n2 - i - 1];\n    b2[n2 - i - 1] = t;\n  }\n  for (int i = 0; i < n3 / 2; i++) {\n    int t = b3[i];\n    b3[i] = b3[n3 - i - 1];\n    b3[n3 - i - 1] = t;\n  }\n  for (int i = 1; i < n1; i++) {\n\t  b1[i] += b1[i - 1];\n  }\n  for (int i = 1; i < n2; i++) {\n\t  b2[i] += b2[i - 1];\n  }\n  for (int i = 1; i < n3; i++) {\n\t  b3[i] += b3[i - 1];\n  }\n  int maxc = -1;\n  for (int i = 1; i <= min(n3, k - 1); i++) {\n    if (k - i <= n1) {\n      maxc = max(maxc, b3[i - 1] + b1[k - i - 1]);\n    }\n    if (k - i <= n2) {\n      maxc = max(maxc, b3[i - 1] + b2[k - i - 1]);\n    }\n  }\n  printf(\"%d\\n\", maxc);\n  return 0;\n}", "src_uid": "104cf5253e027929f257364b3874c38b"}
{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.ascii;\nimport std.conv;\nimport std.string : strip;\n\nauto swapCase(dchar chr)\n{\n    return isUpper(chr) ? toLower(chr) : toUpper(chr);  \n}\n\nvoid main()\n{\n    string str = readln.strip;\n\n    if (str[1..$].all!(a => isUpper(a)))\n    {\n        str.map!(a => swapCase(a)).writeln;\n    }\n    else\n        str.writeln;\n}", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"}
{"source_code": "import std.math;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.container;\nimport std.algorithm;\n\nvoid main()\n{\n    long a, b;\n    readf(\"%d %d\\n\", &a, &b);\n    long sol(long x, long y) {\n        long ans = (x + y + 1) * 2;\n        int[] f;\n        for (long i = 1; i * i <= x; ++i) {\n            if (!(x % i))\n                f ~= cast(int) i;\n        }\n        auto r = assumeSorted(f);\n        for (long i = 2; i * i <= x + y; ++i) {\n            if ((x + y) % i)\n                continue;\n            auto pos = r.length - r.upperBound(i).length - 1;\n            if (pos >= 0 && (x + y) / i >= x / r[pos])\n                ans = min(ans, 2 * ((x + y) / i + i));\n        }\n        return ans;\n    }\n    writeln(min(sol(a, b), sol(b, a)));\n}\n", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1"}
{"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\nenum f=[\"Danil\",\"Olya\",\"Slava\",\"Ann\",\"Nikita\"];\nvoid main(){\n    string s=readln.strip;\n    int r=0;\n    foreach(ref x;f){\n        if(s.indexOf(x)>=0) r++;\n        if(s.indexOf(x)!=s.lastIndexOf(x)||r>1){\n            if(r<=1) r++;\n            break;\n        }\n    }\n    if(r==1)\n        writeln(\"YES\");\n    else writeln(\"NO\");\n}\n\n", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"}
{"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[] ans;\n\nvoid main() {\n\t\n\tstring s = readln.strip;\n\tstring t = readln.strip;\n\n\tans ~= t;\n\n\tint k = 1;\n\nx:\n\tif (ans[$ - k] != 'a') {\n\t\tans[$ - k] = cast(char) (cast(int) (ans[$ - k]) - 1);\n\t\tgoto y;\n\t}\n\telse\n\t\tif (k < ans.length) {\n\t\t\tans[$ - k] = cast(char) (cast(int) (ans[$ - k]) + 1);\n\t\t\t++k;\n\t\t\tgoto x;\n\t\t}\n\ny:\n\twriteln((ans > s && ans < t) ? ans : \"No such string\");\n}", "src_uid": "47618510d2a17b1cc1e6a688201d51a3"}
{"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    struct pt { int x, y; }\n    struct sq { pt[4] pts; }\n    \n    sq[2] sqs;\n    \n    foreach (i; 0..2) {\n        foreach (j; 0..4) {\n            readf(\" %s %s\", &sqs[i].pts[j].x, &sqs[i].pts[j].y);\n        }\n        readln;\n    }\n    \n    debug { sqs.writeln; }\n    \n    foreach (ref s; sqs) s.pts = s.pts.array.multiSort!(q{ a.x < b.x }, q{ a.y < b.y }).array;\n   \n    debug { sqs.writeln; }\n    \n    auto xmax = sqs[0].pts[3].x;\n    auto ymax = sqs[0].pts[3].y;\n    auto xmin = sqs[0].pts[0].x;\n    auto ymin = sqs[0].pts[0].y;\n    auto x1center = cast(double) (xmin + xmax) / 2.0;\n    auto y1center = cast(double) (ymin + ymax) / 2.0;\n    auto sideLen = xmax - xmin;\n    \n    auto x2center = sqs[1].pts[1].x;\n    auto y2center = sqs[1].pts[0].y;\n    auto diag2 = abs(sqs[1].pts[0].x - sqs[1].pts[1].x);\n    \n    bool checkParallel(double center1, int len1, int center2, int len2) {\n        return cast(double) len1 / 2.0 + len2 >= abs(center2 - center1);\n    }\n    \n    bool ok = false;\n    if (xmin <= x2center && x2center <= xmax) {\n        ok = checkParallel(y1center, sideLen, y2center, diag2);\n    } else if (ymin <= y2center && y2center <= ymax) {\n        ok = checkParallel(x1center, sideLen, x2center, diag2);\n    } else {\n        ok = abs(x1center - x2center) + abs(y1center - y2center) <= sideLen + diag2;\n    }\n    \n    writeln(ok ? \"YES\" : \"NO\");\n}", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a"}
{"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 long mod = 10^^9 + 7;\nimmutable lim = 5 * 10^^6 + 10;\nint t, l, r;\n\nvoid main() {\n    scan(t, l, r);\n\n    auto p = iota(r + 1).array;\n\n    for (int i = 2; i*i < r + 1; i++) {\n        if (p[i] == i) {\n            for (int j = i*i; j < r + 1; j += i) {\n                p[j] = min(p[j], i);\n            }\n        }\n    }\n\n    auto f = new long[](r + 1);\n\n    for (int i = 2; i < r + 1; i++) {\n        f[i] = 1L * i * (i - 1) / 2L;\n\n        for (int x = i; x > 1; x /= p[x]) {\n            f[i] = min(f[i], f[i / p[x]] + 1L * i * (p[x] - 1) / 2L);\n        }\n    }\n\n    debug {\n        writeln(\"f:\", f);\n    }\n\n    long ans;\n    long tp = 1L;\n\n    foreach (i ; 0 .. r - l + 1) {\n        (ans += tp * (f[l + i] % mod) % mod) %= mod;\n        (tp *= t) %= 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}\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": "c9d45dac4a22f8f452d98d05eca2e79b"}
{"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\tstring s = readln.strip;\n\tauto a = s.split('/').filter!(t => !t.empty()).array;\n\twrite('/');\n\tforeach (i; 0 .. a.length)\n\t{\n\t\twrite(a[i]);\n\t\tif (i + 1 < a.length)\n\t\t\twrite('/');\n\t}\n}\n", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"}
{"source_code": "import std.stdio;\nvoid main()\n{write(25);}", "src_uid": "dcaff75492eafaf61d598779d6202c9d"}
{"source_code": "import std.stdio;\nimport std.math;\n\nvoid main(){\n  uint n;\n  readf(\"%s\\n\",&n);\n\n  solve1(n);\n  //solve2(n+1);\n}\n\nvoid solve2(uint size){\n  ulong mod = 1000000007;\n  ulong[] m = new ulong[size];\n\n  m[0] = 0;\n  m[1] = 0;\n  m[2] = 3;\n  m[3] = 6;\n  for(uint i = 4; i < m.length; i++){\n    auto sum = 0;\n    //writefln(\"<%s>\",i);\n    for(uint n = 0; n < i-2; n++){\n      sum += pow(2,n)*m[i-n-2];\n      //writefln(\"%s,%s = %s\",n,i-n-2,pow(2,n)*m[i-n-2]);\n    }\n    m[i] = (3*(sum + pow(2,i-2))) % mod;\n  }\n\n  writeln(m[size-1]);\n}\n\nvoid solve1(uint n){\n  uint k = n;\n  if(n < 10){\n    n = 10;\n  }\n\n  ulong mod = 1000000007;\n  //ulong size = 1000000;\n  //ulong size = 10;\n  ulong[] m = new ulong[n+1];\n\n  m[0] = 0;\n  m[1] = 0;\n  m[2] = 3;\n  m[3] = 6;\n  for(uint i = 4; i < m.length; i++){\n    auto x1 = (2*m[i-1] % mod);\n    m[i] = ((x1 + m[i-2]*3) % mod);\n  }\n\n  writeln(m[k]);\n}\n//192336614\n", "src_uid": "77627cc366a22e38da412c3231ac91a8"}
{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref 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\tfor (long i = 2; i*i <= n; ++i)\n\t\t{\n\t\t\tif (n % i) continue;\n\t\t\tans[ti] = [n / i, n / i * (i-1)];\n\t\t\tbreak;\n\t\t}\n\t\tif (ans[ti].empty)\n\t\t{\n\t\t\tans[ti] = [1, n-1];\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e[0], \" \", e[1]);\n\n\tstdout.flush;\n\tdebug readln;\n}", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"}
{"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\tans[] = long.max;\n\tforeach (i; 0..t)\n\t{\n\t\tauto n = RD!int;\n\t\tauto k = RD!int;\n\t\tauto d = RD!int;\n\t\tauto a = RDA!int;\n\t\tint[int] cnt;\n\t\tforeach (j; 0..d)\n\t\t{\n\t\t\t++cnt[a[j]];\n\t\t}\n\t\tans[i] = min(ans[i], cnt.keys.length);\n\n\t\tforeach (j; d..n)\n\t\t{\n\t\t\t++cnt[a[j]];\n\t\t\tif (cnt[a[j-d]] == 1)\n\t\t\t{\n\t\t\t\tcnt.remove(a[j-d]);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t--cnt[a[j-d]];\n\t\t\t}\n\t\t\tans[i] = min(ans[i], cnt.keys.length);\n\t\t\tdebug writeln(ans[i]);\n\t\t}\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush();\n\tdebug readln();\n}", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094"}
{"source_code": "void main() {\n  import std.stdio, std.string, std.conv, std.algorithm;\n\n  int y, b, r;\n  rd(y, b, r);\n\n  int mx = 0;\n  for (int i = 1; i <= y; i++) {\n    for (int j = 1; j <= b; j++) {\n      for (int k = 1; k <= r; k++) {\n        if (i + 1 == j && j + 1 == k) {\n          mx = max(mx, i + j + k);\n        }\n      }\n    }\n  }\n  writeln(mx);\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": "03ac8efe10de17590e1ae151a7bae1a5"}
{"source_code": "import std.stdio, std.getopt, std.random, std.range, std.string, std.conv;\nimport std.algorithm, std.container, std.datetime;\nimport core.bitop;\n\nclass Primes {\n    immutable bool[] isPrime;\n    immutable int[] primes;\n    this(int n) {\n        auto used = new bool[n];\n        int[] p;\n        used[0] = used[1] = true;\n        for (int i = 2; i < n; i++) {\n            if (used[i]) continue;\n            p ~= i;\n            for (int j = i*2; j < n; j+= i) {\n                used[j] = true;\n            }\n        }\n        isPrime = used.idup.map!(i => !i).array;\n        primes = p.idup;\n    }\n\n    int[] primeDecomp(long i) {\n    \tassert(n*n >= i);\n    \tint[] res;\n    \tforeach (d; primes) {\n    \t\tif (d*d > i) break;\n    \t\twhile (!(i % d)) {\n    \t\t\tres ~= d;\n    \t\t\ti /= d;\n    \t\t}\n    \t}\n    \tif (i > 1) res ~= cast(int)i;\n    \treturn res;\n    }\n};\n\nint n;\nlong[] a;\nint[] ps;\n\nbool ok(int p, int d) {\n\tlong aa = a[p];\n\tforeach (j; 0..n) {\n\t\tif (!(d & (1<<j))) continue;\n\t\tif (aa % a[j]) return false;\n\t\taa /= a[j];\n\t}\n\treturn true;\n}\n\nint count(int p, int d) {\n\tint res = ps[p];\n\tforeach (j; 0..n) {\n\t\tif (!(d & (1<<j))) continue;\n\t\tres -= ps[j];\n\t}\n\treturn res;\n}\n\nint[][] dpcalc;\nint calc(int p, int d) {\n\tif (p == n) {\n\t\tif (popcnt(d) == 1) return 0;\n\t\treturn 1;\n\t}\n\tif (dpcalc[p][d] != -1) return dpcalc[p][d];\n\tint res = ((ps[p] == 1) ? 1 : ps[p]+1) + calc(p+1, d | (1<<p));\n\tforeach (i; 1..(1<<p)) {\n\t\tif ((i & d) != i) continue;\n\t\tif (!ok(p, i)) continue;\n\t\tres = min(res, count(p, i)+1+calc(p+1, (d & (~i)) | (1<<p)));\n\t}\n\treturn res;\n}\n\nint solve() {\n\tauto p = new Primes(10^^6+100);\n\treadf(\"%d\\n\", &n);\n\ta = readln().split().map!(to!long).array.sort;\n\tps.length = n;\n\tforeach (i; 0..n) {\n\t\tps[i] = cast(int)p.primeDecomp(a[i]).length;\n\t}\n\tdpcalc = new int[][](n, 1<<n);\n\tforeach (dp; dpcalc) {\n\t\tdp[] = -1;\n\t}\n\treturn calc(0, 0);\n}\n\nint main() {\n\twriteln(solve());\n    return 0;\n}", "src_uid": "52b8b6c68518d5129272b8c56e5b7662"}
{"source_code": "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);\n\nM[500_000 + 1] fact;\n\n// binomial coefficient\nM bc(long t, long a)\n{\n  auto res = fact[cast(uint)t] * (fact[cast(uint)a] * fact[cast(uint)(t - a)])^^(mod - 2);\n  return res;\n}\nM noIncSeqs(long k, long n)\n{\n  return bc(n - 1, k - 1);\n}\n\nvoid main(string[] args)\n{\n  inputFile = stdin;\n  fact[0] = M(1);\n  foreach(i; 1 .. fact.length)\n    fact[i] = M(i) * fact[i - 1];\n  auto n = next!long;\n  auto k = next!long;\n  M noSeqs = 0;\n  foreach(a1; 1 .. n + 1)\n    {\n      if (a1 * k > n) break;\n      auto maxNum = n / a1;\n      noSeqs = noSeqs + noIncSeqs(k, maxNum);\n    }\n  noSeqs.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 this.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", "src_uid": "8e8eb64a047cb970a549ee870c3d280d"}
{"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  uint n = readln.strip.to!int;\n  auto s = readln[0 .. n];\n  auto l = s.count ('L');\n  auto r = s.count ('R');\n  writeln (l + r + 1);\n}\n\n", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"}
{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\nimport std.regex;\n\nvoid main() {\n  auto s = readln.chomp.split.sort.uniq.array;\n  (4 - s.length).writeln;\n}\n", "src_uid": "38c4864937e57b35d3cce272f655e20f"}
{"source_code": "import std.stdio;\nimport std.string;\n\nint main(){\n\tstring tab;\n\ttab = readln();\n\tint ile = 0;\n\tchar pop = 'b';\n\tfor (int i = 0; i < tab.length; i++){\n\t\tif (tab[i] != pop){\n\t\t    ile = 1;\n\t\t    pop = tab[i];\n\t\t}\n\t\telse if (tab[i] == pop){\n\t\t    ile++;\n\t\t}\n\t\tif (ile > 6){\n\t\t\tprintf(\"YES\");\n\t\t\treturn 0;\n\t\t}\n\t}\n\tprintf(\"NO\");\n\treturn 0;\n\n\n}\n", "src_uid": "ed9a763362abc6ed40356731f1036b38"}
{"source_code": "import std.stdio, std.string, std.algorithm;\n\nvoid main() {\n    string song;\n    readf(\"%s\\n\", &song);    \n    writeln(song.split(\"WUB\").filter!(x => !x.empty()).join(\" \"));\n}\n", "src_uid": "edede580da1395fe459a480f6a0a548d"}
{"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint m, n;\n\tscanf(\"%d %d\", &m, &n);\n\tprintf(\"%d\", m*n / 2);\n    return 0;\n}\n", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"}
{"source_code": "import std.stdio, std.array, std.string, 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 s1 = readln.chomp;\n    auto s2 = readln.chomp;\n\n    int pos = 11;\n    foreach (c; s1) {\n        pos = (c == '+') ? pos + 1 : pos - 1;\n    }\n\n    auto dp = new real[][](25, 25);\n    foreach (i; 0..21)\n        fill(dp[i], 0);\n    dp[0][11] = 1;\n    \n    foreach (i; 0..s2.length) {\n        foreach (j; 1..22) {\n            if (s2[i] == '+')\n                dp[i+1][j+1] += dp[i][j];\n            else if (s2[i] == '-')\n                dp[i+1][j-1] += dp[i][j];\n            else {\n                dp[i+1][j+1] += dp[i][j] * 0.5;\n                dp[i+1][j-1] += dp[i][j] * 0.5;\n            }\n        }\n    }\n    //dp[s2.length].writeln;\n    writefln(\"%.10f\", dp[s2.length][pos]);\n}\n", "src_uid": "f7f68a15cfd33f641132fac265bc5299"}
{"source_code": "import std.stdio, std.string;\nimport std.array, std.conv;\nimport std.algorithm;\n\nstring[] solve(int m, int s)\n{\n    if (m * 9 < s) return [\"-1\", \"-1\"];\n    if (s == 0)\n    {\n        if (m == 1) return [\"0\", \"0\"];\n        return [\"-1\", \"-1\"];\n    }\n    auto mi = \"\";\n    auto sum = s;\n    foreach (i; 0 .. m)\n    {\n        foreach (j; 0 .. 10)\n        {\n            if (i == 0 && j == 0) continue;\n            if (j <= sum && (m - 1 - i) * 9 >= sum - j)\n            {\n                mi ~= j + '0';\n                sum -= j;\n                break;\n            }\n        }\n    }\n    auto ma = \"\";\n    sum = s;\n    foreach (i; 0 .. m)\n    {\n        foreach_reverse (j; 0 .. 10)\n        {\n            if (i == 0 && j == 0) continue;\n            if (j <= sum && (m - 1 - i) * 9 >= sum - j)\n            {\n                ma ~= j + '0';\n                sum -= j;\n                break;\n            }\n        }\n    }\n    return [mi, ma];\n}\n\nint main(string[] args)\n{\n    auto r = map!(x => to!int(x))(readln.strip.split(\" \")).array;\n    auto m = r[0], s = r[1];\n    auto ret = solve(m, s);\n    writeln(join(ret, \" \"));\n    return 0;\n}", "src_uid": "75d062cece5a2402920d6706c655cad7"}
{"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 m = cin.readInt;\n\n                int[] people = new int[n];\n\n                foreach (ref i; people) i = cin.readInt;\n                \n                int bus = 1;\n                int remaining = m;\n                int currGroup = 0;              \n\n                for (; currGroup < n;) {\n                        if (remaining >= people[currGroup]) {\n                                remaining -= people[currGroup];\n                                currGroup++;\n                        }\n                        if (currGroup == n) break;\n                        if (remaining < people[currGroup]) {\n                                bus++;\n                                remaining = m;\n                        }\n                }\n                writeln(bus);\n        }\n}\n", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f"}
{"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\tauto d = new int [n + 1];\r\n\t\tfor (int i = 2; i <= n; i++)\r\n\t\t{\r\n\t\t\tfor (int j = i; j <= n; j += i)\r\n\t\t\t{\r\n\t\t\t\td[j] += 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tauto f = new int [n + 1];\r\n\t\tauto g = new int [n + 1];\r\n\t\tf[0] = 1;\r\n\t\tg[0] = f[0];\r\n\t\tfor (int i = 1; i <= n; i++)\r\n\t\t{\r\n\t\t\tf[i] = (g[i - 1] + d[i]) % mod;\r\n\t\t\tg[i] = (g[i - 1] + f[i]) % mod;\r\n\t\t}\r\n\t\twriteln (f[n]);\r\n\t}\r\n}\r\n", "src_uid": "09be46206a151c237dc9912df7e0f057"}
{"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 m = RD!int;\n\tauto k = RD!int;\n\n\twriteln(m >= n && k >= n ? \"Yes\" : \"No\");\n\tstdout.flush();\n\tdebug readln();\n}", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"}
{"source_code": "import std.stdio;\n\nvoid main()\n{\n    int w;\n    readf(\" %s\", &w);\n\n    if (w == 2) {\n        writeln(\"NO\");\n    }\n    else if (w % 2 == 0)\n    {\n        writeln(\"YES\");\n    }\n    else\n    {\n        writeln(\"NO\");\n    }\n}", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"}
{"source_code": "import std.algorithm,std.regex,std.stdio,std.string;\nvoid main(){\n\treadln;\n\t\" vaporeon jolteon flareon espeon umbreon leafeon glaceon sylveon \"\n\t.match(' '~readln.strip~' ').captures[0].write;\n}\n", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"}
{"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\tint n = readln.strip.to!int;\n\t\n\tif (n < 10) {\n\t\twriteln(n);\n\t} else if (n < 100) {\n\t\twriteln(9 + (n - 9) * 2);\n\t} else if (n < 1000) {\n\t\twriteln(9 + 90 * 2 + (n - 99) * 3);\n\t} else if (n < 10000) {\n\t\twriteln(9 + 90 * 2 + 900 * 3 + (n - 999) * 4);\n\t} else if (n < 100000) {\n\t\twriteln(9 + 90 * 2 + 900 * 3 + 9000 * 4 + (n - 9999) * 5);\n\t} else if (n < 1000000) {\n\t\twriteln(9 + 90 * 2 + 900 * 3 + 9000 * 4 + 90000 * 5 + (n - 99999) * 6);\n\t} else if (n < 10000000) {\n\t\twriteln(9 + 90 * 2 + 900 * 3 + 9000 * 4 + 90000 * 5 + 900000 * 6 + (n - 999999) * 7);\n\t} else if (n < 100000000) {\n\t\twriteln(9 + 90 * 2 + 900 * 3 + 9000 * 4 + 90000 * 5 + 900000 * 6 + 9000000L * 7 + (n - 9999999L) * 8L);\n\t} else if (n < 1000000000) {\n\t\twriteln(9 + 90 * 2 + 900 * 3 + 9000 * 4 + 90000 * 5 + 900000 * 6 + 9000000 * 7 + 90000000 * 8 + (n - 99999999) * 9L);\n\t} else {\n\t\twriteln(9 + 90 * 2 + 900 * 3 + 9000 * 4 + 90000 * 5 + 900000 * 6 + 9000000 * 7 + 90000000L * 8 + 900000000L * 9 + 10);\n\t}\n}", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"}
{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio, std.string, std.conv, std.algorithm;\n\nT[] getVals(T)() { return to!(T[])(readln().chomp().split(\" \")); }\n\nvoid main() {\n    auto nk = getVals!(int)();\n    auto n = nk[0], k = nk[1];\n    auto xs = getVals!(int)();\n    auto candies = 0, present = 0;\n    foreach (i, v; xs) {\n        candies += v;\n        present = min(candies, 8);\n        candies -= present;\n        k -= present;\n        if (k <= 0) {\n            writeln(i+1);\n            return;\n        }\n    }\n    writeln(-1);\n}", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"}
{"source_code": "import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.compiler,\n\tstd.complex, std.container, std.conv, std.datetime, std.functional,\n\tstd.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\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, pos, l, r;\n\tread(n, pos, l, r);\n\tif (l == 1 && r == n)\n\t\twriteln(0);\n\telse if (l == 1)\n\t{\n\t\twriteln(abs(r - pos) + 1);\n\t}\n\telse if (r == n)\n\t\twriteln(abs(l - pos) + 1);\n\telse\n\t\twriteln(min(abs(r - pos), abs(l - pos)) + r - l + 2);\n}\n", "src_uid": "5deaac7bd3afedee9b10e61997940f78"}
{"source_code": "import std.stdio, std.range, std.algorithm, std.string, std.conv, std.typecons;\n\nvoid main(){\n\tauto x=readln().strip.split.map!(to!int).array;\n\tint n=x[0],m=x[1],c0=x[2],d0=x[3];\n\tauto buns=iota(m).map!(_=>readln().strip.split.map!(to!int).array);\n\tTuple!(int,int)[] ss;\n\tforeach(bun;chain(only([0,0,c0,d0]),buns)){\n\t\tint num=bun[1]?bun[0]/bun[1]:2000;\n\t\tint cost=bun[2];\n\t\tint benefit=bun[3];\n\t\tforeach(k;0..num) ss~=tuple(cost,benefit);\n\t}\n\tauto t=0.repeat(n+1).array;\n\tforeach(s;ss){\n\t\tforeach_reverse(i;0..t.length){\n\t\t\tif(i<s[0]) continue;\n\t\t\tt[i]=max(t[i],t[i-s[0]]+s[1]);\n\t\t}\n\t}\n\twriteln(t[n]);\n}\n", "src_uid": "4e166b8b44427b1227e0f811161d3a6f"}
{"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.splitter.map !(to !(int)).array;\n\t\tauto p = n.iota.array;\n\t\tmakeIndex (a, p);\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\t\twritefln (\"%(%s %)\", n.iota.map !(i => a[p[(q[i] + 1) % n]]));\n\t}\n}\n", "src_uid": "e314642ca1f82be8f223e2eba00b5531"}
{"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 r, h;\n    readf(\"%s %s\", &r, &h);\n    readln;\n\n    int getAns(int r, int h) {\n        if (h < r) {\n            return 1;\n        }\n        \n        int d = 2*r;\n        \n        int fit = 1 + (h-r) / d;\n        int ans = 2 * fit;\n        \n        int side1 = r;\n        int side2 = d - r  +  h - ((fit-1) * d + r); \n        bool center = side1.to!long * side1 + side2.to!long * side2 >= d.to!long * d;\n        \n        return fit * 2 + (center ? 1 : 0);\n    }\n     \n    //scale up by 2, pass circle radius and height\n    getAns(r, 2*h).writeln;\n}", "src_uid": "ae883bf16842c181ea4bd123dee12ef9"}
{"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\tauto s = readln.strip;\n\n\tuint n;\n\n\twhile(s.length)\n\t{\n\t\tn++;\n\n\t\tif(!(s.length & 1) && s[0..$ / 2] == s[$ / 2..$])\n\t\t{\n\t\t\tn += s.length / 2;\n\t\t\tbreak;\n\t\t}\n\n\t\ts.popBack;\n\t}\n\n\tn.writeln;\n}\n", "src_uid": "ed8725e4717c82fa7cfa56178057bca3"}
{"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  int x, y, z;\n  readf(\" %s %s %s\", x, y, z);\n  char ans = ' ';\n  int maxx = x-y + z; // up 1: down: -1\n  int minn = x-y - z;\n  if (minn > 0)  ans = '+';\n  else if ( maxx < 0)  ans = '-';\n  else if (maxx == 0 && minn == 0) ans = '0';\n  else ans = '?';\n\n  writeln(ans);\n\n}\n", "src_uid": "66398694a4a142b4a4e709d059aca0fa"}
{"source_code": "import std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.math;\n\n\n\nvoid main()\n{\n\tint m = to!int(readln()[0..$ - 1]);\n\tint[] c = new int[m];\n\tfor (int i = 0; i < m; ++i) {\n\t\treadf(\" %d\", &c[i]);\n\t}\n\tint x, y;\n\treadf(\" %d %d\", &x, &y);\n\t\n\tint k = 0;\n\tint t = 0;\n\tforeach (tl; c) {\n\t\tt += tl;\n\t}\n\tfor (int i = 0; i < m; ++i) {\n\t\tk += c[i];\n\t\tt -= c[i];\n\t\tif (k > y || t < x) {\n\t\t\twriteln(0);\n\t\t\treturn;\n\t\t}\n\t\tif (k >= x && t <= y) {\n\t\t\twriteln(i + 2);\n\t\t\treturn;\n\t\t}\n\t}\n\tassert(false);\n\n}\n", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"}
{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nalias sum = reduce!(\"a + b\");\n\nint n;\nvoid main() {\n    readf(\"%d\\n\", &n);\n    int[] us = new int[n];\n    int[] ls = new int[n];\n    for (int i = 0; i < n; i++) {\n        readf(\"%d %d\\n\", &us[i], &ls[i]);\n    }\n    if ((us.sum + ls.sum) % 2 == 1) {\n        writeln(-1);\n    } else if (us.sum % 2 == 1 && ls.sum % 2 == 1) {\n        for (int i = 0; i < n; i++) {\n            if (us[i] % 2 != ls[i] % 2) {\n                writeln(1);\n                return;\n            }\n        }\n        writeln(-1);\n    } else {\n        writeln(0);\n    }\n}\n", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"}
{"source_code": "import std.stdio, std.array, std.string, 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!long);\n    auto N = s[0];\n    auto K = s[1];\n    long ans = N + 1 + N;\n    if (K == 1 || K == N) {\n        ans += N - 1;\n    } else {\n        long left = K - 1;\n        long right = N - K;\n        long x = min(left, right) * 2 + max(left, right);\n        ans += x;\n    }\n\n    ans.writeln;\n}\n", "src_uid": "24b02afe8d86314ec5f75a00c72af514"}
{"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    readln;\n    auto s = readln.strip();\n    \n    int [string] mp;\n    foreach (a, b; lockstep (s, s.dropOne())) {\n        auto cur = [a,b].to!string;\n        ++mp[cur];\n    }\n    \n    auto mx = mp.byKeyValue.maxElement!(kv => kv.value).key;\n    writeln (mx);\n}", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"}
{"source_code": "import std.stdio;\nimport std.math;\n\nvoid main() {\n  int a, b;\n  readf(\" %s %s\", &a, &b);\n\n  auto a_win = 0, b_win = 0, draw = 0;\n  const dice = [1, 2, 3, 4, 5, 6];\n  foreach (int pip; dice) {\n    const a_score = abs(a-pip), b_score = abs(b-pip);\n    if (a_score < b_score) {\n      a_win++;\n    } else if (b_score < a_score) {\n      b_win++;\n    } else {\n      draw++;\n    }\n  }\n\n  writefln(\"%s %s %s\", a_win, draw, b_win);\n}\n\n", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"}
{"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[] to_s(int x) {\n    int[] s;\n    while (x > 0) {\n        int y = x % 3;\n        s ~= y;\n        x /= 3;\n    }\n    return s;\n}\n\nvoid main() {\n    int A, B; scanf(\"%d %d\\n\", &A, &B);\n    auto a = A.to_s,\n         b = B.to_s;\n    while (a.length != b.length) {\n        (a.length < b.length ? a : b) ~= 0;\n    }\n    auto c = new int[a.length];\n    foreach (i; 0 .. a.length) {\n        c[i] = (b[i] - a[i] + 3) % 3;\n    }\n\n    long ans = 0;\n    foreach (i; 0 .. c.length) {\n        ans += (3 ^^ i) * c[i];\n    }\n    writeln(ans);\n}\n", "src_uid": "5fb635d52ddccf6a4d5103805da02a88"}
{"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 b,g,n;\n    readf!\" %s %s %s\"(b,g,n);\n\n    int ans = 0;\n    foreach (i; 0 .. b+1) {\n        if (i <= n && n - i <= g) ans++;\n    }\n\n    writeln(ans);\n}\n", "src_uid": "9266a69e767df299569986151852e7b1"}
{"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        int eng = 0, 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}", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d"}
{"source_code": "import std.stdio, std.string;\n\n//int[] div[2010];\nint len[2010];\nint div[2010][2010];\nint dp[2010][2010];\n\nstatic immutable int mod = 1000000007;\n\nvoid init()\n{\n    foreach (int i; 1 .. 2001)\n    {\n        foreach (int j; 1 .. i + 1)\n        {\n            if (i % j == 0)\n            {\n                div[i][len[i] ++] = j;\n                //div[i] ~= j;\n            }\n        }\n    }\n}\n\nint recur(int num, int pos)\n{\n    if (dp[num][pos] != -1)\n    {\n        return dp[num][pos];\n    }\n    if (pos == 1)\n    {\n        return dp[num][pos] = 1;\n    }\n    dp[num][pos] = 0;\n    foreach (int i; 0 .. len[num])//div[num].length)\n    {\n        int ret = recur(div[num][i], pos - 1);\n        dp[num][pos] = (dp[num][pos] + ret) % mod;\n    }\n    return dp[num][pos];\n}\n\nvoid solve(int n, int k)\n{\n    foreach (int i; 1 .. n + 1)\n    {\n        foreach (int j; 0 .. k + 1)\n        {\n            dp[i][j] = -1;\n        }\n    }\n    int ans = 0;\n    foreach (int i; 1 .. n + 1)\n    {\n        int ret = recur(i, k);\n        ans = (ans + ret) % mod;\n    }\n    printf(\"%d\\n\", ans);\n}\n\nvoid main(string[] args)\n{\n    init();\n    int N, K;\n    while (scanf(\"%d%d\", &N, &K) == 2)\n    {\n        solve(N, K);\n    }\n}", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa"}
{"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 A, B;\n\nint gcd(int x, int y) {\n    if (y == 0) return x;\n    return gcd(y, x % y);\n}\n\nint func(ref int x) {\n    int ans = 0;\n\n    for ( ; x % 2 == 0; ) {\n        x /= 2;\n        ans += 1;\n    }\n    for ( ; x % 3 == 0; ) {\n        x /= 3;\n        ans += 1;\n    }\n    for ( ; x % 5 == 0; ) {\n        x /= 5;\n        ans += 1;\n    }\n\n    if (x != 1) ans = -1;\n\n    return ans;\n}\n\nvoid main () {\n    A = readInt();\n    B = readInt();\n\n    int d = gcd(A, B);\n\n    A /= d;\n    B /= d;\n\n    int cx = func(A);\n    int cy = func(B);\n\n    int ans = cx + cy;\n\n    if (cx == -1 || cy == -1) ans = -1;\n\n    writeln(ans);\n}\n", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"}
{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.string;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\n\nvoid main() {\n  int n;\n  readf(\" %s\", &n);\n  readln;\n  auto a = readln.strip.split.map!(to!int).array.sort;\n  foreach (i; 0..n) {\n    foreach (j; i + 1..n) {\n      foreach (k; j + 1..n) {\n        if (a[i] == a[j] || a[j] == a[k]) continue;\n        if (a[k] - a[i] <= 2) {\n          writeln(\"YES\");\n          return;\n        }\n      }\n    }\n  }\n  writeln(\"NO\");\n}\n\n", "src_uid": "d6c876a84c7b92141710be5d76536eab"}
{"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n, k;\n\tscanf(\"%d %d\", &n, &k);\n\tint max_time = 240;\n\tint max_problem_time = max_time - k;\n\tlong sum = 0;\n\tforeach (int i; 1..(n+1))\n\t{\n\t\tsum += 5 * i;\n\t\tif (sum > max_problem_time)\n\t\t{\n\t\t\tprintf(\"%d\", i-1);\n\t\t\treturn 0;\n\t\t}\n\t}\n\tprintf(\"%d\", n);\n\treturn 0;\n}", "src_uid": "41e554bc323857be7b8483ee358a35e2"}
{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, 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 S = readToken();\n      \n      int[] ks, vs, os;\n      foreach (i; 0 .. N) {\n        switch (S[i]) {\n          case 'K': ks ~= i; break;\n          case 'V': vs ~= i; break;\n          default: os ~= i;\n        }\n      }\n      const ksLen = cast(int)(ks.length);\n      const vsLen = cast(int)(vs.length);\n      const osLen = cast(int)(os.length);\n      debug {\n        writeln(\"ks = \", ks);\n        writeln(\"vs = \", vs);\n        writeln(\"os = \", os);\n      }\n      \n      auto costO = new int[][][](osLen + 1, ksLen + 1, vsLen + 1);\n      auto costK = new int[][][](osLen + 1, ksLen + 1, vsLen + 1);\n      auto costV = new int[][][](osLen + 1, ksLen + 1, vsLen + 1);\n      foreach (i; 0 .. osLen + 1) foreach (x; 0 .. ksLen + 1) foreach (y; 0 .. vsLen + 1) {\n        if (i < osLen) {\n          foreach (xx; 0 .. x) if (ks[xx] > os[i]) ++costO[i][x][y];\n          foreach (yy; 0 .. y) if (vs[yy] > os[i]) ++costO[i][x][y];\n        }\n        if (x < ksLen) {\n          foreach (ii; 0 .. i) if (os[ii] > ks[x]) ++costK[i][x][y];\n          foreach (yy; 0 .. y) if (vs[yy] > ks[x]) ++costK[i][x][y];\n        }\n        if (y < vsLen) {\n          foreach (ii; 0 .. i) if (os[ii] > vs[y]) ++costV[i][x][y];\n          foreach (xx; 0 .. x) if (ks[xx] > vs[y]) ++costV[i][x][y];\n        }\n      }\n      \n      auto dp = new int[][][](osLen + 2, ksLen + 1, vsLen + 1);\n      foreach (i; 0 .. osLen + 2) {\n        foreach (x; 0 .. ksLen + 1) foreach (y; 0 .. vsLen + 1) {\n          dp[i][x][y] = INF;\n        }\n      }\n      dp[0][0][0] = 0;\n      foreach (i; 0 .. osLen + 1) {\n        foreach (x; 0 .. ksLen + 1) foreach (y; 0 .. vsLen + 1) {\n          if (dp[i][x][y] < INF) {\n            int cK = dp[i][x][y];\n            foreach (xx; x .. ksLen + 1) {\n              int cKV = cK;\n              foreach (yy; y .. vsLen + 1) {\n                int cc = cKV;\n                if (i < osLen) {\n                  cc += costO[i][xx][yy];\n                }\n                chmin(dp[i + 1][xx][yy], cc);\n                if (yy < vsLen) {\n                  cKV += costV[i][xx][yy];\n                }\n              }\n              if (xx < ksLen) {\n                cK += costK[i][xx][y];\n              }\n            }\n          }\n        }\n      }\n      debug {\n        foreach (i; 0 .. osLen + 2) {\n          writefln(\"dp[%s] = %s\", i, dp[i]);\n        }\n      }\n      \n      const ans = dp[osLen + 1][ksLen][vsLen];\n      writeln(ans);\n    }\n  } catch (EOFException e) {\n  }\n}\n", "src_uid": "08444f9ab1718270b5ade46852b155d7"}
{"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.length = 3;\n\tscanf(\"%d %d %d\", &n[0], &n[1], &n[2]);\n\tn.sort!(\"a > b\");\n\tint sum = n[0] - n[2];\n\twrite(sum);\n\treturn 0;\n}", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"}
{"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\nT modpow(T)(T a, T n, T m)\n{\n  a %= m;\n  if (n == 0)\n    return 1;\n  if (n & 1)\n    {\n      auto res = a * modpow(a, n - 1, m);\n      res %= m;\n      return res; \n    }\n  auto res = modpow(a, n / 2, m);\n  res *= res;\n  return res % m;\n}\n\nvoid main()\n{\n  alias ln = long;\n  const ln p = 1_000_000_000 + 7;\n  ln n, m; get(n, m);\n  wr(modpow(pmod(modpow(2, m, p) - 1, p), n, p));\n}\n", "src_uid": "71029e5bf085b0f5f39d1835eb801891"}
{"source_code": "import core.stdc.stdio;\nint n;\nchar[101] s;\nvoid main()\n{\n\tscanf(\"%d%s\",&n,&s);\n\tfor (int i=0;i<n;i++) if (s[i]!='?') if (s[i]==s[i+1])\n\t{\n\t\tputs(\"NO\");\n\t\treturn;\n\t}\n\tfor (int i=0;i<n;i++) if (s[i]=='?') if (s[i-1]==s[i+1] || i==0 || i==n-1 || s[i]==s[i+1])\n\t{\n\t\tputs(\"YES\");\n\t\treturn;\n\t}\n\tputs(\"NO\");\n}", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"}
{"source_code": "import std.conv;\nimport std.stdio;\n\nimmutable int MOD   =  1_000_000_007;\nimmutable int HALF  = (MOD >> 1) + 1;\nimmutable int MAX_N =             54;\n\nstruct modint\n{\n\tlong value;\n\n\talias value this;\n\n\tthis (long nvalue)\n\t{\n\t\tvalue = nvalue;\n\t}\n\n\tmodint opBinary (string op) (long other)\n\t{\n\t\treturn mixin (\"modint ((value \" ~ op ~ \" other) % MOD)\");\n\t}\n\n\tmodint opOpAssign (string op, T) (T other)\n\t{\n\t\treturn mixin (\"(this = this \" ~ op ~ \" other)\");\n\t}\n}\n\nvoid main ()\n{\n\tauto c = new modint [] [] (MAX_N, MAX_N);\n\n\tforeach (n; 0..MAX_N)\n\t{\n\t\tc[n][0] = 1;\n\t\tforeach (k; 1..n + 1)\n\t\t{\n\t\t\tc[n][k] = c[n - 1][k - 1] + c[n - 1][k];\n\t\t}\n\t}\n\n\tauto f = new modint [] [] [] (MAX_N, MAX_N, 2);\n\t// 0 is occupied, 1 is free\n\tf[1][0][1] = 1;\n\n\tforeach (n; 2..MAX_N)\n\t{\n\t\tforeach (k; 0..n + 1)\n\t\t{\n\t\t\tforeach (b; 0..2)\n\t\t\t{\n\t\t\t\t// one child\n\t\t\t\tint pk = k - (b == 0);\n\t\t\t\tif (pk >= 0)\n\t\t\t\t{\n\t\t\t\t\tmodint mult = n - 1;\n\t\t\t\t\tf[n][k][b] = mult * f[n - 1][pk][!b];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// two children\n\t\t\tforeach (x; 1..n - 1)\n\t\t\t{\n\t\t\t\tint y = n - 1 - x;\n\t\t\t\tassert (x > 0 && y > 0);\n\t\t\t\tmodint mult = c[n - 1][x];\n\t\t\t\tmult *= x;\n\t\t\t\tmult *= y;\n\n\t\t\t\tforeach (xk; 0..k + 1)\n\t\t\t\t{\n\t\t\t\t\tint yk = void;\n\n\t\t\t\t\t// occupied\n\t\t\t\t\tyk = k - xk - 1;\n\t\t\t\t\tif (yk >= 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[n][k][0] += f[x][xk][1] *\n\t\t\t\t\t\t    f[y][yk][0] * mult;\n\t\t\t\t\t\tif (x < y ||\n\t\t\t\t\t\t    (x <= y && xk <= yk))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmodint mult2 = mult;\n\t\t\t\t\t\t\tif (x == y && xk == yk)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmult2 *= HALF;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tf[n][k][0] += mult2 *\n\t\t\t\t\t\t\t    f[x][xk][1] *\n\t\t\t\t\t\t\t    f[y][yk][1];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// free\n\t\t\t\t\tyk = k - xk;\n\t\t\t\t\tif (x < y || (x <= y && xk <= yk))\n\t\t\t\t\t{\n\t\t\t\t\t\tmodint mult2 = mult;\n\t\t\t\t\t\tif (x == y && xk == yk)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmult2 *= HALF;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tf[n][k][1] += f[x][xk][0] *\n\t\t\t\t\t\t    f[y][yk][0] * mult2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tint n, k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\twriteln (f[n][k][0] + f[n][k][1]);\n\t}\n}\n", "src_uid": "f98b740183281943eafd90328854746b"}
{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport core.stdc.stdio;\n\nstring readline()\n{\n\tstring result = readln();\n\tif (result[result.length - 1] == '\\n') result.length--;\n\treturn result;\n}\n\nint main(string[] argv)\n{\n\tint a, b, c;\n\tscanf(\"%d %d %d\", &a, &b, &c);\n\tint[8] r;\n\tr[0] = a + b + c;\n\tr[1] = a * b * c;\n\tr[2] = a + b * c;\n\tr[3] = a * b + c;\n\tr[4] = (a * b) + c;\n\tr[5] = (a + b) * c;\n\tr[6] = a + (b * c);\n\tr[7] = a * (b + c);\n\n\tint max = int.min;\n\tforeach (int i; 0..8)\n\t{\n\t\tif (r[i] > max) max = r[i];\n\t}\n\tprintf(\"%d\", max);\n\treturn 0;\n}\n", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"}
{"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 h1, a1, d1;\n\twhile (readf (\" %s %s %s\", &h1, &a1, &d1) > 0)\n\t{\n\t\tint h2, a2, d2;\n\t\treadf (\" %s %s %s\", &h2, &a2, &d2);\n\t\tint ch, ca, cd;\n\t\treadf (\" %s %s %s\", &ch, &ca, &cd);\n\n\t\tint res = int.max;\n\t\tscope (exit)\n\t\t{\n\t\t\twriteln (res);\n\t\t}\n\n\t\tif (a2 <= d1)\n\t\t{\n\t\t\tres = min (res, ca * max (0, d2 - a1 + 1));\n\t\t\tcontinue;\n\t\t}\n\n\t\tauto cost = new int [20001];\n\t\tcost[] = short.max;\n\t\tforeach (int da; 0..201)\n\t\t{\n\t\t\tint na = a1 + da - d2;\n\t\t\tif (na <= 0)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint at = (h2 + na - 1) / na;\n\t\t\tcost[at] = min (cost[at], da * ca);\n\t\t}\n\t\tforeach (int i; 1..20001)\n\t\t{\n\t\t\tcost[i] = min (cost[i], cost[i - 1]);\n\t\t}\n\n\t\tforeach (int dh; 0..20001)\n\t\t{\n\t\t\tforeach (int dd; 0..201)\n\t\t\t{\n\t\t\t\tint nd = a2 - dd - d1;\n\t\t\t\tif (nd <= 0)\n\t\t\t\t{\n\t\t\t\t\tres = min (res, cost[20001 - 1] +\n\t\t\t\t\t    dh * ch + dd * cd);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint dt = (h1 + dh + nd - 1) / nd;\n\t\t\t\tdt = min (dt, 20001);\n\t\t\t\tdt--;\n\t\t\t\tif (dt <= 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tres = min (res, cost[dt] + dh * ch + dd * cd);\n\t\t\t}\n\t\t}\n\t}\n}\n", "src_uid": "bf8a133154745e64a547de6f31ddc884"}
{"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);\n    scan(m);\n\n    int ans;\n\n    if (n > 30) {\n        ans = m;\n    }\n    else {\n        ans = m % 2^^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}", "src_uid": "c649052b549126e600691931b512022f"}
{"source_code": "import std.stdio;\n\nvoid main() {\n  int n;\n  readf(\" %s\", &n);\n  if (n & 1) {\n    writeln(\"black\");\n  } else {\n    writeln(\"white\");\n    writeln(\"1 2\");\n  }\n}\n", "src_uid": "52e07d176aa1d370788f94ee2e61df93"}
{"source_code": "void main(){\n  import std.stdio, std.string, std.conv, std.algorithm;\n\n  long n, m, a, b; rd(n, m, a, b);\n  \n  long x=(((n+m-1)/m)*m-n)*a;\n  long y=(n-(n/m)*m)*b;\n\n  writeln(min(x, y));\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": "c05d753b35545176ad468b99ff13aa39"}
{"source_code": "import std.stdio, std.range, std.string, std.conv, std.algorithm;\n\nvoid main() {\n    int d1, d2, d3;\n    readf(\"%d %d %d\\n\", &d1, &d2, &d3);\n    writeln(min((d1 + d2) * 2, (d2 + d3) * 2, (d3 + d1) * 2, d1 + d2 + d3));\n}", "src_uid": "26cd7954a21866dbb2824d725473673e"}
{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && 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 u = RD;\n\tauto v = RD;\n\t\n\tif (u > v || (v - u) % 2)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tauto x = v - u;\n\t\tlong[] ans;\n\t\tlong[] tmp;\n\t\tlong t;\n\t\tforeach (i; 0..60)\n\t\t{\n\t\t\tauto bit = 1L << i;\n\t\t\tif (x & bit)\n\t\t\t{\n\t\t\t\ttmp ~= [bit >> 1, bit >> 1];\n\t\t\t}\n\t\t\tif (u & bit)\n\t\t\t{\n\t\t\t\tt |= bit;\n\t\t\t}\n\t\t}\n\t\tif (t != 0)\n\t\t\tans ~= t;\n\t\ttmp.sort!\"a > b\"();\n\t\tdebug writeln(ans);\n\t\tdebug writeln(tmp);\n\t\tforeach (e; tmp)\n\t\t{\n\t\t\tbool ok;\n\t\t\tforeach (i; 0..ans.length)\n\t\t\t{\n\t\t\t\tif ((ans[i] & e) == 0)\n\t\t\t\t{\n\t\t\t\t\tans[i] += e;\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 ~= e;\n\t\t\t}\n\t\t}\n\t\t/*int[long] cnt;\n\t\tforeach (e; ans)\n\t\t{\n\t\t\t++cnt[e];\n\t\t}\n\t\tans = [];\n\t\twhile (!cnt.empty)\n\t\t{\n\t\t\tforeach (key; cnt.keys.sort)\n\t\t\t{\n\t\t\t\tbool flag;\n\t\t\t\tif (cnt[key] >= 4)\n\t\t\t\t{\n\t\t\t\t\tauto c = cnt[key] / 4;\n\t\t\t\t\tcnt[key] -= c * 4;\n\t\t\t\t\tauto p = 2;\n\t\t\t\t\twhile (c >= 4)\n\t\t\t\t\t{\n\t\t\t\t\t\tc /= 4;\n\t\t\t\t\t\tp *= 2;\n\t\t\t\t\t}\n\t\t\t\t\tcnt[key*p] += 2;\n\t\t\t\t\tflag = true;\n\t\t\t\t}\n\t\t\t\tforeach (i; 0..cnt[key])\n\t\t\t\t{\n\t\t\t\t\tans ~= key;\n\t\t\t\t}\n\t\t\t\tcnt.remove(key);\n\t\t\t\tif (flag) break;\n\t\t\t}\n\t\t}*/\n\t\twriteln(ans.length);\n\t\tif (!ans.empty)\n\t\t\tans.map!(to!string).join(\" \").writeln;\n\t}\n\n\tstdout.flush;\n\tdebug readln;\n}", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"}
{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.regex;\nimport std.algorithm.iteration;\nimport std.array;\nimport std.functional;\n\nvoid main()\n{\n  auto n = stdin.readln.strip.to!int;\n  int h = 1;\n  int t = 1;\n  alias fn = unaryFun!\"a*(a+1)/2\";\n  for (;t<=n; t+=fn(++h)) {}\n  write(--h);\n} ", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"}
{"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, m;\n    scan(n, m);\n\n    long ansmin = max(0, n - 2*m);\n\n    long v;\n\n    while (v*(v-1)/2 < m) {\n        v++;\n    }\n\n    long ansmax = n - v;\n\n    writeln(ansmin, \" \", ansmax);\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}", "src_uid": "daf0dd781bf403f7c1bb668925caa64d"}
{"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 offs = (readline() == \"R\" ? 1 : -1);\n\tstring s = readline();\n\tstring[] keyboard; keyboard.length = 3;\n\tkeyboard[0] = \"qwertyuiop\";\n\tkeyboard[1] = \"asdfghjkl;\";\n\tkeyboard[2] = \"zxcvbnm,./\";\n\tstring res = \"\";\n\tforeach (char c; s)\n\t{\n\t\tforeach(int i; 0..3)\n\t\t{\n\t\t\tforeach (int j; 0..keyboard[i].length)\n\t\t\t{\n\t\t\t\tif (c == keyboard[i][j])\n\t\t\t\t{\n\t\t\t\t\tres ~= keyboard[i][j-offs];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twrite(res);\n\treturn 0;\n}", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"}
{"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 = 998_244_353;\n\nvoid main()\n{\n    auto vs = readln.chomp.split.map!(to!int).array;\n    \n    int mx = vs.maxElement;\n    \n    auto pw = new int[] (mx+1);\n    pw[0] = 1;\n    foreach (i; 1 .. mx+1) { pw[i] = pw[i-1].to!long * i % MD; }\n    \n    auto nt = new int[][] (mx+1, mx+1);\n    foreach (n; 0 .. mx+1) {\n        nt[n][0] = 1;\n        foreach (k; 1 .. n+1) {\n            nt[n][k] = (nt[n-1][k] + nt[n-1][k-1]) % MD;\n        }\n    }\n    \n    debug { pw.writeln; nt.writeln; }\n    \n    auto prs = new int[][] (3, 2);\n    foreach (i; 0 .. vs.length) {\n        foreach (j; i+1 .. vs.length) {\n            prs ~= [vs[i], vs[j]];\n        }\n    }\n    \n    int ans = 1;\n    foreach (pr; prs) {\n        int mn = pr.minElement;\n        \n        int tot = 0;\n        foreach (edges; 0 .. mn+1) {\n            int cur = nt[pr[0]][edges].to!long * nt[pr[1]][edges] % MD * pw[edges] % MD;\n            tot = (tot + cur) % MD;\n        }\n        \n        ans = ans.to!long * tot % MD;\n    }\n    \n    ans.writeln;\n}", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383"}
{"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 ans;\n\n    for(int a = 0; a*a <= n; ++a){\n        int b = n - a*a;\n        ans += (b*b == m - a);\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}", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"}
{"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\tstring s = readln.chomp;\n\tint p;\n\tint l;\n\tp = l = 0;\n\tforeach (c; s) {\n\t\tfinal switch (c) {\n\t\t\tcase 'o':\n\t\t\t\t++p;\n\t\t\t\tbreak;\n\t\t\tcase '-':\n\t\t\t\t++l;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tif (p == 0 || l % p == 0) {\n\t\t\"YES\".writeln;\n\t} else {\n\t\t\"NO\".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", "src_uid": "6e006ae3df3bcd24755358a5f584ec03"}
{"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    string cmd;\n\n    scan(n);\n    scan(cmd);\n\n    int x, y;\n\n    foreach (i ; 0 .. n) {\n        if (cmd[i] == 'U') y++;\n        if (cmd[i] == 'D') y--;\n        if (cmd[i] == 'L') x--;\n        if (cmd[i] == 'R') x++;\n    }\n\n    writeln(n - abs(x)- abs(y));\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}", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a"}
{"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 mod = 10 ^^ 9 + 7;\nimmutable int sLog = 20;\nimmutable int sMax = 1 << sLog;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.strip.map !(c => c == '1').array;\n\t\tauto f = new int [] [] (n + 1, sMax);\n\t\tforeach (ref g; f)\n\t\t{\n\t\t\tg[] = 0;\n\t\t\tg[0] = 1;\n\t\t}\n\t\tint res = 0;\n\t\tforeach (i; 0..n + 1)\n\t\t{\n\t\t\tfor (int s = 1; s < sMax; s = (s << 1) | 1)\n\t\t\t{\n\t\t\t\tres += f[i][s];\n\t\t\t\tif (res >= mod)\n\t\t\t\t{\n\t\t\t\t\tres -= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint v = 0;\n\t\t\tforeach (j; i..n)\n\t\t\t{\n\t\t\t\tv = (v << 1) | a[j];\n\t\t\t\tif (v == 0)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (v > sLog)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tforeach (s; 0..sMax)\n\t\t\t\t{\n\t\t\t\t\tint t = s | (1 << (v - 1));\n\t\t\t\t\tf[j + 1][t] += f[i][s];\n\t\t\t\t\tif (f[j + 1][t] >= mod)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[j + 1][t] -= mod;\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", "src_uid": "61f88159762cbc7c51c36e7b56ecde48"}
{"source_code": "import std.algorithm.iteration;\nimport std.ascii;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n  auto input = readln.stripRight.split!(isWhite).map!(a => a.parse!int);\n  auto sheetsPerPerson = (input[1] + input[2] - 1) / input[2];\n  auto sheets = (input[0] * sheetsPerPerson + input[3] - 1) / input[3];\n\n  writeln(sheets);\n}\n", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780"}
{"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 = 32;\n\nvoid main ()\n{\n\tint n, total;\n\twhile (readf (\" %s %s\", &n, &total) > 0)\n\t{\n\t\treadln;\n\t\tauto c = readln.splitter.map !(to !(int)).array;\n\t\tauto p = n.iota.array;\n\t\tp.schwartzSort !(i => c[i] * 1.0L / (1 << i),\n\t\t    q{a < b}, SwapStrategy.stable);\n\t\tlong res = long.max;\n\t\tlong cur = 0;\n\t\tforeach (i; p)\n\t\t{\n\t\t\tint times = total >> i;\n\t\t\tcur += times * 1L * c[i];\n\t\t\ttotal -= times << i;\n\t\t\tif (!total)\n\t\t\t{\n\t\t\t\tres = min (res, cur);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tres = min (res, cur + c[i]);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "src_uid": "04ca137d0383c03944e3ce1c502c635b"}
{"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\nbool even(int x) { return x % 2 == 0; }\n\nbool solve(int n, int m, int k) {\n  if (n.even && m.even) return k.even;\n  \n  if (n.even) {\n    return solve(m, n, n * m / 2 - k);\n  } else {\n    return k >= m / 2 && solve(n - 1, m, k - m / 2);\n  }\n}\n\nvoid main() {\n  int t;\n  read(t);\n  \n  while (t--) {\n    int n, m, k;\n    read(n, m, k);\n    \n    writeln(solve(n, m, k) ? \"YES\" : \"NO\");\n  }\n}\n\n", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"}
{"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 LIMIT = 1_000_000;\n\nvoid main ()\n{\n\tlong c, h1, h2, w1, w2;\n\twhile (readf (\" %s %s %s %s %s\", &c, &h1, &h2, &w1, &w2) > 0)\n\t{\n\t\tlong res = 0;\n\n\t\tfor (long q1 = 0; q1 <= LIMIT && q1 * w1 <= c; q1++)\n\t\t{\n\t\t\tlong q2 = (c - q1 * w1) / w2;\n\t\t\tres = max (res, q1 * h1 + q2 * h2);\n\t\t}\n\n\t\tswap (h1, h2);\n\t\tswap (w1, w2);\n\n\t\tfor (long q1 = 0; q1 <= LIMIT && q1 * w1 <= c; q1++)\n\t\t{\n\t\t\tlong q2 = (c - q1 * w1) / w2;\n\t\t\tres = max (res, q1 * h1 + q2 * h2);\n\t\t}\n\n\t\twriteln (res);\n\t}\n}\n", "src_uid": "eb052ca12ca293479992680581452399"}
{"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 s = readln.chomp.to!(dchar[]);\n    \n    debug { s.writeln; }\n    \n    bool ok = false;\n    foreach (a,b,c; lockstep(s, s.dropOne, s.drop(2))) {\n        debug { writeln(a, ' ', b, ' ', c); }\n        auto arr = [a,b,c];\n        \n        ok |= arr.sort().array == cast(dchar[]) ['A', 'B', 'C'];\n    }\n    \n    writeln(ok ? \"Yes\" : \"No\");\n}", "src_uid": "ba6ff507384570152118e2ab322dd11f"}
{"source_code": "import std.stdio,\n\tstd.array,\n\tstd.conv,\n\tstd.algorithm;\n\nvoid main() {\n\tint[] nums = to!(int[])(readln.split);\n\tint n = nums[0];\n\tnums = nums[1..$].sort.uniq.array;\n\tint[] data = [0] ~ [-1<<31].replicate(n);\n\n\tforeach(i; 1..n+1){\n\t\tforeach(m; nums){\n\t\t\tif(i-m >= 0){\n\t\t\t\tdata[i] = max(data[i], data[i-m]+1);\n\t\t\t}\n\t\t}\n\t}\n\twriteln(data[n]);\n}\n", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"}
{"source_code": "import std.stdio, std.array, std.string, 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\nimmutable int MOD = 10^^9+7;\nint N, K, D;\nauto mem = new int[][][](120, 120, 2);\n\nint dp(int n, int h, bool d) {\n    if (n == 0) return d;\n    if (n < 0) return 0;\n    if (mem[n][h][d] >= 0) return mem[n][h][d];\n\n    mem[n][h][d] = 0;\n    foreach (i; 1..K+1) {\n        mem[n][h][d] = (mem[n][h][d] + dp(n-i, h+1, (d || (i >= D)))) % MOD;\n    }\n    return mem[n][h][d];\n}\n\nvoid main() {\n    scanf(\"%d %d %d\", &N, &K, &D);\n    mem.each!(me => me.each!(m => fill(m, -1)));\n    dp(N, 0, false).writeln;\n    //mem[0..30].writeln;\n}\n", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"}
{"source_code": "import std.stdio;\n\nvoid main() {\n    string a = \"\", b = \"\";\n    string s = readln;\n    int i = 0;\n    for (; i < s.length - 1; ++i) {\n        if (s[i] == '|') break;\n        a ~= s[i];\n    }\n    ++i;\n    for (; i < s.length - 1; ++i) {\n        b ~= s[i];\n    }\n    string x = readln;\n    for (i = 0; i < x.length - 1; ++i) {\n        if (a.length > b.length) {\n            b ~= x[i];\n        } else {\n            a ~= x[i];\n        }\n    }\n    if (a.length != b.length) {\n        writeln(\"Impossible\");\n        return;\n    }\n    write(a);\n    write(\"|\");\n    write(b);\n    writeln();\n}", "src_uid": "917f173b8523ddd38925238e5d2089b9"}
{"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.string;\n\nint fun (const (char) [] s)\n{\n\treturn s.find !(d => d != '0')\n\t    .map !(d => d - '0').fold !((a, b) => a * b) (1);\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto t = s.dup;\n\t\tauto res = fun (t);\n\t\tforeach_reverse (i, ref c; t)\n\t\t{\n\t\t\tif (c != '0')\n\t\t\t{\n\t\t\t\tc -= 1;\n\t\t\t}\n\t\t\tif (i + 1 < t.length)\n\t\t\t{\n\t\t\t\tt[i + 1] = '9';\n\t\t\t}\n\t\t\tres = max (res, fun (t));\n\t\t}\n\t\twriteln (res);\n\t}\n}\n", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"}
{"source_code": "import std.algorithm,std.stdio;void main(){readln.count!`\"aeiou13579\".canFind(a)`.writeln;}", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"}
{"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;\n    scan(n);\n\n    bool[] p = [true, true, false];\n\n    foreach (i ; 0 .. n) {\n        int win;\n        scan(win);\n        win--;\n\n        if (!p[win]) {\n            writeln(\"NO\");\n            return;\n        }\n\n        foreach (j ; 0 .. 3) {\n            if (j != win) {\n                p[j] ^= 1;\n            }\n        }\n    }\n\n    writeln(\"YES\");\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": "6c7ab07abdf157c24be92f49fd1d8d87"}
{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\n\nvoid main() {\n  readln;\n  readln.chomp.split.map!(to!int).array.sort.map!(to!string).join(\" \").writeln;\n}\n", "src_uid": "ae20712265d4adf293e75d016b4b82d8"}
{"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 x; scanf(\"%d\\n\", &x);\n    writefln(\"%d %d %d\", x, 0, 0);\n}\n", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"}
{"source_code": "import std.stdio;\n\nstring ones(int x) {\n    switch (x) {\n        case 0: return \"zero\";\n        case 1: return \"one\";\n        case 2: return \"two\";\n        case 3: return \"three\";\n        case 4: return \"four\";\n        case 5: return \"five\";\n        case 6: return \"six\";\n        case 7: return \"seven\";\n        case 8: return \"eight\";\n        case 9: return \"nine\";\n        default: return \"\";\n    }\n}\n\nstring teens(int x) {\n    switch (x) {\n        case 0: return \"ten\";\n        case 1: return \"eleven\";\n        case 2: return \"twelve\";\n        case 3: return \"thirteen\";\n        case 4: return \"fourteen\";\n        case 5: return \"fifteen\";\n        case 6: return \"sixteen\";\n        case 7: return \"seventeen\";\n        case 8: return \"eighteen\";\n        case 9: return \"nineteen\";\n        default: return \"\";\n    }\n}\n\nstring tens(int x) {\n    switch (x) {\n        case 2: return \"twenty\";\n        case 3: return \"thirty\";\n        case 4: return \"forty\";\n        case 5: return \"fifty\";\n        case 6: return \"sixty\";\n        case 7: return \"seventy\";\n        case 8: return \"eighty\";\n        case 9: return \"ninety\";\n        default: return \"\";\n    }\n}\n\nvoid main() {\n    int number;\n    readf(\"%d\\n\", &number);\n\n    if (number < 10) {\n        writeln(ones(number));\n    } else {\n        int one = number % 10;\n        int ten = (number / 10) % 10;\n\n        if (ten == 1) {\n            writeln(teens(one));\n        } else {\n            if (one != 0) {\n                writeln(tens(ten) ~ \"-\" ~ ones(one));\n            } else {\n                writeln(tens(ten));\n            }\n        }\n    }\n}\n", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"}
{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.container, std.math, std.typecons;\n\nint x1, y1, x2, y2;\nint x, y;\n\nvoid main() {\n    scan(x1, y1, x2, y2);\n    scan(x, y);\n\n    if (abs(x1 - x2) % x || abs(y1 - y2) % y) {\n        writeln(\"NO\");\n        return;\n    }\n\n    int xd = abs(x1 - x2) / x;\n    int yd = abs(y1 - y2) / y;\n\n    if ((xd - yd) & 1) {\n        writeln(\"NO\");\n    }\n    else {\n        writeln(\"YES\");\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}", "src_uid": "1c80040104e06c9f24abfcfe654a851f"}
{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\nlong comb(int n, int k)\n{\n    long res = 1;\n    foreach (i; n - k + 1 .. n + 1)\n    {\n        res *= i;\n    }\n    foreach (i; 2 .. k + 1)\n    {\n        res /= i;\n    }\n    return res;\n}\n\nint saiki(int mask, int idx, int k, int[] dp)\n{\n    if (dp[mask] != -1)\n    {\n        return dp[mask];\n    }\n    if (idx == k)\n    {\n        dp[mask] = 1;\n        return 1;\n    }\n    auto res = 0;\n    foreach (i; 0 .. k)\n    {\n        if (i != idx && (mask & (1 << i)) == 0)\n        {\n            auto ret = saiki(mask | (1 << i), idx + 1, k, dp);\n            res += ret;\n        }\n    }\n    dp[mask] = res;\n    return res;\n}\n\nvoid solve(int n, int k)\n{\n    long ans = 0;\n    auto dp = new int[1 << k];\n    foreach (i; 0 .. k + 1)\n    {\n        auto ret0 = comb(n, i);\n        fill(dp, -1);\n        auto ret1 = saiki(0, 0, i, dp);\n        ans += ret0 * ret1;\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        solve(n, k);\n    }\n    return 0;\n}", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f"}
{"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    string t = \"QAQ\";\n\n    int n = s.length.to!int;\n    int m = t.length.to!int;\n\n    auto dp = new int[][](n + 1, m + 1);\n    dp[0][0] = 1;\n\n    foreach (i ; 1 .. n + 1) {\n        foreach (j ; 0 .. m + 1) {\n            dp[i][j] = dp[i-1][j];\n            if (1 <= j && s[i-1] == t[j-1]) {\n                dp[i][j] += dp[i-1][j-1];\n            }\n        }\n    }\n\n    debug {\n        writefln(\"%(%(%s %)\\n%)\", dp);\n    }\n\n    int ans = dp[n][m];\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}\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": "8aef4947322438664bd8610632fe0947"}
{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid format(int x) {\n    int h = x / 60;\n    int m = x % 60;\n    printf(\"%02d:%02d\\n\", h, m);\n}\n\nvoid main() {\n    int sh, sm, th, tm; \n    readf(\"%d:%d\\n\", &sh, &sm);\n    readf(\"%d:%d\\n\", &th, &tm);\n    int s = sh * 60 + sm;\n    int t = th * 60 + tm;\n    format((s - t + 24 * 60) % (24 * 60));\n}\n", "src_uid": "595c4a628c261104c8eedad767e85775"}
{"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.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)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tsize_t l=0,r=a.length;\n\t\twhile(r-l>1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]<g))r=m;\n\t\t\telse l=m;\n\t\t}\n\t\treturn (!(a[l]<g))?l:r;\n\t}\n\tsize_t upb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\tif(pos==a.length)return pos;\n\t\telse return a[pos]==g?pos+1:pos;\n\t}\n\tsize_t binf(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\tauto pos=lowb(a,g);\n\t\treturn (g==a[pos])?pos:a.length;\n\t}\n\tbool binary_search(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))\n\t{\n\t\treturn binf(a,g)!=a.length;\n\t}\n}\nvoid putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nbool getarr(X)(X a,in size_t n)\n{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\telse s+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,m;\nloop:while(read(n,m))\n\t{\n\t\tif(n==m)writeln(n);\n\t\telse writeln(2);\n\t}\n}", "src_uid": "a8d992ab26a528f0be327c93fb499c15"}
{"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\tscanf(\"%d\", &n);\n\tint[] a, b;\n\ta.length = n; b.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tint l1, l2;\n\t\tscanf(\"%d %d\", &l1, &l2);\n\t\ta[i] = l1; b[i] = l2;\n\t}\n\tint[int] fb;\n\tforeach (int i; 0..n)\n\t{\n\t\tfb[a[i]]++;\n\t}\n\tint num = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\ttry {\n\t\t\tint ll = fb[b[i]];\n\t\t\tnum += ll;\n\t\t} catch {\n\t\t}\n\t}\n\tprintf(\"%d\", num);\n\treturn 0;\n}\n\n", "src_uid": "745f81dcb4f23254bf6602f9f389771b"}
{"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    string s;\n    sc.read(s);\n    int n = s.length.to!int;\n    bool check(string t) {\n        return !equal(t, t.retro);\n    }\n    int ans = 0;\n    foreach (i; 0..n) {\n        foreach (j; i+1..n+1) {\n            if (check(s[i..j])) ans = max(ans, j-i);\n        }\n    }\n    writeln(ans);\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", "src_uid": "6c85175d334f811617e7030e0403f706"}
{"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 h, int m, int s, int t1, int t2)\n{\n\tfor (int t = t1; t != t2; t = (t + 1) % 120)\n\t{\n\t\tif (t == h || t == m || t == s)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nvoid main ()\n{\n\tint h, m, s, t1, t2;\n\twhile (readf (\" %s %s %s %s %s\", &h, &m, &s, &t1, &t2) > 0)\n\t{\n\t\tlong res = 0;\n\t\th = h % 12 * 10 + 1;\n\t\tm = m % 60 * 2 + 1;\n\t\ts = s % 60 * 2;\n\t\tt1 = t1 % 12 * 10;\n\t\tt2 = t2 % 12 * 10;\n\t\twriteln (solve (h, m, s, t1, t2) ||\n\t\t    solve (119 - h, 119 - m, 119 - s, 119 - t1, 119 - t2) ?\n\t\t    \"YES\" : \"NO\");\n\t}\n}\n", "src_uid": "912c8f557a976bdedda728ba9f916c95"}
{"source_code": "import std.stdio, std.array, std.string, 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 L = s[1].to!long;\n    auto R = s[2].to!long;\n\n    long r = R + 2 - R % 3;\n    long l = L - L % 3;\n    long x = (r - l + 1) / 3;\n\n    auto num = new long[](3);\n    num[] = x;\n\n    if (L % 3 == 1) {\n        num[0] -= 1;\n    } else if (L % 3 == 2) {\n        num[0] -= 1;\n        num[1] -= 1;\n    }\n\n    if (R % 3 == 0) {\n        num[1] -= 1;\n        num[2] -= 1;\n    } else if (R % 3 == 1) {\n        num[2] -= 1;\n    }\n\n\n    auto dp = new long[][](N+1, 3);\n    dp[0][0] = 1;\n\n    foreach (i; 0..N) {\n        foreach (j; 0..3) {\n            foreach (k; 0..3) {\n                (dp[i+1][(j+k)%3] += dp[i][j] * num[k] % MOD) %= MOD;\n            }\n        }\n    }\n\n    dp[N][0].writeln;\n}\n", "src_uid": "4c4852df62fccb0a19ad8bc41145de61"}
{"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 a = RD;\n\tauto b = RD;\n\tauto c = RD;\n\n\tauto week = min(min(a / 3, b / 2), c / 2);\n\tauto arr = [0, 0, 1, 2, 0, 2, 1];\n\tarr ~= arr.dup;\n\n\tlong best;\n\tforeach (day; 0..7)\n\t{\n\t\tauto aa = a - week * 3;\n\t\tauto bb = b - week * 2;\n\t\tauto cc = c - week * 2;\n\t\tlong cnt;\n\t\tforeach (i; day..14)\n\t\t{\n\t\t\tif (arr[i] == 0)\n\t\t\t{\n\t\t\t\tif (aa == 0) break;\n\t\t\t\t--aa;\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t\telse if (arr[i] == 1)\n\t\t\t{\n\t\t\t\tif (bb == 0) break;\n\t\t\t\t--bb;\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (cc == 0) break;\n\t\t\t\t--cc;\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t}\n\t\tbest = max(best, cnt);\n\t}\n\tauto ans = week * 7 + best;\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"}
{"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\nvoid main() {\n  int[] i1 = readln.chomp.split(\":\").to!(int[]),\n        i2 = readln.chomp.split(\":\").to!(int[]);\n\n  int bh = i1[0],\n      eh = i2[0];\n  int bm = i1[1],\n      em = i2[1];\n  int mh, mm;\n  int dur;\n\n  if (bm < em) {\n    dur = (eh - bh) * 60 + em - bm;\n  } else {\n    dur = (eh - bh - 1) * 60 + 60 + em - bm;\n  }\n\n  mh = bh + (bm + dur/2) / 60;\n  mm = (bm + dur/2) % 60;\n  writefln(\"%02d:%02d\", mh, mm);\n}\n", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"}
{"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++]; }\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) {\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\nint gcd(int a, int b) {\n\treturn (b != 0) ? gcd(b, a % b) : a;\n}\n\nvoid main(string[] args) {\n\tint N = readInt;\n\tint[] A = new int[N];\n\tforeach (i; 0 .. N) {\n\t\tA[i] = readInt;\n\t}\n\tint g = 0;\n\tforeach (a; A) {\n\t\tg = gcd(g, a);\n\t}\n\twriteln(g * N);\n}\n\n", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"}
{"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[][] mat = new int[][](3, 3);\nvoid toggle(int i, int j) {\n        mat[i][j] = mat[i][j] == 1 ? 0 : 1;\n        if (i + 1 < 3) mat[i + 1][j] = mat[i + 1][j] == 1 ? 0 : 1;\n        if (j + 1 < 3) mat[i][j + 1] = mat[i][j + 1] == 1 ? 0 : 1;\n        if (i - 1 >= 0) mat[i - 1][j] = mat[i - 1][j] == 1 ? 0 : 1;\n        if (j - 1 >= 0) mat[i][j - 1] = mat[i][j - 1] == 1 ? 0 : 1;\n}\n\nvoid main() {\n        IO cin;\n        int t = 1;\n        // t = cin.readInt;\n        while (t--) {\n                int[][] state = new int[][](3, 3);\n                for (int i = 0; i < 3; i++) {\n                        for (int j = 0; j < 3; j++) {\n                                mat[i][j] = 1;\n                        }\n                }\n\n                foreach (ref i; state) foreach (ref j; i) j = cin.readInt;\n\n                for (int i = 0; i < 3; i++) {\n                        for (int j = 0; j < 3; j++) {\n                                if (state[i][j] % 2) {\n                                        toggle(i, j);\n                                }\n                        }\n                }\n\n                foreach (i; mat) {\n                        foreach (j; i) {\n                                write(j);\n                        }\n                        writeln();\n                }\n        }        \n}", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6"}
{"source_code": "import std.algorithm;\nimport std.stdio;\n\nimmutable int MAX_N = 1_000_000;\n\nbool [] bool_primes (int 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\nint [] cumulative_sums (const bool [] a) {\n    auto res = new int [a.length];\n    res[0] = a[0];\n    foreach (i; 1..a.length)\n        res[i] = res[i - 1] + a[i];\n    return res;\n}\n\nimmutable bool [] p = bool_primes (MAX_N);\nimmutable int [] cs = cumulative_sums (p);\n\nvoid main () {\n    int a, b, k;\n    while (readf (\" %s %s %s\", &a, &b, &k)) {\n        bool check (int l) {\n            foreach (x; a..b - l + 2)\n                if (cs[x + l - 1] - cs[x - 1] < k)\n                    return false;\n            return true;\n        }\n\n        int l = binary_search !(check) (1, b - a + 2);\n        if (l > b - a + 1)\n            l = -1;\n        writefln (\"%s\", l);\n    }\n}\n\n\nint binary_search (alias pred) (int lo, int hi) {\n    while (lo < hi) {\n        int me = (lo + hi) / 2;\n        if (pred (me))\n            hi = me;\n        else\n            lo = me + 1;\n    }\n    return lo;\n}", "src_uid": "3e1751a2990134f2132d743afe02a10e"}
{"source_code": "import core.bitop, std.algorithm, std.array, std.range, std.stdio, std.string;\nvoid main () {\n\treadln;\n\tauto s = readln.strip.split.sort.uniq.array;\n\t1024.iota.filter !(m => s.map !(c => m.reduce !((a, b) =>\n\t    a & ~(c.find (\"RGBYW12345\"[b]).empty << b)) (10.iota))\n\t    .array.sort.uniq.array.length == s.length)\n\t    .map!popcnt.reduce!min.writeln;\n}\n", "src_uid": "3b12863997b377b47bae43566ec1a63b"}
{"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\tint b=0;\n\tint c=0;\n\tint res=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\treadf(\" %d\", &c);\n\tfor (int i=0; i<c; i++)\n\t{\n\t\tres=res+a+a+b+b-4;\n\t\ta=a-4;\n\t\tb=b-4;\n\t}\n\twriteln(res);\n\treturn 0;\n}", "src_uid": "2c98d59917337cb321d76f72a1b3c057"}
{"source_code": "void main(){\n  import std.stdio, std.string, std.conv, std.algorithm;\n\n  int n; rd(n);\n  auto as=readln.split.to!(int[]);\n\n  auto used=new bool[](1001);\n  int[] com;\n  foreach_reverse(a; as){\n    if(used[a]==false){\n      com=a~com;\n      used[a]=true;\n    }\n  }\n\n  writeln(com.length);\n  writefln(\"%(%s %)\", com);\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": "1b9d3dfcc2353eac20b84c75c27fab5a"}
{"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\twriteln ((((1L << n)) - 1) << 1);\n\t}\n}\n", "src_uid": "f1b43baa14d4c262ba616d892525dfde"}
{"source_code": "import std.conv, std.stdio, std.string, std.array, std.range, std.algorithm;\n\nstring s = \"CODEFORCES\";\n\nvoid main() {\n\t\n\tchar[] t = readln.strip.dup;\n\t\n\tint len, j;\n\tchar[] begin, end;\n\t\n\tforeach (i, e; s) {\n\t\tif (e == t[i]) {\n\t\t\tbegin ~= t[i];\n\t\t}\n\t\telse {\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tj = 0;\n\tforeach_reverse (i, e; s) {\n\t\tif (e == t[$ - j - 1]) {\n\t\t\tend ~= t[$ - j - 1];\n\t\t}\n\t\telse {\n\t\t\tbreak;\n\t\t}\n\t\t++j;\n\t}\n\t\n\tif ((begin ~ end).length >= 10) {\n\t\twriteln(\"YES\");\n\t\treturn;\n\t}\n\t\n\twriteln(\"NO\");\n}", "src_uid": "bda4b15827c94b526643dfefc4bc36e7"}
{"source_code": "import std.algorithm, std.array, std.conv, std.stdio, std.string;\n\nbool solve () {\n\tif (!readln) return false;\n\tauto adj = new int [] [128];\n\tint step = 0, cur = 1;\n\n\timmutable string answer = q{{writeln (\"! \", cur); stdout.flush; return true;}};\n\n\timmutable string ask = q{\n\t\twriteln (\"? \", cur); stdout.flush; step += 1;\n\t\treadln; adj[cur] = readln.split.map !(to !(int)).array;\n\t\tif (adj[cur].length == 2) mixin (answer);\n\t};\n\n\tauto u = [cur];\n\tmixin (ask);\n\twhile (adj[cur].length != 1) {\n\t\tcur = adj[cur].filter !(u => adj[u].empty).front;\n\t\tu ~= cur; mixin (ask);\n\t\tdebug {writeln (\"p \", u);}\n\t}\n\treverse (u);\n\tcur = 1;\n\tdo\n\t{\n\t\twhile (adj[cur].length != 1 || u.length < 2) {\n\t\t\tcur = adj[cur].filter !(u => adj[u].empty).front;\n\t\t\tu ~= cur; mixin (ask);\n\t\t\tdebug {writeln (\"t \", u);}\n\t\t}\n\t\tu = u[0..$ / 2 + 1];\n\t\tcur = u[$ - 1];\n\t\tdebug {writeln (\"x \", u);}\n\t}\n\twhile (u.length < 4);\n\tint [] q;\n\twhile (step < 16) {\n\t\tq ~= adj[cur].filter !(u => adj[u].empty).array;\n\t\tcur = q[0]; q = q[1..$]; mixin (ask);\n\t}\n\tcur = q[0]; mixin (answer);\n}\n\nvoid main () {readln; while (solve) {}}\n", "src_uid": "5c0db518fa326b1e405479313216426a"}
{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && 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 x0 = RD;\n\tauto y0 = RD;\n\tauto ax = RD;\n\tauto ay = RD;\n\tauto bx = RD;\n\tauto by = RD;\n\tauto xs = RD;\n\tauto ys = RD;\n\tauto t = RD;\n\t\n\t/*auto x_base = min(x0, xs);\n\tauto y_base = min(y0, ys);\n\tx0 -= x_base;\n\ty0 -= y_base;\n\txs -= x_base;\n\tys -= y_base;*/\n\n\tlong dist(long[] lhs, long[] rhs)\n\t{\n\t\treturn max(lhs[0], rhs[0])-min(lhs[0], rhs[0]) + max(lhs[1], rhs[1])-min(lhs[1], rhs[1]);\n\t}\n\n\tlong[][] pos;\n\tpos ~= [x0, y0];\n\tforeach (i; 1..10^^17)\n\t{\n\t\tauto x = pos[$-1][0];\n\t\tauto y = pos[$-1][1];\n\t\tpos ~= [x * ax + bx, y * ay + by];\n\t\tdebug writeln(pos[$-1]);\n\t\tdebug writeln([xs, ys]);\n\t\tdebug writeln(dist(pos[$-1], [xs, ys]));\n\t\tif (pos[$-1][0] < x || pos[$-1][1] < y || (pos[$-1][0]-xs + pos[$-1][1]-ys) > t)\n\t\t{\n\t\t\tpos.length = pos.length - 1;\n\t\t\tbreak;\n\t\t}\n\t}\n\tdebug writeln(pos);\n\n\tlong ans;\n\tforeach (i; 0..pos.length)\n\t{\n\t\t{\n\t\t\tauto tt = t;\n\t\t\tauto p = [xs, ys];\n\t\t\tlong cnt;\n\t\t\tforeach (j; i..pos.length)\n\t\t\t{\n\t\t\t\ttt -= dist(pos[j], p);\n\t\t\t\tif (tt < 0) break;\n\t\t\t\tp = pos[j].dup;\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t\tans.chmax(cnt);\n\t\t\tdebug writeln(\"i:\", i, \" cnt:\", cnt);\n\t\t}\n\t\t{\n\t\t\tauto tt = t;\n\t\t\tauto p = [xs, ys];\n\t\t\tlong cnt;\n\t\t\tforeach_reverse (j; 0..i+1)\n\t\t\t{\n\t\t\t\ttt -= dist(pos[j], p);\n\t\t\t\tif (tt < 0) break;\n\t\t\t\tp = pos[j].dup;\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t\tans.chmax(cnt);\n\t\t\tdebug writeln(\"i:\", i, \" cnt:\", cnt);\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28"}
{"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  writeln(n%2 == 0 ? \"Mahmoud\" : \"Ehab\");\n}\n", "src_uid": "5e74750f44142624e6da41d4b35beb9a"}
{"source_code": "import std.stdio;\nimport std.format;\nimport std.range;\nimport std.algorithm;\nimport std.math;\n\nvoid findx(long k) {\n  int num_digit = 1;\n  long mul =1;\n  long acc = 0;\n\n  while(true) {\n    acc = acc + 9*mul*num_digit;\n    if (acc >= k) {\n      break;\n    }\n    num_digit++;\n    mul = mul*10;\n  }\n  long l = mul;\n  long a = acc - 9*mul*num_digit;\n  assert(k > a);\n  k = k-a;\n  long idx = (k-1) / num_digit;\n  long res = k - idx*num_digit;\n  long nn = l + idx;\n\n  stderr.writeln(res);\n\n  writeln( format(\"%d\", nn)[cast(uint)(res-1)] );\n}\n\nvoid main() {\n  long k;\n  stdin.readf(\"%d\", k);\n\n\n  findx(k);\n\n}\n", "src_uid": "1503d761dd4e129fb7c423da390544ff"}
{"source_code": "import std.stdio;\n\nint main()\n{\n\tint i,j,now,x,y;\n\tint[][] v = [\n\t[3,3,0,4,4,0,3,3],\n\t[3,3,0,4,4,0,3,3],\n\t[2,2,0,3,3,0,2,2],\n\t[2,2,0,3,3,0,2,2],\n\t[1,1,0,2,2,0,1,1],\n\t[1,1,0,2,2,0,1,1]\n\t];\n\tchar[11][11] mp;\n\tchar tmp;\n\tnow=0;\n\tx=y=0;\n\tfor(i=0;i<6;i++)\n\t{\n\t\tfor(j=0;j<8;j++)\n\t\t{\n\t\t\tscanf(\"%c \",&mp[i][j]);\n\t\t\tif(mp[i][j]=='.'&&v[i][j]>now)\n\t\t\t{\n\t\t\t\tnow=v[i][j];\n\t\t\t\tx=i;\n\t\t\t\ty=j;\n\t\t\t}\n\t\t}\n\t}\n\tmp[x][y]='P';\n\tfor(i=0;i<6;i++)\n\t{\n\t\tfor(j=0;j<8;j++)\n\t\t{\n\t\t\tprintf(\"%c\",mp[i][j]);\n\t\t}\n\t\tprintf(\"\\n\");\n\t}\n\treturn 0;\n}", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"}
{"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 (string s, string [] t)\n{\n\tif (t.canFind (s))\n\t{\n\t\treturn true;\n\t}\n\tforeach (a; t)\n\t{\n\t\tforeach (b; t)\n\t\t{\n\t\t\tif (\"\" ~ a[1] ~ b[0] == s)\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tint n = readln.strip.to !(int);\n\t\tstring [] t;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tt ~= readln.strip;\n\t\t}\n\t\twriteln (solve (s, t) ? \"YES\" : \"NO\");\n\t}\n}\n", "src_uid": "cad8283914da16bc41680857bd20fe9f"}
{"source_code": "import std.stdio;\nimport std.typecons;\n\nbool ispal(string s) {\n\tint len = s.length;\n\n\tforeach (i; 0 .. len / 2) {\n\t\tif (s[i] != s[len - 1 - i])\n\t\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nvoid main() {\n\n\tstring s;\n\n\treadf(\"%s\\n\", &s);\n\n\tforeach (i; 0 .. s.length + 1) {\n\t\tforeach (j; 'a' .. 'z' + 1) {\n\t\t\tstring copy;\n\t\t\tforeach (k; 0 .. i)\n\t\t\t\tcopy ~= s[k];\n\t\t\tcopy ~= j;\n\t\t\tforeach (l; i .. s.length)\n\t\t\t\tcopy ~= s[l];\n\t\t\tif (ispal(copy)) {\n\t\t\t\twriteln(copy);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(\"NA\");\n}", "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b"}
{"source_code": "import std.conv;\nimport std.math;\nimport std.stdio;\n\nvoid main()\n{\n  int n, m;\n  readf!\"%d\\n\"(n);\n  m = sqrt(float(n)).to!int;\n\n  auto best = -1;\n\n  // compute minimum operations for each square\n  // this can probably be a greedy algorithm\n  foreach (i; 1..m+1) {\n    auto s = (i * i).to!string;\n    auto r = n.to!string;\n    auto d = 0;\n    auto k = 0; // current position in s\n\n    // for each character in r\n    foreach (j; 0..r.length) {\n      // if we've reached the end of s, we're just deleting trailing characters\n      if (k == s.length || r[j] != s[k]) {\n\td++;\n      } else {\n\tk++;\n      }\n    }\n\n    if (k == s.length) {\n      // we were able to construct the square\n      if (best == -1 || d < best) {\n\tbest = d;\n      }\n    }\n  }\n\n  writeln(best);\n}\n", "src_uid": "fa4b1de79708329bb85437e1413e13df"}
{"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, m, a, b;\n    readf(\"%d %d %d %d\", &n, &m, &a, &b);\n\n    int ans = min(cast(int)ceil(cast(double)n / m) * b,\n        n / m * b + n % m * a,\n        a * n);\n    writeln(ans);\n}", "src_uid": "faa343ad6028c5a069857a38fa19bb24"}
{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.array;\n\nvoid main() {\n\n\tauto a = readln.split.map!(to!int).array;\n\n\tlong sum = (a[0] + a[2] * a[0]) * a[2] / 2;\n\twriteln(max(0L, sum - a[1]));\n}", "src_uid": "e87d9798107734a885fd8263e1431347"}
{"source_code": "import std.stdio;\n\nconst int N = 4000005;\nconst long P = 998244353;\nint n, m, s, i;\nlong ans = 0, E;\nint[N] inv;\n\nvoid main()\n{\n    readf!\"%d %d\"(n, m);\n    s = n + m;\n    for (inv[0] = inv[1] = 1, i = 2; i <= s; ++i)\n        inv[i] = inv[P % i] * (-P / i) % P;\n    for (i = 1; i <= n; ++i)\n        ans = (ans + inv[i]) % P;\n    ans = (ans * m + 1) % P;\n    E = (1 + n * cast(long)inv[m + 1]) % P;\n    ans = (ans * E % P + P) % P;\n    write(ans);\n}\n", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613"}
{"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    int[][] a = new int[][](n, n);\n\n    for (int i = 0; i < n; i++) {\n        a[i][0] = 1;\n        a[0][i] = 1;\n    }\n\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < n; j++) {\n            a[i][j] = a[i - 1][j] + a[i][j - 1];\n        }\n    }\n\n    writeln(a[n - 1][n - 1]);\n}", "src_uid": "2f650aae9dfeb02533149ced402b60dc"}
{"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  auto b=readln.split.to!(int[]);\n\n  bool[int] h;\n  foreach(e; b) h[e]=true;\n  int cnt=0;\n  foreach(e1; a)foreach(e2; b){\n    if((e1^e2) in h) cnt++;\n  }\n\n  if(cnt&1) writeln(\"Koyomi\");\n  else writeln(\"Karen\");\n}\n\nvoid chmax(T)(ref T x, T y){\n  if(x<y) x=y;\n}\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}", "src_uid": "1649d2592eadaa8f8d076eae2866cffc"}
{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.conv;\n\n\n///solve\nvoid solve() {\n    int n;\n    readf(\" %s\\n\", &n);\n    if (n == 1) {\n        int today;\n        readf(\" %s\\n\", &today);\n        if (today == 15) {\n            writeln(\"DOWN\");\n            return;\n        }\n        if (today == 0) {\n            writeln(\"UP\");\n            return;\n        }\n        writeln(-1);\n        return;\n    }\n    int[] day_idx___size = readln.split.map!(x => x.to!int).array;\n    // writeln(day_idx___size);\n    int today, yesterday;\n    today = day_idx___size[$ - 1];\n    yesterday = day_idx___size[$ - 2];\n    if (today == 15) {\n        writeln(\"DOWN\");\n        return;\n    }\n    if (today == 0) {\n        writeln(\"UP\");\n        return;\n    }\n    if (today > yesterday) {\n        writeln(\"UP\");\n        return;\n    }\n    if (today < yesterday) {\n        writeln(\"DOWN\");\n        return;\n    }\n}\n\nvoid main() {\n    debug {\n        \"35j34lkjrtl\".writeln;\n    }\n    solve();\n}\n", "src_uid": "8330d9fea8d50a79741507b878da0a75"}
{"source_code": "module main;\n\nimport std.stdio;\n\nvoid main()\n{\n    long x, newx = 0, i = 1;\n\n    readf(\" %s\", &x);\n\n    long temp = x;\n\n    while ( temp > 0 )\n    {\n        if (temp % 10 < 5 || temp == 9)\n            newx += i * (temp % 10);\n        else\n            newx += i * (9 - temp % 10);\n        i *= 10;\n        temp /= 10;\n    }\n    writeln(newx);\n}", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"}
{"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    long n, k;\n    while (read(&n, &k))\n        writeln(bsf(k) + 1);\n}\n", "src_uid": "0af400ea8e25b1a36adec4cc08912b71"}
{"source_code": "import std.stdio;\n\n/* Lucky number: numero al cui interno compaiono solamente le cifre 4\n   e 7 */\n/* Nearly lucky number: il numero di cifre fortunate in un numero sono\n   un lucky number */\nushort[] digits(ulong number) {\n  ushort[] digits;\n  if (number == 0)\n    return digits ~= 0;\n  while (number > 0) {\n    ushort d = number % 10;\n    digits ~= d;\n    number /= 10;\n  }\n  return digits;\n}\n\nbool is_lucky(ulong number) {\n  foreach (digit; digits(number)) {\n    if (digit != 4 && digit != 7) {\n      return false;\n    }\n  }\n  return true;\n}\n\nbool is_nearly_lucky(ulong number) {\n  int lucky_digits = 0;\n  foreach (digit; digits(number)) {\n    if (digit == 4 || digit == 7) {\n      lucky_digits++;\n    }\n  }\n  return is_lucky(lucky_digits);\n}\n\nint main() {\n    ulong number = 0;\n    readf(\"%s\", &number);\n    if (is_nearly_lucky(number)) {\n\twriteln(\"YES\");\n    } else {\n\twriteln(\"NO\");\n    }\n    return 0;\n}", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"}
{"source_code": "\nimmutable multi = true;\nimmutable mod = 1000000007L;\nalias Zp = Z!mod;\nstatic this()\n{\n\tZp.makeFactorials(200_000+1);\n}\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto k = readInt!int;\n\tif (k == 0) \n\t{\n\t\treturn writeln(1);\n\t}\n\tZp[] solveMem = new Zp[](k);\n\tZp properEvenSubsets = Zp(0);\n\tfor(int t = 0; t < n; t += 2) properEvenSubsets = properEvenSubsets + Zp.C(n, t);\n\tZp solve(int d)\n\t{\n\t\tif (d == 0) \n\t\t{\n\t\t\tZp ans = Zp(0);\n\t\t\t// 1 - 0\n\t\t\tif (n % 2 == 0) ans = ans + Zp(1);\n\t\t\t// 1 - 1\n\t\t\tif (n % 2 == 1) ans = ans + Zp(1);\n\t\t\t// 0 - 0\n\t\t\tans = ans + properEvenSubsets;\n\t\t\treturn ans;\n\t\t}\n\t\tZp ans = Zp(0);\n\t\t// 1 - 0\n\t\tif (n % 2 == 0)\n\t\t{\n\t\t\tans = ans + Zp(2)^^(cast(long)d * cast(long)n);\n\t\t}\n\t\t// 1 - 1\n\t\tif (n % 2 == 1)\n\t\t{\n\t\t\tans = ans + solveMem[d - 1];\n\t\t}\n\t\t// 0 - 0\n\t\tans = ans + properEvenSubsets * solveMem[d - 1];\n\t\treturn ans;\n\t}\n\tforeach(d; 0 .. k) solveMem[d] = solve(d);\n\tsolveMem[k-1].rep.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// 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", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881"}
{"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 s;\n\tlong x;\n\twhile (readf (\" %s %s\", &s, &x) > 0)\n\t{\n\t\tlong [2] f = [1, 0];\n\t\tlong res = (s == x) ? -2 : 0;\n\t\twhile (s > 0 || x > 0)\n\t\t{\n\t\t\tlong [2] g = [0, 0];\n\t\t\tforeach (a; 0..2)\n\t\t\t{\n\t\t\t\tforeach (b; 0..2)\n\t\t\t\t{\n\t\t\t\t\tforeach (t; 0..2)\n\t\t\t\t\t{\n\t\t\t\t\t\tint xbit = a ^ b;\n\t\t\t\t\t\tint ssum = a + b + t;\n\t\t\t\t\t\tint sbit = ssum & 1;\n\t\t\t\t\t\tint cbit = ssum >> 1;\n\t\t\t\t\t\tif (sbit == (s & 1) &&\n\t\t\t\t\t\t    xbit == (x & 1))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tg[cbit] += f[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\tf[] = g[];\n\t\t\ts >>= 1;\n\t\t\tx >>= 1;\n\t\t}\n\t\tres += f[0];\n\t\twriteln (res);\n\t}\n}\n", "src_uid": "18410980789b14c128dd6adfa501aea5"}
{"source_code": "import std.stdio, std.array, 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 A = readln.chomp;\n    auto B = readln.chomp;\n    if (B.length > A.length) {\n        auto C = A.to!(dchar[]);\n        C.sort!\"a > b\";\n        C.writeln;\n        return;\n    }\n\n    auto N = A.length.to!int;\n    auto dp = new long[][](1 << N, 2);\n    foreach (i; 0..(1<<N)) dp[i].fill(-1);\n    dp[0][0] = 0;\n\n    auto masks = (1<<N).iota.array;\n    masks.sort!((a,b) => a.popcnt < b.popcnt);\n\n    foreach (mask; masks) {\n        int done = mask.popcnt;\n        foreach (k; 0..2) {\n            if (dp[mask][k] == -1) continue;\n            foreach (i; 0..N) {\n                if (mask & (1<<i)) continue;\n                if (k == 0 && A[i] > B[done]) continue;\n                int next = mask | (1 << i);\n                int under = k || (A[i] < B[done]);\n                dp[next][under] = max(dp[next][under],\n                                      dp[mask][k] + 10L^^(N-done-1) * (A[i]-'0'));\n            }\n        }\n    }\n\n    dp[(1<<N)-1].reduce!max.writeln;\n}\n", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"}
{"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.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    long n = scan!long, m = scan!long;\n    \n    Finite pow = Finite(1);\n    foreach(i; 0 .. n - 3) pow *= 2;\n\n    Finite ans = pascal(m - n + 1, n - 1) * (n - 2) * pow;\n    ans.print;\n}\n\n\nstruct Finite{\n\tlong value; static long mod = 998244353;\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\n// ---以下はユーティリティ--- //\n\n/// mod p における階乗\n/// 例 perm(6) = Finite(120)\n/// オーダーはプログラム全体で出てくる最大の引数Nに対してO(N)\nFinite perm(long x){ int i = Finite.val(x).to!int;\n\tstatic Finite[] _perm = [];\n\tif(_perm.length == 0) _perm ~= Finite(1);\n\twhile(i >= _perm.length) _perm ~= _perm[$ - 1] * _perm.length;\n\treturn _perm[i];\n}\n\n/// mod p における階乗の逆元\n/// 例 invperm(6) = Finite(1) / Finite(120)\n/// オーダーはプログラム全体で出てくる最大の引数Nに対してO(N)\n/// ※ invperm(x) と inv(perm(x)) は同じ値だが、後者は計算量が O(mod) になる\nFinite invperm(long x){ int i = Finite.val(x).to!int;\n\tstatic Finite[] _iperm = [];\n\tif(_iperm.length == 0) _iperm ~= Finite(1);\n\twhile(i >= _iperm.length) _iperm ~= _iperm[$ - 1] / _iperm.length;\n\treturn _iperm[i];\n}\n\n/// mod p における二項係数(定義に注意:(a + b)! / a! / b! )\n/// 例 pascal(3, 2) = Finite(10)\n/// ただし、「a < 0 または b < 0」のとき答えは 0 を返します。\nFinite pascal(long a, long b){\n\tif(a < 0 || b < 0) return Finite(0);\n\treturn perm(a + b) * invperm(a) * invperm(b);\n}\n", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba"}
{"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint o=a%4;\n\tif (o==0)\n\t{\n\t\twriteln(1);\n\t\twriteln('A');\n\t}\n\telse if (o==1)\n\t{\n\t\twriteln(0);\n\t\twriteln('A');\n\t}\n\telse if (o==2)\n\t{\n\t\twriteln(1);\n\t\twriteln('B');\n\t}\n\telse\n\t{\n\t\twriteln(2);\n\t\twriteln('A');\n\t}\n\treturn 0;\n}", "src_uid": "488e809bd0c55531b0b47f577996627e"}
{"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\n\nvoid main(){\n\n  int n; rd(n);\n  auto s=readln.chomp.to!(char[]);\n\n  if(n==1){\n    writeln(\"Yes\");\n    return;\n  }\n\n  bool[char] set;\n  foreach(c; s){\n    if(c in set){\n      writeln(\"Yes\");\n      return;\n    }\n    set[c]=true;\n  }\n\n  writeln(\"No\");\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": "6b22e93f7e429693dcfe3c099346dcda"}
{"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 x = cin.readInt;\n                int y = cin.readInt;\n                writeln(ceil(y / 100.0 * n) > x ? ceil(y / 100.0 * n) - x : 0);\n        }        \n}", "src_uid": "7038d7b31e1900588da8b61b325e4299"}
{"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.string;\n\nint main(string[] argv)\n{\n\tstring line = readln();\n\tif (line[line.length - 1] == '\\n') line.length--;\n\tint h = line.indexOf('h');\n\tint e = line.indexOf('e', (h != -1 ? h+1 : 0));\n\tint l = line.indexOf('l', (e != -1 ? e+1 : 0));\n\tint sl = line.indexOf('l', (l != -1 ? l+1 : 0));\n\tint o = line.indexOf('o', (sl != -1 ? sl+1 : 0));\n\tif (h != -1 && e != -1 && l != -1 && sl != -1 && o != -1\n\t && e > h && l > e && sl > l && o > sl)\n\t{\n\t\tprintf(\"YES\");\n\t} else {\n\t\tprintf(\"NO\");\n\t}\n\treturn 0;\n}\n\n", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"}
{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\n\nvoid advance(ref int i) {\n    ++i;\n    if (i == 4) i = 0;\n}\nvoid retreat(ref int i) {\n    --i;\n    if (i == -1) i = 3;\n}\n\nint main() {\n    debug stdin = File(\"in.txt\", \"r\");\n\n    char[4] brd1, brd2;\n    readf(\"%s%s\\n\", &brd1[0], &brd1[1]);\n    readf(\"%s%s\\n\", &brd1[3], &brd1[2]);\n    readf(\"%s%s\\n\", &brd2[0], &brd2[1]);\n    readf(\"%s%s\\n\", &brd2[3], &brd2[2]);\n\n    string s2 = to!string(brd2);\n    int il, ir;\n    if (brd1[0] == 'X') il = 0;\n    else if (brd1[1] == 'X') il = 1;\n    else if (brd1[2] == 'X') il = 2;\n    else if (brd1[3] == 'X') il = 3;\n    ir = il;\n    advance(ir);\n    foreach ( i; 0 .. 12 ) {\n        string s1 = to!string(brd1);\n        if (s1 == s2) {\n            writeln(\"YES\");\n            return 0;\n        }\n        char tmp;\n        tmp = brd1[ir];\n        brd1[ir] = brd1[il];\n        brd1[il] = tmp;\n        advance(il);\n        advance(ir);\n    }\n    retreat(il); retreat(ir);\n    foreach ( i; 0 .. 12 ) {\n        string s1 = to!string(brd1);\n        if (s1 == s2) {\n            writeln(\"YES\");\n            return 0;\n        }\n        char tmp;\n        tmp = brd1[il];\n        brd1[il] = brd1[ir];\n        brd1[ir] = tmp;\n        retreat(il);\n        retreat(ir);\n    }\n    writeln(\"NO\");\n\n    return 0;\n}", "src_uid": "46f051f58d626587a5ec449c27407771"}
{"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    long n, k;\n    scan(n, k);\n\n    long a = 1L;\n    while (a <= n) {\n        a *= 2;\n    }\n\n    long ans;\n\n    if (k == 1) ans = n;\n    else ans = a - 1;\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": "16bc089f5ef6b68bebe8eda6ead2eab9"}
{"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 bits = 0;\n\twhile (n > 0)\n\t{\n\t\tbits += (n % 2);\n\t\tn = n >> 1;\n\t}\n\tprintf(\"%d\", bits);\n\treturn 0;\n}", "src_uid": "03e4482d53a059134676f431be4c16d2"}
{"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\twriteln (n * 1L * (n + 1) * 3 + 1);\n\t}\n}\n", "src_uid": "c046895a90f2e1381a7c1867020453bd"}
{"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 gcd (int a, int b)\n{\n\tif (b > a) \n\t{\n\t\tint t = a;\n\t\ta = b;\n\t\tb = t;\n\t}\n\tint r = 1;\n\twhile (r > 0)\n\t{\n\t\tr = a % b;\n\t\ta = b;\n\t\tb = r;\n\t}\n\treturn a;\n}\n\nint main(string[] argv)\n{\n\tint a, b, n;\n\tscanf(\"%d %d %d\", &a, &b, &n);\n\tint w = -1;\n\twhile (n > 0)\n\t{\n\t\t++w; w %= 2;\n\t\tint g = gcd(w == 0 ? a : b, n);\n\t\tn -= g;\n\t}\n\tprintf(\"%d\", w);\n\treturn 0;\n}\n\n", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"}
{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nstruct ModularClass(T)\n{\n  alias pmod = positiveModularRepresentative;\n  T representative, modulus;\n  this(T representative, T modulus)\n  {\n    this.representative = pmod(representative, modulus);\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  alias eqLowerBound = maxRepresentative;\n  T minRepresentative(T lowerBound)\n  {\n    return lowerBound + pmod(representative - lowerBound, modulus);\n  }\n  alias eqUpperBound = minRepresentative;\n  static ModularClass!T multiplesOf(T modulus)\n  {\n    return ModularClass!T(0, modulus);\n  }\n  ModularClass!T opBinary(string operation)(ModularClass!T other) if (operation == \"+\" || operation == \"-\" || operation == \"*\")\n  {\n    assert(other.modulus == this.modulus, \"Trying to operate on modular classes of diferent modulus.\");\n    return ModularClass!T(mixin(q{this.representative}, operation, q{other.representative}), this.modulus);\n  }\n  ModularClass!T opBinary(string operation)(long n) if (operation == \"^\")\n  {\n    if(n == 0)\n      {\n\treturn ModularClass!T(1, this.modulus);\n      }\n    if(n & 1)\n      {\n\tauto res = this^(n - 1);\n\treturn this * res;\n      }\n    else\n      {\n\tauto res = this^(n >> 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}\n\nauto primeDivisors(T)(T x)\n{\n  T[] res;\n  for(T candidate = 2; candidate * candidate <= x; candidate++)\n    {\n      if (x % candidate == 0)\n\tres ~= candidate;\n      while (x % candidate == 0)\n\t  x /= candidate;\n    }\n  if (x > 1)\n    res ~= x;\n  return res;\n}\nimmutable p = 1_000_000_000 + 7;\nalias mod = StaticModularClass!(long, p);\nauto maxDivideFact(T)(T prime, T n)\n{\n  T pot = 0;\n  while(n)\n    {\n      pot += n / prime;\n      n /= prime;\n    }\n  mod res = prime;\n  return (res ^ pot);\n}\n\nstruct Test\n{\n  int x, y;\n}\n\nint[1000] s = -2;\n\nvoid main()\n{\n  long x, n; get(x, n);\n  wr(x.primeDivisors.fold!((acc, prime) => acc * maxDivideFact(prime, n))(mod(1)).representative);\n}\n", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"}