code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto S = readln.chomp.to!(wchar[]); if (S[0] != 'A') { writeln("WA"); return; } auto len = S.length; int C; foreach (i, c; S) { if (!i) continue; if (i >= 2 && i <= len - 2 && c == 'C') { ++C; } else if (c >= 'A' && c <= 'Z') { writeln("WA"); return; } } if (C != 1) { writeln("WA"); return; } writeln("AC"); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD; auto A = new long[][][](N); foreach (i; 0..N) { auto M = RD; foreach (j; 0..M) { auto x = RD-1; auto y = RD; A[i] ~= [x, y]; } } long ans; foreach (i; 0..2^^N) { bool ok = true; long cnt; (){ foreach (j; 0..N) { auto bit = 1L << j; if ((i & bit) == 0) continue; ++cnt; foreach (e; A[j]) { auto x = e[0]; auto y = e[1]; auto state = (i >> x) & 1; if (state != y) { ok = false; return; } } }}(); if (ok) { debug writeln("i:", i); ans.chmax(cnt); } } writeln(ans); stdout.flush; debug readln; }
D
void main() { int[] tmp = readln.split.to!(int[]); int w = tmp[0], a = tmp[1], b = tmp[2]; writeln(abs(b-a) > w ? abs(b-a) - w : 0); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { auto N = readln.chomp.map!(ch => (ch - '0').to!int).retro.array; N ~= 0; auto L = N.length.to!int; auto dp = new int[][](L + 1, 2); fillAll(dp, inf); dp[0][0] = 0; foreach (i ; 0 .. L) { foreach (j ; 0 .. 2) { foreach (d ; 0 .. 10) { int x = N[i] + j; if (x <= d) { // 繰り下がりが発生しない chmin(dp[i + 1][0], dp[i][j] + d + d - x); } else { // x > d, 繰り下がりが発生する chmin(dp[i + 1][1], dp[i][j] + d + 10 + d - x); } } } } auto ans = dp[L][0]; writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
void main() { int n = readln.chomp.to!int; int[] s = new int[n]; foreach (i; 0 .. n) { s[i] = readln.chomp.to!int; } bool[] dp = new bool[10001]; dp[0] = true; foreach (p; s) { foreach_reverse (i, d; dp) { if (d) { dp[i+p] = true; } } } foreach_reverse (i, d; dp) { if (d && (i % 10 != 0 || i == 0)) { i.writeln; break; } } } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { auto S = sread(); long[3] cnt; foreach (c; S) cnt[c - 'a']++; long m = max(abs(cnt[0] - cnt[1]), abs(cnt[1] - cnt[2]), abs(cnt[0] - cnt[2])); writeln((m < 2) ? "YES" : "NO"); }
D
import std.stdio, std.array, std.conv, std.string, std.algorithm, std.math; void main() { while (true) { auto input = readln.chomp.split.map!(to!int); auto h = input[0]; auto w = input[1]; if (h == 0 && w == 0) { break; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { write("#"); } writeln; } writeln; } }
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; void main(){ auto ip = readln.chomp; writeln(ip.count("o")*100+700); }
D
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } void main() { auto K = readln.chomp.to!int; auto numbers = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]; int solve() { return numbers[K-1]; } solve().writeln; }
D
import std.stdio; import std.string; void main() { string S = readln.chomp; ulong len = S.length; ulong ans = 0; foreach (i; 0..len){ if (S[i] != '0' + (i % 2)) ans++; } if ((len - ans) < ans) ans = len - ans; writeln(ans); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto xab = readints; int x = xab[0], a = xab[1], b = xab[2]; if (b - a <= 0) writeln("delicious"); else if (b - a <= x) writeln("safe"); else writeln("dangerous"); }
D
import std.stdio; import std.string; import std.conv; import std.array; import std.algorithm; import std.range; void main(){ auto Q=readln.split.to!(int[]),a=Q[0],b=Q[1],c=Q[2]; if(b-a==c-b)writeln("YES"); else writeln("NO"); }
D
import std.stdio; import std.string; import std.format; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; import std.concurrency; import std.traits; import core.bitop : popcnt; alias Generator = std.concurrency.Generator; const long INF = long.max/3; const long MOD = 10L^^9+7; void main() { int[] as = readln.chomp.map!"a=='0'?0:1".array; int N = as.length.to!int; int l = 1, r = N+1; bool isOk(int c) { int[] bs = as.dup; int n = 0; foreach(i; 0..c) { bs[i] += n; if (bs[i]%2 == 0) continue; if (i > N-c) continue; bs[i]++; n++; } foreach(i; 0..c) { if (bs[i]%2 != 0) return false; } return true; } while(r-l > 1) { int c = (l + r)/2; if (isOk(c)) { l = c; } else { r = c; } } l.writeln; } // ---------------------------------------------- void scanln(Args...)(auto ref Args args) { import std.meta; template getFormat(T) { static if (isIntegral!T) { enum getFormat = "%d"; } else static if (isFloatingPoint!T) { enum getFormat = "%g"; } else static if (isSomeString!T || isSomeChar!T) { enum getFormat = "%s"; } else { static assert(false); } } enum string str = [staticMap!(getFormat, Args)].join(" ") ~ "\n"; // readf!str(args); mixin("str.readf(" ~ Args.length.iota.map!(i => "&args[%d]".format(i)).join(", ") ~ ");"); } void times(alias fun)(int n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } T ceil(T)(T x, T y) if (__traits(isIntegral, T)) { // `(x+y-1)/y` will only work for positive numbers ... T t = x / y; if (t * y < x) t++; return t; } T floor(T)(T x, T y) if (__traits(isIntegral, T)) { T t = x / y; if (t * y > x) t--; return t; } // fold was added in D 2.071.0 static if (__VERSION__ < 2071) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { static if (S.length < 2) { return reduce!fun(seed, r); } else { return reduce!fun(tuple(seed), r); } } } } // cumulativeFold was added in D 2.072.0 static if (__VERSION__ < 2072) { template cumulativeFold(fun...) if (fun.length >= 1) { import std.meta : staticMap; private alias binfuns = staticMap!(binaryFun, fun); auto cumulativeFold(R)(R range) if (isInputRange!(Unqual!R)) { return cumulativeFoldImpl(range); } auto cumulativeFold(R, S)(R range, S seed) if (isInputRange!(Unqual!R)) { static if (fun.length == 1) return cumulativeFoldImpl(range, seed); else return cumulativeFoldImpl(range, seed.expand); } private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args) { import std.algorithm.internal : algoFormat; static assert(Args.length == 0 || Args.length == fun.length, algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); static if (args.length) alias State = staticMap!(Unqual, Args); else alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns); foreach (i, f; binfuns) { static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles, { args[i] = f(args[i], e); }()), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); } static struct Result { private: R source; State state; this(R range, ref Args args) { source = range; if (source.empty) return; foreach (i, f; binfuns) { static if (args.length) state[i] = f(args[i], source.front); else state[i] = source.front; } } public: @property bool empty() { return source.empty; } @property auto front() { assert(!empty, "Attempting to fetch the front of an empty cumulativeFold."); static if (fun.length > 1) { import std.typecons : tuple; return tuple(state); } else { return state[0]; } } void popFront() { assert(!empty, "Attempting to popFront an empty cumulativeFold."); source.popFront; if (source.empty) return; foreach (i, f; binfuns) state[i] = f(state[i], source.front); } static if (isForwardRange!R) { @property auto save() { auto result = this; result.source = source.save; return result; } } static if (hasLength!R) { @property size_t length() { return source.length; } } } return Result(range, args); } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { auto minElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto minimum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b < minimum) { element = a; minimum = b; } } return element; } auto maxElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto maximum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b > maximum) { element = a; maximum = b; } } return element; } }
D
import std; auto input() { return readln().chomp(); } alias sread = () => readln.chomp(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { string s; s = input(); // writeln(s); string key; key = "keyence"; foreach (i; 0 .. key.length + 1) { string tmp = s[0 .. i] ~ s[$ - (7 - i) .. $]; // writeln(tmp); if (tmp == key) { writeln("YES"); return; } } writeln("NO"); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } }
D
void main() { int[] tmp = readln.split.to!(int[]); int r = tmp[0], d = tmp[1], x = tmp[2]; foreach (i; 0 .. 10) { x = r * x - d; x.writeln; } } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.typecons;
D
import std.algorithm; import std.array; import std.conv; import std.range; import std.stdio; import std.string; import std.typecons; void main () { string s; while ((s = readln.strip) != "") { s = readln.strip; writeln (s.count ('R') > s.count ('B') ? "Yes" : "No"); } }
D
// import chie template :) {{{ static if (__VERSION__ < 2090) { import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip, std.numeric; } else { import std; } // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan(T...)(ref T args) { foreach (ref arg; args) { arg = next!(typeof(arg)); } } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } // }}} // ModInt {{{ struct ModInt(ulong modulus) { import std.traits : isIntegral, isBoolean; import std.exception : enforce; private { ulong val; } this(const ulong n) { val = n % modulus; } this(const ModInt n) { val = n.value; } @property { ref inout(ulong) value() inout { return val; } } T opCast(T)() { static if (isIntegral!T) { return cast(T)(val); } else if (isBoolean!T) { return val != 0; } else { enforce(false, "cannot cast from " ~ this.stringof ~ " to " ~ T.stringof ~ "."); } } ModInt opAssign(const ulong n) { val = n % modulus; return this; } ModInt opOpAssign(string op)(ModInt rhs) { static if (op == "+") { val += rhs.value; if (val >= modulus) { val -= modulus; } } else if (op == "-") { if (val < rhs.value) { val += modulus; } val -= rhs.value; } else if (op == "*") { val = val * rhs.value % modulus; } else if (op == "/") { this *= rhs.inv; } else if (op == "^^") { ModInt res = 1; ModInt t = this; while (rhs.value > 0) { if (rhs.value % 2 != 0) { res *= t; } t *= t; rhs /= 2; } this = res; } else { enforce(false, op ~ "= is not implemented."); } return this; } ModInt opOpAssign(string op)(ulong rhs) { static if (op == "+") { val += ModInt(rhs).value; if (val >= modulus) { val -= modulus; } } else if (op == "-") { auto r = ModInt(rhs); if (val < r.value) { val += modulus; } val -= r.value; } else if (op == "*") { val = val * ModInt(rhs).value % modulus; } else if (op == "/") { this *= ModInt(rhs).inv; } else if (op == "^^") { ModInt res = 1; ModInt t = this; while (rhs > 0) { if (rhs % 2 != 0) { res *= t; } t *= t; rhs /= 2; } this = res; } else { enforce(false, op ~ "= is not implemented."); } return this; } ModInt opUnary(string op)() { static if (op == "++") { this += 1; } else if (op == "--") { this -= 1; } else { enforce(false, op ~ " is not implemented."); } return this; } ModInt opBinary(string op)(const ulong rhs) const { mixin("return ModInt(this) " ~ op ~ "= rhs;"); } ModInt opBinary(string op)(ref const ModInt rhs) const { mixin("return ModInt(this) " ~ op ~ "= rhs;"); } ModInt opBinary(string op)(const ModInt rhs) const { mixin("return ModInt(this) " ~ op ~ "= rhs;"); } ModInt opBinaryRight(string op)(const ulong lhs) const { mixin("return ModInt(this) " ~ op ~ "= lhs;"); } long opCmp(ref const ModInt rhs) const { return cast(long)value - cast(long)rhs.value; } bool opEquals(const ulong rhs) const { return value == ModInt(rhs).value; } ModInt inv() const { ModInt ret = this; ret ^^= modulus - 2; return ret; } string toString() const { import std.format : format; return format("%s", val); } } // }}} // alias {{{ alias Heap(T, alias less = "a < b") = BinaryHeap!(Array!T, less); alias MinHeap(T) = Heap!(T, "a > b"); // }}} // memo {{{ /* - ある値が見つかるかどうか <https://dlang.org/phobos/std_algorithm_searching.html#canFind> canFind(r, value); -> bool - 条件に一致するやつだけ残す <https://dlang.org/phobos/std_algorithm_iteration.html#filter> // 2で割り切れるやつ filter!"a % 2 == 0"(r); -> Range - 合計 <https://dlang.org/phobos/std_algorithm_iteration.html#sum> sum(r); - 累積和 <https://dlang.org/phobos/std_algorithm_iteration.html#cumulativeFold> // 今の要素に前の要素を足すタイプの一般的な累積和 // 累積和のrangeが帰ってくる(破壊的変更は行われない) cumulativeFold!"a + b"(r, 0); -> Range - rangeをarrayにしたいとき array(r); -> Array - 各要素に同じ処理をする <https://dlang.org/phobos/std_algorithm_iteration.html#map> // 各要素を2乗 map!"a * a"(r) -> Range - ユニークなやつだけ残す <https://dlang.org/phobos/std_algorithm_iteration.html#uniq> uniq(r) -> Range - 順列を列挙する <https://dlang.org/phobos/std_algorithm_iteration.html#permutations> permutation(r) -> Range - ある値で埋める <https://dlang.org/phobos/std_algorithm_mutation.html#fill> fill(r, val); -> void - バイナリヒープ <https://dlang.org/phobos/std_container_binaryheap.html#.BinaryHeap> // 昇順にするならこう(デフォは降順) BinaryHeap!(Array!T, "a > b") heap; heap.insert(val); heap.front; heap.removeFront(); - 浮動小数点の少数部の桁数設定 // 12桁 writefln("%.12f", val); - 浮動小数点の誤差を考慮した比較 <https://dlang.org/phobos/std_math.html#.approxEqual> approxEqual(1.0, 1.0099); -> true - 小数点切り上げ <https://dlang.org/phobos/std_math.html#.ceil> ceil(123.4); -> 124 - 小数点切り捨て <https://dlang.org/phobos/std_math.html#.floor> floor(123.4) -> 123 - 小数点四捨五入 <https://dlang.org/phobos/std_math.html#.round> round(4.5) -> 5 round(5.4) -> 5 */ // }}} void main() { auto cin = new Scanner; int n, a, b; string s; cin.scan(n, a, b, s); int pass, fpass; foreach (c; s) { if (c == 'a' && pass < a + b) { pass++; writeln("Yes"); } else if (c == 'b' && pass < a + b && fpass < b) { pass++; fpass++; writeln("Yes"); } else { writeln("No"); } } }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto x = readln.chomp.split.to!(int[]); if (x[0]+x[1]<x[2]) { writeln("No"); } else { writeln("Yes"); } }
D
// tested by Hightail - https://github.com/dj3500/hightail import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; import std.datetime, std.bigint; int n; int[][] adj; void main() { scan(n); adj = new int[][](n, 0); int ai, bi; foreach (i ; 0 .. n - 1) { scan(ai, bi); ai--; bi--; adj[ai] ~= bi; adj[bi] ~= ai; } auto d = new int[](n); auto p = new int[](n); void dfs(int u, int par, int dep) { d[u] = dep; p[u] = par; foreach (v ; adj[u]) { if (v != par) { dfs(v, u, dep + 1); } } } dfs(0, 0, 0); int x = (d[n - 1] - 1) / 2; int pos = n - 1; while (x--) { pos = p[pos]; } int dfs2(int u) { int res = 1; foreach (v ; adj[u]) { if (v != p[u]) { res += dfs2(v); } } return res; } int cnt = dfs2(pos); if (cnt*2 >= n) { writeln("Snuke"); } else { writeln("Fennec"); } } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import core.bitop; import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.format; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; void main() { auto v = readln.chomp.split.map!(to!int); int x = v[0]; int a = v[1]; int b = v[2]; if (abs(x - a) < abs(x - b)) { "A".writeln; } else { "B".writeln; } }
D
import std; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long K = lread(); long A, B; scan(A, B); writeln((A % K == 0 || (((A + K) / K) * K <= B)) ? "OK" : "NG"); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto A = RD; auto B = RD; bool[long] set; set[A] = true; set[B] = true; foreach (i; 1..4) { if (set.get(i, false) == false) writeln(i); } stdout.flush; debug readln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(char[]); auto front = S[0..2]; auto rear = S[2..$]; auto front_ok = front != "00" && front.to!int <= 12; auto rear_ok = rear != "00" && rear.to!int <= 12; if (front_ok && rear_ok) { writeln("AMBIGUOUS"); } else if (front_ok) { writeln("MMYY"); } else if (rear_ok) { writeln("YYMM"); } else { writeln("NA"); } }
D
import std.stdio,std.conv,std.string,std.array; void main(){ auto a=readln.chomp.split; int x = to!int(a[0]), y = to!int(a[1]); writeln( x*y , " " , (x+y)*2); }
D
import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ long l = read.to!long; long n = read.to!long; long[] xs; foreach(i; 0 .. n) xs ~= read.to!long; // 右から始め、右にi本、左にj本焼いて右で終わるとする // このとき折り返しの回数は min(i - 1, j) を f とすると右も左も f // 折り返すのは i - f - 1 番から i - 2 番までと、i 番から i + f - 1 番まで // 折り返さないのは i - 1 番 // sum xs[i - f - 1 .. i - 1] * 2 + xs[i - 1] + l * f * 2 - sum xs[i .. i + f] * 2 // 左から始め、右にi本、左にj本焼いて左で終わるとする // このとき折り返しの回数は min(i, j - 1) を f とすると右も左も f // 折り返すのは i - f 番から i - 1 番までと、i + 1 番から i + f 番まで // 折り返さないのは i 番 // sum xs[i - f .. i] * 2 + (l - xs[i]) + l * f * 2 - sum xs[i + 1 .. i + f + 1] * 2 // 左から始め、右にi本、左にj本焼いて右で終わるとする // このとき折り返しの回数は min(i, j) を f とすると右は f - 1 で左は f // 折り返すのは i - f 番から i - 2 番までと、i 番から i + f - 1 番まで // 折り返さないのは i - 1 番 // sum xs[i - f .. i - 1] * 2 + xs[i - 1] + l * f * 2 - sum xs[i .. i + f] * 2 // 右から始め、右にi本、左にj本焼いて左で終わるとする // このとき折り返しの回数は min(i, j) を f とすると右は f で左は f - 1 // 折り返すのは i - f 番から i - 1 番までと、i + 1 番から i + f - 1番まで // 折り返さないのは i 番 // sum xs[i - f .. i] * 2 + (l - xs[i]) + l * f * 2 - sum xs[i + 1 .. i + f] * 2 long[] sum = [0]; // sum[i] は0からiの前までの和 foreach(i; 0 .. n) sum ~= sum[$ - 1] + xs[i]; long ans = -1; foreach(i; 1 .. n + 1){ long j = n - i; long f = min(i - 1, j); long a = (sum[i - 1] - sum[i - f - 1]) * 2 + xs[i - 1] + l * f * 2 - (sum[i + f] - sum[i]) * 2; if(a > ans) ans = a; debug writeln("i: ", i); debug writeln("a: ", a); debug writeln("ans: ", ans); } foreach(i; 0 .. n){ long j = n - i; long f = min(i, j - 1); long a = (sum[i] - sum[i - f]) * 2 + (l - xs[i]) + l * f * 2 - (sum[i + f + 1] - sum[i + 1]) * 2; if(a > ans) ans = a; debug writeln("i: ", i); debug writeln("a: ", a); debug writeln("ans: ", ans); } foreach(i; 1 .. n){ long j = n - i; long f = min(i, j); long a = (sum[i - 1] - sum[i - f]) * 2 + xs[i - 1] + l * f * 2 - (sum[i + f] - sum[i]) * 2; if(a > ans) ans = a; debug writeln("i: ", i); debug writeln("a: ", a); debug writeln("ans: ", ans); } foreach(i; 1 .. n){ long j = n - i; long f = min(i, j); long a = (sum[i] - sum[i - f]) * 2 + (l - xs[i]) + l * (f - 1) * 2 - (sum[i + f] - sum[i + 1]) * 2; if(a > ans) ans = a; debug writeln("i: ", i); debug writeln("a: ", a); debug writeln("ans: ", ans); } ans.writeln; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } int calc(int n, bool[][] adj) { auto refs = new int[](n + 1); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (adj[i][j]) refs[j]++; } } int ans = 0; bool update = true; while (update) { update = false; for (int i = 1; i <= n; i++) { if (refs[i] == 1) { ans++; update = true; refs[i] = 0; for (int j = 1; j <= n; j++) { if (adj[i][j]) { refs[j]--; } } } } } return ans; } void main() { auto nm = readints; int n = nm[0], m = nm[1]; auto adj = new bool[][](n + 1, n + 1); for (int i = 0; i < m; i++) { auto ab = readints; int a = ab[0], b = ab[1]; adj[a][b] = adj[b][a] = true; } writeln(calc(n, adj)); }
D
import std.stdio; import std.algorithm; import std.string; import std.conv; void main() { int n, x; scanf("%d %d\n", &n, &x); auto ls = readln.chomp.split.to!(int[]); int d, cnt; foreach(l; ls) { d += l; ++cnt; if (d > x) { cnt.write; return; } } write(n+1); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int N, W; scan(N, W); auto w = new int[](N); auto v = new int[](N); iota(N).each!(i => scan(w[i], v[i])); auto dp = new long[](W + 1); foreach (i ; 0 .. N) { foreach_reverse (j ; w[i] .. W + 1) { chmax(dp[j], dp[j - w[i]] + v[i]); } } auto ans = dp[W]; writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignum = 1_000_000_007; alias Pair = Tuple!(long, "number", long, "times"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long x, y, count; scan(x, y); while(x <= y) { x *= 2; count++; } count.writeln(); }
D
import std.stdio, std.range, std.conv, std.string; import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting; void main() { long[] input = readln().split.to!(long[]); long A = input[0]; long B = input[1]; writeln(A*B/2); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { auto n = lread(); auto a = aryread(); // writeln(a); auto s = new long[](n + 1); s[1] = a[0]; foreach (i; 0 .. n) { s[i + 1] = s[i] + a[i]; } // writeln(s); long ans; long mod = (10 ^^ 9) + 7; long aj; foreach (i; 0 .. n) { // writeln(a[i], " ", s[n] - s[i + 1]); a[i] %= mod; aj = s[n] - s[i + 1]; aj %= mod; ans += a[i] * aj; ans %= mod; } writeln(ans % mod); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range; import std.bigint; void main(){ long[] ins = readln.chomp.split.map!(to!long).array; long n = ins[0], x = ins[1]; long y = n - x; long a, b; if(x > y) a = x, b = y; else a = y, b = x; long ans = a + b; while(b > 0){ long r = a % b; ans += b * 2 * (a / b); a = b; b = r; } ans -= a; ans.writeln; }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm; void main() { auto a = readln.split.map!(to!int); int count = 0; foreach (i; a[0]..a[1]+1) if (a[2] % i == 0) count++; writeln(count); }
D
// import chie template :) {{{ import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip; // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } // }}} void main() { auto cin = new Scanner; string s = cin.next!string; if (s[2] == s[3] && s[4] == s[5]) { writeln("Yes"); } else { writeln("No"); } }
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; final class InputReader { private: ubyte[] p, buffer; bool eof; bool rawRead () { if (eof) { return false; } p = stdin.rawRead (buffer); if (p.empty) { eof = true; return false; } return true; } ubyte nextByte(bool check) () { static if (check) { if (p.empty) { if (!rawRead ()) { return 0; } } } auto r = p.front; p.popFront (); return r; } public: this () { buffer = uninitializedArray!(ubyte[])(16<<20); } bool seekByte (in ubyte lo) { while (true) { p = p.find! (c => c >= lo); if (!p.empty) { return false; } if (!rawRead ()) { return true; } } } template next(T) if (isSigned!T) { T next () { if (seekByte (45)) { return 0; } T res; ubyte b = nextByte!false (); if (b == 45) { while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 - (b - 48); } } else { res = b - 48; while (true) { b = nextByte!true (); if (b < 48 || b >= 58) { return res; } res = res * 10 + (b - 48); } } } } template next(T) if (isUnsigned!T) { T next () { if (seekByte (48)) { return 0; } T res = nextByte!false () - 48; while (true) { ubyte b = nextByte!true (); if (b < 48 || b >= 58) { break; } res = res * 10 + (b - 48); } return res; } } T[] nextA(T) (in int n) { auto a = uninitializedArray!(T[]) (n); foreach (i; 0 .. n) { a[i] = next!T; } return a; } } void main() { auto r = new InputReader (); immutable nt = r.next!uint (); foreach (tid; 0 .. nt) { const n = r.next!uint (); const m = r.next!uint (); auto a = r.nextA!uint (n); const s = sum (a[1 .. $]); int delta = min (m - a[0], s); writeln (a[0] + delta); } }
D
void main() { dchar[] s = rdDchar; dchar[] t = rdDchar; long pos = t.length - 1; bool ok; foreach_reverse (long i, x; s) { if (x == t[pos] || x == '?') { bool check; if (i - pos >= 0) { check = true; foreach (j; 0 .. pos) { if (s[i-pos+j] != t[j] && s[i-pos+j] != '?') { check = false; break; } } } if (check) { ok = true; foreach (j; 0 .. pos+1) { s[i-pos+j] = t[j]; } foreach (j; 0 .. s.length) { if (s[j] == '?') s[j] = 'a'; } break; } } } writeln(ok ? s.to!string : "UNRESTORABLE"); } /* void main() { dchar[] s = rdDchar; dchar[] t = rdDchar; long last = t.length - 1; bool ok; foreach_reverse (i, x; s) { if (x == t[last] || x == '?') { bool check = true; if (i.to!long - last >= 0) { foreach (j; 0 .. last) { if (s[i-last+j] != t[j] && s[i-last+j] != '?') { check = false; break; } } } else check = false; if (check) { ok = true; foreach (j; 0 .. last+1) { s[i-last+j] = t[j]; } foreach (j; 0 .. s.length) { if (s[j] == '?') s[j] = 'a'; } break; } } } if (ok) s.writeln; else "UNRESTORABLE".writeln; } */ enum long mod = 10^^9 + 7; enum long inf = 1L << 60; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdDchar = rdElem!(dchar[]); T rdElem(T)() if (is(T == struct)) { T result; string[] input = rdRow!string; assert(T.tupleof.length == input.length); foreach (i, ref x; result.tupleof) { x = input[i].to!(typeof(x)); } return result; } T[] rdRow(T = long)() { return readln.split.to!(T[]); } T[] rdCol(T = long)(long col) { return iota(col).map!(x => rdElem!T).array; } T[][] rdMat(T = long)(long col) { return iota(col).map!(x => rdRow!T).array; } void rdVals(T...)(ref T data) { string[] input = rdRow!string; assert(data.length == input.length); foreach (i, ref x; data) { x = input[i].to!(typeof(x)); } } void wrMat(T = long)(T[][] mat) { foreach (row; mat) { foreach (j, compo; row) { compo.write; if (j == row.length - 1) writeln; else " ".write; } } } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.mathspecial; import std.traits; import std.container; import std.functional; import std.typecons; import std.ascii; import std.uni; import core.bitop;
D
import std.stdio; import std.array; import std.conv; void main() { while (1) { auto input = split(readln()); switch (input[1]) { case "+": writeln(to!(int)(input[0]) + to!(int)(input[2])); break; case "-": writeln(to!(int)(input[0]) - to!(int)(input[2])); break; case "*": writeln(to!(int)(input[0]) * to!(int)(input[2])); break; case "/": writeln(to!(int)(input[0]) / to!(int)(input[2])); break; case "?": return; default: writeln("ERROR"); break; } } }
D
import std.stdio, std.algorithm, std.conv, std.string, std.array, std.math; void main() { readln; const s = readln.chomp; if (s.length%2 == 0 && s[0..$/2] == s[$/2..$]) { "Yes".writeln; return; } "No".writeln; }
D
/+ dub.sdl: name "hello" +/ import std.algorithm; import std.conv; import std.stdio; import std.string; void main() { auto N = readln.chomp.to!int; auto A = readln.chomp.to!int; writeln(N * N - A); }
D
import std.stdio; import std.algorithm; import std.range; import std.conv; import std.format; import std.array; import std.math; import std.string; import std.container; import std.numeric; void main() { int N, M; readlnTo(N, M); long ans = 1; for (long i = 1; i * i <= M; i++) { if (M % i != 0) continue; if (M >= i * N) ans = max(ans, i); if (M >= (M / i) * N) ans = max(ans, M / i); } ans.writeln; } // helpers void readlnTo(T...)(ref T t) { auto s = readln.split; assert(s.length == t.length); foreach(ref ti; t) { ti = s[0].to!(typeof(ti)); s = s[1..$]; } }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto s = readln.chomp; auto t = readln.chomp; auto res = false; foreach (i; 0..s.length) { auto f = true; foreach (j; 0..s.length) { if (s[j] != t[(j+i)%s.length]) { f = false; } } if (f) { res = true; } } if (res) { writeln("Yes"); } else { writeln("No"); } }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}} void main() { int n, wt; readV(n, wt); int[] w, v; readC(n, w, v); auto u = w.dup; u[] -= w[0]; auto dp = new int[][][](n+1, n+1, n*3+1); foreach (i; 0..n) foreach (j; 0..n+1) dp[i][j][] = -1; dp[0][0][0] = 0; foreach (i; 0..n) foreach (j; 0..n+1) foreach (k; 0..n*3+1) { dp[i+1][j][k] = dp[i][j][k]; if (j >= 1 && k >= u[i] && dp[i][j-1][k-u[i]] >= 0) dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j-1][k-u[i]]+v[i]); } auto ans = 0; foreach (j; 0..n+1) foreach (k; 0..n*3+1) if (j.to!long*w[0]+k <= wt) ans = max(ans, dp[n][j][k]); writeln(ans); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto av = readln.split.to!(long[]); auto A = av[0]; auto V = av[1]; auto bw = readln.split.to!(long[]); auto B = bw[0]; auto W = bw[1]; auto T = readln.chomp.to!long; if (A == B) { writeln("YES"); return; } writeln(V * T - W * T >= abs(A - B) ? "YES" : "NO"); }
D
import std.stdio; void main(){ foreach(i; 1 .. 10){ foreach(j; 1 .. 10){ writeln(i, "x", j, "=", i * j); } } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void main() { auto xkd = readln.split.to!(long[]); auto X = xkd[0]; auto K = xkd[1]; auto D = xkd[2]; X = abs(X); if (X/D >= K) { writeln(X - K*D); return; } auto k = K - X/D; if (k%2 == 0) { writeln(X - D*(X/D)); } else { writeln(abs(X - D*(X/D+1))); } }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto a = readln.chomp.split.to!(int[]); int odd, even, even4; foreach (i; 0..n) { if (a[i] % 4 == 0) { even4++; } else if (a[i] % 2 == 0) { even++; } else { odd++; } } if (even4 >= n / 2) { writeln("Yes"); } else if (even4 - odd >= 0) { writeln("Yes"); } else { writeln("No"); } }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long r, g, b, n; scan(r, g, b, n); long count; foreach (i; 0 .. n + 1) { foreach (j; 0 .. n + 1) { long difference = n - r * i - g * j; if(difference < 0) { break; } if(difference % b == 0) { count++; } } } writeln(count); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.container; import std.datetime; int s; long number (string str) { auto l = s; s++; while (str[s] >= '0' && str[s] <= '9') s++; return str[l..s].to!long; } long factor (string str) { long res; if (str[s] == '(') { s++; res = expression(str); s++; } else { res = number(str); } return res; } long term (string str) { auto res = factor(str); while (1) { if (str[s] == '*') { s++; res *= factor(str); } else if (str[s] == '/') { s++; res /= factor(str); } else { break; } } return res; } long expression (string str) { auto res = term(str); while (1) { if (str[s] == '+') { s++; res += term(str); } else if (str[s] == '-') { s++; res -= term(str); } else { break; } } return res; } void main() { auto n = readln.chomp.to!int; foreach (i; 0..n) { s = 0; auto eqn = readln.chomp.to!string; eqn.expression.writeln; } }
D
import std.stdio; import std.typecons; void main() { int r, c, n, k; scanf("%d%d%d%d", &r, &c, &n, &k); Tuple!(int, int)[] alts = new Tuple!(int, int)[n]; for (int i = 0; i < n; i++) scanf("%d%d", &alts[i][0], &alts[i][1]); int res = 0; for (int i = 1; i <= r; i++) for (int j = 1; j <= c; j++) for (int p = i; p <= r; p++) for (int q = j; q <= c; q++) { int count = 0; foreach (Tuple!(int, int) alt; alts) if (alt[0] >= i && alt[0] <= p && alt[1] >= j && alt[1] <= q) count++; if (count >= k) res++; } printf("%d\n", res); }
D
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int k, p; scan(k, p); if (p == 1) { writeln(0); return; } long ans; foreach (i ; 1 .. k + 1) { long zcy = 1L * i * 10L^^(digit(i)) + revnum(i); (ans += zcy) %= p; } writeln(ans); } int digit(int num) { return num > 0 ? digit(num / 10) + 1 : 0; } long revnum(long n) { long res; while (n > 0) { res *= 10; res += (n % 10); n /= 10; } return res; } unittest { assert(revnum(0) == 0); assert(revnum(8) == 8); assert(revnum(10) == 1); assert(revnum(123) == 321); assert(revnum(10100) == 101); writeln("ok"); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio :write, writeln; import std.array; import std.range; import std.typecons; import std.algorithm : max, min; string[] src = [ "111111101010101111100101001111111", "100000100000000001010110001000001", "101110100110110000011010001011101", "101110101011001001111101001011101", "101110101100011000111100101011101", "100000101010101011010000101000001", "111111101010101010101010101111111", "000000001111101111100111100000000", "100010111100100001011110111111001", "110111001111111100100001000101100", "011100111010000101000111010001010", "011110000110001111110101100000011", "111111111111111000111001001011000", "111000010111010011010011010100100", "101010100010110010110101010000010", "101100000101010001111101000000000", "000010100011001101000111101011010", "101001001111101111000101010001110", "101101111111000100100001110001000", "000010011000100110000011010000010", "001101101001101110010010011011000", "011101011010001000111101010100110", "111010100110011101001101000001110", "110001010010101111000101111111000", "001000111011100001010110111110000", "000000001110010110100010100010110", "111111101000101111000110101011010", "100000100111010101111100100011011", "101110101001010000101000111111000", "101110100011010010010111111011010", "101110100100011011110110101110000", "100000100110011001111100111100000", "111111101101000101001101110010001" ]; void main(){ string v = src[ next!int ]; v[ next!int ].writeln; } import std.stdio : readln; import std.conv : to; import std.string : split, chomp; import std.traits; string[] input; string delim = " "; T next(T)() in { assert(hasNext()); } out { input.popFront; } body { return input.front.to!T; } bool hasNext(){ if(input.length > 0){ return true; } string str = readln; if(str.length > 0){ input ~= str.chomp.split(delim); return true; }else{ return false; } } void dbg(T...)(T vs) { import std.stdio : stderr; foreach(v; vs) stderr.write(v.to!string ~ " "); stderr.write("\n"); } T clone(T)(T v){ T v_; static if(isInputRange!(T)){ foreach(ite; v){ v_ ~= ite.clone; } }else{ v_ = v; } return v_; }
D
module main; import core.stdc.stdio; int main(string[] argv) { int n = 0; scanf("%d", &n); if((n & 1) == 1) { n -= 3; putchar('7'); } for(int i = 0; i < n; i += 2) putchar('1'); return 0; }
D
// import chie template :) {{{ import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip; // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string; import std.traits : isSomeString; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) { this.file = file; this.idx = 0; fromString(s); } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.strip.to!(char[]); } str = s.split; idx = 0; return str[idx++]; } T next(T)() { return next.to!(T); } T[] nextArray(T)(size_t len) { T[] ret = new T[len]; foreach (ref c; ret) { c = next!(T); } return ret; } void scan()() { } void scan(T, S...)(ref T x, ref S args) { x = next!(T); scan(args); } void fromString(StrType)(StrType s) if (isSomeString!(StrType)) { str ~= s.to!(char[]).strip.split; } } // }}} void main() { auto cin = new Scanner; int n; long res; cin.scan(n); foreach (i; 1 .. n + 1) { if (!(i % 3 == 0 || i % 5 == 0)) { res += i; } } writeln(res); }
D
import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; void main(){ int n, t; { int[] tmp = readln.chomp.split.map!(to!int).array; n = tmp[0], t = tmp[1]; } int[] as = readln.chomp.split.map!(to!int).array; int[] bs; bs.length = as.length; int b = bs[$ - 1]; for(int i = as.length.to!int - 1; i >= 0; i --){ if(b < as[i]) b = as[i]; bs[i] = b; } int[] cs; cs.length = as.length; for(int i = 0; i < cs.length; i ++) cs[i] = bs[i] - as[i]; int ans; int max = -1; foreach(c; cs){ if(c > max) max = c, ans = 1; else if(c == max) ans += 1; } ans.writeln; }
D
void main() { auto N = ri; if(N <= 999) { "ABC".writeln; } else { "ABD".writeln; } } // =================================== import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import std.traits; import std.math; import std.container; import std.bigint; import std.numeric; import std.conv; import std.typecons; import std.uni; import std.ascii; import std.bitmanip; import core.bitop; T readAs(T)() if (isBasicType!T) { return readln.chomp.to!T; } T readAs(T)() if (isArray!T) { return readln.split.to!T; } T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { res[i] = readAs!(T[]); } return res; } T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) { auto res = new T[][](height, width); foreach(i; 0..height) { auto s = rs; foreach(j; 0..width) res[i][j] = s[j].to!T; } return res; } int ri() { return readAs!int; } double rd() { return readAs!double; } string rs() { return readln.chomp; }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; } T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; } T[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(T)(ref T x, T y) { x = (x + y) % mod; } void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; } void modm(T)(ref T x, T y) { x = (x * y) % mod; } void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); } void main() { auto H = RD; auto W = RD; writeln(min(H, W) == 1 ? 1 : (H*W+1) / 2); stdout.flush; debug readln; }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less); // dfmt on void main() { long N, R; scan(N, R); if (10 <= N) { writeln(R); } else { writeln(R + 100 * (10 - N)); } }
D
import std.stdio; import std.regex; void main(){ //auto io = new IO(); char[][char] card; card['a'] = str();//io.rect!char()[0]; card['b'] = str(); card['c'] = str(); char[char] ptr; ptr['a']=ptr['b']=ptr['c']=0; //= ["a":0,"b":0,"c":0]; char target = 'a'; foreach( i ; 0..100*100*100+10 ){ auto now = ptr[target]; if ( now >= card[target].length ){ target.toUpper().writeln(); return; } ptr[target]++; target = card[target][now]; } } char[] str(){ char[] ret; foreach( elm ; readln().chomp().split() ){ //ret ~= elm.to!char(); ret ~= elm; } return ret; } import std.stdio,std.conv,std.string,std.uni; import std.algorithm,std.array,std.math; import std.bigint;
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; // dfmt on void main() { long A, P; scan(A, P); long x = A * 3 + P; writeln(x / 2); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf3 = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int a, b, c; scan(a, b, c); auto ans = min(b / a, c); writeln(ans); } int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) { auto adj = new int[][](n, 0); foreach (i ; 0 .. m) { int u, v; scan(u, v); if (is1indexed) { u--, v--; } adj[u] ~= v; if (isUndirected) { adj[v] ~= u; } } return adj; } alias Edge = Tuple!(int, "to", int, "cost"); Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) { auto adj = new Edge[][](n, 0); foreach (i ; 0 .. m) { int u, v, c; scan(u, v, c); if (is1indexed) { u--, v--; } adj[u] ~= Edge(v, c); if (isUndirected) { adj[v] ~= Edge(u, c); } } return adj; } void yes(bool b) {writeln(b ? "Yes" : "No");} void YES(bool b) {writeln(b ? "YES" : "NO");} T[] readArr(T)() {return readln.split.to!(T[]);} T[] readArrByLines(T)(int n) {return iota(n).map!(i => readln.chomp.to!T).array;} void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; alias sread = () => readln.chomp(); ulong bignum = 1_000_000_007; alias Pair = Tuple!(long, "begin", long, "end"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long n, a, b; scan(n, a, b); (min(a * n, b)).writeln(); }
D
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial; void main(){ auto N=readln.chomp.to!int; if(N==1){ writeln(1); return; } long[int] divs; auto primes=get_primes(N); foreach(p;primes){ divs[p]=0; } foreach(n;2..N+1){ foreach(p;primes){ while(n%p==0){ n/=p; divs[p]++; } if(n==1)break; } } auto res=1L; foreach(d;divs.values){ res=res*(d+1)%1000000007; } writeln(res); } int[] get_primes(int max){ int[] ps; foreach(n;2..max+1){ if(isPrime(n,ps))ps~=n; } return ps; } bool isPrime(int n, int[] prims){ foreach(p;prims){ if(n%p==0)return false; } return true; }
D
void main() { long x = rdElem; bool op(long len, long cnt) { if (len <= 2) return cnt <= x; return op((len-1)>>1, cnt+1); } long ok, ng = inf; while (ng - ok > 1) { long m = (ok + ng) >> 1; if (op(m, 0)) ok = m; else ng = m; } ok.writeln; } enum long mod = 10L^^9 + 7; enum long inf = 1L << 60; enum double eps = 1.0e-9; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdDchar = rdElem!(dchar[]); T rdElem(T)() if (is(T == struct)) { T result; string[] input = rdRow!string; assert(T.tupleof.length == input.length); foreach (i, ref x; result.tupleof) { x = input[i].to!(typeof(x)); } return result; } T[] rdRow(T = long)() { return readln.split.to!(T[]); } T[] rdCol(T = long)(long col) { return iota(col).map!(x => rdElem!T).array; } T[][] rdMat(T = long)(long col) { return iota(col).map!(x => rdRow!T).array; } void rdVals(T...)(ref T data) { string[] input = rdRow!string; assert(data.length == input.length); foreach (i, ref x; data) { x = input[i].to!(typeof(x)); } } void wrMat(T = long)(T[][] mat) { foreach (row; mat) { foreach (j, compo; row) { compo.write; if (j == row.length - 1) writeln; else " ".write; } } } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.mathspecial; import std.traits; import std.container; import std.functional; import std.typecons; import std.ascii; import std.uni; import core.bitop;
D
import std.stdio, std.conv, std.string, std.range, std.algorithm; void main() { int d = readln.chomp.to!int; ("Christmas " ~ repeat("Eve", 25 - d).join(" ")).writeln; }
D
import std.stdio; import std.string; import std.algorithm; import std.conv; void main() { int N=to!int(chomp(readln())); string[] input=split(readln()); int ans=1<<30; foreach(item;input) { int A=to!int(item); int cnt=0; while(A%2==0) A/=2,cnt++; ans=min(ans,cnt); } writeln(ans); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); //auto PS = new Tuple!(long,string)[](M); //x[]=1;でlong[]全要素1に初期化 void main() { auto n = lread(); auto h = aryread(); foreach (i; 0 .. (n - 1)) { if (h[i] > h[i + 1]) { h[i + 1] += 1; } } // writeln(h); foreach (i; 0 .. (n - 1)) { if (h[i] <= h[i + 1]) { continue; } else { writeln("No"); return; } } writeln("Yes"); } void scan(L...)(ref L A) { auto l = readln.split; foreach (i, T; L) { A[i] = l[i].to!T; } } void arywrite(T)(T a) { a.map!text.join(' ').writeln; }
D
import std.stdio; import std.conv; import std.string; void main() { string s = chomp(readln()); // ?????????????????? long l = to!long(s); writeln(l*l*l); }
D
void main() { int[] tmp = readln.split.to!(int[]); int a = tmp[0], b = tmp[1], c = tmp[2]; writeln(a <= c && c <= b ? "Yes" : "No"); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { long A, B, C; scan(A, B, C); long K = lread(); long m = A.max(B).max(C); writeln(A + B + C + (m * ((2 ^^ K) - 1))); }
D
import std.stdio; import std.conv; import std.string; import std.algorithm; import std.range; void main() { auto input = readln.split.to!(int[]); auto N = input[0]; auto M = input[1]; ulong X; ( 2 ^^ M * (M * 1900 + (N - M) * 100) ).writeln; }
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container, std.typecons; void main() { auto sw = readln.chomp.split.to!(int[]); if(sw[0]<=sw[1]) writeln("unsafe"); else writeln("safe"); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int n, k; scan(n, k); writeln(n % k == 0 ? 0 : 1); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; enum R = [ "SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1 ]; void main() { writeln(R[readln.chomp]); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; } T[][] 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; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } //long mod = 10^^9 + 7; long mod = 998_244_353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto n = RD!int; auto ans = new char[][](n, n); ans[0][0] = 'W'; ans[0][1] = 'B'; ans[0][2] = 'W'; ans[1][0] = 'B'; ans[2][0] = 'W'; ans[1][1] = 'W'; bool visit(int y, int x, int c) { bool ok; if (inside(y, 0, n) && inside(x, 0, n)) { if (ans[y][x] == char.init) { ans[y][x] = c == 0 ? 'B' : 'W'; ok = true; } } return ok; } int[3][] open = [[0,0,0], [0,1,1], [0,2,0], [1,0,1], [2,0,0], [1,1,0]]; while (!open.empty) { auto node = open.front; open.popFront; auto y = node[0]; auto x = node[1]; auto c = node[2]; if (visit (y-1, x-2, c)) open ~= [y-1, x-2, c^1]; if (visit (y+1, x-2, c)) open ~= [y+1, x-2, c^1]; if (visit (y-1, x+2, c)) open ~= [y-1, x+2, c^1]; if (visit (y+1, x+2, c)) open ~= [y+1, x+2, c^1]; if (visit (y-2, x-1, c)) open ~= [y-2, x-1, c^1]; if (visit (y-2, x+1, c)) open ~= [y-2, x+1, c^1]; if (visit (y+2, x-1, c)) open ~= [y+2, x-1, c^1]; if (visit (y+2, x+1, c)) open ~= [y+2, x+1, c^1]; } foreach (y; 0..n) { writeln(ans[y]); } stdout.flush(); debug readln(); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } } bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } } long mod = 10^^9 + 7; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto A = RD; auto B = RD; writeln(max(max(A+B, A * 2 - 1), B * 2 - 1)); stdout.flush(); debug readln(); }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.numeric; import std.stdio; import std.string; void main() { long n = readln.chomp.to!long; for (long cake = 0; cake <= 100; ++cake) { for (long donuts = 0; donuts <= 100; ++donuts) { if (cake * 4 + donuts * 7 == n) { writeln("Yes"); return; } } } writeln("No"); }
D
import std.stdio,std.conv,std.string; void main(){ bool[9][9] m; foreach(y;0..8){ foreach(x,c;readln.chomp){ m[y*2][1+x*2]=c=='1'; } foreach(x,c;readln.chomp){ m[y*2+1][x*2]=c=='1'; } } int x,y,dir=6; while(true){ final switch(dir){ case 2: if(x!=8&&m[y][x+1]){ x+=2; dir=6; dir.p; }else if(y!=8&&m[y+1][x]){ y+=2; dir.p; }else{ dir=4; } break; case 4: if(y!=8&&m[y+1][x]){ y+=2; dir=2; dir.p; }else if(x!=0&&m[y][x-1]){ x-=2; dir.p; }else{ dir=8; } break; case 6: if(y!=0&&m[y-1][x]){ y-=2; dir=8; dir.p; }else if(x!=8&&m[y][x+1]){ x+=2; dir.p; }else{ dir=2; } break; case 8: if(x!=0&&m[y][x-1]){ x-=2; dir=4; dir.p; }else if(y!=0&&m[y-1][x]){ y-=2; dir.p; }else{ dir=6; } } if(!x&&!y)break; } writeln; } void p(int dir){ final switch(dir){ case 2:'D'.write;break; case 4:'L'.write;break; case 6:'R'.write;break; case 8:'U'.write;break; } }
D
module app; import core.bitop; import std.algorithm; import std.array; import std.bigint; import std.conv; import std.stdio; import std.string; struct Input { int n; } void parseInput(T)(out Input input, T file) { with (file) with (input) { auto single = readln().strip(); n = single.to!int; } } struct Output { } auto main2(Input* input) { foreach (a; 1..10) foreach (b; 1..10) if (a * b == input.n) return "Yes"; return "No"; } unittest { writeln("begin unittest"); } unittest // example1 { string example = `10`; Input input = void; parseExample(input, example); auto result = main2(&input); writeln(result); assert(result == "Yes"); } unittest // example2 { string example = `50`; Input input = void; parseExample(input, example); auto result = main2(&input); writeln(result); assert(result == "No"); } unittest // example3 { string example = `81`; Input input = void; parseExample(input, example); auto result = main2(&input); writeln(result); assert(result == "Yes"); } unittest { writeln("end unittest"); } void parseExample(out Input input, string example) { struct Adapter { string[] _lines; this(string input) { _lines = input.splitLines(); } string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; } } parseInput(input, Adapter(example)); } void main() { Input input = void; parseInput(input, stdin); auto result = main2(&input); writeln(result); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm: canFind; void main() { string[] inputs = split(readln()); string A = inputs[0]; string B = inputs[1]; string C = inputs[2]; if(A[$-1] == B[0] && B[$-1] == C[0]) "YES".writeln; else "NO".writeln; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.format; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { long a,b; scan(a,b); (a - b + 1).writeln(); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } } bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto N = RD!int; auto M = RD!int; writeln(min(N - M, max(1, M))); stdout.flush(); debug readln(); }
D
import std; void main() { string s = read!string; writeln(s.canFind('7') ? "Yes" : "No"); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int;
D
import std.stdio, std.conv, std.array,std.string,std.algorithm; void main() { auto n=readln.chomp.to!int,k=readln.chomp.to!int; int i,ans=1; for(i=0;i<n;i++){ ans=min(2*ans,ans+k); } writeln(ans); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.numeric; void main() { auto s = readln.chomp; auto k = readln.chomp.to!long; int index; foreach (e; s) { if (e != '1') { break; } index++; } if (index.to!long >= k) { writeln("1"); } else { s[index].writeln; } }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; } string RDR()() { return readln.chomp; } T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; } size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;} size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; } bool inside(T)(T x, T b, T e) { return x >= b && x < e; } long lcm(long x, long y) { return x * y / gcd(x, y); } long mod = 10^^9 + 7; //long mod = 998244353; //long mod = 1_000_003; void moda(ref long x, long y) { x = (x + y) % mod; } void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; } void modm(ref long x, long y) { x = (x * y) % mod; } void main() { auto S = RD!string; long ans; foreach (c; S) { if (c == '+') ++ans; else --ans; } writeln(ans); stdout.flush(); debug readln(); }
D
import std.stdio, std.string, std.conv; void main() { auto u = readln.chomp, A = u[0], B = u[1], C = u[2]; auto s = readln.chomp, D = s[0], E = s[1], F = s[2]; if(A == F && B == E && C == D){ writeln("YES"); } else { writeln("NO"); } }
D
import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } /* 行列累乗 有向パス 数え上げ ---------------------------------------- a -> b と、b -> c をつなげると a -> c のパスになる 「aからbへの長さiのパスの総数」をx[i][a][b]とすると、x[i + j][a][c] = sum(b)(x[i][a][b] + x[j][b][c]) これを使って、K を、K/2 と K/2 に分けていけば、log K のオーダーでできるはず ---------------------------------------- 上記を整理して、以下のようにすればよい xs[l][i][j] は、i から j への長さ (1<<i) のパスの個数 xs[1] は与えられる a[i][j]に他ならない xs[l][i][j] = sum(t)(xs[l - 1][i][t] * xs[l - 1][t][j]) これを表すために、 (long[][], long[][]) => long[][] の演算 a ** b を (a ** b)[i][j] = sum(t)(a[i][t] * b[t][j]) で定義する xs[1] = a xs[l] = xs[l - 1] ** xs[l - 1] そして求めるものは ans = xs[l1] ** xs[l2] ** xs[l3] ** ... ただし、l1 などは (1<<l) & k > 0 であるような l のすべての項の和 ---------------------------------------- */ const mod = 1_000_000_007; void main(){ int n = read.to!int; long k = read.to!long; long[][] as; foreach(i; 0 .. n){ as ~= [[]]; foreach(j; 0 .. n){ as[i] ~= read.to!long; } } long[][][] xs = [as]; for(int l = 1; (1L<<l) <= k; l ++) xs ~= prod(xs[l - 1], xs[l - 1]); debug writeln("xs: ", xs); long[][] p; foreach(l, q; xs){ if((1L<<l) & k){ if(p.length) p = prod(p, q); else p = q; } } long ans; foreach(i; 0 .. n) foreach(j; 0 .. n) ans += p[i][j], ans %= mod; ans.writeln; } long[][] prod(long[][] a, long[][] b){ long[][] res; foreach(i; 0 .. a.length){ res ~= [[]]; foreach(j; 0 .. a.length){ long x = 0; foreach(t; 0 .. a.length) x += a[i][t] * b[t][j], x %= mod; res[i] ~= x; } } return res; }
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { string s = read!string; auto n = s.count!(c => c == 'o') + (15 - s.length); writeln(n >= 8 ? "YES" : "NO"); }
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}} alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7; // dfmt on void main() { string L = sread(); auto dp = new long[][](L.length + 1, 2); // 確定桁数, a+b<L確定 dp[0][0] = 1; dp[0][1] = 0; foreach (i; 0 .. L.length) { if (L[i] == '1') { dp[i + 1][0] = dp[i][0] * 2 % MOD; dp[i + 1][1] = (dp[i][0] + dp[i][1] * 3) % MOD; } else { dp[i + 1][0] = dp[i][0]; dp[i + 1][1] = dp[i][1] * 3 % MOD; } } writeln(dp[L.length].sum() % MOD); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; import std.numeric; void main() { auto n = readln.chomp.to!long; long res = (10L^^12)+1; foreach (long a; 1..10^^6+1) { if (n % a) continue; auto b = n / a; res = min(res, a - 1 + b - 1); } res.writeln; }
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ int n = read.to!int; for(int k = 0, m = 1; m <= n; k += 1, m *= 2){ if(m == n){ "No".writeln; return; } } "Yes".writeln; int[2][] ans; int[int] memo; // n + i をつなげた親が memo[i] for(int k = 0, m = 1; m <= n; k += 1, m *= 2){ if(m > 1) ans ~= [m / 2, m]; ans ~= [n + m + 1, n + m]; memo[m] = m; for(int i = m + 1; i < m * 2 && i <= n; i ++){ ans ~= [m, i]; if(i - m / 2 < m) ans ~= [i - m / 2, n + i], memo[i] = i - m / 2; else ans ~= [memo[i - m], n + i], memo[i] = memo[i - m]; } } foreach(an; ans){ writeln(an[0], " ", an[1]); } }
D
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int L; string s, t; scan(L); scan(s); scan(t); if (s > t) { swap(s, t); } if (s == t[0 .. s.length]) { string ss; string tt = t ~ t; while (ss.length < t.length) { ss ~= s; } if (ss > tt) { swap(s, t); } } int n = s.length.to!int; int m = t.length.to!int; int k = 0; int kk = 0; while (n * kk <= L) { if ((L - n*kk) % m == 0) { k = kk; } kk++; } string ans; foreach (i ; 0 .. k) { ans ~= s; } foreach (i ; 0 .. (L - n*k) / m) { ans ~= t; } writeln(ans); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }
D
import std.stdio,std.string,std.conv; int main() { string s; int count = 0; while((s = readln.chomp).length != 0) { if(s.length == 1) { count++; } else { bool flag = true; foreach(i;0..s.length/2) { if(s[i] != s[s.length - i - 1]) { flag = false; } } if(flag) { count++; } } } count.writeln; return 0; }
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", long, "x"); T lread(T = long)() { return readln.chomp.to!T(); } T[] aryread(T = long)() { return readln.split.to!(T[])(); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void minAssign(T, U = T)(ref T dst, U src) { dst = cast(T) min(dst, src); } void maxAssign(T, U = T)(ref T dst, U src) { dst = cast(T) max(dst, src); } void main() { auto s = sread(); writeln(s.front, s.length - 2, s.back); }
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto A = new int[](N+1); foreach (i; 0..M) { s = readln.split.map!(to!int); A[s[0]-1] += 1; A[s[1]-1] -= 1; } foreach (i; 0..N) { A[i+1] += A[i]; } writeln((N-1).iota.map!(i => A[i] % 2 == 0).all ? "YES" : "NO"); }
D
void main(){ int r = _scan(); if( r<1200 )writeln("ABC"); else if( r<2800 )writeln("ARC"); else writeln("AGC"); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split()){ ln ~= elm.to!T(); } return ln; }
D
import std.stdio; import std.string; void main(){ string str = chomp(readln()); int len = cast(int)str.length; char[1000] str2; foreach(i; 0 .. len){ str2[i] = str[len - i - 1]; } str2[len] = '\0'; writeln(str2); }
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { int x; readV(x); auto c = 0; foreach (i; 1..10^^5) { c += i; if (c >= x) { writeln(i); return; } } }
D
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric; T[][] combinations(T)(T[] s, in int m) { if (!m) return [[]]; if (s.empty) return []; return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); } void main() { auto Ns = readln.split.to!(ulong[]); writeln(Ns[0] * Ns[1] / gcd(Ns[0], Ns[1])); }
D
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons; const dx = [1,0,-1,0]; const dy = [0,1,0,-1]; void read(T...)(auto ref T args){ auto line = readln().split(); foreach(i,ref arg; args) arg = line[i].to!(typeof(arg)); } int sum(int n){return n * (n + 1)/ 2;} void main(){ int m;m.read; for(;m>0;m--){ string cars;cars.read; bool[string] exist; foreach(i;1..cars.length){ auto f = (string a) =>[a,a.dup.reverse.idup]; foreach(c1;f(cars[0..i])) { foreach(c2;f(cars[i..$])){ exist[c1 ~ c2] = true; exist[c2 ~ c1] = true; } } } exist.length.writeln; } }
D