code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math; void main() { auto nk = readln.split.to!(int[]); auto N = nk[0]; auto K = nk[1]; readln; int cnt = 1; N -= K; --K; while (N > 0) { ++cnt; N -= K; } writeln(cnt); }
D
import std.stdio, std.string, std.conv; void main() { int[][] c; for (int i = 0; i < 3; i++) { c ~= to!(int[])(readln.chomp.split); } int[3] a, b; // a[0] = 0 と仮定 foreach (i, e; c[0]) { b[i] = e; } for (int i = 1; i < 3; i++) { a[i] = c[i][i] - b[i]; } bool f = true; f...
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 MOD =...
D
import core.stdc.stdlib; import std.algorithm; import std.array; import std.conv; import std.math; import std.numeric; import std.stdio; import std.string; // void toBaseMinus2(in long rest, in long digit, in string result) // { // // stderr.writeln(rest, ", ", digit, ", ", result.dup.reverse); // if (rest ==...
D
import std.stdio, std.string, std.conv; long solve(long n) { import std.algorithm; long result = long.max; for (long i = 1; i * i <= n; ++i) { if (n % i == 0) result = min(result, i+n/i-2); } return result; } void main() { long n = readln.chomp.to!long; solve(n).writeln; }
D
import std.stdio, std.string; void main(){ int w, h; while(true){ scanf("%d %d", &h, &w); if( w== 0&&h == 0) break; for(int i = 0; i < h; ++i){ for(int j = 0; j < w; ++j){ if (i == 0 || i == h-1){ write("#"); } else if (j == 0 || j == w-1){ write("#"); }else{ write(".")...
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 xy = readln.split.to!(long[]); auto x = xy[0]; auto y = xy[1]; auto ab = readln.split.to!(long[]); ...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; void main() { auto input = readln.chomp.split.to!(int[]); auto H = input[0]; auto W = input[1]; auto S = new string[H]; foreach(ref i ; S) i = readln.chomp.to!string; int[8] dx = [-1, 1, ...
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; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ int n = read.to!int; int m = read...
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(...
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); } ...
D
void main() { long[] nk = rdRow; long n = nk[0], k = nk[1]; long[] rsp = rdRow; string t = rdStr; string u; long score; foreach (i, x; t) { dchar now = check(x); if (i >= k) { if (u[i-k] == now) { if (i + k >= n) ...
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; int a, b; void main() { scan(a, b); if (!(a > 0 || b < 0)) { writeln("Zero"); } else if (b < 0 && (...
D
void main() { problem(); } void problem() { auto a = scan; string solve() { return a[$-1] == 's' ? a ~ "es" : a ~ "s"; } solve().writeln; } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, s...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; long a, b, c, d, e, f; rd(a, b, c, d, e, f); /* 100b/(a+b) < 100b'/(a'+b') 100b*(a'+b') < 100b'*(a+b) */ long mx_w=100*a, mx_s; for(long w1=100*a; w1<=f; w1+=100*a){ for(long w2=0; w2<=f; w2+=100*b){ for(long s1=0; s1...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; void main() { int input; immutable limitList = 500000; bool[] listNumbers = new bool[](limitList); int[] listPrimeNumbers; listNumbers.fill(true); foreach (i; 2..limitList.to!double.sqrt.to!int) { ...
D
import std.functional, std.algorithm, std.container, std.typetuple, std.typecons, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; void main() { int[] NK = readln.chomp.split.to!(int[]); int N = NK[0], ...
D
import std.algorithm; import std.array; import std.ascii; import std.bigint; import std.complex; import std.container; import std.conv; import std.functional; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; auto readInts() { return array(map!(to!int)(readln().strip().split...
D
void main() { (rs.canFind("9") ? "Yes" : "No").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.t...
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.concurrency; import std.traits; import std.uni; import s...
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; ulong M = 10UL^^9 + 7; ulong fact(ulong n) { if (n <= 1) { return 1; } else { return n * fact(n - 1) % M; } } void main() { ulong n ...
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { auto sc = new Scanner(stdin); long q, h, s, d; sc.read(q, h, s, d); h = min(h, 2*q); s = min(s, 2*h); d = min(d, 2*...
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 = "%.15f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_r...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; 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.string, std.range, std.conv, std.algorithm, std.typecons; void main(){ alias Tuple!(int, "x", int, "y") Point; int W, H, N; auto input = readln.split.map!(to!int); W = input[0], H = input[1], N = input[2]; int total; Point before; foreach (i; 0..N) { input = readln.split.map!(to!int); ...
D
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons; import core.stdc.stdio; // foreach, foreach_reverse, writeln void main() { int n; scanf("%d", &n); int[] a = new int[n]; foreach (i; 0..n) scanf("%d", &a[i]); int[int] t; t[0] = 0; long ans = 0; foreach (i;...
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_r...
D
import std.stdio,std.string,std.conv; int main() { int[char] roman = ['I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000]; string s; while((s = readln.chomp).length != 0) { int ans = 0; for(int i=0;i<s.length-1;i++) { if(roman[s[i]] >= roman[s[i+1]]) ans += roman[s[i]]; else ans -= roman[s[i]]; } ...
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!(long[]); auto l = 0...
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 n; readV(n); auto m = 0, a ...
D
import std.stdio,std.string,std.conv,std.algorithm,std.range,std.array; void main(){ foreach(_;0..readln.chomp.to!int){ readln.replace("Hoshino","Hoshina").write; } }
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).array; auto N = s[0]; auto A = s[1].to!long; auto B = s[2].to!long; aut...
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", ...
D
// Cheese-Cracker: cheese-cracker.github.io dchar[] stringify(ll num){ dchar[] res; while(num > 0){ res ~= to!dchar('0' + (num % 10)); num /= 10; } res.reverse; return res; } dchar[][] pow2; void preProcess(){ ll num = 1; for(int i = 0; i <= 62; ++i){ pow2 ~= string...
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=(...
D
import std.stdio; import std.conv; import std.algorithm; import std.string; import std.file; int main() { int[] hs; string l; readln(); while((l = readln()).length >= 2){ int a, b, c; a = to!int(l.split()[0]), b = to!int(l.split()[1]), c = to!int(l.split...
D
import std.stdio; import core.stdc.stdio; import std.array; import std.conv; import std.algorithm; import std.range; void main() { int n,a; scanf("%d%d",&n,&a); int x = n % 500; writeln(x <= a ? "Yes" : "No"); }
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_r...
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, std.bitmanip; const long MOD = 10^^9 + 7; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; a...
D
void main() { auto S = rs; auto T = rs; if(S.length + 1 == T.length && T[0..$-1] == S) { writeln("Yes"); } else writeln("No"); } // =================================== import std.stdio; import std.string; import std.functional; import std.algorithm; import std.range; import std.traits; import std.math; import s...
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; void main() { string S, T; readlnTo(S); readlnTo(T); int[] a = new int[26]; int[] b = new int[26]; a.fill(-1); b.fill(-1); bool ok...
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto data = readln.split; auto H = data[0].to!int, W = data[1].to!int; data = readln.split; auto h = data[0].to!int, w = data[1].to!int; writeln(H*W - h*W - w*H ...
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 MOD =...
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(...
D
void main() { auto n = ri; n %= 10; if (n == 0) writeln("pon"); if (n == 1) writeln("pon"); if (n == 2) writeln("hon"); if (n == 3) writeln("bon"); if (n == 4) writeln("hon"); if (n == 5) writeln("hon"); if (n == 6) writeln("pon"); if (n == 7) writeln("hon"); if (n == 8) writeln("pon"); if (n ==...
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 times(alias pred)(int n) { foreach(i; 0..n) pred(); } auto ...
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 s = sread(); auto t = sread(); if...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp; writeln(n[0] == n[2] ? "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, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} ...
D
import std.stdio; import std.array; import std.conv; void main(){ string[] input = readln.split; int A = input[0].to!int; int B = input[1].to!int; int C = input[2].to!int; int cnt; while(C > 0){ C--; cnt++; if(B > 0){ B--; cnt++; } else if(A > 0){ A--; } else{ break; } } if(B > 0) c...
D
import std.stdio; import std.algorithm; import std.math; import std.conv; import std.string; T readNum(T)(){ return readStr.to!T; } T[] readNums(T)(){ return readStr.split.to!(T[]); } string readStr(){ return readln.chomp; } void main(){ auto n = readNum!int; auto p = readNums!int; int ret; foreach(i...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); int tot = 0; for (int i = 1; i <= n; i += 2) { int k = 2; for (int j = 2; j * j <= i; j++) { if (i % j == 0) k += 2; } if (k == 8) { tot++; } } writeln(tot); } void rd(T...)(ref T ...
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() { long k, a, b; scan(k, a, b); long ans; if (k <= a) { ans = 1; } else if (a <= b) { ans = -1; } else { ...
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 r...
D
import std.stdio; import std.conv; import std.algorithm; import std.range; import std.string; import std.math; import std.format; void main() { foreach (string line; stdin.lines) { auto a = line.chomp.split.map!(to!int).array; auto b = readln.chomp.split.map!(to!int).array; int hit, blow; foreach (i...
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; void main() { int[] vx = [-1, 0, 1, 0]; int[] vy = [0, -1, 0, 1]; while(t...
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(...
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[] group(string s, string t) { int[] gs; ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto X = readln.chomp; int s, r; foreach (c; X) { if (c == 'S') { ++s; } else if (s > 0) { --s; } else { ++r; } } ...
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 nq = readints(); int n = ...
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, std.bitmanip; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto K = s[1]; auto A = readln.split.map!(to!...
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto S = readln.chomp; long[] Ls; long[] Rs; foreach (i; 0..S.length) { if (S[i] == 'L') Ls ~= i; else Rs ~= i; } auto Lss = assumeSorted(Ls); auto Rss = assum...
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 ...
D
void main() { problem(); } void problem() { auto N = scan!int; int countF(int n) { int c; foreach(x; 1..101) { auto tx = x^^2; if (tx > n) break; foreach(y; x..101) { auto ty = tx + y^^2 + x*y; if (ty > n) break; foreach(z; y..101) { auto t = ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nk = readln.split.to!(int[]); auto N = nk[0]; auto K = nk[1]; auto as = readln.split.to!(long[]); long[] cs, ss; cs.length = N; ss.length = N; long s, sx; fore...
D
import std.stdio; import std.conv; import std.array; void main(){ string x = readln.split[0]; if (x == "3" || x == "5" || x == "7"){ writeln("YES"); }else{ writeln("NO"); } }
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto n = readln.strip.to !(int); auto a = readln.splitter.map !(to !(int)).array; bool [int] b; b[a[0]] = true; foreach (i; 1..n) {...
D
import std.stdio; import std.string; import std.conv; int main() { string str; while((str = readln()).length != 0) { int d = str.chomp.to!int; int value = 0,s = 0; while(value != 600-d) { value += d; int line = value*value; s += line * d; } writeln(s); } return 0; }
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(...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!long; if (N%2 == 1 || N <= 10) { writeln(0); } else { long r; N /= 10; while (N) { r += N; N /= 5; }...
D
import std.stdio; import std.algorithm; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() {//try{ auto tokens = split(my_readln()); auto S = to!string(tokens[0]); ulong best = 999; foreach (i; 0..S.length-2) {...
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[] aryread(T = long)(){return r...
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() { char[] s; scan(s); int ans = 100000; ...
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 a, b; readV(a, b); writeln(a...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; import std.range; void main() { auto S = readln.chomp.to!(char[]); auto ni = (iota('a', 'z').chain('z'.only)).find!(c => !S.canFind(c)); ni.empty ? writeln("None") : writeln(ni.front); }
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.c...
D
import std.stdio; import std.algorithm; import std.math; import std.conv; import std.string; T readNum(T)(){ return readStr.to!T; } T[] readNums(T)(){ return readStr.split.to!(T[]); } string readStr(){ return readln.chomp; } void main(){ auto nk = readNums!ulong; auto a = readNums!ulong; a ~= a; ulon...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; int[][10^^5+1] X, Y; bool[10^^5+1] XF, YF; void main() { auto N = readln.chomp.to!int; foreach (_; 0..N) { auto xy = readln.split.to!(int[]); X[xy[0]] ~= xy[1]; Y[xy[1]] ~= xy[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; void main() { auto S = readln.chomp; auto T = S.to!(dchar[]); T.reverse(); S = T.to!string; auto N = S.length.to!int; ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; bool[10^^5] PS; int[10^^5] BS; void main() { auto nm = readln.split.to!(int[]); auto N = nm[0]; auto M = nm[1]; PS[0] = true; foreach (i; 0..N) BS[i] = 1; foreach (_; 0..M) { auto xy ...
D
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm; import std.uni, std.math, std.container, std.typecons, std.typetuple; import core.bitop, std.datetime; immutable long mod = 10^^9 + 7; immutable int inf = mod; void main(){ int n = readln.chomp.to!int; auto a = new int[](n + 1); ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto hw = readln.split.to!(int[]); auto H = hw[0]; auto W = hw[1]; char[][] ss; foreach (_; 0..H) ss ~= readln.chomp.to!(char[]); auto DP = new int[][][](2, H, W); foreach...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { writeln(readln.split.join.to!int % 4 == 0 ? "YES" : "NO"); }
D
// Cheese-Cracker: cheese-cracker.github.io void solve(){ auto n = scan; auto m = scan; long a = n / 3; long b = m / 3; long lefa = n % 3; long lefb = m % 3; long res = lefb * a + lefa * b + min(lefa, lefb) + (a * b * 3); writeln(res); } void main(){ long tests = scan; // To...
D
import std.stdio, std.string, std.conv; void main() { string s = readln.chomp; int K = readln.chomp.to!(int); // s.to!(char[]); char[] ans; foreach (char c; s[0..(s.length - 1)]) { if (c == 'a') { ans ~= c; } else if ('z' - c + 1 <= K) { ans ~= 'a'; K -= 'z' - c + ...
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 hs = readln.chomp.split.to!(int[]); int res; ...
D
import std; void main() { int n, m; scan(n, m); auto hs = readints; auto s = new bool[n]; foreach (_; 0..m) { int a, b; scan(a, b); a--; b--; if (hs[a] <= hs[b]) s[a] = true; if (hs[a] >= hs[b]) s[b] = true; } auto ans = s.count!"!a"; writeln(ans); } void s...
D
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 &&...
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 mod = 10L^^9 + 7; enum inf = 10^^9; void main() { int n; scan(n); string s; scan(s); int q; scan(q); auto k = readln.split.to!(in...
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(...
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; i...
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 - ...
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...
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[])();} ...
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++) { ...
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+...
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 times(alias fun)(int n) { foreach(i; 0..n) fun(); } auto re...
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; int calc(int a, int b, ...
D
import std.stdio; import std.algorithm; import std.math; import std.conv; import std.string; T readNum(T)(){ return readStr.to!T; } T[] readNums(T)(){ return readStr.split.to!(T[]); } string readStr(){ return readln.chomp; } void main(){ auto nk = readNums!int; auto s = readStr; int len = 1, ret; for...
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); } ...
D