code
stringlengths
4
1.01M
language
stringclasses
2 values
import std.stdio, std.string, std.conv, std.algorithm; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { bool[] alp = new bool[](26); string s = readln.chomp; foreach (ch ; s) { alp[ch - 'a'] = 1; } foreach (i ; 0 .. 26) { if (!alp[i]) {...
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
// 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.conv; int main() { string s = readln(); write(toUpper(s)); return 0; }
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; import std.conv; void main() { auto N = r; auto ip = readln.split.to!(int[]), D = ip[0], X = ip[1]; int count; foreach(_; 0..N) { count += ceil(D / r.to!real).to!int; //count++; } (count + X).writeln; } int r() { r...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rgb = readln.split.joiner.array.to!int; writeln(rgb % 4 == 0 ? "YES" : "NO"); }
D
import std; void main() { int n, m; scan(n, m); auto hs = readints; int[][] adj; foreach (_; 0..n) adj ~= [[]]; foreach (_; 0..m) { int a, b; scan(a, b); a--; b--; adj[a] ~= b; adj[b] ~= a; } int ans = 0; for (int i = 0; i < hs.length; i++) { boo...
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, std.container, std.range; class Tree { Tree[26] children; long[26] counts; char c; this(char c) { this.c = c; } void add(string s) { assert(this.c == '\n'); auto las...
D
import std.conv; import std.stdio; import std.string; void main() { auto s = readln.strip; writeln( solve( s ) ); } auto solve( in string s ) { auto checkA = false; auto checkC = false; auto checklower = true; foreach( i, c; s ) { if( i == 0 && c == 'A' ) { checkA = true; continue; } if( 2 <...
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.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.ascii; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } int size(T)(in T s) { return cast(int)s.length; } void main() ...
D
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; stri...
D
void main(){ int[] vals = inln(); ( ((vals[2]+0.5)/vals[0]).to!int()*vals[1] ).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; // 1要素のみの入力 T inelm(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] inln(...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; int N, M; int[][int] RS; int[200000] IS; void main() { auto nm = readln.split.to!(int[]); N = nm[0]; M = nm[1]; foreach (_; 0..M) { auto ab = readln.split.to!(int[]); auto a = ab[0] - 1; ...
D
module app; import core.bitop; import std.algorithm; import std.array; import std.bigint; import std.conv; import std.stdio; import std.string; struct Input { int n; int k; int[] h; } void parseInput(T)(out Input input, T file) { with (file) with (input) { auto nk = readln().strip().split(); n = nk[0].to!i...
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 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.conv, std.string, std.array, std.range, std.algorithm; void main(){ auto s = readln.strip; long a = 0; long b = 0; foreach (i, c; s) { if ((i % 2 == 0) == (c == '1')) { a++; } else { b++; } } writeln(min(a, b)); }
D
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math; import core.stdc.stdio; // foreach, foreach_reverse, writeln void main() { string s = chomp(readln()); int n = to!int(s.length); int K; scanf("%d", &K); string[] S; foreach (len; 1..K+1) { foreach (i; 0..n-len+1) { S ~= s[i..i+len];...
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.array, std.container, std.range; import std.numeric, std.math, std.bigint, std.random; import std.string, std.uni, std.regex, std.conv; import std.bitmanip, core.bitop; import std.stdio, std.typecons; void main() { auto w = readln.chomp; auto r = 0; for (;;) { auto t = readln.chomp...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!long; foreach (h; 1L..3501L) foreach (m; h..3501L) { auto a = 4*h*m-n*(h+m); auto b = n*h*m; if (a > 0 && b % a == 0) { writeln(h, " ", m, " ", b/a); return; } } ...
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto n = readln.chomp.to!int; auto s = readln.chomp; int m; foreach (i; 1..n-1)...
D
import std.stdio; import std.conv; import std.string; import std.typecons; import std.algorithm; import std.array; import std.range; import std.math; import std.regex : regex; import std.container; import std.bigint; void main() { auto x = readln.chomp.split.to!(int[]); writeln(x[0]-1+(x[0]<=x[1])); }
D
void main(){ auto ABCK = readLine!long(); auto A = ABCK[0]; auto B = ABCK[1]; auto C = ABCK[2]; auto K = ABCK[3]; if( K <= A ){ K.writeln(); } else if( K <= A+B ) { A.writeln(); } else { (A - (K-(A+B))).writeln(); } return; } import std; string readStr(){ return readln().chomp(); } T[] r...
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; import std.algorithm; import std.array; void main() { auto l = readln.chomp.split.map!(to!int).array; int n = l[0], c = l[1]; long[][] cc = new long[][](31, 200010); long[] imos = new long[](200010); for (int i = 0; i < n; ++i) { auto m = readln.c...
D
void main(){ string input; input = readln().chomp().dup; string ans; foreach(elm; input){ if(elm == 'B'){ if( ans.length==0 )continue; ans.popBack(); }else{ ans ~= elm; } } writeln(ans.length==2? ans[$-2..$]: ans[0..$] ); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.ma...
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 n, q; rdVals(n, q); auto st = SegTree!("a + b", long, 0)(n); foreach (i; 0 .. q) { long com, x, y; rdVals(com, x, y); --x; if (com) st.query(x, y).writeln; else st.update(x, st[x]+y); } } struct SegTree(alias pred, T, T init) { i...
D
void main() { long n = rdElem; long[] h = rdRow; long[] dp = new long[n]; dp[1] = abs(h[0] - h[1]); foreach (i; 2 .. n) { dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i])); } dp[n-1].writeln; } enum long mod = 10^^9 + 7; enum long inf = 1L << 60; enum double eps ...
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { while(true) { auto input=readln.split.map!(to!int); if(input[0]==0&&input[1]==0) break; int m=input[1]-input[0]; int th, fiv, han; for(; m>=1000; ++th) m-=1000; for(; m>=500; ++fiv) m-=500; ...
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; void main() { auto N = readln.chomp.to!int; auto a = readln.split...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math : abs; void main() { auto N = to!int(split(readln())[0]); int[] A = [0]; A ~= to!(int[])(split(readln())); int X = 0; foreach (i; 0..N) { X += abs(A[i] - A[i+1]); } X += abs ( A[$-1] - A[0] ); foreach ( i; 1..N ...
D
import std.stdio,std.string,std.conv; int main() { string s; while((s = readln.chomp).length != 0) { string[] _s = s.split(","); int n = _s[0].to!int; double w = _s[1].to!double; double h = _s[2].to!double; if(25.0 <= w/(h*h)) { n.writeln; } } return 0; }
D
/* imports all std modules {{{*/ import std.algorithm, std.array, std.ascii, std.base64, std.bigint, std.bitmanip, std.compiler, std.complex, std.concurrency, std.container, std.conv, std.csv, std.datetime, std.demangle, std.encoding, std.exception, std.file, std.format, std.functi...
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.numeric; void main() { auto n = readln.chomp.to!int; int[string] cnt; int m; forea...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; const ma = 10 ^^ 5; void main() { auto n = readln.chomp.to!size_t; auto a = readln.split.to!(int[]); auto b = new int[](ma); foreach (ai; a) { if (ai > 0) ++b[ai-1]; ++b[ai]; if (ai < ma-1) ++b[ai+1]; } writeln(b.reduce!max); ...
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.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; void main(){ auto ip = readln.split.to!(int[]); writeln(ip[0] + 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 s = readln.chomp; auto r = ['R', 'U', 'D']; auto l = ['L', 'U', 'D']; boo...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } void main() { auto nab = readints; int n = nab[0], a ...
D
import std.stdio : writeln; void main() { int n,a,b; scan(n,a,b); long ans; foreach (i ; 1 .. n + 1) { int d = digitSum(i); if (a <= d && d <= b) { ans += i; } } writeln(ans); } int digitSum(int x) { return x > 0 ? digitSum(x / 10) + x % 10 :...
D
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm; void main(){ auto S = readln.chomp; auto F = S[0..2].to!int; auto R = S[2..$].to!int; if((1<=F&&F<=12) && (1<=R&&R<=12)) writeln("AMBIGUOUS"); else if(1<=F&&F<=12) writeln("MMYY"); else if(1<=R&&R<=12) writeln("YYM...
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!(long[]); const H = tmp[0], W = tmp[1]; const s = H.iota.map!(_ => readln.chomp).array; foreach (y; 0..H) { foreach (x; 0..W) { if (s[y][x] =...
D
import std.stdio, std.conv, std.string, std.algorithm.searching, std.algorithm.iteration; void main() { auto N = readln().strip.to!int; int[] pList = []; foreach(i; 0..N) { pList ~= readln().strip.to!int; } writeln(pList.sum - pList.reduce!"a<b?b:a" / 2); }
D
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.string, std.array, std.conv; void main() { int[] tmp = readln.chomp.split.to!(int[]); int w = tmp[0], h = tmp[1], x = tmp[2], y = tmp[3], r = tmp[4]; writeln(0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h ? "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.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() { string s = readln.chomp; string t = readln.chomp; long[][] alpha = new long[][](26); foreach (i, x; s) { alpha[x-'a'] ~= i + 1; } long n = s.length.to!long; long cnt; long index; foreach (x; t) { auto a = alpha[x-'a'].assumeSorted; if ...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf3 = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int a, b, c, d, e; scan(a);scan(b);scan(c);sca...
D
import std.stdio, std.array, std.conv, std.typecons, std.algorithm; long impl(long n, long w, const ref long[] ws, const ref long[] vs, ref long[][] dp) { if(dp[n][w] == -1) { const auto prev_w = w-ws[n-1]; const auto yes = prev_w >= 0 ? impl(n-1, prev_w, ws, vs, dp) + vs[n-1] : -1; const a...
D
import std.stdio; import std.conv; import std.string; import std.algorithm; void main() { auto n=map!(to!int)(readln.strip.split); int cnt = 0; for(int i = n[0];i<=n[1];i++) if(n[2] % i == 0) cnt++; writeln(cnt); }
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.7.4" +/ import std.stdio, std.algorithm, std.range, std.conv, std.math; // import dcomp.foundation, dcomp.scanner; // import dcomp.geo.primitive, dcomp.geo.circle, dcomp.geo.polygon; bool solve() { alias P = Point2D!double; alias L = Line2D!double;...
D
import std.stdio, std.string, std.conv, std.array, std.algorithm, std.range, std.typecons, std.numeric, std.math; void main() { long n = readln.strip.to!long; auto ps = readln.strip.split(" ").to!(long[]).array; long cnt = 0; foreach (i; 0..n) { if (ps[i] != i+1) { cnt++; }...
D
import std.stdio; import std.string; import std.conv; import std.algorithm.searching; void main(){ auto str = readln.chomp; if(str[2] == str[3] && str[4] == str[5]) { "Yes".writeln; } else { "No".writeln; } }
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { long[] buf = readln.chomp.split.to!(long[]); long N = buf[0], K = buf[1]; if (K == 0) { writeln(N * N); return; } long ans; for (int i = 1; i <= N; i++) { ans += max(0, (i - K) * (N / i)); ans += max(...
D
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons; void main() { const as = readln.split.to!(long[]); writeln(as.reduce!max - as.reduce!min); }
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; immutable long MOD = 10^^9 + 7; long powmod(long a, long x, long m) { long ret = 1; while (x) { if (x % 2...
D
import std.stdio, std.string, std.conv; import std.array, std.algorithm, std.range; void main() { int t=0; foreach(s;stdin.byLine()) { int n=0; foreach(c;s) if('0'<=c && c<='9') n=n*10+c-'0'; else t+=n,n=0; t+=n; } writeln(t); }
D
void main() { string s = readln.chomp; writeln(s.countUntil("YAKI") == 0 ? "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 s...
D
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.math; import std.regex; import std.range; void main() { auto X = readln.chomp.to!int, A = readln.chomp.to!int, B = readln.chomp.to!int; auto tmp = X - A; (tmp % B).writeln; }
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
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 main() { auto rd = readln.split.to!(int[]); auto a = rd[0], b = rd[1], c = rd[2], d = rd[3], e = rd[4], f = rd[5]; auto ansW = 0, ansS = 0, ansK = real(0); foreach (i; 0..f/a+1) foreach (j; 0..f/b+1) { auto w = i*a + j*b; ...
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.conv; import std.stdio; import std.string; void scan(TList...)(ref TList Args) { auto line = readln.split(); foreach (i, T; TList) { T val = line[i].to!(T); Args[i] = val; } } void main() { ulong A, B; scan(A, B); writeln(f(A - 1) ^ f(B)); } ulong f(ulong x) { ...
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int n = readln.chomp.to!int; int[] a = new int[n]; int[] b = readln.chomp.split.to!(int[]); a[0] = b[0], a[1] = b[0]; foreach (i; 1 .. n-1) { a[i] = min(a[i], b[i]); a[i+1] = b[i]; } a.sum.writeln; }
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 k, int[] ws) { bool match(int limit...
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 c...
D
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container, std.typecons; void main() { auto n = readln.chomp.to!int; auto p = readln.chomp.split.to!(int[]); int count=0, minimum=n+1; for(int i=0; i<n; i++) { if(p[i]<=minimum) { count++; minimum = min(minim...
D
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; stri...
D
import std.stdio; import std.range; import std.array; import std.string; import std.conv; import std.algorithm; import std.math; import std.typecons; import std.variant; size_t[] solve(string a, string b) { size_t[] result; foreach (i; 0 .. a.length) { if (a[i] != b[i]) { result.assumeSafeAppend ~= i + 1; re...
D
import std.algorithm; import std.range; import std.stdio; import std.string; immutable string str = "Bulbasaur"; void main () { string s; while ((s = readln.strip) != "") { int [256] num; foreach (char c; s) { num[c] += 1; } int res = int.max; foreach (char c; str) { int d = cast (int) (str.cou...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range; void get(Args...)(ref Args args) { import std.traits, std.meta, std.typecons; static if (Args.length == 1) { alias Arg = Args[0]; static if (isArray!Arg) { ...
D
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; stri...
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
/+ dub.sdl: name "A" dependency "dunkelheit" version="1.0.1" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dkh.foundation, dkh.scanner, dkh.algorithm; int main() { Scanner sc = new Scanner(stdin); scope(exit) assert(!sc.hasNext); int n, m; int[] v; sc.read(n, m, v); ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto T = readln.chomp.to!int; foreach (_t; 0..T) { auto nk = readln.split.to!(int[]); auto N = nk[0]; auto K = nk[1]; int[] as; bool has; foreach ...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int t; rd(t); while (t--) { long s, a, b, c; rd(s, a, b, c); auto n = s / c; writeln(n + n / a * b); } } void rd(T...)(ref T x) { import std.stdio : readln; import std.string : split; import std.conv : to; auto l =...
D
import std.stdio; import std.algorithm; import std.array; int main() { int n; scanf("%d", &n); int x = 0, y = 0; for (int z, i = 0; i < n; i++) { scanf("%d", &z); if (z % 2 == 1) x = x + 1; else y = y + 1; } int ans; if (x < y) ans = x; else { ans = y; x = x - y; ans = ans + x / 3; } write...
D
import std.stdio; import std.string; void main () { while (readln.strip != "") { writeln (25); } }
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.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 rd = readln.split.to!(size_t[]), h = rd[0], w = rd[1]; foreach (_; 0..h) { auto c = readln.chomp; writeln(c); writeln(c); } }
D
void main() { string[] ab = readln.split; int n = (ab[0] ~ ab[1]).to!int; int m = n.to!double.sqrt.to!int; writeln(n == m * m ? "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 st...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; import std.math; int n; rd(n); int cur=0, x=0, y=0; while(n--){ int t, nx, ny; rd(t, nx, ny); auto d=(nx-x).abs+(ny-y).abs; if(d>(t-cur)){writeln("No"); return;} auto r=(t-cur)-d; if(r&1){writeln("No"); return;} cur=t...
D
import std; int calc(long k, int[] a) { a = [0] ~ a; auto used = new long[a.length]; used[] = -1; int p = 1; long step = 0; while (true) { if (step == k) { return p; } if (used[p] != -1) { // writeln("loop ", step - used[p]); auto m =...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; enum P = 10L^^9+7; void main() { auto S = readln.chomp; auto N = S.length; auto DP = new long[][](N+1, 4); DP[0][0] = 1; foreach (i, c; S) { foreach (j; 0..4) DP[i+1][j] = DP[i][j] * (c ...
D
import std.stdio; import std.conv; import std.array; void main() { auto reader = readln.split; int r = reader[0].to!int; writeln(3 * r * r); }
D
import std.stdio, std.string, std.array, std.conv; int[] factors(int n) { int[] result; while (n % 2 == 0) { result ~= 2; n /= 2; } for (int i = 3; i * i <= n; i += 2) { while (n % i == 0) { result ~= i; n /= i; } } if (n != 1) result ~= n...
D
import std.algorithm; import std.array; import std.container; 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[]...
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
void main(){ string s = readln().chomp(); writeln(s.count("A")%3==0? "No": "Yes"); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math; // 1要素のみの入力 T _scan(T= int)(){ return to!(T)( readln().chomp() ); } // 1行に同一型の複数入力 T[] _scanln(T = int)(){ T[] ln; foreach(string elm; readln().chomp...
D
import std.stdio; import std.conv; import std.string; import std.array; import std.algorithm; void main() { auto s = readln.chomp.split.map!(to!char).array; if (s[0] < s[1]) "<".writeln; else if (s[0] > s[1]) ">".writeln; else "=".writeln; }
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 nmxy = readln.split.to!(int[]); auto X = nmxy[2]; auto Y = nmxy[3]; auto xs = readln.split.to!(int[]); auto ys = readln.split.to!(int[]); int xmax = int.min, ymin = int.max...
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() { foreach(i; 1..1000000) { int n = readln.chomp.to!int; ...
D