code
stringlengths
4
1.01M
language
stringclasses
2 values
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; int c; foreach (i; 0..N-2) { if (S[i..i+3] == "ABC") ++c; } writeln(c); }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto nm = readln.split.to!(int[]); auto N = nm[0]; auto M = nm[1]; auto MAP = new char[][](N.to!size_t, M.to!size_t); foreach (i; 0..N) foreach (j, c; readln.chomp) MAP[i][j] = c; ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; enum A = "AKIHABARA"; void main() { auto S = readln.chomp; size_t i, j; while (i < S.length && j < A.length) { if (S[i] == A[j]) { ++i; ++j; } else if (A[j] == 'A') { ...
D
import std.stdio; import std.conv; import std.string; int main() { string str = chomp(readln); int val = to!(int)(str); int h = val/3600; val %= 3600; int m = val/60; val %= 60; int s = val; writeln(h, ":", m, ":", s); return 0; }
D
/+ dub.sdl: name "C" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); int[3] x; sc.read(x); x[].sort!"a%2<b%2"; int an...
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() { string s; scan(s); int n = s.length.to!int; auto a = new int[](n + 1); foreach (i ; 0 .. n) { a[i + 1] = a[i] ^ (1<<(s[i] - 'a')); } ...
D
import std.stdio; import std.array; import std.math; import std.conv; void main(){ string str; while((str = readln()).length != 0){ string[] input = split(str); int a = to!int(input[0]); int b = to!int(input[1]); writeln(digit(a + b)); } } uint digit(in int num){ if(num <= 0) return 0; else return cast...
D
import std.conv, std.stdio; import std.algorithm, std.array, std.range, std.string; import std.numeric; void main() { auto buf = readln.chomp.split.to!(int[]), b = readln.chomp.split.to!(int[]); size_t answer; foreach (i; 0..buf[0]) if (-buf[2] < readln.chomp.split.to!(int[]).dotProd...
D
/+ dub.sdl: name "C" 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); int n, m, q; sc.read(n, m, q); int Y = n*2 - 1; int X = m*2 - 1; int[][] mp = new i...
D
import std.stdio; import std.algorithm; import std.array; 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 N = to!ulong(tokens[0]); ulong[] a, b, c; foreach (i; 0...
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.string, std.ascii; void main() { string s = readln.chomp; writeln( (s.length >= 6 && s.count!(isDigit) >= 1 && s.count!(isUpper) >= 1 && s.count!(isLower) >= 1) ? "VALID" : "INVALID" ); }
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
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; long P = 10^^9+7; long[10^^6*2+50] F, RF; long pow(long x, long n) { long y = 1; while (n) { if (n%2 == 1) y = (y * x) % P; x = x^^2 % P; n /= 2; } return y; } long inv(long...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { long n, m; scan(n, m); if (n > m) swap(n, m); if (n == 1 && m == 1) { writeln(1); } else if (n == 1) { writeln(m - 2); } else { writeln((n-2)*(m-2)); } } vo...
D
import std.stdio; import std.conv; import std.array; import std.string; import std.algorithm; void main() { int n; n = to!int(chomp(readln())); int res = 0; for(int i = 0; i < n; i++) { string [] t; int l, r; t = chomp(readln()).split(); l = to!int(t[0]); r = to!int(t[1]); res += r-l+1; } writeln(r...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; int N, M; string[100] NS, MS; void main() { N = readln.chomp.to!int; foreach (i; 0..N) NS[i] = readln.chomp; M = readln.chomp.to!int; foreach (i; 0..M) MS[i] = readln.chomp; auto ns = NS[0..N]; auto ms =...
D
void main() { long n = readln.chomp.to!long; long[] a = readln.split.to!(long[]); long mod = 10 ^^ 9 + 7; long total; foreach (i; 0 .. 61) { long cnt; foreach (j; 0 .. n) { if ((1L << i) & a[j]) ++cnt; } long mul = (1L << i) % mod; mu...
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
/+ 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 calc(char[] s, char mas) { int n = s.length.to!int; if (s.count(mas) == n) return 0; char[] t = new char[n-1]; foreach (i; 0..n-1) {...
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.algorithm, std.conv, std.array, std.string; int[500] CS; int[500] SS; int[500] FS; void main() { auto N = readln.chomp.to!int; foreach (i; 0..N-1) { auto csf = readln.split.to!(int[]); CS[i] = csf[0]; SS[i] = csf[1]; FS[i] = csf[2]; } foreach (s; ...
D
void main() { long i, o, t, j, l, s, z; rdVals(i, o, t, j, l, s, z); long k = o; if (i && j && l && (i & 1) + (j & 1) + (l & 1) >= 2) { k += 3; --i, --j, --l; } k += i / 2 * 2; k += j / 2 * 2; k += l / 2 * 2; k.writeln; } enum long mod = 10^^9 + 7; enum long in...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; void main() { string str = readln(); write(toUpper(str)); }
D
import std.stdio; void main(){ int n = 1000; while(n--) writeln("Hello World"); }
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; 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.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.algorithm, std.range, std.conv, std.string, std.math; import core.stdc.stdio; // foreach, foreach_reverse, writeln void main() { int n; scanf("%d", &n); int[] a = new int[n]; int[] b = new int[n]; bool same = true; foreach (i; 0..n) { scanf("%d%d", &a[i], &b[i]); if (a[i] != b[i]) same...
D
import std; enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;} T scan(T=long)(){return readln.chomp.to!T;} void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;} T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);} //END OF TEMPLATE void main(){ ulong n; u...
D
void main() { auto N = ri; auto S = rs; auto arr = new int[](N); arr[0] = S[0] == '.' ? 1 : 0; foreach(i; 1..N) arr[i] = S[i] == '.' ? 1 + arr[i-1] : arr[i-1]; ulong res = S.count('.'); foreach(i; 0..N) { res = min(res, (i+1 - arr[i]) + arr.back - arr[i]); } res.writeln; } // ===============================...
D
import std.stdio; import std.string; void main() { string ans = "WA"; char[] s = readln.strip.dup; if (s[0] == 'A') { ulong c = 0; foreach(i, e; s[0..$ - 1]) { if (e == 'C' && i > 1) { c = i; break; } } if (c > 1) { ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; alias C = Tuple!(int, "size", int, "p"); void solve(int N, int M) { auto CS = new int[](N); foreach (s; readln.split.to!(int[])[1..$]) CS[s-1] = 0; foreach (s; readln.split.to!(int[])[1..$]) CS[s-1] = 1;...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto l = readln.split.to!(long[]); auto A = l[0]; auto B = l[1]; auto C = l[2]; auto D = l[3]; auto n = B/C + B/D - B/(C*D/gcd(C,D)); auto m = (A-1)/C + (A-1)/D - (A-1)/(C*D...
D
import std.stdio,std.conv,std.string,std.array; void main(){ auto x=readln.chomp.split; int a = to!int(x[0]), b = to!int(x[1]); if(a<b){writeln("a < b");} if(a>b){writeln("a > b");} if(a==b){writeln("a == b");} }
D
import std.stdio, std.string, std.algorithm, std.range, std.conv, std.math; void main() { auto NK = readln.chomp.split.map!(to!int); auto N = NK[0]; auto K = NK[1]; (K * pow(K - 1, N - 1)).writeln; }
D
import std.stdio; import std.string; import std.range; //standard input/output void main() { auto S = readln.chomp; int res = 700; if(S[0] == 'o') res += 100; if(S[1] == 'o') res += 100; if(S[2] == 'o') res += 100; writeln(res); /* int res = 700; foreach(i; S) if(i == 'o') res += 100; writeln(res); */ /...
D
import std.string; import std.stdio; import std.conv; import std.algorithm; import std.range; int n,s; long[1001][11] dp; void main(){ dp[0][0] = 1; for(int i=0;i<=100;i++){ for(int j=9;j>=1;j--){ for(int k=0;k<=1000;k++){ if(0<=i+k&&i+k<=1000) dp[j][i+k] += dp[j-1][k]; } } } whil...
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 S = N.iota.map!(_ => readln.chomp).array; auto trie = new Tri...
D
void main() { string n = rdStr; long len = n.length; long total; foreach (x; n) { total += x - '0'; } max(total, (n[0]-'1')+9*(len-1)).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; } ali...
D
void main() { long n, q; rdVals(n, q); bool[] ball = new bool[n]; ball[0] = ball[1] = true; long now; foreach (i; 0 .. q) { long a, b; rdVals(a, b); --a, --b; if (now == a) now = b; else if (now == b) now = a; swap(ball[a], ball[b]); 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.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; import std.container : DList; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads...
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 i = readNums!int; writeln(i.sum - i.reduce!max); }
D
void main() { problem(); } void problem() { auto N = scan!ulong; ulong solve() { // Sum_{k=1..n} k/2 * floor(n/k) * floor(1 + n/k) ulong ans; foreach(k; 1..N+1) { ulong x = N / k; ans += x * (2*k + (x - 1) * k) / 2; } return ans; } solve().writeln; } // --------------------...
D
void main() { auto N = ri; auto A = N.iota.map!(v => ri).array; auto arr = new int[](N), arr2 = new int[](N); arr[0] = A[0]; arr2[$ - 1] = A[$ - 1]; foreach(i; 1..N) { arr[i] = max(arr[i-1], A[i]); } foreach_reverse(i; 0..N-1) { arr2[i] = max(arr2[i+1], A[i]); } debug arr.writeln; debug arr2.writeln; wr...
D
void main() { int[] tmp = readln.split.to!(int[]); int x = tmp[0], a = tmp[1], b = tmp[2]; if (a - b >= 0) { "delicious".writeln; } else if (a - b + x >= 0) { "safe".writeln; } else { "dangerous".writeln; } } import std.stdio; import std.string; import std.array; import ...
D
import std.stdio, std.conv, std.string, std.math, std.algorithm; void main(){ auto ip = readln.split.to!(int[]); if(ip[1] - ip[0] == ip[2] - ip[1]) "YES".writeln; else "NO".writeln; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; void main() { int[] buf = readln.chomp.split.to!(int[]); int a = buf[0], b = buf[1]; int ans = a - 1 + (a <= b ? 1 : 0); writeln(ans); }
D
/+ dub.sdl: name "C" 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); int n, m; int[] a; sc.read(n, m, a); a[] -= 1; int[] cnt = new int[n]; a.each!(x => cnt[x...
D
import std.stdio; import std.string; import std.conv; import std.range; import std.array; import std.algorithm; void main() { string input = "4823108376"; while ((input = readln.chomp).length != 0) { while (input.length > 1) { string output; for (int i = 0; i < input.length-1; ...
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() { long n, a, b, c, d, e; scan(n);scan(a);scan(b)...
D
unittest { assert( [ "01B0" ].parse.expand.solve == "00" ); assert( [ "0BB1" ].parse.expand.solve == "1" ); } import std.conv; import std.range; import std.stdio; import std.typecons; void main() { stdin.byLineCopy.parse.expand.solve.writeln; } auto parse( Range )( Range input ) if( isInputRange!Range && is( El...
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 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.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.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; void main() { auto z = readln.strip.splitter.map! (i => i.to!int).array; int h = z[0]; int w = z[1]; string [] a = new string[h]; foreach (t; 0 .. h) { a[t] = readln[0 .. w]; ...
D
import std.stdio; import std.conv; import std.string; void main() { string input = chomp(readln()); int output = to!(int)(input); output = output*output*output; writeln(output); }
D
/+ dub.sdl: name "B" dependency "dunkelheit" version=">=0.9.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner; int main() { Scanner sc = new Scanner(stdin); scope(exit) sc.read!true; int k; long[] a; sc.read(k, a); long dw = 2, up = 2; ...
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.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, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int N; scan(N); auto H = readln.split.to!(i...
D
import std.stdio, std.string, std.conv; import std.algorithm; void main() { auto input = getStdin!(string[]); string s = input[0] ~ input[0]; string p = input[1]; if (s.count(p) > 0) { "Yes".writeln; } else { "No".writeln; } } T getStdin(T)() { string[] cmd; string line; while ((line = chomp(st...
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.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n, a, b; scan(n, a, b); writeln(min(n*a, b)); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args...
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; immutable long MOD = 10^^9 + 7; void main() { auto N = readln.chomp.to!int; auto Comb = new Combination(); if (N...
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric; import std.typecons, std.functional, std.traits; import std.algorithm, std.container; import core.stdc.stdlib, core.bitop; void main() { auto S = scanString; long res = long.max; if(S.all!"a=='0'"||S....
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; int sum_p, max_p; foreach (_; 0..N) { auto p = readln.chomp.to!int; sum_p += p; max_p = max(max_p, p); } writeln(sum_p - max_p /...
D
import std.stdio; import std.string; import std.conv; import std.array; import std.range; void main(){ auto F=readln.split.to!(int[]),A=F[0],B=F[1]; if(A+B>=24)writeln((A+B)-24); else writeln(A+B); }
D
import std.stdio; import std.conv; import std.string; import std.format; void main() { string s = chomp(readln()); string[] array = s.split(" "); int W = to!int(array[0]); int H = to!int(array[1]); int x = to!int(array[2]); int y = to!int(array[3]); int r = to!int(array[4]); // (0, 0) <= (x, y) <=...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } int calc(int n, bool[][] adj) { bool isBridge()...
D
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional, std.container, std.typecons; void main() { auto input = readln.split.to!(int[]); int H = input[0], W = input[1], A = input[2], B = input[3]; bool[] reversed = new bool[H]; foreach(i; 0..B) { reversed[i] = true; ...
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.math, std.array, std.container, std.typecons; void main() { auto nm = readln.chomp.split.to!(int[]); if(nm[0]==nm[1]) writeln("Yes"); else writeln("No"); }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(long[]), x = rd[0], y = rd[1]; auto c = 1; for (;;) { x *= 2; if (x > y) break; ++c; } writeln(c); }
D
import std.stdio; import std.algorithm; import std.array; import std.conv; import std.datetime; import std.numeric; import std.math; import std.string; string my_readln() { return chomp(readln()); } void main() { auto tokens = my_readln().split(); auto A = tokens[0].to!uint; auto B = tokens[1].to!uint; auto C = t...
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; bool next(bool[][] m, int x, int y){ auto s = new bool[][](10+4, 10+4); foreach(i; -1..2){ foreach(j; -1..2...
D
import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; void main() { auto rd = readln.split.map!(to!int); auto a = rd[0], b = rd[1], c = rd[2]; auto d = 0; foreach (i; a..b...
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int N = readln.chomp.to!(int); int[][] A; for (int i = 0; i < 2; i++) { A ~= readln.chomp.split.to!(int[]); } int ans; for (int i = 0; i < N; i++) { int t, row; for (int j = 0; j < N; j++) { if (j...
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 a = new int[][](3, 3); foreach (i; 0..3) { a[i] = readln.chomp.split.to!(i...
D
import std.conv, std.stdio; import std.algorithm, std.array, std.string, std.range; void main() { auto s = cast(ubyte[])readln.chomp; (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No").writeln; }
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 ...
D
// unihernandez22 // https://atcoder.jp/contests/abc076/tasks/abc076_c // string manipulation import std.stdio; import std.string; void main() { string s = readln.chomp; string t = readln.chomp; ulong idx = -1; bool matched; foreach(i; 0..(s.count-t.count)+1) { if (s[i] == '?' || s[i] == t[0]) { matched = tr...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.typecons; alias Edge = Tuple!(int, "to", int, "weight"); Edge[][10 ^^ 5 + 1] ES; long[10 ^^ 5 + 1] LS; void main() { auto N = readln.chomp.to!int; foreach (i; 0..N - 1) { auto e = readln.split.to!(int[]); ES[e[0]] ~= Edge(e...
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.to!(char[]).array; auto k = r...
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() { string s = readln.chomp; writeln(s[0 .. min($, 4)] == "YAKI" ? "Yes" : "No"); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (r...
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 File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(T = long)() ...
D
const int max = 1000000; void main(){ int s = _scan(); int[int] dic; dic[s]++; // 初項sでa_1, ... なので2から始まる foreach(i; 2..max+1){ if(s&1) s = 3*s +1; else s = s/2; dic[s]++; if(dic[s]==2){ i.writeln(); break; } } } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1...
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; string cnv(real w) { if(w<=48) return "light fly"; if(w<=51) return "fly"; if(w<=54) return "bantam"; if(w<=57) return "feather"; if(w<=60) return "light"; if(w<=64) return "light welter"; if(w<=69) return "...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.array; void main(){ auto N=readln.chomp.to!int; auto K=readln.chomp.to!int; auto X=readln.chomp.to!int; auto Y=readln.chomp.to!int; if(N>K)writeln(X*K+(N-K)*Y); else writeln(N*X); }
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 n = readln.chomp.to!int; auto a = readln.chomp.to!int; wri...
D
import std.stdio, std.math, std.conv; void main() { foreach(input; stdin.byLine) { foreach(n; 1..int.max) { if(9.8 * sqrt(5.0 / 4.9 * (n - 1)) >= input.to!double) { n.writeln; break; } } } }
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; auto a = readln.split.to!(int[]); auto calc(int fs) { auto t = 0, ans = 0L; foreach (i, ai; a) { auto s = i % 2 == 0 ? fs : -fs; t += ai; if (t * s <= 0) { ans += ...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int n; long x; scan(n, x); auto a = new long[](n + 1); // 長さ auto b = new long[](n + 1); // Pの枚数 a[0] = b[0] = 1; fore...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int h, w; scan(h, w); auto map = new char[][](h, w); iota(h).each!(i => map[i] = readln.chomp.to!(char[])); if (map[0][0] != '#') { writeln("Impossible"); return; } int pi, ...
D
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range; T[] Reads(T)() { return readln.split.to!(T[]); } alias reads = Reads!int; void scan(Args...)(ref Args args) { string[] ss = readln.split; foreach (i, ref arg ; args) arg = ss[i].parse!int; } uint MOD ...
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; alias Edge = Tuple!(int, "u", int, "v"); long[] f(long x) { if (x == 0) { long[] ans = new long[](42); ...
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 N = readln.chomp.to!long; long[] AS; long a_sum; foreach (a; readln.split.to!(long[])) { AS ~= a; a_sum += a; } if (N == 1) { ...
D