code
stringlengths
4
1.01M
language
stringclasses
2 values
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.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; immutable inf = 10^^9 + 7; void main() { int n; scan(n); bool[] p = [true, true, false]; foreach (i ; 0 .. n) { int win; scan(win); ...
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.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; 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!T;r.popFro...
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; string s; void main() { scan(s); if (s.canFind('N') == s.canFind('S') && s.canFind('W') == s.canFind('E')) { ...
D
import std.stdio; import std.array; import std.algorithm; import std.conv; import std.numeric; import std.string; void main() { auto s = readln.chomp; auto t = new int[4]; foreach (i, j; s) { t[i] = j.to!int - '0'.to!int; } foreach(i; 0..2) { foreach(j; 0..2) { foreach(k; 0..2) { int a...
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() { int N; scan(N); auto a = readln.split.to!(long[]); au...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto ks = readln.split.to!(int[]); auto K = ks[0]; auto S = ks[1]; int r; foreach (i; 0..K+1) { foreach (j; 0..K+1) { auto k = S - i - j; if (0 <= k &...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { long n; scan(n); long ans = 100000; while (n > 0) { ans = min(ans, abs(753 - n % 1000)); n /= 10; } writel...
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() { int N; scan(N); int ans; foreach (i ; 0 .. N) { int li, ri; scan(li, ri); ans += ri - li + 1; } writeln(ans); } vo...
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 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; enum MAX = 1_000_100; ulong MOD = 1_000_000_007...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.uni; // unicode void main() { auto s = readln.split; writeln(s.map!"a[0]".array.toUpper); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; bool check(const char[] arr) { auto p = arr[0]; foreach (e; arr[1..$]) { if (p != e) return false; } return true; } void main() { auto s = readln.chomp; if (check(s)) { writeln(0); return; } aut...
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.split.to!(int[]); auto ab = s[0] * s[1]; auto f = false; ...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { string s = readln.chomp; int w = readln.chomp.to!(int); string ans = ""; for (int i = 0; i < s.length; i += w) { ans ~= s[i]; } writeln(ans); }
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 { ...
D
import std.conv; import std.stdio; import std.array; import std.range; import std.string; import std.algorithm; void main() { int sum = 0; foreach(_; 0..10) { sum += readln().chomp().to!int; } writeln(sum); }
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, 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.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, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!int; writeln("ABC", n); }
D
void main() { problem(); } void problem() { auto A = scan!long; auto B = scan!long; auto C = scan!long; auto K = scan!int; bool solve() { foreach(p; [0,1,2].permutationsWithRepetitions(K)) { auto a = A; auto b = B; auto c = C; foreach(_; 0..p.count(0)) a *= 2; foreach(_; ...
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional; void main() { auto S = readln.chomp.dup; bool po() { if (S[0] != 'A') return false; if (S[2..$-1].count('C') != 1) return false; foreach (i; 2..S.length-1) { ...
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!int; auto S = readln.chomp; auto Q = readln.chomp.to!int; auto ks = readln.split.to!(int[]); foreach (k; ks) { long res; auto ms = new long[...
D
import std.stdio, std.array, std.conv, std.typecons, std.algorithm, std.numeric, std.bigint; T diff(T)(const T a, const T b) { return a > b ? a - b : b - a; } T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } T[] readToArray(T)() { return readln.split.to!(T[]); } void main() { const i...
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nkc = readln.split.to!(int[]); auto N = nkc[0]; auto K = nkc[1]; auto C = nkc[2]; auto S = readln.chomp; int[] ls, rs; ls.length = N; ls[] = -1; rs.length = N; ...
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void readC(T...)(size_t n,ref T t){foreach(ref v;t)...
D
void main(){ char alph = _scan!char(); ( ('a'<=alph && alph<='z') ? 'a' : 'A').writeln(); } 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(...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp.to!(char[]); int X = 700; if (S[0] == 'o') X += 100; if (S[1] == 'o') X += 100; if (S[2] == 'o') X += 100; writeln(X); }
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 ...
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 T = readln.chomp.to!int; auto A = readln.split.map!(to!long).array; foreach (a; A) { ...
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; int p; bool ok(int s) { int i = s / 50 % 475; foreach (_; 0..25) { i = (i * 96 + 42) % 475; if (26 + i == p) return...
D
import std.stdio, std.algorithm, std.conv, std.string; enum arrow { L,R,U,D }; void main(){ int n = readln.chomp.to!int(); const arrow[dchar] toArrow = [ 'L':arrow.L, 'R':arrow.R, 'U':arrow.U, 'D':arrow.D ]; foreach(i; 0..n){ auto score = readln.chomp.map!(a=>toArrow[a])(); writeln(score.isNatural? "Yes": "No...
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, std.regex; void main() { auto N = readln.chomp.to!int; auto G = new int[][](N); foreach (_; 0..N-1) { auto...
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); writeln((s[0...
D
import std.stdio, std.conv, std.math, std.string, std.range, std.array, std.algorithm; void main(){ auto buf = readln().strip().split().map!(to!int)(); immutable N = buf[0]; auto a = readln().strip().split().map!(to!int)(); long[long] m; long ans; long shift; foreach(ea; a) { ...
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; void main() { int n...
D
void main() { auto W = rs; ulong cnt; while(true) { auto s = rs; if(s == "END_OF_TEXT") break; foreach(v; s.split) { if(v.toLower == W.toLower) cnt++; } } cnt.writeln; } // =================================== import std.stdio; import std.string; import std.functional; import std.algorithm; import std....
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, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto abck = readln.split.to!(long[]); auto A = abck[0]; auto B = abck[1]; auto C = abck[2]; auto K = abck[3]; long r; if (K > 0) { r += min(K, A); K -= min(K...
D
void main() { long n = rdElem; long[] a = n.rdCol; writeln(a.any!"a & 1" ? "first" : "second"); } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; T rdElem(T = long)() if (!is(T == struct)) { return readln.chomp.to!T; } alias rdStr = rdElem!string; alias rdDchar = rdElem!(dchar[]); T rdElem(T)(...
D
import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } void main(){ auto s = readl...
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; auto A = readln.chomp.to!long; auto B = readln.chomp.to!long; auto C = readln.chomp.to!long; auto D = readln.chomp.to!long; auto E = readln.chomp.t...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(int[]), n = rd[0], c = rd[1]; struct Program { int s, t, c; } auto p = new Program[](n); bool[int][int] h; foreach (i; 0..n) { auto rd2 = readln.splitter; auto si = rd2.front.to!int; rd2.popFro...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; enum P = 998244353L; void main() { auto abcd = readln.split.to!(long[]); auto A = abcd[0]; auto B = abcd[1]; auto C = abcd[2]; auto D = abcd[3]; auto DP = new long[]...
D
// Vicfred // https://atcoder.jp/contests/dp/tasks/dp_a import std.algorithm; import std.math; import std.array; import std.conv; import std.stdio; import std.string; void main() { const int n = readln.chomp.to!int; const int[] h = readln.split.map!(to!int).array; int[] dp = new int[n]; dp[1] = abs(h...
D
import std.algorithm; import std.concurrency; import std.container; import std.conv; import std.functional; import std.math; import std.meta; import std.random; import std.range; import std.stdio; import std.string; import std.traits; import std.typecons; void main() { auto input = readln.chomp.split.map!(to!long...
D
import std.stdio; import std.string; import std.conv; void main(){ int x = readln().chomp().to!int(); writeln(x * x * x); }
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int n, k; scan(n, k); auto w = new int[][][](2, k, k); foreach (i ; 0 .. n) { int xi, yi; char ci; scan(xi, yi, ci); if (ci == 'B') yi += k; int e = (xi / k % 2 ...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(int[]), x = rd[0], t = rd[1]; writeln(max(x-t, 0)); }
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, 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 edges = new int[][](N); foreach (i; 0..N-1) { auto s = readln.split.ma...
D
import std.stdio; import std.algorithm; import std.string; import std.functional; import std.array; import std.conv; import std.math; import std.typecons; import std.regex; import std.range; void main(){ int n = readln().chomp().to!int; int[101][101] mat; int[][] num; num ~= new int[n+1]; for(int ...
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 a = aryread!string(); // writeln(a); writeln(a[0][0], a...
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_...
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 core.stdc.stdio; import std.algorithm; void main(){ int[] map = new int[100000]; int[] t = new int[10000]; while(1){ int r,c; scanf("%d%d",&r,&c); if(r==0&&c==0) break; t[] = 0; for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ scanf("%d",&map[i*c+j]); t[j] += 1-map[i*c+j]...
D
void main() { int[] tmp = readln.split.to!(int[]); int a = (tmp[0] + 13) % 15, b = (tmp[1] + 13) % 15; if (a > b) { "Alice".writeln; } else if (a < b) { "Bob".writeln; } else { "Draw".writeln; } } import std.stdio; import std.string; import std.array; import std.conv; 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 readA(T)(size_t n,ref T[]t){t=new T[](n);auto ...
D
void main(){ int a, b; scanf("%d %d", &a, &b); int ans = (a + b)%24; ans.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 = ...
D
void main() { long n = rdElem; Edge[][] edge = new Edge[][](n); foreach (i; 0 .. n-1) { long a, b; rdVals(a, b); --a, --b; edge[a] ~= Edge(b, i), edge[b] ~= Edge(a, i); } long[] list = new long[n-1]; list[] = -1; void dfs(long x, long from, long color) ...
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 n, l; { long[] tmp = readln.chomp.split.map!(to!long).array; n = tmp[0], l = tmp[1]; } long[] as = readln.chomp.split.map!(to!long).array; st...
D
import std.stdio; import std.array; import std.conv; import std.algorithm; import std.string; void main(){ int totalTime = 0; for(int i = 0; i < 4; i++){ totalTime += readln().chomp().to!int(); } writeln(totalTime / 60); writeln(totalTime % 60); }
D
import std.functional, std.algorithm, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv; class UnionFind { long[] data; this (size_t size) { data.length = size; foreach (ref e; data) { e = -1; } } void unite...
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.conv, std.range, std.stdio, std.string; void main() { auto s = readln.chomp; writeln(s[1] == s[2] && (s[0] == s[1] || s[2] == s[3]) ? "Yes" : "No"); }
D
import std.stdio; import std.conv; import std.string; import std.format; import std.algorithm; //string lines = q"[ //abcdeffg]"; void main() { string lines; string buf; while (!stdin.eof) { buf = stdin.readln(); lines ~= buf; } string[] array = splitLines(lines); int N = array[0].split(" "...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int y, b, r; scan(y, b, r); int ans = 0; foreach (i ; 1 .. y + 1) { foreach (j ; 1 .. b + 1) { foreach (k ; 1 ....
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { auto tmp = readln.split.to!(int[]); writeln(tmp[0] * tmp[1] / 2); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; enum P = 10L^^9+7; void main() { auto N = readln.chomp.to!int; auto AS = readln.split.to!(long[]); long x, r; foreach (a; AS) { (r += x * a % P) %= P; (x +=...
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 N = scanElem; auto X = scanElem; auto a = X; auto b = N-X; long res = a+b; if(a>b)...
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; writeln(s[0..4], " ", s[4..$]); }
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 = 998244353; const int INF = 1 << 29; void main() { auto N = readln.chomp.to!int; auto S = N.iota.map!...
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, 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_...
D
void main() { long n = rdElem; Edge[][] tree = new Edge[][](n); foreach (i; 0 .. n-1) { long a, b, c; rdVals(a, b, c); --a, --b; tree[a] ~= Edge(b, c), tree[b] ~= Edge(a, c); } long q, k; rdVals(q, k); --k; long[] dist = new long[n]; void DFS(lo...
D
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional; void main(){ (readln().chomp.isHaiku?"YES":"NO").writeln(); } auto isHaiku(string str){ return ["5 7 5", "7 5 5", "5 5 7"].canFind(str); }
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { const N = readln.chomp.to!long; const S = readln.chomp; const K = readln.chomp.to!long; S.map!(c => c != S[K-1] ? "*" : [c]).join.writeln; }
D
void main(){ int n = _scan(); string s = readln().chomp(); writeln( s[0..n/2] == s[n/2..$]? "Yes": "No" ); } 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(s...
D
import std.stdio; import std.conv; import std.string; void main(){ // input int[] input; for(auto i = 0; i < 3; i++){ input ~= to!int(readln().chomp()); } immutable int start_money = input[0]; immutable int a_price = input[1]; immutable int b_price = input[2]; immutable int answer = (start_money - a_pric...
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void readC(T...)(size_t n,ref T t){foreach(ref v;t)...
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
import std.stdio: readln, writeln; import std.string: chomp, split; import std.conv: to; void main() { auto dataSet = chomp(readln()).split(" "); int m = to!int(dataSet[0]), f = to!int(dataSet[1]), r = to!int(dataSet[2]); while(1 + m || 1 + f || 1 + r) { if(0 == (1 + m) * (1 + f...
D
void main() { long n, m; ipElems(n, m); long[] burger = new long[n+1], patty = new long[n+1]; burger[0] = patty[0] = 1; foreach (i; 0 .. n) { burger[i+1] = 2 * burger[i] + 3; patty[i+1] = 2 * patty[i] + 1; } long countPatty(long l, long y) { if (l == 0) retu...
D
import std.stdio; import std.algorithm; import std.string; import std.range; import std.array; import std.conv; import std.complex; import std.math; import std.ascii; import std.bigint; import std.container; import std.typecons; auto readInts() { return array(map!(to!int)(readln().strip().split())); } auto readInt() ...
D
import std.stdio, std.conv, std.string; import std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } int DEBUG_LEVEL = 0; void pr...
D
import std.stdio, std.string, std.conv; void main() { int[] tmp = readln.split.to!(int[]); int n = tmp[0], k = tmp[1]; long mod = 1_000_000_007; long[] fac = new long[n+1]; long[] finv = new long[n+1]; long[] inv = new long[n+1]; fac[0] = 1, fac[1] = 1; finv[0] = 1, finv[1] = 1; inv...
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 A = data[0].to!long, B = data[1].to!long; long f(long n) { switch(n%4) { case 0: return n; case 1: return 1; case 2: return 1+...
D
import std.stdio; int main(string[] argv) { for(int i = 1;i <= 9;i++){ for(int j = 1;j <= 9;j++){ writeln(i,"x",j,"=",i*j); } } return 0; }
D
import std.stdio; void main(string[] args) { foreach(int i ; 1..10) { foreach(int j; 1..10) { writeln(i,"x",j,"=",i*j); } } }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; import std.range; import std.regex; void main(){ auto z=readln.split.to!(int[]),a=z[0],b=z[1]; writeln(a*b-(a+b-1)); }
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; void main() { int x; scan(x); auto ans = (x / 500) * 1000 + (x % 500) / ...
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; void main() { readi...
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, std.format, std.math; void main() { auto n = readln.chomp.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