code
stringlengths
4
1.01M
language
stringclasses
2 values
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n, r; rd(n, r); auto as = readln.split.to!(int[]); auto bs = new int[](n); foreach (int i, a; as) { if (a) { foreach (int j; max(0, i - r + 1) .. min(n, i + r)) { bs[j]++; } } } if (bs.find(0).length >...
D
import std.stdio; import std.algorithm; import std.conv; import std.string; import std.array; import std.math; void main(){ readln(); int[] monster = readln().chomp.split.map!(to!int).array; int min_mon; while(true){ monster = monster.uniq.array; if(monster.length == 1){break;} min_mon = monster.r...
D
import std.stdio; import std.ascii; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; import std.numeric; void main() { auto k = readln.chomp.to!long; writeln((k/2) * (k - (k/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() { int[4] type; foreach (line; stdin.byLine) { auto st = line.split(","); if (st[1] == "A") type[0]++; ...
D
void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], k = tmp[1]; int[] a = readln.split.to!(int[]); int m = a.countUntil(1).to!int; int l = (m + k - 2) / (k - 1); m = max(m, (k-1)*l); int r = (n - m + k - 3) / (k - 1); writeln(l + r); } import std.stdio; import std.stri...
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){ret...
D
void main() { writeln(readln.chomp.count('9') ? "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; import std.range; import std.array; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.container; import std.typecons; import std.random; import std.math; import core.time; void main() { int n = readln.chomp.to!int; int[] a = 0 ~ readln.chomp.split.map!(to!int...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () ...
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DE...
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() { // 日本語文字列のテスト int w = readint; ...
D
import std.stdio, std.array, std.algorithm, std.string, std.conv, std.math; void main() { int n = readln.chomp.to!int; int[int] chie; auto b = map!(x => x.to!int)(readln.chomp.split); int res = 0; foreach (x; b) { ++chie[x]; } foreach (x, cnt; chie) { if (cnt >= x) { res += min(cnt - x, cnt...
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DE...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = () ...
D
import std.stdio, std.array, std.conv, std.algorithm, std.string, std.numeric, std.range; void main() { auto n = readln.strip.to!int; foreach(i; 0..n){ readln.chomp.replace("Hoshino", "Hoshina").writeln(); } }
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]; int r; while (N) { ++r; N /= K; } 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; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TL...
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() { readln; auto p = readln.chomp.split.map!(to!int).array; int cnt; foreach (i; 0...
D
import core.bitop; import std.algorithm; import std.ascii; import std.bigint; import std.conv; import std.functional; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.random; import std.typecons; import std.container; ulong MOD = 1_000_000_007; ulong INF = 1_000_00...
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.string; const int[] dr = [0, 0, 1, -1]; const int[] dc = [1, -1, 0, 0]; void main() { auto s = readln.split.map!(to!int); ...
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; import std.string; import std.conv; immutable MAX_INPUT = 1000; immutable MAX_COUNT = 1000; int main(string[] argv) { int Count; string[] Ans; Count = readln().chomp().to!int(); if(Count <= MAX_COUNT){ for(int i = 0;i < Count;i++){ string[] tmp = readln().chomp().split(" "); int[3] ...
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
void main() { auto N = ri, A = ri; (N % 500 <= A ? "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.bigint; import std.numeric; import std.conv; import std.type...
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.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; alias Pair = Tuple!(int, "a", int, "b"); void main() { ...
D
//dlang template---{{{ import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; import std.typecons; import std.math; import std.range; // MIT-License https://github.com/kurokoji/nephele class Scanner { import std.stdio : File, stdin; import std.conv : to; import std.array : ...
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.conv, std.functional, std.string; import std.algorithm, std.array, std.container, 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....
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DE...
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.conv; import std.math; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto s = readln.strip; int res = s.length.to !(int); int a = 0, b = 0; foreach (c; s) { if (c == 'A') { a ...
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; 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(); long ok = (N + 1); long ng = -1; while...
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.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; if (n[0] == n[2]) { writeln("Yes"); } else { writ...
D
import std.stdio; import std.conv; import std.array; void main() { auto reader = readln.split; int A = reader[0].to!int; int B = reader[1].to!int; int C = reader[2].to!int; if ((A < C && C < B) || (A > C && C > B)) writeln("Yes"); else writeln("No"); }
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto p = readln.chomp.split.to!(int[]); int cnt; ...
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.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 s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto edges = new int[][](N...
D
// import chie template :) {{{ import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv, std.range, std.container, std.bigint; // }}} void main() { bool[101010] e; e[2 .. 101010] = true; e[0 .. 2] = false; foreach (i; 2 .. 101010) { ...
D
void main() { long n, a, b; rdVals(n, a, b); long result = modPow(2, n) - 1; long fa = 1, fb = 1; foreach (i; 0 .. b) { if(i < a) fa = fa * (n - i) % mod; fb = fb * (n - i) % mod; } long[] finv = new long[b+1]; long[] inv = new long[b+1]; finv[0] = 1, finv[1] =...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.functional, std.math, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container; ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000; alias sread = () => readln.chomp(); alias lread(T = long) = (...
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 N = S.length.to!int; int ans = 0; for (int p = 0, q = N-1; p < q; ) { if ...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math : abs; import core.stdc.stdlib : exit; void main() { auto A = to!int(split(readln())[0]); auto B = to!int(split(readln())[0]); auto C = to!int(split(readln())[0]); auto D = to!int(split(readln())[0]); writeln( (A < B ? A...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto s = new char[][](2, n); foreach (i; 0 .. 2) s[i] = readln.chomp.to!(char[]); const long mod = 10 ^^ 9 + 7; auto dp = new long[][](2, n); if (s[0][0] == s[1][0]) dp[0][0] += 3; else dp[1][1] += 6; fo...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); if (n % 3 < 2) { writeln(1, " ", 1, " ", n - 2); } else { writeln(1, " ", 2, " ", n - 3); } } void rd(T...)(ref T x) { import std.stdio, std.string, std.conv; auto l = readln.split; assert(l.length == x.lengt...
D
import std.stdio, std.string, std.array, std.conv; void main() { int[][][] bld = new int[][][](4, 3, 10); int n = readln.chomp.to!int; foreach (i; 0 .. n) { int[] tmp = readln.chomp.split.to!(int[]); int b = tmp[0], f = tmp[1], r = tmp[2], v = tmp[3]; bld[b-1][f-1][r-1] += v; } ...
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.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 N = readln.chomp.to!int; auto A = readln.split.map!(to!long).array; long hi = 10^^9; long lo = -(10^...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a = new int[](n); foreach (i; 0 .. n) rd(a[i]); bool[int] map; foreach (e; a) { if (e in map) map.remove(e); else map[e] = true; } writeln(map.length); } void rd(T...)(ref T x) { import...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { auto s = readln.chomp; auto y = new int[s.length]; int begin, i; char mode = 'R'; foreach(c; s) { if (c != mode && mode == 'R') { y[i-1] += (i-begin+1)/2; y[i] += (i-begin+1)/2 + (i-begin+1)%2; begin = i; mode ...
D
void main() { long n, k; rdVals(n, k); long[] h = rdRow; long[] dp = new long[n]; dp[] = inf; dp[0] = 0; foreach (i; 1 .. n) { foreach (j; 1 .. k+1) { if (i - j < 0) break; dp[i] = min(dp[i], dp[i-j]+abs(h[i-j]-h[i])); } } dp[n-1]...
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.string; import std.algorithm; void main() { int n; scanf("%d\n", &n); int incl, lb, ra, half; for(size_t i;i < n; ++i){ auto l = readln.chomp; incl += l.count("AB"); auto b = l[0] == 'B'; auto a = l[$-1] == 'A'; if (a) ++ra; if (b) ++lb; if ((a || b) && (a != b)) ++half; ...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a = readln.split.to!(int[]); int o, t, f; foreach (e; a) { if (e % 4 == 0) f++; else if (e % 2 == 0) t++; else o++; } t %= 2; o += t; if (o <= f + 1) { writeln("Yes"); } else...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { char[] r; foreach (c; readln.chomp) { if (c == '?') { r ~= 'D'; } else { r ~= c; } } writeln(r); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto X = readln.chomp.to!int; writeln(X == 7 || X == 5 || X == 3 ? "YES" : "NO"); }
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 ...
D
void main() { auto N = readAs!ulong; ulong a = 0; if(N % 2 == 1) { writeln(0); return; } for(ulong i = 10; N >= i; i *= 5) a += N / i; a.writeln; } // =================================== import std.stdio; import std.string; import std.functional; import std.algorithm; import std.range; import std.traits; im...
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() { string s; readV(s); auto r = 10...
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.stdlib; immutable int INF = 1 << 29; void main() { auto N = readln.chomp.to!int; auto A = readln.split.map!(to!long).arra...
D
import std.stdio; import std.range; import std.array; import std.algorithm; import std.string; void main(){ auto input_1 = readln.chomp; auto input_2 = readln.chomp; auto input_3 = readln.chomp; auto answer = "" ~ input_1[0] ~ input_2[1] ~ input_3[2]; writeln(answer); }
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; void main() { auto N = readln.chomp.to!int; auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array; bool ok = true; ...
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; // }}} // tbh.scanner {{{ class Scanner { import std.stdio; import std.conv ...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int q; rd(q); while (q--) { long n, a, b; rd(n, a, b); auto ans = n * a; if (n & 1) { ans = min(ans, n / 2 * b + a); } else { ans = min(ans, n / 2 * b); } writeln(ans); } } void rd(T...)(ref T x) { ...
D
void main() { auto S = rs; auto N = S.length; auto arr = new int[](N); arr[0] = 1; foreach(i; 0..N-1) arr[i+1] = (10*arr[i]) % 2019; debug arr.writeln; int[int] m; int tmp = S[$-1] - '0'; m[tmp]++; foreach(i; 0..N) { tmp = tmp + arr[i] * (S[$-i-1] - '0'); debug tmp.writeln; tmp %= 2019; m[tmp]++; } ...
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() { long n, m; scan(n, m); auto 杯 = new long[](n); 杯[] = 1; ...
D
import std.stdio; import std.string; void main(){ writeln(toUpper(chomp(readln()))); }
D
import std.stdio; void main() { foreach (i; 0..1000) { writeln("Hello World"); } }
D
import std.stdio; import std.range; import std.array; import std.algorithm; import std.string; import std.conv; void main(){ immutable n = readln.chomp.to!int; auto d_x = readln.chomp.split.map!(to!int); auto days = d_x[0]; auto rest = d_x[1]; int[] as; as.length = n; as.each!((ref a){ ...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; void main(){ auto Q=readln.split.to!(int[]),r=Q[0],g=Q[1],b=Q[2]; if((100*r+10*g+b)%4==0)writeln("YES"); else writeln("NO"); }
D
import std.stdio, std.conv, std.string, std.algorithm, std.range; void main() { auto N = readln.split[0].to!int; auto A = readln.split.to!(int[]); auto B = readln.split.to!(int[]); auto C = readln.split.to!(int[]); int result = 0; int before = -1; foreach(a; A) { result += B[a - 1]; if (before !...
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; void main() { auto s = readln.chomp.to!(char[]); int k; scan(k); in...
D
import std.stdio; void main() { writeln("ABC" ~ readln()); }
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_r...
D
import std.stdio, std.conv, std.string, std.algorithm, std.array; void main() { int n, m; scanf("%d %d", &n, &m); int[] map; map.length=n; for (int i = 0; i < m; i++) { int from, to; scanf("%d %d", &from, &to); from--; ...
D
import std.stdio; import std.algorithm; import std.math; import std.conv; import std.string; import std.numeric; T readNum(T)(){ return readStr.to!T; } T[] readNums(T)(){ return readStr.split.to!(T[]); } string readStr(){ return readln.chomp; } void main(){ auto input = readNums!long; auto a = input[0], b...
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(...
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 S = readln.chomp; auto K = readln.chomp.to!int; auto N = S.length.to!int; auto dp = new...
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.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; bool calc(string s) { ...
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, t; readV(a, b, t); wri...
D
import std.algorithm; import std.array; 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 main() { int k; scan(k); auto a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2...
D
void main() { long n = rdElem; void dfs(string s, long len, long cnt) { if (len == n) { s.writeln; return; } foreach (i; 0 .. cnt+2) { long num = max(cnt, (s[len-1] - 'a') + 1); if (i <= num) dfs(s~lowercase[i], len+1,...
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, 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() { string s; readV(s); auto c1 = s...
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; struct Spl{auto r="".splitter;auto rd(){r=readln.splitter;}auto bd(T)(ref T t){t=r.front.to!T;r.popFront;}} auto _s = Spl(); auto getV(T...)(ref T t){foreach(ref u;t)_s.bd(u);} auto getA(T)(size_t n,ref T t){t=new ...
D
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); } voi...
D
import std.stdio, std.string, std.algorithm, std.array; void main() { int t; scanf("%d", &t); getchar(); foreach(i; 0..t){ int n, s; scanf("%d %d", &n, &s); auto num_zero = (n - 1) / 2; writeln(s / (n - num_zero)); } }
D
import std.stdio; import std.conv; import std.algorithm; import std.string; int main(string[] args) { uint i; uint[] hills; hills.length = 10; uint t; string buf; uint count = 0; while ((buf = readln()) != null) { hills[count] = to!(uint)(strip(buf)); count++; } sort!("a > b")(hills); for ...
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.string; import std.uni; import std.range; import std.algorithm; void main() { size_t k = 0; auto c = readln.strip.toLower; while (!stdin.eof) { auto a = readln.strip.toLower; if (a == "END_OF_TEXT") ...
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 bignu...
D
void main() { long k, a, b; rdVals(k, a, b); long diff = k - a + 1; long c = a + (b - a) * (diff / 2) + diff % 2; max(k+1, c).writeln; } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string;...
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.algorithm, std.conv, std.range, std.stdio, std.string; import std.math; // math functions void main() { auto n = readln.chomp.to!size_t; auto a = readln.split.to!(long[]); auto c1 = new long[](n), c2 = new long[](n); c1[0] = a[0]; foreach (i; 1..n) c1[i] = a[i] + c1[i-1]; c2[n-1] = a[n-1...
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; import core.stdc.stdlib; void main() { auto M = scanElem; auto K = scanElem; if(K >= pow(2, M)){ writeln(-1); ...
D
import std.stdio, std.conv, std.array,std.string,std.algorithm; void main() { auto input=readln.split; writeln(max(input[0].to!int*input[1].to!int,input[2].to!int*input[3].to!int)); }
D
void main() { long[] tmp = readln.split.to!(long[]); long x = tmp[0], y = tmp[1]; writeln(log2(y/x).to!long + 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...
D