code
stringlengths
4
1.01M
language
stringclasses
2 values
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; int calc(int[] a) { ...
D
import std.stdio; import std.math; import std.conv; import std.string; int solve(int x) { return pow(x,3); } void main() { writeln(solve(to!int(chomp(readln)))); }
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; long MOD = 10^^9 + 7; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto K = s[1]; auto B = new int[][](...
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.range, std.algorithm, std.conv; void main(){ readln; auto S = readln.chomp.split.map!(to!int).array; readln; auto T = readln.chomp.split.map!(to!int).array; int c = 0; foreach(i; T){ if(!S.find(i).empty) c++; } c.writeln(); // filter!("a")(c...
D
import std.stdio, std.array, std.conv, std.typecons, std.algorithm; T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; } void main() { immutable i = readln.split.to!(ulong[]); immutable a = i[0], b = i[1]; auto ans = a >= 13 ? b : (a >= 6 ? b/2 : 0); writeln(ans); }
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.string, std.conv; import std.array, std.algorithm, std.range; void main() { immutable n = readln().chomp().to!int(); auto a = iota(n).map!(_=>readln().split().map!(to!int).array()).array(); int idx(int i, int j){ return i*(n+1)+j; } auto s = new int[(n+1)^^2]; foreach(i;0..n) ...
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 nk = readln.split.to!(long[]); auto N = nk[0]; auto K = nk[1]; auto cs = new long[](N+1); foreach (long i; 0..N+1) { cs[i] = i; if (i) cs[i] ...
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; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } class Node{ int id; int groupId; Node...
D
void main() { long a = readln.chomp.to!long - 1; long b = readln.chomp.to!long - 1; bool[3] ok; ok[] = true; ok[a] = ok[b] = false; foreach (i, x; ok) { if (x) writeln(i + 1); } } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; im...
D
import core.stdc.stdio; import std.algorithm; void main(){ int n; scanf("%d",&n); int[] a = new int[n]; foreach(ref v;a) scanf("%d",&v); long[][] dp = new long[][](n,n); int l = n%2; if(l) foreach(i;0..n) dp[0][i]=a[i]; foreach(s;1..n){ l^=1; foreach(i;0..n) if(l) dp[s][i]=max(dp[s-1][i]+a[(i...
D
class UF{ int[] par; this(int n){ par.length=n; foreach(i; 0..n) par[i]=i; } int find(int x){ if(x==par[x]) return par[x]; else return par[x]=find(par[x]); } void unite(int x, int y){ if((x=find(x))!=(y=find(y))) par[x]=y; } bool same(int x, int y){ return find(x)==find(y); } }...
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, h, w; scan(n, h, w); iota(n).map!(i => readln.split.to!(int[])).count!(a => a[0] >= h && a[1] >= w).writeln; } ...
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 = 10^^9 + 7; void main() { int n, w; scan(n, w); auto dp = new long[](w + 1); foreach (i ; 0 .. n) { int wi, vi; scan(wi...
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 h, w, k; scan(h, w, k); auto c = new ...
D
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} void main() { string s; readV(s); auto a = s.i...
D
import std.stdio, std.string, std.algorithm, std.range, std.conv, std.typecons, std.math; void main(){ auto x = readln.chomp.to!ulong; auto n = x / 11 * 2; auto m = x % 11; if (1 <= m && m <= 6) { n++; } else if (7 <= m) { n += 2; } writeln(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 = "%.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.array, std.stdio, std.conv, std.string, std.math, std.random, std.range,std.functional, std.typecons; import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.comparison; void main() { int Q = readln().strip.to!int; foreach(i;0..Q) { auto aList = rea...
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() { readln; readln.split.to!(int[]).count!"a % 2 == 0".writeln; } void scan(T...)(ref T args) { import std.stdio : readln; import std.a...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(...
D
import std.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 std.stdio; import std.string; import std.conv; import std.algorithm; import std.container; import std.array; import std.math; import std.range; import std.typecons; import std.ascii; import std.format; class Iku { int dist; long cost; } class Node { int now; long cost; } void bfs(int k, int n, Iku[][]...
D
void main(){ import std.stdio, std.string, std.conv, std.algorithm; int n, m; rd(n); rd(m); auto a=new int[](n); foreach(i; 0..n) rd(a[i]); auto mx=reduce!(max)(a); int sub=0; foreach(e; a) sub+=(mx-e); if(m<=sub){ writeln(mx, " ", mx+m); return; } auto k2=mx+m; m-=sub; writeln(mx+(m+n...
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.conv, std.string, std.algorithm, std.math; void main() { while (true) { auto input = readln.chomp.split; int a = input[0].to!int; int b = input[2].to!int; char op = input[1].to!char; if (op == '?') { break; } switch (op) { case '+': writeln(a + b); ...
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; import std.concurrency; long MOD = 10L^^9+7; void main() { int ...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int x,a,b; scan(x); scan(a); scan(b); auto ans = a + (x - a) / b * b; ans = x - ans; writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm :...
D
void main() { int n = readln.chomp.to!int; int k = readln.chomp.to!int; int x = readln.chomp.to!int; int y = readln.chomp.to!int; writeln(n > k ? x * k + (n - k) * y : x * n); } import std.stdio; import std.string; import std.array; import std.conv; import std.algorithm; import std.range; import st...
D
void solve(){ } void main(){ int n = inelm(); int a = inelm(); (n*n-a).writeln(); } import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range; const long mod = 10^^9+7; alias instr = () => readln().chomp(); T inelm(T= int)(){ return to!(T)( readln().chomp() ); } T[] inary(T = int)...
D
import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.format; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int a, b, c, d, e, f; double max_noudo = 0; int ans_suwar = 0; int ans_sugar = 0; bool[][] done; void search(...
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; final class InputReader { private: ubyte[] p, buffer; bool eof; bool rawRead () { if (eof) { return fals...
D
import std.stdio,std.string,std.conv,std.array,std.algorithm; void main(){ for(;;){ auto rcs = readln().chomp().split(); auto scorelist = [to!int(rcs[0]),to!int(rcs[1]),to!int(rcs[2])]; if( scorelist[0]==-1 && scorelist[1]==-1 && scorelist[2]==-1 ){ break; } if( scorelist[0]==-1 || scorelist[1]==-1 ){ ...
D
import std.stdio, std.string, std.conv; import std.typecons; import std.algorithm, std.array, std.range, std.container; void main() { auto data = readln.split; auto N = data[0].to!long, X = data[1].to!long; long height(long level) { return 2^^(level+2) - 3; } long p_num(long level) { return 2^^(level+1) - 1; } ...
D
import std.stdio; import std.ascii; import std.algorithm; import core.stdc.stdio; int main() { int t = readInt!int; foreach(ti; 0 .. t) { string str = readString; auto a = new int[](str.length); foreach(i, ref ai; a) switch(str[i]) { case '0': ai ...
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.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; pragma(inline, true) void scan(Args...)(ref Args args) { string[] ss = readln.split; foreach (i, ref arg ; args) arg = ss[i].par...
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 ans; foreach (i; 1 .. 41) { immutable power = 2L^^i; if (B < power) break; ...
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; import std.typecons; void main() { auto a = read.to!int; auto b = read.to!int; if (a + b == 15) writeln("+"); else if (a * b == 15) 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() { auto ...
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
// Vicfred // https://atcoder.jp/contests/abc160/tasks/abc160_b import std.conv; import std.stdio; import std.string; void main() { int n = readln.chomp.to!int; long ans = (n/500)*1000; n -= (n/500)*500; ans += (n/5)*5; ans.writeln; }
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; 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.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto N = readln.chomp.to!double; writeln(sqrt(N).to!int^^2); }
D
void main() { long n = rdElem; long[] p = rdRow; long cnt; long pmax = p[0]; foreach (x; p) { if (x <= pmax) ++cnt; pmax = min(pmax, x); } cnt.writeln; } T rdElem(T = long)() { //import std.stdio : readln; //import std.string : chomp; //import std.conv : to...
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.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.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.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.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n, m; char[] s; scan(n, m); scan(s); foreach (i ; 0 .. m) { int l, r; char c1, c2; scan(l, r, c1, c2); ...
D
import std.algorithm; import std.conv; import std.range; import std.stdio; import std.string; void main () { auto tests = readln.strip.to !(int); foreach (test; 0..tests) { auto x = readln.strip.to !(int); int step = 0; int pos = 0; while (pos < x) { step += 1; pos += step; } writeln (step + (po...
D
void main() { problem(); } void problem() { const N = scan!long; long solve() { long ans; foreach(i; 1..N+1) { if (i % 3 != 0 && i % 5 != 0) ans += i; } return ans; } solve().writeln; } // ---------------------------------------------- import std.stdio, std.conv, std.array, std.str...
D
/+ dub.sdl: name "B" dependency "dcomp" version=">=0.6.0" +/ import std.stdio, std.algorithm, std.range, std.conv; // import dcomp.foundation, dcomp.scanner; int main() { Scanner sc = new Scanner(stdin); int n, m, x; sc.read(n, m, x); foreach (i; 0..n+1) { foreach (j; 0..m+1) { ...
D
import std.stdio, std.string, std.array, std.conv, std.numeric; int arrayLCM(int[] x) { while (x.length > 1) { int a = x[0]; int b = x[1]; int r = gcd(a, b); x[1] = a * b / r; x = x[1..$]; } return x[0]; } void main() { int n = readln.chomp.to!int; int[] a =...
D
import std.stdio, std.conv, std.algorithm, std.range, std.string, std.numeric; void main() { size_t a,b; auto n = readln.chomp.to!size_t - 1; auto ary = readln.chomp.split.to!(size_t[]); a = ary[0]; b = ary[1]; foreach(cnt;0..n){ auto tmp = readln.chomp.split.to!(size_t[]); auto inp_x = tmp[0]; auto i...
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(){ string s = readln.chomp; int ans; char x = 'a'; foreach(c; s){ if(x != 'a') if(x != c) ans += 1; x = c; } ans.writeln; }
D
import std.stdio, std.string, std.conv, std.array, std.algorithm; void main() { int count; while (true) { auto x = readln.chomp; if (x == "0") break; writeln("Case " ~ to!string(++count) ~ ": " ~ x); } }
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; auto s = readln.chomp.to!(char[]); auto n = s.length; auto a = new long[](n + 1), c = new long[](n + 1), q = new long[](n + 1); foreach (i; 0 .. n) { a[i + 1] += a[i]; c[i + 1] += c[i]; q[i + 1] += q[i]; if (s[i] == 'A') ...
D
import std.algorithm; import std.array; import std.bigint; import std.bitmanip; import std.conv; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; 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!(...
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, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DE...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(...
D
import 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.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 std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons; import std.math, std.numeric; void main() { readln.chomp.count!"a == '1'".writeln; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to;...
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() { int N; scan(N); auto x = readln...
D
import std.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(...
D
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, 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, p; scan(a, p); auto ans = (3*a + p)...
D
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math; int read() { return readln.chomp.to!int; } int[] reads() { return readln.split.to!(int[]); } void main() { int n = read(); int[] a = reads(); int ans = -114514810; foreach (i; 0..n) foreach (j; 0..n) { if (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.stdio, std.conv, std.functional, std.string; import std.algorithm, std.array, std.container, std.range, std.typecons; import std.bigint, std.numeric, std.math, std.random; import core.bitop; string FMT_F = "%.10f"; static File _f; void file_io(string fn) { _f = File(fn, "r"); } static string[] s_rd; T _RD(...
D
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; immutable long mod = 10^^9 + 7; void main() { int n; scan(n); auto ps = sieveEratos(n + 1); auto cnt = new int[](n + 1); foreach (m ; 2 .. n + 1) { ...
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; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int d; scan(d); write("Christmas "); foreach (i ; 0 .. 25 - d) { write("Eve "); } writeln; } void...
D
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math, std.functional, std.numeric, std.range, std.stdio, std.string, std.random, std.typecons, std.container, std.format; // dfmt off T lread(T = long)(){return readln.chomp.to!T();} T[] aryread(T = long)(){return readln.split.to!(T[])();} ...
D
void main() { import std.stdio, std.string, std.conv, std.algorithm; int n; rd(n); auto a = readln.split.to!(long[]); // 3 2 4 1 2 // 0 3 5 9 10 12 auto acc = new long[](n + 1); foreach (i; 0 .. n) acc[i + 1] = acc[i] + a[i]; long inf = 1_000_000_000_000_000_000; auto mn = inf; for (int ...
D
void main(){ import std.stdio, std.conv, std.string, std.algorithm; auto s=readln.chomp; int n=s.length.to!int; auto ps=new int[][](n, 26); foreach(ref e; ps) fill(e, -1); auto bar=new int[](26); fill(bar, -1); foreach_reverse(i; 0..n){ bar[s[i]-'a']=i; foreach(j; 0..26){ if(bar[j]!=-1)...
D
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto N = readln.chomp.to!int; auto A = N.iota.map!(_ => readln.split.map!(to!int).array).array; auto B = N.iota.m...
D
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; void main() { string s = readln.strip; foreach (i; 0 .. 26) { auto c = (i + 97).to!(char); if (s.find (c).empty) { writeln (s, c); return; } } int l = s.le...
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; alias sread = () => readln.chomp(); alias lread = () => readln.chomp.to!long(); alias aryread(T = long) = () => readln.split.to!(T[]); void main() { long n, m; scan(n, m); // writeln(m); auto a = aryread(); // writeln(a); long sum_x; sum_x = sum(a); // writeln(sum_x); ...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string; void main() { long[][][] MEMO; MEMO.length = 51; foreach (ref memo1; MEMO) { memo1.length = 51; foreach (ref memo2; memo1) { memo2.length = (50*50+1); foreach (ref memo3; memo2) { memo3...
D
void main() { long n, m; rdVals(n, m); long[] num = new long[n]; num[] = -1; foreach (i; 0 .. m) { long s, c; rdVals(s, c); --s; if (num[s] == -1 || num[s] == c) num[s] = c; else { writeln(-1); return; } } ...
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
void main() { long n = readln.chomp.to!long; string digits = "0357"; long cnt; foreach (i; 0 .. 1000000) { long x = i; long len; string nums; while (x) { ++len; nums ~= digits[x%4]; x /= 4; } long num; ...
D
void main(){ string s = readln().chomp(); string outs; foreach(i; 0..s.length){ outs ~= "x"; } outs.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; f...
D
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric; void main() { auto np = readln.split.to!(long[]); auto N = np[0]; auto P = np[1]; if (N == 1) { writeln(P); return; } long r = 1; auto p = P; for (long x = 2; x^^2 <= P...
D
import std.conv, std.stdio; import std.algorithm, std.array, std.range, std.string; import std.functional; void main() { auto n = readln.chomp.to!int; long answer; foreach (a; 1..n+1) foreach (b; 1..n+1) { immutable g = gcd(a, b); foreach (c; 1..n+1) a...
D
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math; int read() { return readln.chomp.to!int; } int[] reads() { return readln.split.to!(int[]); } void main() { int n = read(); int[] a = reads(); long f(long b) { return iota(n) .map!(i => abs(a[i] - (b ...
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; import std.range; import std.array; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.container; import std.typecons; import std.random; import std.csv; import std.regex; import std.math; import core.time; import std.ascii; import std.digest.sha; import std.outb...
D
//prewritten code: https://github.com/antma/algo import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.traits; final class InputReader { private: ubyte[] p, buffer; bool eof; bool rawRead () { if (eof) { return fals...
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.conv, std.string, std.math; void main(){ auto ip = readln.split.to!(string[]); auto A = ip[0]; auto B = ip[1]; auto C = ip[2]; if(A[$-1] == B[0] && B[$-1] == C[0]) "YES".writeln; else "NO".writeln; }
D
void main() { long a, b, c, d; rdVals(a, b, c, d); foreach (i; 0 .. 1000) { if (i & 1) { a -= d; if (a <= 0) { "No".writeln; return; } } else { c -= b; if (c <...
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; void main() { auto N = readln.chomp.to!int; auto K = readln.chomp.to!int; auto ret = 1; foreach (_; 0..N) ret = min(ret * 2, ret + K); writeln(ret); }
D