code
stringlengths
4
1.01M
language
stringclasses
2 values
void main() { auto D = ri; switch(D) { case 25: writeln("Christmas"); break; case 24: writeln("Christmas Eve"); break; case 23: writeln("Christmas Eve Eve"); break; case 22: writeln("Christmas Eve Eve Eve"); break; default: break; } } // =================================== import std.stdio; import std.string; import std.functional; 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
void main() { int[] tmp = readln.split.to!(int[]); int a = tmp[0], b = tmp[1]; string s = readln.chomp; bool ok = true; foreach (i, x; s) { if (i == a) { if (x != '-') { ok = false; } } else { if (!x.isNumber) { ok = false; } } } writeln(ok ? "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 std.stdio, std.conv, std.string, std.range, std.algorithm, std.range; void main() { auto N = readln.split[0].to!int; auto H = readln.split.to!(int[]); for(int i = N - 1; i > 0; i--) { if(H[i-1] > H[i]) H[i-1]--; } for (int i = 1; i < N; i++) { if (H[i - 1] > H[i]) { writeln("No"); return; } } writeln("Yes"); }
D
import std.stdio; import std.string; // chomp????????????????????????(?????????????????????) import std.conv; // to???????????????????????? void main() { int x = to!int(chomp(readln())); writeln(x ^^ 3); }
D
void main() { string s = rdStr; bool[] alpha = new bool[26]; if (s.length == 26) { alpha[s[$-1]-'a'] = true; foreach_reverse (i; 0 .. 25) { if (s[i] < s[i+1]) { s[0..i].write; long idx; foreach (j; s[i]-'a'+1 .. 26) { if (alpha[j]) { idx = j; break; } } (idx + 'a').to!dchar.writeln; return; } alpha[s[i]-'a'] = true; } writeln(-1); } else { alpha[] = true; foreach (x; s) { alpha[x-'a'] = false; } writeln(s, (alpha.countUntil(true) + 'a').to!dchar); } } T rdElem(T = long)() { //import std.stdio : readln; //import std.string : chomp; //import std.conv : to; return readln.chomp.to!T; } alias rdStr = rdElem!string; dchar[] rdDchar() { //import std.conv : to; return rdStr.to!(dchar[]); } T[] rdRow(T = long)() { //import std.stdio : readln; //import std.array : split; //import std.conv : to; return readln.split.to!(T[]); } T[] rdCol(T = long)(long col) { //import std.range : iota; //import std.algorithm : map; //import std.array : array; return iota(col).map!(x => rdElem!T).array; } T[][] rdMat(T = long)(long col) { //import std.range : iota; //import std.algorithm : map; //import std.array : array; return iota(col).map!(x => rdRow!T).array; } void wrMat(T = long)(T[][] mat) { //import std.stdio : write, writeln; 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.container; import std.typecons; import std.ascii; import std.uni;
D
import std.stdio, std.string, std.conv; import std.math; auto solve(string s_) { immutable n = s_.to!long(); immutable s = readln.chomp.to!long(); if(s==n) return s+1; immutable m = sqrt(n.to!real()).to!long+1; foreach(i;2..m) { long v=n, c=0; while(v) c+=v%i, v/=i; if(c==s) return i; } foreach_reverse(i;1..m) { auto v1=n/i, v2=n/(i+1), r=s-i-(n%(n/i)), v=v1-r/i; if(r>=0 && r%i==0 && v2<v && v<=v1 && v>i) return v; } return -1; } void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }
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 = 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; auto K = RD; /*string S; foreach (i; 0..3) { S ~= cast(char)(uniform(0, 3) + 'a'); } long _ans; auto K = uniform(1, 4); { string T; foreach (i; 0..K) T ~= S; long i = 1; while (i < T.length) { if (T[i] == T[i-1]) { ++_ans; i += 2; } else { ++i; } } debug writeln("S:", S); debug writeln("K:", K); debug writeln("T:", T); debug writeln("ans:", _ans); }*/ long cnt; long i = 1; while (i < S.length) { if (S[i] == S[i-1]) { ++cnt; i += 2; } else { ++i; } } debug writeln(cnt); long ans; if (S.length == 1) { ans = K/2; } else { if (S[0] != S[$-1]) { ans = cnt*K; } else { long cnt2, cnt3; foreach (c; S) { if (S[0] != c) break; ++cnt2; } foreach_reverse (c; S) { if (S[0] != c) break; ++cnt3; } if (cnt2 == S.length) { ans = S.length * K / 2; } else if (cnt2 % 2 == 1 && cnt3 % 2 == 1) { ans = cnt*K+K-1; } else { ans = cnt*K; } } } writeln(ans); stdout.flush(); debug readln(); }
D
import std.stdio; import std.array; import std.algorithm; import std.conv; int gcd (int x, int y) { if(x < y) swap(x, y); if(y == 0) return x; return gcd(y, x % y); } void main () { int a, b; while(true) { string[] input = split(readln()); if(input.length == 0) break; a = to!int(input[0]); b = to!int(input[1]); int gcd_ab = gcd(a, b); int lcm_ab = a / gcd_ab * b; writeln(gcd_ab, " ", lcm_ab); } }
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 Q = readln.chomp.to!int; long ans; while (Q--) { auto n = readln.chomp.to!long; if (n % 4 == 0) { writeln(n / 4); } else if (n % 4 == 1) { if (n <= 5) writeln(-1); else writeln((n-9)/4 + 1); } else if (n % 4 == 2) { if (n == 2) writeln(-1); else writeln((n-6)/4 + 1); } else { if (n <= 11) writeln(-1); else writeln((n-15)/4 + 2); } } }
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; void main() { readln.replace("peach", "~").replace("apple", "peach").replace("~", "apple").write; }
D
import std.stdio; import std.string; import std.conv; import std.range; import std.array; import std.algorithm; void main(){ auto a=readln.chomp.to!int; writeln(a/3); }
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 N = RD; auto M = RD; auto ab = new long[2][](N); auto cd = new long[2][](M); foreach (i; 0..N) { ab[i] = [RD, RD]; } foreach (i; 0..M) { cd[i] = [RD, RD]; } foreach (i; 0..N) { long best = long.max, pos; foreach (j; 0..M) { auto d = abs(cd[j][0] - ab[i][0]) + abs(cd[j][1] - ab[i][1]); if (d < best) { best = d; pos = j; } } writeln(pos+1); } 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 T = readln.chomp.to!int; foreach (_t; 0..T) { auto N = readln.chomp.to!long; if (N == 1) { writeln("FastestFinger"); continue; } if (N == 2 || N%2 == 1) { writeln("Ashishgup"); continue; } auto n = N; int t; while (n%2 == 0) { ++t; n /= 2; } if (n == 1) { writeln("FastestFinger"); continue; } if (t > 1) { writeln("Ashishgup"); continue; } int c; for (long k = 3; k^^2 <= N; k += 2) { while (n%k == 0) { ++c; n /= k; } } if (n != 1) { ++c; } writeln(c == 1 ? "FastestFinger": "Ashishgup"); } }
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; static import std.ascii; // 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() { auto S = sread(); long N = S.to!long; long s = S.map!"a-'0'"().sum(); writeln(N % s == 0 ? "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 a, b; cin.scan(a, b); int cnt = 1; int res; while (cnt < b) { cnt--; cnt += a; res++; } writeln(res); }
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 route = Tuple!(long, "From", long, "To"); long bignum = 1_000_000_007; 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() { auto s = sread(); long warea, barea; bool flag = (s[0] == 'W'); foreach (e; s) { if(flag && e == 'W') { warea++; flag = false; } if(!flag && e == 'B') { barea++; flag = true; } } writeln(warea + barea - 1); }
D
import std.stdio,std.string,std.conv; int main(){ auto input=readln.chomp.split; auto a=input[0].to!int; auto b=input[1].to!int; auto at=(a*13).to!int; auto bt=(b*10).to!int; foreach(y;bt..at+1){ if((y*0.08).to!int==a&&(y*0.1).to!int==b){ y.writeln; return 0; } } "-1".writeln; return 0; }
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, core.stdc.stdio; void main() { auto N = readln.chomp.to!int; auto edges = new int[][](N); foreach (_; 0..N-1) { auto s = readln.split.map!(to!int); edges[s[0] - 1] ~= s[1] - 1; edges[s[1] - 1] ~= s[0] - 1; } int dfs(int n, int p) { int ret = 0; foreach (m; edges[n]) if (m != p) ret ^= (dfs(m, n) + 1); return ret; } writeln( dfs(0, -1) ? "Alice" : "Bob" ); }
D
import std.stdio, std.conv, std.string; import std.algorithm, std.array, std.container; import std.numeric, std.math; import core.bitop; T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; } string RDR()() { return readln.chomp; } long mod = pow(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!long; auto M = RD!long; if (abs(N - M) > 1) { writeln(0); return; } long cnt1 = 1, cnt2 = 1; foreach (i; 0..N) { modm(cnt1, N - i); } foreach (i; 0..M) { modm(cnt2, M - i); } long ans = cnt1; modm(ans, cnt2); if (N == M) modm(ans, 2); writeln(ans); stdout.flush(); }
D
void main() { writeln(readln.chomp.count('x') < 8 ? "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 std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto X = readln.chomp.to!(long); long res = 0; foreach (b; 1..X+1) { foreach (p; 2..10) { if (b^^p <= X) { res = max(res, b^^p); } } } writeln(res); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto b = readln.chomp.to!(char); switch (b) { case 'A': writeln("T"); return; case 'T': writeln("A"); return; case 'C': writeln("G"); return; case 'G': writeln("C"); return; default: return; } }
D
import std.stdio, std.string, std.conv; void main() { long n = readln.chomp.to!long; writeln((n - 1) * n / 2); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto abc = readln.split.to!(long[]); auto a = abc[0]; auto b = abc[1]; auto c = abc[2]; if (c-a-b > 0 && 4*a*b < (c-a-b)^^2L) { writeln("Yes"); } else { writeln("No"); } }
D
void main(){ int n = inelm(); ( n*(1+n)/2 ).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
void main() { long h = rdElem; long w = rdElem; long n = rdElem; long a = max(h, w); writeln((n + a - 1) / a); } T rdElem(T = long)() { //import std.stdio : readln; //import std.string : chomp; //import std.conv : to; return readln.chomp.to!T; } alias rdStr = rdElem!string; dchar[] rdDchar() { //import std.conv : to; return rdStr.to!(dchar[]); } T[] rdRow(T = long)() { //import std.stdio : readln; //import std.array : split; //import std.conv : to; return readln.split.to!(T[]); } T[] rdCol(T = long)(long col) { //import std.range : iota; //import std.algorithm : map; //import std.array : array; return iota(col).map!(x => rdElem!T).array; } T[][] rdMat(T = long)(long col) { //import std.range : iota; //import std.algorithm : map; //import std.array : array; return iota(col).map!(x => rdRow!T).array; } void wrMat(T = long)(T[][] mat) { //import std.stdio : write, writeln; 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.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, D; scan(A, B, C, D); // writefln("%d %d %d %d", A, B, C, D); writeln((min(B, D) - max(A, C)).max(0)); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp; writeln(s[0], s.length-2, s[$-1]); }
D
import std.stdio,std.array,std.string,std.algorithm,std.conv; immutable STR_LENGTH = 20; int main(string[] argv) { char[] buf; stdin.readln(buf); char[] c; for(int i = 0;i < STR_LENGTH;i++){ if(buf.length > i){ c ~= buf[i]; } } reverse(c); writeln(c); return 0; }
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(){ long[] tmp = readln.chomp.split.map!(to!long).array; long a = tmp[0], b = tmp[1]; string ans; if(b < 0){ if((a - b) % 2) ans = "Positive"; // eg -4 .. -1 else ans = "Negative"; // eg -3 .. -1 } else if(a <= 0) ans = "Zero"; else ans = "Positive"; ans.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; import std.format; void main() { auto ip = readln.chomp.to!int; writeln(24 + (24 - ip)); }
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() { string s; scan(s); auto ok = new string[](0); void dfs(int i, string t) { if (i == 4) { ok ~= t; return; } if (i == 0) { dfs(i + 1, t ~ "AKIH"); dfs(i + 1, t ~ "KIH"); } else if (i == 1) { dfs(i + 1, t ~ "AB"); dfs(i + 1, t ~ "B"); } else if (i == 2) { dfs(i + 1, t ~ "AR"); dfs(i + 1, t ~ "R"); } else { dfs(i + 1, t ~ "A"); dfs(i + 1, t); } } dfs(0, ""); foreach (t ; ok) { if (s == t) { writeln("YES"); return; } } writeln("NO"); } struct UnionFind { private { int N; int[] p; int[] rank; } this (int n) { N = n; p = iota(N).array; rank = new int[](N); } int find_root(int x) { if (p[x] != x) { p[x] = find_root(p[x]); } return p[x]; } bool same(int x, int y) { return find_root(x) == find_root(y); } void unite(int x, int y) { int u = find_root(x), v = find_root(y); if (u == v) return; if (rank[u] < rank[v]) { p[u] = v; } else { p[v] = u; if (rank[u] == rank[v]) { rank[u]++; } } } } 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); } } } struct Queue(T) { private { int N, head, tail; T[] data; } this(int n) { N = n + 1; data = new T[](N); } bool empty() { return head == tail; } bool full() { return (tail + 1) % N == head; } T front() { return data[head]; } void push(T x) { assert(!full); data[tail++] = x; tail %= N; } void pop() { assert(!empty); head = (head + 1) % N; } void clear() { head = tail = 0; } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto K = readln.chomp.to!int; writeln(K/2 * ((K+1)/2)); }
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 readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=rdsp;foreach(ref j;v.tupleof)pick(r,j);}} void main() { int n; readV(n); struct P { int x, y, h; } P[] p; readS(n, p); auto pf = p.find!(pi => pi.h > 0); if (pf.empty) { foreach (x; 0..101) foreach (y; 0..101) if (p.all!(pi => pi.x != x && pi.y != y)) { writeln(x, " ", y, " ", 1); return; } } else { auto pt = pf[0]; foreach (x; 0..101) foreach (y; 0..101) { auto h = pt.h + (x-pt.x).abs + (y-pt.y).abs; if (p.all!(pi => max(h - (x-pi.x).abs - (y-pi.y).abs, 0) == pi.h)) { writeln(x, " ", y, " ", h); return; } } } }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { auto nab = readln.split.to!(long[]); auto N = nab[0]; auto A = nab[1]; auto B = nab[2]; writeln(max(0, B*(N-1)+A - (A*(N-1)+B) + 1)); }
D
import std.algorithm; import std.array; import std.container; import std.conv; import std.range; import std.stdio; import std.string; T binarySearch(T)(T[] haystack, T needle) { auto min = 0UL; auto max = haystack.length - 1; while (min <= max) { auto mid = (min + max) / 2; if (haystack[mid] == needle) { return needle; } else if (haystack[mid] < needle) { min = mid + 1; } else { max = mid - 1; } } return -1; } void main() { auto n = readln.chomp.to!int; auto s = readln.chomp.split.map!(to!int).array; auto q = readln.chomp.to!int; auto t = readln.chomp.split.map!(to!int).array; auto c = 0; foreach (e_t; t) { if (binarySearch(s, e_t) == e_t) { c++; } } c.writeln; }
D
import std.stdio,std.string,std.conv,std.array,std.algorithm; void main(){ foreach(i;1..int.max){ string[] a = readln().chomp().split(); if( a[0]=="0" && a[1]=="0" ){ break; } if( to!int(a[0]) < to!int(a[1]) ){ writeln( a[0]," ",a[1] ); }else{ writeln( a[1]," ",a[0] ); } } }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto N = readln.chomp.to!long; auto a = N.iota.map!(_ => readln.chomp.to!long-1).array; long c = 0; foreach (i; 0..N) { c = a[c]; if (c == 1) { writeln(i+1); return; } } writeln(-1); }
D
import std.stdio, std.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.container, std.datetime; void main() { auto a = readln.chomp.to!int; auto b = readln.chomp.to!int; auto h = readln.chomp.to!int; writeln((a+b)*h/2); }
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 main() { auto q = RD!int; auto ans = new bool[](q); foreach (qi; 0..q) { auto n = RD!int; auto m = RD; auto tlh = new long[][](n); foreach (i; 0..n) { tlh[i] = [RD, RD, RD]; } bool ok = true; long t, h = m, l = m; foreach (i; 0..n) { auto d = tlh[i][0] - t; l = max(tlh[i][1], l-d); h = min(tlh[i][2], h+d); debug writeln("i:", i, " l:", l, " h:", h); if (l > tlh[i][2] || h < tlh[i][1]) { ok = false; break; } t = tlh[i][0]; } ans[qi] = ok; } foreach (e; ans) writeln(e ? "YES" : "NO"); stdout.flush; debug readln; }
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 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); } enum MOD = (10 ^^ 9) + 7; void main() { long A, B, C, X, Y; scan(A, B, C, X, Y); long ans = long.max; ans = ans.min(A * X + B * Y); ans = ans.min(C * (max(X, Y) * 2)); ans = ans.min(C * (min(X, Y) * 2) + (X < Y ? B : A) * (max(X, Y) - min(X, Y))); writeln(ans); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.numeric; ulong[100] TS; T lcm(T)(T a, T b) { return a / gcd(a, b) * b; } void main() { auto N = readln.chomp.to!int; foreach (i; 0..N) { TS[i] = readln.chomp.to!ulong; } auto res = TS[0]; foreach (t; TS[1..N]) { res = lcm(res, t); } writeln(res); }
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, K; scan(N, K); long ans; while (0 < N) N /= K, ans++; writeln(ans); }
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 N, M, Q; scan(N, M, Q); auto a = new long[](Q); auto b = new long[](Q); auto c = new long[](Q); auto d = new long[](Q); foreach (i; 0 .. Q) scan(a[i], b[i], c[i], d[i]); a[] -= 1; b[] -= 1; long dfs1(long[] A) { if (A.length == N) { // writeln(A); long ret; foreach (i; 0 .. Q) { if (A[b[i]] - A[a[i]] == c[i]) ret += d[i]; } return ret; } long m = A.length == 0 ? 1 : A[$ - 1]; long ret = long.min; foreach (x; m .. M + 1) { ret = ret.max(dfs1(A ~ x)); } return ret; } writeln(dfs1([])); }
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; // }}} // nep.scanner {{{ class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : split; import std.string : chomp; private File file; private char[][] str; private size_t idx; this(File file = stdin) { this.file = file; this.idx = 0; } private char[] next() { if (idx < str.length) { return str[idx++]; } char[] s; while (s.length == 0) { s = file.readln.chomp.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 main() { auto cin = new Scanner; int a, b; cin.scan(a, b); if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) { writeln("Possible"); } else { writeln("Impossible"); } }
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 = 998_244_353; //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 t = RD!int; auto ans = new long[](t); foreach (ti; 0..t) { auto n = RD!int; ans[ti] = n; } foreach (e; ans) writeln(e); stdout.flush; debug readln; }
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; void main() { while (1) { auto n = readln.chomp.to!int; if (!n) break; auto bmi = double.max; auto id = int.max; foreach (i; 0..n) { auto x = readln.chomp.split.map!(to!int); auto t = abs(22 - x[2] / (x[1]/100.0)^^2); if (t < bmi || (t == bmi && x[0] < id)) { bmi = t; id = x[0]; } } id.writeln; } }
D
import std.stdio : readln, writeln, writefln; import std.array : array, split; import std.conv : to; import std.range.primitives; import std.range : enumerate, iota, repeat, retro, assumeSorted; import std.algorithm.searching : all, any, canFind, count, countUntil; import std.algorithm.comparison : max, min, clamp; import std.algorithm.iteration : each, group, filter, map, reduce, permutations, sum, uniq; import std.algorithm.sorting : sort; import std.algorithm.mutation : reverse, swap; void main() { string s; scan(s); writeln("2018", s[4 .. $]); } void scan(T...)(ref T args) { import std.stdio : readln; import std.array : split; import std.conv : to; import std.range.primitives; 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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void main() { auto K = readln.chomp.to!long; auto k = K; int r; while (k) { ++r; foreach (long i; 0..10) { if ((k+K*i)%10 == 7) { k = (k+K*i)/10; goto ok; } } writeln(-1); return; ok: } writeln(r); }
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[] 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() { auto S = sread(); long ans = S.length; ans -= 2; while (S[0 .. ans / 2] != S[ans / 2 .. ans]) ans -= 2; writeln(ans); }
D
import std; import core.bitop; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () => readln.chomp.to!(T); alias aryread(T = long) = () => readln.split.to!(T[]); alias Pair = Tuple!(long, "money", long, "stack"); alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less); void main() { long h, w; scan(h, w); auto a = new string[](h); iota(h).each!(x => a[x] = sread()); long[char] cntalf; foreach (e; a) { foreach (f; e) { if (f in cntalf) cntalf[f] += 1; else cntalf[f] = 1; } } long cnt4, cnt2, cnt1; foreach (key, value; cntalf) { cnt4 += value / 4; cnt2 += (value % 4) / 2; cnt1 += value % 2; } bool check = true; long need4 = (h / 2) * (w / 2), need2 = (h % 2) * (w / 2) + (w % 2) * (h / 2), need1 = (h % 2) * (w % 2); if (need4 > cnt4) check = false; cnt2 += (cnt4 - need4) * 2; if (need2 > cnt2) check = false; if (need1 > cnt1) check = false; if (check) writeln("Yes"); else writeln("No"); } void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int t; rd(t); while (t--) { int l, r; rd(l, r); writeln(l, " ", l * 2); } } void rd(T...)(ref T x) { import std.stdio : readln; import std.string : split; import std.conv : to; auto l = readln.split; assert(l.length == x.length); foreach (i, ref e; x) e = l[i].to!(typeof(e)); }
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, std.datetime; // 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() { auto S = sread(); long N = S.length + 1; auto d = new long[](N); foreach_reverse (i; 0 .. N - 1) { if (S[i] == '>') { d[i] = d[i + 1] + 1; } } foreach (i; 0 .. N - 1) { if (S[i] == '<') { d[i + 1] = max(d[i + 1], d[i] + 1); } } // writeln(d); d.sum().writeln(); }
D
import std; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); //aryread!string(); void main() { auto st = aryread!string(); // writeln(st); long a, b; scan(a, b); auto u = sread(); // writeln(u); if (u == st[0]) { writeln(a - 1, ' ', b); } else if (u == st[1]) { writeln(a, ' ', b - 1); } } 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
void main(){ int n = _scan(); writeln(n%1000==0? 0: 1000-n%1000); } 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.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]||x[0]+x[2]==x[1]||x[1]+x[2]==x[0]) { writeln("Yes"); } else { writeln("No"); } }
D
import std.stdio,std.string,std.conv,std.array,std.algorithm; void main(){ for(;;write("\n")){ auto a = readln().chomp().split(); if( a[0]=="0" && a[1]=="0" ){ break; } int h=to!int(a[0]) , w=to!int(a[1]); foreach(y;0..h){ foreach(x;0..w){ if( (x+y)%2==1 ){ write("."); }else{ write("#"); } } write("\n"); } } }
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.ascii; void main() { readln.chomp.replace(",", " ").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() { long[] ans = new long[31]; ans[0] = 1; foreach(i; 1..31) { ans[i] += ans[i-1]; if (i>1) ans[i] += ans[i-2]; if (i>2) ans[i] += ans[i-3]; } while(true) { int n = readln.chomp.to!int; if (n==0) break; writeln((ans[n]+3650-1)/3650); } }
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 A = RD; auto B = RD; writeln(A * B % 2 == 0 ? "Even" : "Odd"); stdout.flush(); debug readln(); }
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.ascii; void main() { auto a = readln.chomp.to!int; auto s = readln.chomp; if (a >= 3200) { writeln(s); } else { writeln("red"); } }
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; void scan(T...)(ref T args) { auto 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); } } } 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; } enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; bool isPrime(int N) { if (N <= 1) return false; for (int i = 2; i*i <= N; i++) { if (N % i == 0) return false; } return true; } enum lim = 10^^5 + 1; void main() { int Q; scan(Q); auto b = new bool[](lim); foreach (i ; 1 .. lim) { b[i] = (i % 2) && isPrime(i) && isPrime((i + 1) / 2); } auto c = new int[](lim + 1); foreach (i ; 1 .. lim + 1) { c[i] = c[i - 1] + b[i - 1]; } foreach (_ ; 0 .. Q) { int li, ri; scan(li, ri); auto ans = c[ri + 1] - c[li - 1]; writeln(ans); } }
D
import std.stdio, std.string, std.range; void main(){ string s = readln.chomp; foreach(i; 0..3){ if(s[i] == s[i+1]){ writeln("Bad"); return; } } writeln("Good"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; bool eq(char a, char b) { return a == '?' || b == '?' || a == b; } void main() { auto a = readln.chomp.to!(char[]); auto b = readln.chomp.to!(char[]); auto c = readln.chomp.to!(char[]); auto A = a.length.to!int; auto B = b.length.to!int; auto C = c.length.to!int; bool[20000] ab, ac, bc; ab[] = true; ac[] = true; bc[] = true; foreach (i; 0..A) foreach (j; 0..B) if (!eq(a[i], b[j])) ab[i-j + 10000] = false; foreach (i; 0..A) foreach (j; 0..C) if (!eq(a[i], c[j])) ac[i-j + 10000] = false; foreach (i; 0..B) foreach (j; 0..C) if (!eq(b[i], c[j])) bc[i-j + 10000] = false; auto r = int.max; foreach (i; -4000..4001) foreach (j; -4000..4001) { if (ab[i+10000] && ac[j+10000] && bc[j-i+10000]) { r = min(r, max(A, i+B, j+C)-min(0, i, j)); } } writeln(r); }
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional, std.traits; import std.algorithm, std.container; void main() { auto S = scanElem!string; long s,res; foreach(c; S) { if(c=='S')s++; if(c=='T'&&s!=0) { s--; res+=2; } } writeln(S.length-res); } class UnionFind{ UnionFind parent = null; void merge(UnionFind a) { if(same(a)) return; a.root.parent = this.root; } UnionFind root() { if(parent is null)return this; return parent = parent.root; } bool same(UnionFind a) { return this.root == a.root; } } void scanValues(TList...)(ref TList list) { auto lit = readln.splitter; foreach (ref e; list) { e = lit.fornt.to!(typeof(e)); lit.popFront; } } T[] scanArray(T = long)() { return readln.split.to!(long[]); } void scanStructs(T)(ref T[] t, size_t n) { t.length = n; foreach (ref e; t) { auto line = readln.split; foreach (i, ref v; e.tupleof) { v = line[i].to!(typeof(v)); } } } long scanULong(){ long x; while(true){ const c = getchar; if(c<'0'||c>'9'){ break; } x = x*10+c-'0'; } return x; } T scanElem(T = long)() { char[] res; int c = ' '; while (isWhite(c) && c != -1) { c = getchar; } while (!isWhite(c) && c != -1) { res ~= cast(char) c; c = getchar; } return res.strip.to!T; } 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 { import std.typecons : tuple; return reduce!fun(tuple(seed), r); } } } 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); } } struct Factor { long n; long c; } Factor[] factors(long n) { Factor[] res; for (long i = 2; i ^^ 2 <= n; i++) { if (n % i != 0) continue; int c; while (n % i == 0) { n = n / i; c++; } res ~= Factor(i, c); } if (n != 1) res ~= Factor(n, 1); return res; } long[] primes(long n) { if(n<2)return []; auto table = new long[n+1]; long[] res; for(int i = 2;i<=n;i++) { if(table[i]==-1) continue; for(int a = i;a<table.length;a+=i) { table[a] = -1; } res ~= i; } return res; } bool isPrime(long n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (long i = 3; i ^^ 2 <= n; i += 2) if (n % i == 0) return false; return true; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nabcd = readln.split.to!(int[]); auto N = nabcd[0]; auto A = nabcd[1]-1; auto B = nabcd[2]-1; auto C = nabcd[3]-1; auto D = nabcd[4]-1; auto S = readln.chomp.to!(char[]); auto len = S.length; if (D < C) { swap(A, B); swap(C, D); } bool moved; while (A != C || B != D) { if (B < D) { if (B+1 < len && S[B+1] != '#' && B+1 != A) { ++B; moved = true; } else if (B+2 < len && S[B+2] != '#' && B+2 != A) { B += 2; moved = true; } } if (A < C && !moved) { if (A+1 < len && S[A+1] != '#' && A+1 != B) { ++A; moved = true; } else if (A+2 < len && S[A+2] != '#' && A+1 != B && A+2 != B) { A += 2; moved = true; } } if (!moved) { writeln("No"); return; } moved = false; } writeln("Yes"); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto T = readln.chomp.to!int; foreach (_; 0..T) { auto nm = readln.split.to!(int[]); auto N = nm[0]; auto M = nm[1]; if (N > M) swap(N, M); writeln(N == 1 || (N == 2 && M == 2) ? "YES" : "NO"); } }
D
void main() { long[] tmp = readln.split.to!(long[]); long x = tmp[0], y = tmp[1]; writeln(x % y != 0 ? x : -1); } 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; 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; import std.concurrency; import core.bitop : popcnt; alias Generator = std.concurrency.Generator; int INF = int.max/3; void main() { int K = 26; int[] cs = readln.chomp.map!"a-'a'".map!(to!int).array; int[] as = new int[cs.length]; foreach(i, c; cs) { as[i] = 1<<c ^ (i==0 ? 0 : as[i-1]); } int[] dp = INF.repeat((1<<K)+1).array; dp[0] = 0; int opt; as.each!( a => dp[a] = min( dp[a], opt = (K+1).iota.map!( i => dp[1<<(K-1)>>i ^ a] ).reduce!min + 1 ) ); opt.writeln; } // ---------------------------------------------- void scanln(Args...)(ref Args args) { foreach(i, ref v; args) { "%d".readf(&v); (i==args.length-1 ? "\n" : " ").readf; } // ("%d".repeat(args.length).join(" ") ~ "\n").readf(args); } 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; } // 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.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 h, w; scan(h, w); long ans = min(solve(h, w), solve(w, h)); writeln(ans); } long solve(int h, int w) { long ans = inf6; foreach (x ; 0 .. w + 1) { long b = 1L * h * x; long a = 1L * (h / 2) * (w - x); long c = 1L * ((h + 1) / 2) * (w - x); auto m = max(abs(a - b), abs(a - c), abs(b - c)); ans = min(ans, m); a = 1L * h * ((w - x) / 2); c = 1L * h * ((w - x + 1) / 2); m = max(abs(a - b), abs(a - c), abs(b - c)); ans = min(ans, m); } return 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); } } }
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 modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); } void main() { auto C = RD!string; writeln(cast(string)[C[0]+1]); stdout.flush; debug readln; }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}} void 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;}} void 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;}}} void 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;}}} void main() { string[] s; readM(3, s); writeln(s[0][0], s[1][1], s[2][2]); }
D
void main() { import std.stdio, std.string, std.array, std.algorithm, std.conv; auto b = readln.chomp.split.map!(to!int); b[0].solve(b[1]).writeln; } int solve(in int nTestCase, in int mTLE) { immutable base = 100 * nTestCase + 1800 * mTLE, pInv = 1 << mTLE; /* S := 1 p + 2 pq + 3 pq^2 + ... qS := 1 pq + 2 pq^2 + 3 pq^3 + ... S = (p + pq + pq^2 + ...) / (1-q) S = 1 + q + q^2 + ... S = 1/(1-q) = 1/p = pInv; */ return base * pInv; } unittest { assert (1.solve(1) == 3800); assert (10.solve(2) == 18400); assert (100.solve(5) == 608000); import std.stdio; stderr.writeln("unittest passed!"); }
D
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { bool[] alp = new bool[](26); string s = readln.chomp; foreach (ch ; s) { alp[ch - 'a'] = 1; } foreach (i ; 0 .. 26) { if (!alp[i]) { writeln(('a' + i).to!char); return; } } writeln("None"); } 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; import std.string; import std.conv; int main() { string s = readln(); write(toUpper(s)); return 0; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; class Tree { Tree[26] children; long[26] counts; char c; this(char c) { this.c = c; } void add(string s) { assert(this.c == '\n'); auto last = s[$-1]; if (children[last - 'a'] is null) { children[last - 'a'] = new Tree(last); } long[26] cs; children[last - 'a'].add(s[0..$-1], cs); foreach (i, c; cs) this.counts[i] += c; } void add(string s, ref long[26] cs) { if (s.empty) { ++cs[this.c - 'a']; return; } auto last = s[$-1]; if (children[last - 'a'] is null) { children[last - 'a'] = new Tree(last); } children[last - 'a'].add(s[0..$-1], cs); foreach (i, c; cs) this.counts[i] += c; cs[this.c - 'a'] = 1; } long count(string s) { if (s[$-1] == '\n') s = s[0..$-1]; auto c = s[$-1]; if (s.length == 1) { return this.counts[c - 'a'] - 1; } else { return this.children[c - 'a'].count(s[0..$-1]); } } } void main() { auto N = readln.chomp.to!int; auto tree = new Tree('\n'); string[] ss; foreach (_; 0..N) { auto s = readln.chomp; tree.add(s); ss ~= s; } long r; foreach (s; ss) r += tree.count(s); writeln(r); }
D
import std.conv; import std.stdio; import std.string; void main() { auto s = readln.strip; writeln( solve( s ) ); } auto solve( in string s ) { auto checkA = false; auto checkC = false; auto checklower = true; foreach( i, c; s ) { if( i == 0 && c == 'A' ) { checkA = true; continue; } if( 2 <= i && i <= s.length - 2 && c == 'C' && !checkC ) { checkC = true; continue; } if( c < 'a' || 'z' < c ) { checklower = false; break; } } if( checkA && checkC && checklower ) return "AC"; else return "WA"; }
D
import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } int size(T)(in T s) { return cast(int)s.length; } void main() { int x = readln.chomp.to!int; writeln((x < 1200 ? "ABC" : "ARC")); }
D
void main(){ int[] vals = inln(); ( ((vals[2]+0.5)/vals[0]).to!int()*vals[1] ).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(T = int)(){ T[] ln; foreach(string elm; readln().chomp().split())ln ~= elm.to!T(); return ln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; int N, M; int[][int] RS; int[200000] IS; void main() { auto nm = readln.split.to!(int[]); N = nm[0]; M = nm[1]; foreach (_; 0..M) { auto ab = readln.split.to!(int[]); auto a = ab[0] - 1; auto b = ab[1] - 1; RS[a] ~= b; RS[b] ~= a; } IS[0] = 1; foreach (i; 0..N) { if (IS[i] == 1 && i in RS) { foreach (j; RS[i]) { if (IS[j] == 0) IS[j] = i == 0 ? 1 : 2; } } } writeln( IS[N-1] == 2 ? "POSSIBLE" : "IMPOSSIBLE" ); }
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 N = RD; foreach (i; 0..N) write("a"); writeln(); void f(long n, char c) { foreach_reverse (i; 1..n) { string pre; foreach (j; 0..i) pre ~= c; pre ~= cast(char)(c+1); debug writeln("i:", i); void g(string str, long remain, char d) { if (remain == 0) { writeln(pre ~ str); return; } foreach (i; 'a'..cast(char)(d+1)) { g(str ~ i, remain-1, cast(char)max(d, i+1)); } } g("", N-i-1, cast(char)(c+2)); } } f(N, 'a'); stdout.flush; debug readln; }
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm; void main(){ auto s = readln.strip; long a = 0; long b = 0; foreach (i, c; s) { if ((i % 2 == 0) == (c == '1')) { a++; } else { b++; } } writeln(min(a, b)); }
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 N = RD; bool[long] set; foreach (i; 0..N) { auto d = RD; set[d] = true; } writeln(set.keys.length); stdout.flush(); debug readln(); }
D
import std.algorithm, std.array, std.container, std.range; import std.numeric, std.math, std.bigint, std.random; import std.string, std.uni, std.regex, std.conv; import std.bitmanip, core.bitop; import std.stdio, std.typecons; void main() { auto w = readln.chomp; auto r = 0; for (;;) { auto t = readln.chomp; if (t == "END_OF_TEXT") break; auto ti = t.split; r += ti.count!(a => icmp(a, w) == 0); } writeln(r); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!long; foreach (h; 1L..3501L) foreach (m; h..3501L) { auto a = 4*h*m-n*(h+m); auto b = n*h*m; if (a > 0 && b % a == 0) { writeln(h, " ", m, " ", b/a); return; } } }
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 s = readln.chomp; int m; foreach (i; 1..n-1) { auto a = s[0..i]; auto b = s[i..$]; int[int] cnt1; int[int] cnt2; foreach (e; a) { cnt1[e]++; } foreach (e; b) { cnt2[e]++; } int lm; foreach (k; cnt1.keys) { if (cnt2.get(k, 0)) { lm++; } } m = max(m, lm); } m.writeln; }
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[]); writeln(x[0]-1+(x[0]<=x[1])); }
D
void main(){ auto ABCK = readLine!long(); auto A = ABCK[0]; auto B = ABCK[1]; auto C = ABCK[2]; auto K = ABCK[3]; if( K <= A ){ K.writeln(); } else if( K <= A+B ) { A.writeln(); } else { (A - (K-(A+B))).writeln(); } return; } import std; string readStr(){ return readln().chomp(); } T[] readLine( T = long )(){ return readln().split().to!(T[])(); }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; void main() { auto l = readln.chomp.split.map!(to!int).array; int n = l[0], c = l[1]; long[][] cc = new long[][](31, 200010); long[] imos = new long[](200010); for (int i = 0; i < n; ++i) { auto m = readln.chomp.split.map!(to!int).array; cc[m[2] - 1][2 * m[0] - 1] += 1; cc[m[2] - 1][2 * m[1]] -= 1; } for (int i = 0; i < c; ++i) { for (int j = 1; j <= 200000; ++j) { cc[i][j] += cc[i][j - 1]; if (cc[i][j - 1] == 0 && cc[i][j] > 0) { imos[j] += 1; } else if (cc[i][j] == 0 && cc[i][j - 1] > 0) { imos[j] -= 1; } } } long ans; for (int i = 1; i <= 200000; ++i) { imos[i] += imos[i - 1]; if (ans < imos[i]) ans = imos[i]; } ans.writeln; }
D
void main(){ string input; input = readln().chomp().dup; string ans; foreach(elm; input){ if(elm == 'B'){ if( ans.length==0 )continue; ans.popBack(); }else{ ans ~= elm; } } writeln(ans.length==2? ans[$-2..$]: ans[0..$] ); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; // 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, 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 size = readln.chomp.to!int; auto words = readln.split.to!(string[]); void solve() { string result; foreach(i; 0..size) { result ~= words[0][i]; result ~= words[1][i]; } result.writeln; } solve(); }
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { while(true) { auto input=readln.split.map!(to!int); if(input[0]==0&&input[1]==0) break; int m=input[1]-input[0]; int th, fiv, han; for(; m>=1000; ++th) m-=1000; for(; m>=500; ++fiv) m-=500; for(; m>=100; ++han) m-=100; writeln(han, " ", fiv, " ", th); } }
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 N = readln.chomp.to!int; auto a = readln.split.to!(int[]); int count; foreach(i; a) { while(i % 2 == 0) { i /= 2; count++; } } writeln(count); } //writeln("滲み出す混濁の紋章 不遜なる狂気の器 湧き上がり 否定し 痺れ 瞬き 眠りを妨げる 爬行する鉄の王女 絶えず自壊する泥の人形 結合せよ 反発せよ 地に満ち己の無力を知れ 破道の九十 黒棺")
D
// dfmt off T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;} T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;} void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp(); void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}} static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop; // dfmt on void main() { long N, K; scan(N, K); long ans; foreach (k; K .. N + 2) { long m = k * (k - 1) / 2; long M = N * (N + 1) / 2 - (N - k + 1) * (N - k) / 2; ans += max(M - m + 1, 0); ans %= 1000000007; } writeln(ans); }
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.split.to!(int[]); writeln(ip[0] + ip[1]/2); }
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 r = ['R', 'U', 'D']; auto l = ['L', 'U', 'D']; bool f; foreach (i; 0..s.length) { if (i % 2 && l.find(s[i]).empty) { f = true; } else if (i % 2 == 0 && r.find(s[i]).empty) { f = true; } } if (f) { writeln("No"); } else { writeln("Yes"); } }
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; } void main() { auto nab = readints; int n = nab[0], a = nab[1], b = nab[2]; writeln(min(n * a, b)); }
D
import std.stdio : writeln; void main() { int n,a,b; scan(n,a,b); long ans; foreach (i ; 1 .. n + 1) { int d = digitSum(i); if (a <= d && d <= b) { ans += i; } } writeln(ans); } int digitSum(int x) { return x > 0 ? digitSum(x / 10) + x % 10 : 0; } void scan(T...)(ref T args) { import std.stdio : readln; import std.array : split; import std.conv : to; import std.range.primitives; 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.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm; void main(){ auto S = readln.chomp; auto F = S[0..2].to!int; auto R = S[2..$].to!int; if((1<=F&&F<=12) && (1<=R&&R<=12)) writeln("AMBIGUOUS"); else if(1<=F&&F<=12) writeln("MMYY"); else if(1<=R&&R<=12) writeln("YYMM"); else writeln("NA"); }
D
import std.stdio, std.conv, std.string, std.algorithm.searching, std.algorithm.iteration; void main() { auto N = readln().strip.to!int; int[] pList = []; foreach(i; 0..N) { pList ~= readln().strip.to!int; } writeln(pList.sum - pList.reduce!"a<b?b:a" / 2); }
D