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; struct BITree(alias _fun, alias E, T) if (is(typeof(E) : T)) { import std.functional : binaryFun; alias OP = binaryFun!_fun; /// this(size_t n, T[] ts) { this.n = n; this.tree.length ...
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; const MOD = 10^^9 + 7; long calc(long[] a) { long[61] zero, one; foreach (e; a) { for (int i = 0; i <= 60; i++...
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random; import std.typecons, std.functional, std.traits,std.concurrency; import std.algorithm, std.container; import core.bitop, core.time, core.memory; import std.bitmanip; import std.regex; enum INF = long....
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 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.string, std.conv; import std.algorithm, std.array; import std.math; auto solve(string s_) { auto NA = s_.split.map!(to!int)(); immutable N=NA[0], A=NA[1]; immutable xs=readln.split.map!(to!int).array(); immutable M=N*A+1; auto dp = new long[][](N+1,M); dp[0][0]=1; foreach...
D
import std.stdio; import std.conv; import std.string; import std.algorithm; import std.range; import std.functional; import std.math; import core.bitop; void main() { long H, W, D; { auto input = readln.chomp.split(' ').map!(to!long); H = input[0]; W = input[1]; D = input[2]; ...
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto uf = new UnionFind(N); auto edges ...
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
void main() { auto S = rs; auto w = ri; string res; foreach(i; iota(0, S.length, w)) { res ~= S[i]; } res.writeln; } // =================================== import std.stdio; import std.string; import std.functional; import std.conv; import std.algorithm; import std.range; import std.traits; import std.math; i...
D
import std; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();} T[] aryread(T = long)(){return readln.split.to!(T[])();} void scan(TList...)(ref TList Args){auto line = readln.split(); foreach (i, T; TList){T val = line[i]...
D
import std.stdio, std.string, std.conv, std.algorithm; void main() { int N = readln.chomp.to!(int); int[] buf = readln.chomp.split.to!(int[]); int D = buf[0], X = buf[1]; int[] A; for (int i = 0; i < N; i++) { A ~= readln.chomp.to!(int); } int ans; for (int i = 0; i < N; 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 rgb = readln.chomp.split.map!(to!int); writeln((rgb[0]*100+rgb[1]*10+rgb[2])%4...
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.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens....
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 s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; ...
D
import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; auto rci = iota(n).map!(_ => readln.split.to!(size_t[])).array; auto memo = new size_t[][](n, n + 1); memo.each!(a => a[] = size_t.max); size_t dp(size_t s, size_t t) { if (memo[s][t] < si...
D
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { auto N = readln.chomp.map!(i => (i - '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; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } bool calc(int[] ds, int[] ts) { int[int] map; ...
D
void main() { long[] tmp = rdRow; long n = tmp[0], k = tmp[1]; long[] a = rdRow; long g = a[0]; long amax = a[0]; foreach (x; a) { if (x == k) { "POSSIBLE".writeln; return; } g = gcd(g, x); amax = max(amax, x); } bool ...
D
import std.stdio, std.conv, std.string, std.algorithm; void main() { auto s = readln.strip; writeln(700 + s.count('o') * 100); }
D
import std.stdio; import std.regex; void main(){ auto io = new IO(); auto w = io.line!string()[0]; foreach( a ; alphaB ){ if( w.count(a) % 2 != 0 ){ writeln( "No" ); return; } } writeln("Yes"); return; } import std.stdio,std.conv,std.string; import std.algorithm,std.array,std.math; immutable PR...
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.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
void main() { string n = readln.chomp; long total; foreach (x; n) { total += x - '0'; } max(total, (n[0] - '1') + 9 * (n.length - 1)).writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto S = readln.chomp; int a, b; foreach (i, c; S) { if ((i%2 == 0 && c == '1') || (i%2 == 1 && c == '0')) ++a; if ((i%2 == 0 && c == '0') || (i%2 == 1 && c == '1')) ++b; ...
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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; long P = 10^^9 + 7; int[2*10^^5+1] CS; long[2*10^^5+1] MEMO; void main() { auto N = readln.chomp.to!int; foreach (i; 0..N) { CS[i] = readln.chomp.to!int; } int[2*10^^5+1] acc, right; fo...
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.string, std.array, std.conv; void main() { int n = readln.chomp.to!int; int[] a = readln.chomp.split.to!(int[]); foreach_reverse (i; 0 .. n) { a[i].write; if (i != 0) " ".write; else writeln; } }
D
import std.stdio; import std.string; import std.algorithm; import std.conv; void main(){ int[] a; a = new int[](10); foreach(i; 0..10){ a[i] = readln().chomp().to!int(); } sort!("a > b")(a); foreach(i; 0..3){ writeln(a[i]); } }
D
import std.stdio; import std.conv; import std.string; void main() { string s = chomp(readln()); // ?????????????????? int x = to!int(s.split(" ")[0]); int y = to!int(s.split(" ")[1]); write(x*y); write(" "); writeln(2*x+2*y); }
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 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(); alias Point...
D
import std.stdio; import std.array; import std.string; import std.conv; int main() { import std.stdio; auto input = split(chomp(readln())); int a = to!int(input[0]); int b = to!int(input[1]); if (a <= b) writeln(a); else writeln(a - 1); return 0; }
D
import std.stdio, std.string, std.conv; import std.algorithm, std.array; auto solve(string s_) { auto NK = s_.split.map!(to!int)(); immutable N=NK[0], K=NK[1]; auto as = readln.split.map!(x=>x.to!int()-1).array(); auto g = new int[][N]; foreach(int i,v;as) if(i!=0) g[v]~=i; int n=as[0]==0?0:1;...
D
void main() { problem(); } void problem() { auto A = scan!int; auto B = scan!int; auto C = scan!int; auto K = scan!int; int solve() { int answer; if (K <= A) return K; if (K <= A+B) return A; auto nokori = K - A - B; return A - nokori; } solve().writeln; } // ------------------...
D
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii; import std.typecons, std.functional; import std.algorithm, std.container; void main() { auto N = scanElem; foreach(i;0..N) { if(scanElem%2==1){ writeln("first"); return; } ...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_r...
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; import std.math; void main() { auto N = readln.split[0].to!long; auto A = readln.split[0].to!long; auto B = readln.split[0].to!long; auto C = readln.split[0].to!long; auto D = readln.split[0].t...
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
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; string s, t; } void parseInput(T)(out Input input, T file) { with (file) with (input) { n = readln().strip().to!int; auto array = readln().str...
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; void main() { auto s = readln.split.map!(to!int); auto n = s[0]; auto q = s[1]; auto st = new SegmentTree!(int...
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.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!int; auto AS = readln.split.to!(int[]); AS = [0] ~ AS ~ 0; int s; foreach (i; 0..N+1) s += abs(AS[i] - AS[i+1]); foreach (i; 1..N+1) { writeln(s ...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} ...
D
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm; void main(){ auto ip = readln.split.to!(int[]), A=ip[0], B=ip[1]; if(A<6) writeln(0); else if(A<13) writeln(B/2); else writeln(B); }
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; import std.container; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } class Node{ bool[Node] ad...
D
void main() { string[] s = readln.split; writeln(s[0][0], s[1][0], s[2][0]); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import std.math; import std.numeric; import std.container; import std.typecons; import std.ascii; import std.uni;
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.string, std.conv; import std.range, std.algorithm, std.array; void main() { int a, b; scan(a, b); if (a == 1) a = 14; if (b == 1) b = 14; if (a < b) { writeln("Bob"); } else if (a > b ) { writeln("Alice"); } else { writeln("Draw"); ...
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 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
import core.bitop; import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.format; import std.math; import std.random; import std.range; import std.stdio; import std.string; import std.typecons; int generate() { Mt19937 gen; string str = __DATE__ ~ __TIME__; ui...
D
void main() { long n, m; rdVals(n, m); Bridge[] b = m.rdCol!Bridge; foreach (i; 0 .. m) { b[i].from -= 1, b[i].to -= 1; } long cnt; foreach (i; 0 .. m) { auto tree = new UnionFind(n); foreach (j; 0 .. m) { if (j == i) continue; ...
D
import std.string; import std.stdio; import std.algorithm; import std.conv; import std.typecons; void main() { long[Tuple!(immutable(char), size_t)] dp; long[char] checks; auto s = readln.chomp; auto t = readln.chomp; foreach(c; s) { checks[c] = 0; } bool check = true; foreach(c; t) { if (c !in checks) { ...
D
void main() { long n, k, l; rdVals(n, k, l); auto road = UnionFind(n); foreach (i; 0 .. k) { long p, q; rdVals(p, q); --p, --q; road.unite(p, q); } auto rail = UnionFind(n); foreach (i; 0 .. l) { long r, s; rdVals(r, s); --r, ...
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; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; void main() { auto ...
D
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 X = new int[][](10, 2); foreach (i; 0..10) X[i][0] = 0; foreach (i; 0..10) ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math; bool solve(int s, int g, int[] ns) { auto N = ns.length; auto DP = new bool[][](N+1, 8000*2+1); void sv(int i, int n) { if (!DP[i][n]) { DP[i][n] = true; if (i == N) return; sv(i+1, n+ns[...
D
void main() { dchar[] s = readln.chomp.to!(dchar[]); dchar[] t = s.dup; reverse(t); long cnt; foreach (i; 0 .. s.length/2) { if (s[i] != t[i]) ++cnt; } cnt.writeln; } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range...
D
import std.stdio, std.string, std.conv; void main() { while(true) { int n=readln.chomp.to!int; if(!n)break; int num; for(int i=1; i<n; ++i) { int sum; for(int j=i; j<n; ++j) { sum+=j; if(sum == n) ++num...
D
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; void main() { int sum = 0; foreach(int i; 0..5) { sum += max(40, read...
D
import std; void main(){ int n, k; int[] as; scanf("%d %d\n", &n, &k); auto mem = new bool[n]; foreach(_i; 0..k) { int d; scanf("%d", &d); foreach (_j; 0..d) { int a; scanf("%d", &a); mem[a-1] |= true; } } mem.count!"!a".writeln; }
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons; void main() { auto S_ = readln.chomp.to!(wchar[]); auto T = readln.chomp.to!(wchar[]); wchar[] S; foreach_reverse (i; 0..S_.length - T.length + 1) { auto s = S_.dup; foreach_reverse (j; 0..T.lengt...
D
import std.algorithm; import std.array; import std.ascii; import std.bigint; import std.complex; import std.container; import std.conv; import std.functional; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; auto readInts() { return array(map!(to!int)(readln().strip().split...
D
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; if (N%2 == 1) { writeln("No"); return; } foreach (i; 0..N/2) { if (S[i] != S[N/2+i]) { writel...
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
import std.stdio; import std.string; import std.conv; void main(){ while(true){ auto s = readln(); if(stdin.eof()) break; real w = to!real(chomp(s)); if(w <= 48.0) writeln("light fly"); else if(w <= 51.0) writeln("fly"); else if(w <= 54.0) writeln("bantam"); else if(w <= 57.0) writeln("feather"); else if(...
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 main() { int n; readV(n); int a; readV(a); writeln(n*n-a); }
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; iota(1,N+1).filter!(x => x < 10 || (100 <= x && x < 1000) || (10000 <= x && x < 100000)).walkLength.writeln; }
D
import std.stdio, std.math, std.conv, std.array, std.string, std.algorithm; void main() { uint c = to!uint(readln().chomp); for (uint i = 0; i < c; ++i) { double[] dx = map!(to!double)(readln().chomp.split).array; double[] ap = dx[0..2]; double[] bp = dx[3..5]; double ar = dx[2]...
D
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; import std.typecons; import std.bigint; // import dcomp.foundation, dcomp.scanner; // import dcomp.container.deque; int main() { auto sc = new Scanner(stdin); int n, m, k; sc.read(...
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; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto K = s[1...
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[] solve(int n) { if (n == 3) return [2, 5, 63]; int[] l = [2, 4]; n -= 2; foreach (i; 0..2500) { if (n < 2) break; ...
D
import std.stdio, std.conv, std.string, std.algorithm, std.range; void main() { auto N = readln.split[0].to!int; auto A = new int[N]; auto B = readln.split.to!(int[]); A[0] = B[0]; A[$-1] = B[$-1]; for(auto i = 1; i < A.length - 1; i++) { A[i] = min(B[i-1], B[i]); } A.reduce!"a+b"().writeln; }
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[]); auto T = readln.chomp.to!(char[]); int r; foreach (i; 0..3) if (S[i] == T[i]) ++r; writeln(r); }
D
void main() { long n = rdElem; string[] s = new string[n]; long[] t = new long[n]; foreach (i; 0 .. n) { string[] tmp = rdRow!string; s[i] = tmp[0]; t[i] = tmp[1].to!long; } string x = rdStr; long result = long.min; foreach (i; 0 .. n) { result +=...
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, 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; } lon...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; import std.array; int n; rd(n); long[int] freq; auto y=new int[](n); auto ng=new bool[](n); foreach(i; 0..n){ auto s=readln.chomp.to!(char[]); char[] st; foreach(c; s){ if(c=='('){ st~='('; }else{ ...
D
import std.stdio; import std.algorithm; void main() { int n; scanf("%d", &n); bool[] used = new bool[n]; char[] gender = new char[n]; int[] from = new int[n]; int[] to = new int[n]; for (int i = 0; i < n; i++) { char[10] s; scanf("%s%d%d", s.ptr, &from[i], &to[i]); gender[i] = s[0]; } int res = ...
D
// Cheese-Cracker: cheese-cracker.github.io import std.stdio, std.conv, std.functional, std.string, std.algorithm; import std.container, std.range, std.typecons, std.numeric, std.math, std.random; alias ll = long; alias rbt = redBlackTree; alias tup = Tuple!(long, long); static string[] inp; T rd(T = long)(){while(!in...
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.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto T = readln.chomp.to!int; foreach (_; 0..T) { auto ad = readln.split.to!(long[]); auto A = ad[0]; auto B = ad[1]; auto C = ad[2]; auto D = ad[3]; ...
D
module _; void main() { import std.stdio; import std.string, std.conv; int n = readln.strip.to!int; auto s = readln.strip; bool check(int limit, ref string co, bool doco) { int r = 0, b = 0; foreach(ch; s) { if (ch == '(') { if (r < limit) { r++; if (doco) co ~= '0'; } else if (b < limit)...
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.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.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(...
D
import std.algorithm; import std.array; import std.ascii; import std.bigint; import std.complex; import std.container; import std.conv; import std.functional; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; auto readInts() { return array(map!(to!int)(readln().strip().split...
D
import std; long calc(long n) { long sum(long n) { return n * (n + 1) / 2; } return sum(n) - 3 * sum(n/3) - 5 * sum(n/5) + 15 * sum(n/15); } void main() { int n; scan(n); writeln(calc(n)); } void scan(T...)(ref T a) { string[] ss = readln.split; foreach (i, t; T) a[i] = ss[i].to!t; } T read(...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.15f"; static string[] s_rd; T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_r...
D
import std.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
void main() { string s = rdStr; long len = s.length; long[][] dp = new long[][](len+1, 4); dp[0][0] = 1; foreach (i, x; s) { long c = (x == '?' ? 3 : 1); foreach (j; 0 .. 4) { dp[i+1][j] = (dp[i+1][j] + c * dp[i][j]) % mod; if (j == 3) continue; ...
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
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner, dcomp.numeric.primitive, dcomp.algorithm; int main() { auto sc = new Scanner(stdin); int n; int[] a; sc.read(n, a); int[int] m; ...
D
import std.stdio,std.string,std.conv,std.algorithm; import std.algorithm:rev=reverse; int main(){ auto s=readln.chomp.dup; foreach(t;s[1..3]){ if(t!=s[0]){ writeln("Yes"); return 0; } } writeln("No"); return 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; alias sread = () => readln.chomp(); alias Point2 = Tuple!(long, "y", ...
D